Skip to content

Commit

Permalink
fix(dox): broke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cha0s committed Jan 28, 2024
1 parent 5aac7e9 commit 765a2ee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
22 changes: 11 additions & 11 deletions packages/dox/build/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ const {
todoVisitor,
} = require('./visitors');

exports.parseCode = async (options, code) => {
exports.parseCode = async (code, options = {}) => {
const {ast} = await transformAsync(code, {ast: true, code: false, ...options});
return ast;
};

exports.parseNormalSource = async (root, options, path, source) => {
const ast = await exports.parseCode(options, source);
exports.parseNormalSource = async (path, source, root, options) => {
const ast = await exports.parseCode(source, options);
const buildFiles = [];
const configs = [];
const hookImplementations = [];
Expand Down Expand Up @@ -79,8 +79,8 @@ exports.parseNormalSource = async (root, options, path, source) => {
};
};

exports.parseHookSpecificationSource = async (options, path, source) => {
const ast = await exports.parseCode(options, source);
exports.parseHookSpecificationSource = async (path, source, options) => {
const ast = await exports.parseCode(source, options);
const hookSpecifications = [];
traverse(ast, hookSpecificationVisitor((hookSpecification) => {
const {
Expand All @@ -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$/)) {
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(
(await Promise.all([
...await glob(join(request, 'src', '**', '*.{js,jsx}')),
Expand All @@ -117,7 +117,7 @@ exports.parseFleckRoot = async (root, options, request) => (
.map((filename) => [relative(request, filename), filename])
.map(async ([path, 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)];
}),
)
);
Expand All @@ -130,8 +130,8 @@ exports.parseFlecks = async (flecks) => {
path,
await exports.parseFleckRoot(
path,
babel,
dirname(await flecks.resolver.resolve(join(request, 'package.json'))),
babel,
),
]),
);
Expand Down
6 changes: 3 additions & 3 deletions packages/dox/test/server/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ it('parses hook invocations based on context', async () => {
this.invokeFlat('bar');
`;
let hookInvocations;
({hookInvocations} = await parseSource('@flecks/core/build/flecks.js', source));
({hookInvocations} = await parseSource('build/flecks.js', source, '@flecks/core'));
expect(hookInvocations.length)
.to.equal(2);
({hookInvocations} = await parseSource('nope', source));
({hookInvocations} = await parseSource('build/flecks.js', source, 'nope'));
expect(hookInvocations.length)
.to.equal(1);
});
Expand All @@ -84,6 +84,6 @@ it('parses todos', async () => {
});

it('parses a root', async () => {
expect(await parseFleckRoot('./test/server/root'))
expect(await parseFleckRoot('@test/server', './test/server/root'))
.to.deep.equal(verifiedRoot);
});
4 changes: 3 additions & 1 deletion packages/dox/test/server/visitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,18 @@ it('visits hook invocations', async () => {
flecks.invoke('sup');
flecks.invokeAsync('yep');
flecks.gather('stuff');
flecks.makeMiddleware('hook');
flecks.nope();
this.invoke('sup');
this.invokeAsync('yep');
this.gather('stuff');
this.makeMiddleware('hook');
this.nope();
`,
hookInvocationVisitor,
(visited) => {
expect(visited.length)
.to.equal(8);
.to.equal(10);
},
);
});
Expand Down

0 comments on commit 765a2ee

Please sign in to comment.