diff --git a/packages/core/test/expanding.js b/packages/core/test/expanding.js index 427ede7..0ed3737 100644 --- a/packages/core/test/expanding.js +++ b/packages/core/test/expanding.js @@ -2,7 +2,40 @@ import {expect} from 'chai'; import {Flecks} from '@flecks/core/build/flecks'; -it('detects suspicious hook ordering', async () => { +it('includes all by default', async () => { + const flecks = await Flecks.from({ + config: { + one: {test: ['one', 'two']}, + }, + flecks: { + one: {hooks: {'one.test': () => {}}}, + two: {hooks: {'one.test': () => {}}}, + }, + }); + expect(flecks.expandedFlecks('one.test')) + .to.deep.equal(['one', 'two']); +}); + +it('respects elision', async () => { + const flecks = await Flecks.from({ + config: { + one: {test: ['two', '...', 'three']}, + }, + flecks: { + one: {hooks: {'one.test': () => {}}}, + two: {hooks: {'one.test': () => {}}}, + three: {hooks: {'one.test': () => {}}}, + four: {hooks: {'one.test': () => {}}}, + }, + }); + const expanded = flecks.expandedFlecks('one.test'); + expect(expanded.shift()) + .to.equal('two'); + expect(expanded.pop()) + .to.equal('three'); +}); + +it('detects yet allows suspicious hook ordering', async () => { const flecks = await Flecks.from({ config: { one: {test: ['one', 'two']}, @@ -16,7 +49,19 @@ it('detects suspicious hook ordering', async () => { Flecks.debug = (message) => { suspected = message.includes('Suspicious ordering specification'); }; - flecks.expandedFlecks('one.test'); + expect(flecks.expandedFlecks('one.test')) + .to.deep.equal(['one', 'two']); expect(suspected) .to.be.true; }); + +it('throws on cyclic dependency', async () => { + const flecks = await Flecks.from({ + flecks: { + one: {hooks: {'one.test': Flecks.priority(() => {}, {before: 'two'})}}, + two: {hooks: {'one.test': Flecks.priority(() => {}, {before: 'one'})}}, + }, + }); + expect(() => flecks.expandedFlecks('one.test')) + .to.throw(/Illegal ordering specification/); +}); diff --git a/packages/core/test/middleware.js b/packages/core/test/middleware.js index e536e77..1e01246 100644 --- a/packages/core/test/middleware.js +++ b/packages/core/test/middleware.js @@ -4,7 +4,6 @@ import {Flecks} from '@flecks/core'; const testOne = require('./packages/one'); const testTwo = require('./packages/two'); -const testThree = require('./packages/three'); it('can make middleware', async () => { const flecks = await Flecks.from({ @@ -30,71 +29,3 @@ it('can make middleware', async () => { }); }); }); - -it('respects explicit middleware configuration', async () => { - const flecks = await Flecks.from({ - config: { - '@flecks/core/test': { - middleware: [ - '@flecks/core/two', - '@flecks/core/one', - ], - }, - }, - flecks: { - '@flecks/core/one': testOne, - '@flecks/core/two': testTwo, - }, - }); - const foo = {bar: 1}; - const mw = flecks.makeMiddleware('@flecks/core/test.middleware'); - await new Promise((resolve) => { - mw(foo, () => { - expect(foo.bar).to.equal(3); - resolve(); - }); - }); -}); - -it('respects middleware elision', async () => { - const flecks = await Flecks.from({ - config: { - '@flecks/core/test': { - middleware: [ - '...', - ], - }, - }, - flecks: { - '@flecks/core/one': testOne, - '@flecks/core/two': testTwo, - }, - }); - const foo = {bar: 1}; - const mw = flecks.makeMiddleware('@flecks/core/test.middleware'); - await new Promise((resolve) => { - mw(foo, () => { - expect(foo.bar).to.equal(3); - resolve(); - }); - }); -}); - -it('throws on elision graph cycle', async () => { - const flecks = await Flecks.from({ - config: { - '@flecks/core/test': { - middleware: [ - '...', - ], - }, - }, - flecks: { - '@flecks/core/one': testOne, - '@flecks/core/two': testTwo, - '@flecks/core/three': testThree, - }, - }); - const tryMaking = () => flecks.makeMiddleware('@flecks/core/test.middleware'); - expect(tryMaking).to.throw(); -}); diff --git a/packages/core/test/packages/three/index.js b/packages/core/test/packages/three/index.js deleted file mode 100644 index 060a8e1..0000000 --- a/packages/core/test/packages/three/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import {Flecks} from '@flecks/core'; - -export const hooks = { - '@flecks/core/test.middleware': Flecks.priority( - () => () => {}, - {after: '@flecks/core/one', before: '@flecks/core/two'}, - ), -};