refactor: test compilation
This commit is contained in:
parent
04d7094cea
commit
686eb162e8
|
@ -34,6 +34,7 @@
|
|||
"src",
|
||||
"start.js",
|
||||
"start.js.map",
|
||||
"test",
|
||||
"test.js",
|
||||
"test.js.map"
|
||||
],
|
||||
|
|
|
@ -19,7 +19,10 @@ const config = require('../../../../core/src/bootstrap/fleck.neutrinorc');
|
|||
|
||||
config.use.push((neutrino) => {
|
||||
// Test entrypoint.
|
||||
const testPaths = glob.sync(join(FLECKS_ROOT, 'test/*.js'));
|
||||
const testPaths = glob.sync(join(FLECKS_ROOT, 'test/*.js'), {ignore: 'platforms'});
|
||||
for (let i = 0; i < this.platforms.length; ++i) {
|
||||
testPaths.push(...glob.sync(join(FLECKS_ROOT, `test/platforms/${this.platforms[i]}/*.js`)));
|
||||
}
|
||||
if (testPaths.length > 0) {
|
||||
const testEntry = neutrino.config.entry('test').clear();
|
||||
testPaths.forEach((path) => testEntry.add(path));
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
"compression": "^1.7.4",
|
||||
"debug": "4.3.1",
|
||||
"express": "^4.17.1",
|
||||
"glob": "^7.2.0",
|
||||
"html-webpack-plugin": "^4.5.0",
|
||||
"http-proxy": "^1.17.0",
|
||||
"loader-utils": "^1.4.0",
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
const {realpathSync} = require('fs');
|
||||
const {join} = require('path');
|
||||
const {
|
||||
dirname,
|
||||
join,
|
||||
} = require('path');
|
||||
|
||||
const {Flecks, require: R} = require('@flecks/core/server');
|
||||
const D = require('debug');
|
||||
const glob = require('glob');
|
||||
|
||||
const debug = D('@flecks/http/runtime');
|
||||
|
||||
|
@ -70,17 +74,33 @@ module.exports = (flecks) => (neutrino) => {
|
|||
});
|
||||
}
|
||||
// Tests.
|
||||
const testPaths = paths
|
||||
.map(([path, resolved]) => [path, join(resolved, 'test')])
|
||||
.filter(([, path]) => {
|
||||
try {
|
||||
R.resolve(path);
|
||||
return true;
|
||||
}
|
||||
catch (error) {
|
||||
return false;
|
||||
const testRoots = Array.from(new Set(
|
||||
Object.keys(httpFlecks.resolver)
|
||||
.map((fleck) => [fleck, httpFlecks.root(fleck)]),
|
||||
))
|
||||
.map(([fleck, root]) => (
|
||||
[fleck, dirname(R.resolve(join(root, 'package.json')))]
|
||||
));
|
||||
const testPaths = [];
|
||||
testRoots.forEach(([fleck, root]) => {
|
||||
testPaths.push(...(
|
||||
glob.sync(join(root, 'test/*.js'))
|
||||
.map((path) => [fleck, path])
|
||||
));
|
||||
for (let i = 0; i < httpFlecks.platforms.length; ++i) {
|
||||
testPaths.push(
|
||||
...(
|
||||
glob.sync(join(root, `test/platforms/${httpFlecks.platforms[i]}/*.js`))
|
||||
.map((path) => [fleck, path])
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
// Test entrypoint.
|
||||
if (testPaths.length > 0) {
|
||||
const testEntry = neutrino.config.entry('test').clear();
|
||||
testPaths.forEach(([, path]) => testEntry.add(path));
|
||||
}
|
||||
const tests = realpathSync(R.resolve(join(flecks.resolve('@flecks/http'), 'tests')));
|
||||
neutrino.config.module
|
||||
.rule(tests)
|
||||
|
@ -88,8 +108,18 @@ module.exports = (flecks) => (neutrino) => {
|
|||
.use('runtime/test')
|
||||
.loader(runtime)
|
||||
.options({
|
||||
source: testPaths.map(
|
||||
([original, path]) => `describe('${original}', () => require('${path}'));`,
|
||||
source: Object.entries(
|
||||
testPaths
|
||||
.reduce(
|
||||
(r, [fleck, path]) => ({
|
||||
...r,
|
||||
[fleck]: [...(r[fleck] || []), `require('${path}');`],
|
||||
}),
|
||||
{},
|
||||
),
|
||||
)
|
||||
.map(
|
||||
([original, paths]) => `describe('${original}', () => { ${paths.join(' ')} });`,
|
||||
).join(''),
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user