From 686eb162e8d2a0099772fdefd11090b31b26e5e8 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sat, 26 Feb 2022 11:58:54 -0600 Subject: [PATCH] refactor: test compilation --- packages/core/package.json | 1 + .../src/server/build/fleck.neutrinorc.js | 5 +- packages/http/package.json | 1 + packages/http/src/server/build/runtime.js | 60 ++++++++++++++----- 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index bc188d8..f82f2f0 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -34,6 +34,7 @@ "src", "start.js", "start.js.map", + "test", "test.js", "test.js.map" ], diff --git a/packages/fleck/src/server/build/fleck.neutrinorc.js b/packages/fleck/src/server/build/fleck.neutrinorc.js index 9a640be..7f46c5c 100644 --- a/packages/fleck/src/server/build/fleck.neutrinorc.js +++ b/packages/fleck/src/server/build/fleck.neutrinorc.js @@ -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)); diff --git a/packages/http/package.json b/packages/http/package.json index 200cd19..714f9ea 100644 --- a/packages/http/package.json +++ b/packages/http/package.json @@ -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", diff --git a/packages/http/src/server/build/runtime.js b/packages/http/src/server/build/runtime.js index 38ef7cf..a3e5624 100644 --- a/packages/http/src/server/build/runtime.js +++ b/packages/http/src/server/build/runtime.js @@ -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}'));`, - ).join(''), + source: Object.entries( + testPaths + .reduce( + (r, [fleck, path]) => ({ + ...r, + [fleck]: [...(r[fleck] || []), `require('${path}');`], + }), + {}, + ), + ) + .map( + ([original, paths]) => `describe('${original}', () => { ${paths.join(' ')} });`, + ).join(''), }); };