From 36fdb62bf5d7b40bd9dd922ecf8fa06932873515 Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 5 Jan 2021 11:25:46 -0600 Subject: [PATCH] refactor: testing --- packages/core/test/middleware.js | 106 ++++++++++++------------- packages/http/src/build/.neutrinorc.js | 15 ++-- 2 files changed, 61 insertions(+), 60 deletions(-) diff --git a/packages/core/test/middleware.js b/packages/core/test/middleware.js index bb73de1..526d82f 100644 --- a/packages/core/test/middleware.js +++ b/packages/core/test/middleware.js @@ -1,72 +1,70 @@ import {expect} from 'chai'; import Middleware from '../src/middleware'; -describe('@latus/core', () => { - describe('middleware', () => { - it('should construct with middleware', (done) => { - let called = false; +describe('middleware', () => { + it('should construct with middleware', (done) => { + let called = false; + const middleware = new Middleware([ + (next) => { + called = true; + next(); + }, + ]); + middleware.dispatch(() => { + expect(called).to.be.true; + done(); + }); + }); + it('should pass args', (done) => { + const middleware = new Middleware([ + (arg, next) => { + expect(arg).to.equal(69); + next(); + }, + ]); + middleware.dispatch(69, done); + }); + describe('error handling', () => { + it('should skip when necessary', (done) => { + let progress = 0; const middleware = new Middleware([ (next) => { - called = true; + progress += 1; + next(); + }, + (error, next) => { + throw new Error(); + }, + (next) => { + progress += 1; next(); }, ]); - middleware.dispatch(() => { - expect(called).to.be.true; + middleware.dispatch((error) => { + expect(error).to.equal(undefined); + expect(progress).to.equal(2); done(); }); }); - it('should pass args', (done) => { + it('should use when necessary', (done) => { + let progress = 0; const middleware = new Middleware([ - (arg, next) => { - expect(arg).to.equal(69); + (next) => { + progress += 1; + next(new Error()); + }, + (error, next) => { + next(error); + }, + (next) => { + progress += 1; next(); }, ]); - middleware.dispatch(69, done); - }); - describe('error handling', () => { - it('should skip when necessary', (done) => { - let progress = 0; - const middleware = new Middleware([ - (next) => { - progress += 1; - next(); - }, - (error, next) => { - throw new Error(); - }, - (next) => { - progress += 1; - next(); - }, - ]); - middleware.dispatch((error) => { - expect(error).to.equal(undefined); - expect(progress).to.equal(2); - done(); - }); - }); - it('should use when necessary', (done) => { - let progress = 0; - const middleware = new Middleware([ - (next) => { - progress += 1; - next(new Error()); - }, - (error, next) => { - next(error); - }, - (next) => { - progress += 1; - next(); - }, - ]); - middleware.dispatch((error) => { - expect(error).to.not.equal(undefined); - expect(progress).to.equal(1); - done(); - }); + middleware.dispatch((error) => { + expect(error).to.not.equal(undefined); + expect(progress).to.equal(1); + done(); }); }); }); diff --git a/packages/http/src/build/.neutrinorc.js b/packages/http/src/build/.neutrinorc.js index 53078de..8a0b531 100644 --- a/packages/http/src/build/.neutrinorc.js +++ b/packages/http/src/build/.neutrinorc.js @@ -26,7 +26,10 @@ const client = { neutrino.options.root = fs.realpathSync(root); neutrino.options.source = 'client'; neutrino.options.mains.index = 'index'; - neutrino.options.mains.tests = {entry: './client/tests'}; + neutrino.options.mains.tests = { + entry: './client/tests', + title: 'Mocha tests', + }; const output = 'build'; neutrino.options.output = join( isAbsolute(output) @@ -85,11 +88,11 @@ const client = { '};', ].join('\n')); const testPaths = paths - .map((path) => Latus.runtimePath(`${path}/test`)) - .filter((path) => !!path); - plugin.writeModule(`node_modules/@latus/core/tests`, [ - testPaths.map((path) => `require('${path}')`), - ].join('\n')); + .map((path) => [path, Latus.runtimePath(`${path}/test`)]) + .filter(([, path]) => !!path); + plugin.writeModule(`node_modules/@latus/core/tests`, testPaths.map( + ([original, path]) => `describe('${original}', () => require('${path}'));` + ).join('')); }); }