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',
];
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);

View File

@ -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(),

View File

@ -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 <ms>', '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) {