From 24ba9cc82dd1f63dbf9a1f61d8eece168225aeac Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 4 Feb 2024 13:56:15 -0600 Subject: [PATCH] test: more --- packages/core/test/expanding.js | 49 ++++++++++++++- packages/core/test/middleware.js | 69 ---------------------- packages/core/test/packages/three/index.js | 8 --- 3 files changed, 47 insertions(+), 79 deletions(-) delete mode 100644 packages/core/test/packages/three/index.js 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'}, - ), -};