refactor: tests

This commit is contained in:
cha0s 2024-01-19 05:17:37 -06:00
parent 084da6709c
commit b6a32a2b1f
3 changed files with 21 additions and 15 deletions

View File

@ -31,9 +31,7 @@
"src",
"start.js",
"start.js.map",
"test",
"test.js",
"test.js.map"
"test"
],
"dependencies": {
"@babel/core": "^7.12.10",

View File

@ -34,7 +34,7 @@ exports.hooks = {
// Add tests if they exist.
const testFiles = await glob(join(FLECKS_CORE_ROOT, 'test/**/*.js'));
if (testFiles.length > 0) {
files.push('test', 'test.js');
files.push('test');
}
// Let others have a say.
await flecks.invokeSequentialAsync('@flecks/fleck.packageJson', json, compilation);

View File

@ -106,21 +106,30 @@ module.exports = async (config, env, argv, flecks) => {
config.entry.index.push(...styles);
// Tests.
if (!isProduction) {
const testEntries = await Promise.all(
const testEntries = (await Promise.all(
Object.entries(buildFlecks.roots)
.map(async ([parent, {request}]) => {
const paths = [];
const rootTests = await glob(join(request, 'test', '*.js'));
paths.push(...rootTests);
const tests = [];
const resolved = dirname(await resolver.resolve(join(request, 'package.json')));
const rootTests = await glob(join(resolved, 'test', '*.js'));
tests.push(
...rootTests
.map((test) => test.replace(resolved, parent)),
);
const platformTests = await Promise.all(
buildFlecks.platforms.map((platform) => (
glob(join(request, 'test', 'platforms', platform, '*.js'))
glob(join(resolved, 'test', 'platforms', platform, '*.js'))
)),
);
paths.push(...platformTests.flat());
return [parent, paths];
tests.push(
...platformTests
.flat()
.map((test) => test.replace(resolved, parent)),
);
return [parent, tests];
}),
);
))
.filter(([, tests]) => tests.length > 0);
const tests = await resolver.resolve(
join('@flecks/web', 'server', 'build', 'tests'),
);
@ -134,11 +143,10 @@ module.exports = async (config, env, argv, flecks) => {
source: testsSource.replace(
" await import('@flecks/web/tests');",
testEntries
.filter(([, paths]) => paths.length > 0)
.map(([root, paths]) => (
.map(([root, tests]) => (
[
` describe('${root}', () => {`,
` ${paths.map((path) => `require('${path}');`).join('\n ')}`,
` ${tests.map((test) => `require('${test}');`).join('\n ')}`,
' });',
].join('\n')
)).join('\n\n'),