From e6bb47d812390b0b90a34a88b19fa0ead31870d5 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sat, 10 Feb 2024 00:03:39 -0600 Subject: [PATCH] refactor: platform-specific testing --- packages/build/build/commands.js | 7 +++-- packages/build/build/test.webpack.config.js | 11 +++++-- packages/fleck/build/commands.js | 32 ++++++++++++++++----- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/packages/build/build/commands.js b/packages/build/build/commands.js index 1b05b6d..0e8c943 100644 --- a/packages/build/build/commands.js +++ b/packages/build/build/commands.js @@ -230,14 +230,15 @@ exports.commands = (program, flecks) => { '--mode', (production && !hot) ? 'production' : 'development', ]; const options = { + // @todo This kills the pnpm. Let's use a real IPC channel. + useFork: true, + ...rest, env: { FLECKS_BUILD_IS_PRODUCTION: production, ...(target ? {FLECKS_CORE_BUILD_LIST: target} : {}), ...(hot ? {FLECKS_ENV__flecks_server__hot: 'true'} : {}), + ...rest.env, }, - // @todo This kills the pnpm. Let's use a real IPC channel. - useFork: true, - ...rest, }; if (!watch) { return spawnWith(cmd, options); diff --git a/packages/build/build/test.webpack.config.js b/packages/build/build/test.webpack.config.js index dfc46fa..5458a05 100644 --- a/packages/build/build/test.webpack.config.js +++ b/packages/build/build/test.webpack.config.js @@ -12,6 +12,7 @@ const configFn = require('./common.webpack.config'); const { FLECKS_CORE_ROOT = process.cwd(), + FLECKS_CORE_TEST_PLATFORMS, } = process.env; const tests = join(FLECKS_CORE_ROOT, 'test'); @@ -20,9 +21,13 @@ module.exports = async (env, argv, flecks) => { const config = await configFn(env, argv, flecks); config.output.chunkFormat = false; config.output.path = join(FLECKS_CORE_ROOT, 'dist', 'test'); - // Test entry. - const testPaths = await glob(join(tests, '*.js')); - const {platforms} = flecks; + const testPaths = []; + if (!FLECKS_CORE_TEST_PLATFORMS) { + testPaths.push(...await glob(join(tests, '*.js'))); + } + const platforms = FLECKS_CORE_TEST_PLATFORMS + ? JSON.parse(FLECKS_CORE_TEST_PLATFORMS) + : flecks.platforms; testPaths.push( ...(await Promise.all(platforms.map((platform) => glob(join(tests, platform, '*.js'))))) .flat(), diff --git a/packages/fleck/build/commands.js b/packages/fleck/build/commands.js index 28b0c07..09b31bc 100644 --- a/packages/fleck/build/commands.js +++ b/packages/fleck/build/commands.js @@ -22,9 +22,11 @@ module.exports = (program, flecks) => { ], options: [ program.createOption('-d, --no-production', 'dev build'), + program.createOption('-p, --platform [platforms...]', 'platforms to test') + .default(['default', 'server']), program.createOption('-t, --timeout ', 'timeout').default(2000), - program.createOption('-w, --watch', 'watch for changes'), program.createOption('-v, --verbose', 'verbose output'), + program.createOption('-w, --watch', 'watch for changes'), ], description: [ 'Run tests.', @@ -33,21 +35,29 @@ module.exports = (program, flecks) => { ].join('\n'), action: async (only, opts) => { const { + platform: platforms, production, timeout, watch, } = opts; const {build} = coreCommands(program, flecks); - const tests = await glob(join(FLECKS_CORE_ROOT, 'test', '*.js')); - const serverTests = await glob(join(FLECKS_CORE_ROOT, 'test', 'server', '*.js')); - let files = [] - .concat(tests, serverTests) - .map((path) => relative(FLECKS_CORE_ROOT, path)); + let files = []; + if (platforms.includes('default')) { + files.push(...await glob(join(FLECKS_CORE_ROOT, 'test', '*.js'))); + } + await Promise.all( + platforms + .filter((platform) => 'default' !== platform) + .map(async (platform) => { + files.push(...await glob(join(FLECKS_CORE_ROOT, 'test', platform, '*.js'))); + }), + ); if (0 === files.length) { // eslint-disable-next-line no-console console.log('No tests found.'); return undefined; } + files = files.map((path) => relative(FLECKS_CORE_ROOT, path)); if (only) { if (files.includes(only)) { files = [only]; @@ -60,7 +70,15 @@ module.exports = (program, flecks) => { // Remove the previous test. await rimraf(join(FLECKS_CORE_ROOT, 'dist', 'test')); // Kick off building the test and wait for the file to exist. - await build.action('test', {production, stdio: 'ignore', watch}); + await build.action( + 'test', + { + env: {FLECKS_CORE_TEST_PLATFORMS: JSON.stringify(platforms)}, + production, + stdio: 'ignore', + watch, + }, + ); debug('Testing...', opts); // eslint-disable-next-line no-constant-condition while (true) {