refactor: platform-specific testing

This commit is contained in:
cha0s 2024-02-10 00:03:39 -06:00
parent 1d986b19fd
commit e6bb47d812
3 changed files with 37 additions and 13 deletions

View File

@ -230,14 +230,15 @@ exports.commands = (program, flecks) => {
'--mode', (production && !hot) ? 'production' : 'development', '--mode', (production && !hot) ? 'production' : 'development',
]; ];
const options = { const options = {
// @todo This kills the pnpm. Let's use a real IPC channel.
useFork: true,
...rest,
env: { env: {
FLECKS_BUILD_IS_PRODUCTION: production, FLECKS_BUILD_IS_PRODUCTION: production,
...(target ? {FLECKS_CORE_BUILD_LIST: target} : {}), ...(target ? {FLECKS_CORE_BUILD_LIST: target} : {}),
...(hot ? {FLECKS_ENV__flecks_server__hot: 'true'} : {}), ...(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) { if (!watch) {
return spawnWith(cmd, options); return spawnWith(cmd, options);

View File

@ -12,6 +12,7 @@ const configFn = require('./common.webpack.config');
const { const {
FLECKS_CORE_ROOT = process.cwd(), FLECKS_CORE_ROOT = process.cwd(),
FLECKS_CORE_TEST_PLATFORMS,
} = process.env; } = process.env;
const tests = join(FLECKS_CORE_ROOT, 'test'); const tests = join(FLECKS_CORE_ROOT, 'test');
@ -20,9 +21,13 @@ module.exports = async (env, argv, flecks) => {
const config = await configFn(env, argv, flecks); const config = await configFn(env, argv, flecks);
config.output.chunkFormat = false; config.output.chunkFormat = false;
config.output.path = join(FLECKS_CORE_ROOT, 'dist', 'test'); config.output.path = join(FLECKS_CORE_ROOT, 'dist', 'test');
// Test entry. const testPaths = [];
const testPaths = await glob(join(tests, '*.js')); if (!FLECKS_CORE_TEST_PLATFORMS) {
const {platforms} = flecks; testPaths.push(...await glob(join(tests, '*.js')));
}
const platforms = FLECKS_CORE_TEST_PLATFORMS
? JSON.parse(FLECKS_CORE_TEST_PLATFORMS)
: flecks.platforms;
testPaths.push( testPaths.push(
...(await Promise.all(platforms.map((platform) => glob(join(tests, platform, '*.js'))))) ...(await Promise.all(platforms.map((platform) => glob(join(tests, platform, '*.js')))))
.flat(), .flat(),

View File

@ -22,9 +22,11 @@ module.exports = (program, flecks) => {
], ],
options: [ options: [
program.createOption('-d, --no-production', 'dev build'), program.createOption('-d, --no-production', 'dev build'),
program.createOption('-p, --platform [platforms...]', 'platforms to test')
.default(['default', 'server']),
program.createOption('-t, --timeout <ms>', 'timeout').default(2000), program.createOption('-t, --timeout <ms>', 'timeout').default(2000),
program.createOption('-w, --watch', 'watch for changes'),
program.createOption('-v, --verbose', 'verbose output'), program.createOption('-v, --verbose', 'verbose output'),
program.createOption('-w, --watch', 'watch for changes'),
], ],
description: [ description: [
'Run tests.', 'Run tests.',
@ -33,21 +35,29 @@ module.exports = (program, flecks) => {
].join('\n'), ].join('\n'),
action: async (only, opts) => { action: async (only, opts) => {
const { const {
platform: platforms,
production, production,
timeout, timeout,
watch, watch,
} = opts; } = opts;
const {build} = coreCommands(program, flecks); const {build} = coreCommands(program, flecks);
const tests = await glob(join(FLECKS_CORE_ROOT, 'test', '*.js')); let files = [];
const serverTests = await glob(join(FLECKS_CORE_ROOT, 'test', 'server', '*.js')); if (platforms.includes('default')) {
let files = [] files.push(...await glob(join(FLECKS_CORE_ROOT, 'test', '*.js')));
.concat(tests, serverTests) }
.map((path) => relative(FLECKS_CORE_ROOT, path)); 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) { if (0 === files.length) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log('No tests found.'); console.log('No tests found.');
return undefined; return undefined;
} }
files = files.map((path) => relative(FLECKS_CORE_ROOT, path));
if (only) { if (only) {
if (files.includes(only)) { if (files.includes(only)) {
files = [only]; files = [only];
@ -60,7 +70,15 @@ module.exports = (program, flecks) => {
// Remove the previous test. // Remove the previous test.
await rimraf(join(FLECKS_CORE_ROOT, 'dist', 'test')); await rimraf(join(FLECKS_CORE_ROOT, 'dist', 'test'));
// Kick off building the test and wait for the file to exist. // 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); debug('Testing...', opts);
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
while (true) { while (true) {