fix(dox): broke tests
This commit is contained in:
parent
5aac7e96b4
commit
765a2eed9e
|
@ -14,13 +14,13 @@ const {
|
||||||
todoVisitor,
|
todoVisitor,
|
||||||
} = require('./visitors');
|
} = require('./visitors');
|
||||||
|
|
||||||
exports.parseCode = async (options, code) => {
|
exports.parseCode = async (code, options = {}) => {
|
||||||
const {ast} = await transformAsync(code, {ast: true, code: false, ...options});
|
const {ast} = await transformAsync(code, {ast: true, code: false, ...options});
|
||||||
return ast;
|
return ast;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.parseNormalSource = async (root, options, path, source) => {
|
exports.parseNormalSource = async (path, source, root, options) => {
|
||||||
const ast = await exports.parseCode(options, source);
|
const ast = await exports.parseCode(source, options);
|
||||||
const buildFiles = [];
|
const buildFiles = [];
|
||||||
const configs = [];
|
const configs = [];
|
||||||
const hookImplementations = [];
|
const hookImplementations = [];
|
||||||
|
@ -79,8 +79,8 @@ exports.parseNormalSource = async (root, options, path, source) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.parseHookSpecificationSource = async (options, path, source) => {
|
exports.parseHookSpecificationSource = async (path, source, options) => {
|
||||||
const ast = await exports.parseCode(options, source);
|
const ast = await exports.parseCode(source, options);
|
||||||
const hookSpecifications = [];
|
const hookSpecifications = [];
|
||||||
traverse(ast, hookSpecificationVisitor((hookSpecification) => {
|
traverse(ast, hookSpecificationVisitor((hookSpecification) => {
|
||||||
const {
|
const {
|
||||||
|
@ -101,14 +101,14 @@ exports.parseHookSpecificationSource = async (options, path, source) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.parseSource = async (root, options, path, source) => {
|
exports.parseSource = async (path, source, root, options) => {
|
||||||
if (path.match(/build\/flecks\.hooks\.js$/)) {
|
if (path.match(/build\/flecks\.hooks\.js$/)) {
|
||||||
return exports.parseHookSpecificationSource(options, path, source);
|
return exports.parseHookSpecificationSource(path, source, options);
|
||||||
}
|
}
|
||||||
return exports.parseNormalSource(root, options, path, source);
|
return exports.parseNormalSource(path, source, root, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.parseFleckRoot = async (root, options, request) => (
|
exports.parseFleckRoot = async (root, request, options) => (
|
||||||
Promise.all(
|
Promise.all(
|
||||||
(await Promise.all([
|
(await Promise.all([
|
||||||
...await glob(join(request, 'src', '**', '*.{js,jsx}')),
|
...await glob(join(request, 'src', '**', '*.{js,jsx}')),
|
||||||
|
@ -117,7 +117,7 @@ exports.parseFleckRoot = async (root, options, request) => (
|
||||||
.map((filename) => [relative(request, filename), filename])
|
.map((filename) => [relative(request, filename), filename])
|
||||||
.map(async ([path, filename]) => {
|
.map(async ([path, filename]) => {
|
||||||
const buffer = await readFile(filename);
|
const buffer = await readFile(filename);
|
||||||
return [path, await exports.parseSource(root, options, path, buffer.toString('utf8'))];
|
return [path, await exports.parseSource(path, buffer.toString('utf8'), root, options)];
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -130,8 +130,8 @@ exports.parseFlecks = async (flecks) => {
|
||||||
path,
|
path,
|
||||||
await exports.parseFleckRoot(
|
await exports.parseFleckRoot(
|
||||||
path,
|
path,
|
||||||
babel,
|
|
||||||
dirname(await flecks.resolver.resolve(join(request, 'package.json'))),
|
dirname(await flecks.resolver.resolve(join(request, 'package.json'))),
|
||||||
|
babel,
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
|
@ -64,10 +64,10 @@ it('parses hook invocations based on context', async () => {
|
||||||
this.invokeFlat('bar');
|
this.invokeFlat('bar');
|
||||||
`;
|
`;
|
||||||
let hookInvocations;
|
let hookInvocations;
|
||||||
({hookInvocations} = await parseSource('@flecks/core/build/flecks.js', source));
|
({hookInvocations} = await parseSource('build/flecks.js', source, '@flecks/core'));
|
||||||
expect(hookInvocations.length)
|
expect(hookInvocations.length)
|
||||||
.to.equal(2);
|
.to.equal(2);
|
||||||
({hookInvocations} = await parseSource('nope', source));
|
({hookInvocations} = await parseSource('build/flecks.js', source, 'nope'));
|
||||||
expect(hookInvocations.length)
|
expect(hookInvocations.length)
|
||||||
.to.equal(1);
|
.to.equal(1);
|
||||||
});
|
});
|
||||||
|
@ -84,6 +84,6 @@ it('parses todos', async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('parses a root', async () => {
|
it('parses a root', async () => {
|
||||||
expect(await parseFleckRoot('./test/server/root'))
|
expect(await parseFleckRoot('@test/server', './test/server/root'))
|
||||||
.to.deep.equal(verifiedRoot);
|
.to.deep.equal(verifiedRoot);
|
||||||
});
|
});
|
||||||
|
|
|
@ -219,16 +219,18 @@ it('visits hook invocations', async () => {
|
||||||
flecks.invoke('sup');
|
flecks.invoke('sup');
|
||||||
flecks.invokeAsync('yep');
|
flecks.invokeAsync('yep');
|
||||||
flecks.gather('stuff');
|
flecks.gather('stuff');
|
||||||
|
flecks.makeMiddleware('hook');
|
||||||
flecks.nope();
|
flecks.nope();
|
||||||
this.invoke('sup');
|
this.invoke('sup');
|
||||||
this.invokeAsync('yep');
|
this.invokeAsync('yep');
|
||||||
this.gather('stuff');
|
this.gather('stuff');
|
||||||
|
this.makeMiddleware('hook');
|
||||||
this.nope();
|
this.nope();
|
||||||
`,
|
`,
|
||||||
hookInvocationVisitor,
|
hookInvocationVisitor,
|
||||||
(visited) => {
|
(visited) => {
|
||||||
expect(visited.length)
|
expect(visited.length)
|
||||||
.to.equal(8);
|
.to.equal(10);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user