test: more
This commit is contained in:
parent
8a02c0232d
commit
24ba9cc82d
|
@ -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/);
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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'},
|
||||
),
|
||||
};
|
Loading…
Reference in New Issue
Block a user