2022-03-08 16:46:11 -05:00
|
|
|
/** @file Runs all smoke tests and may add extra smoke-test dependencies to `pnpm-lock.yaml`. */
|
|
|
|
|
2022-02-15 10:51:12 -05:00
|
|
|
// @ts-check
|
|
|
|
|
2024-08-28 09:52:49 -05:00
|
|
|
import { exec } from 'tinyexec';
|
2022-02-15 10:51:12 -05:00
|
|
|
import { promises as fs } from 'node:fs';
|
2023-07-27 11:24:39 -05:00
|
|
|
import { fileURLToPath } from 'node:url';
|
2022-02-15 10:51:12 -05:00
|
|
|
|
|
|
|
/** 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-08 16:46:11 -05:00
|
|
|
const directories = [...(await getChildDirectories(smokeDir)), ...(await getChildDirectories(exampleDir))];
|
2024-08-28 09:52:49 -05:00
|
|
|
/** @type {Partial<import('tinyexec').Options>} */
|
2024-11-04 09:49:33 -05:00
|
|
|
const execOptions = {
|
|
|
|
nodeOptions: { cwd: fileURLToPath(rootDir), stdio: 'inherit' },
|
|
|
|
throwOnError: true,
|
|
|
|
};
|
2022-02-15 10:51:12 -05:00
|
|
|
|
2022-03-08 16:46:11 -05:00
|
|
|
console.log('🤖', 'Preparing', 'pnpm');
|
2024-08-28 09:52:49 -05:00
|
|
|
|
|
|
|
await exec('pnpm', ['install', '--frozen-lockfile=false'], execOptions);
|
2022-02-15 10:51:12 -05:00
|
|
|
|
|
|
|
for (const directory of directories) {
|
2022-03-08 16:46:11 -05:00
|
|
|
const name = directory.pathname.split('/').at(-1) ?? "";
|
|
|
|
const isExternal = directory.pathname.includes(smokeDir.pathname);
|
|
|
|
console.log('🤖', 'Testing', name);
|
2022-02-15 10:51:12 -05:00
|
|
|
|
2021-12-13 17:31:18 -05:00
|
|
|
try {
|
2024-08-28 09:52:49 -05:00
|
|
|
await exec('pnpm', ['install', '--ignore-scripts', '--frozen-lockfile=false'], execOptions);
|
|
|
|
await exec('pnpm', ['astro', 'telemetry', 'disable']);
|
|
|
|
await exec('pnpm', ['run', 'build'], execOptions);
|
2021-12-13 17:31:18 -05:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-01 14:59:06 -05:00
|
|
|
run();
|