2022-02-15 10:51:12 -05:00
|
|
|
/** @file Runs all smoke tests and may add extra smoke-test dependencies to `yarn.lock`. */
|
|
|
|
// @ts-check
|
|
|
|
|
2021-12-13 17:31:18 -05:00
|
|
|
import { execa } from 'execa';
|
2022-02-15 10:51:12 -05:00
|
|
|
import { polyfill } from '@astropub/webapi';
|
|
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
import { promises as fs } from 'node:fs';
|
|
|
|
|
|
|
|
polyfill(globalThis, { exclude: 'window document' });
|
|
|
|
|
|
|
|
/** URL directory containing the entire project. */
|
|
|
|
const rootDir = new URL('../../', import.meta.url);
|
|
|
|
|
|
|
|
/** URL directory containing the example subdirectories. */
|
|
|
|
const exampleDir = new URL('examples/', rootDir);
|
2022-03-01 00:38:17 -05:00
|
|
|
const smokeDir = new URL('smoke/', rootDir);
|
2021-12-13 17:31:18 -05:00
|
|
|
|
2022-03-01 00:38:17 -05:00
|
|
|
/** Returns all child directories of the given directory. */
|
|
|
|
const getChildDirectories = async (/** @type {URL} */ dir) => {
|
|
|
|
/** @type {URL[]} */
|
|
|
|
const dirs = [];
|
2021-12-13 17:31:18 -05:00
|
|
|
|
2022-03-01 00:38:17 -05:00
|
|
|
for await (const dirent of await fs.opendir(dir)) {
|
|
|
|
if (dirent.isDirectory()) {
|
|
|
|
dirs.push(new URL(dirent.name, dir));
|
|
|
|
}
|
|
|
|
}
|
2022-02-15 10:51:12 -05:00
|
|
|
|
2022-03-01 00:38:17 -05:00
|
|
|
return dirs;
|
|
|
|
};
|
2022-02-15 10:51:12 -05:00
|
|
|
|
|
|
|
/** Runs all smoke tests. */
|
|
|
|
async function run() {
|
2021-12-13 17:31:18 -05:00
|
|
|
console.log('');
|
2022-02-15 10:51:12 -05:00
|
|
|
|
2022-03-01 00:38:17 -05:00
|
|
|
const directories = [...await getChildDirectories(exampleDir), ...await getChildDirectories(smokeDir)];
|
2022-02-15 10:51:12 -05:00
|
|
|
|
|
|
|
console.log('🤖', 'Preparing', 'yarn');
|
|
|
|
|
2022-02-18 16:40:03 -05:00
|
|
|
await execa('yarn', [], { cwd: fileURLToPath(rootDir), stdio: 'inherit' });
|
2022-02-15 10:51:12 -05:00
|
|
|
|
|
|
|
for (const directory of directories) {
|
|
|
|
console.log('🤖', 'Testing', directory.pathname.split('/').at(-1));
|
|
|
|
|
2021-12-13 17:31:18 -05:00
|
|
|
try {
|
2022-02-18 16:40:03 -05:00
|
|
|
await execa('yarn', ['run', 'build'], { cwd: fileURLToPath(directory), stdio: 'inherit' });
|
2021-12-13 17:31:18 -05:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2022-02-15 10:51:12 -05:00
|
|
|
|
2022-03-01 00:38:17 -05:00
|
|
|
// Run with the static build too (skip for remote repos)
|
|
|
|
if (directory.pathname.includes(smokeDir.pathname)) {
|
2022-02-23 08:41:10 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await execa('yarn', ['build', '--', '--experimental-static-build'], { cwd: fileURLToPath(directory), stdout: 'inherit', stderr: 'inherit' });
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2022-02-15 10:51:12 -05:00
|
|
|
console.log();
|
2021-12-13 17:31:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-01 00:38:17 -05:00
|
|
|
run();
|