2022-03-08 21:46:11 +00:00
|
|
|
/** @file Runs all smoke tests and may add extra smoke-test dependencies to `pnpm-lock.yaml`. */
|
|
|
|
|
2022-02-15 15:51:12 +00:00
|
|
|
// @ts-check
|
|
|
|
|
2021-12-13 22:31:18 +00:00
|
|
|
import { execa } from 'execa';
|
2022-02-15 15:51:12 +00:00
|
|
|
import { promises as fs } from 'node:fs';
|
2023-07-27 16:24:39 +00:00
|
|
|
import { fileURLToPath } from 'node:url';
|
2022-02-15 15:51:12 +00: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 05:38:17 +00:00
|
|
|
const smokeDir = new URL('smoke/', rootDir);
|
2021-12-13 22:31:18 +00:00
|
|
|
|
2022-03-01 05:38:17 +00:00
|
|
|
/** Returns all child directories of the given directory. */
|
|
|
|
const getChildDirectories = async (/** @type {URL} */ dir) => {
|
|
|
|
/** @type {URL[]} */
|
|
|
|
const dirs = [];
|
2021-12-13 22:31:18 +00:00
|
|
|
|
2022-03-01 05:38:17 +00:00
|
|
|
for await (const dirent of await fs.opendir(dir)) {
|
|
|
|
if (dirent.isDirectory()) {
|
|
|
|
dirs.push(new URL(dirent.name, dir));
|
|
|
|
}
|
|
|
|
}
|
2022-02-15 15:51:12 +00:00
|
|
|
|
2022-03-01 05:38:17 +00:00
|
|
|
return dirs;
|
|
|
|
};
|
2022-02-15 15:51:12 +00:00
|
|
|
|
|
|
|
/** Runs all smoke tests. */
|
|
|
|
async function run() {
|
2021-12-13 22:31:18 +00:00
|
|
|
console.log('');
|
2022-02-15 15:51:12 +00:00
|
|
|
|
2022-03-08 21:46:11 +00:00
|
|
|
const directories = [...(await getChildDirectories(smokeDir)), ...(await getChildDirectories(exampleDir))];
|
2022-02-15 15:51:12 +00:00
|
|
|
|
2022-03-08 21:46:11 +00:00
|
|
|
console.log('🤖', 'Preparing', 'pnpm');
|
2022-02-15 15:51:12 +00:00
|
|
|
|
2022-03-08 21:46:11 +00:00
|
|
|
await execa('pnpm', ['install', '--frozen-lockfile=false'], { cwd: fileURLToPath(rootDir), stdio: 'inherit' });
|
2022-02-15 15:51:12 +00:00
|
|
|
|
|
|
|
for (const directory of directories) {
|
2022-03-08 21:46:11 +00:00
|
|
|
const name = directory.pathname.split('/').at(-1) ?? "";
|
|
|
|
const isExternal = directory.pathname.includes(smokeDir.pathname);
|
|
|
|
console.log('🤖', 'Testing', name);
|
2022-02-15 15:51:12 +00:00
|
|
|
|
2021-12-13 22:31:18 +00:00
|
|
|
try {
|
2022-09-28 15:13:33 +00:00
|
|
|
await execa('pnpm', ['install', '--ignore-scripts', '--frozen-lockfile=false'].filter(x => x), { cwd: fileURLToPath(directory), stdio: 'inherit' });
|
2022-05-03 13:07:28 +00:00
|
|
|
await execa('pnpm', ['astro', 'telemetry', 'disable']);
|
2022-03-08 21:46:11 +00:00
|
|
|
await execa('pnpm', ['run', 'build'], { cwd: fileURLToPath(directory), stdio: 'inherit' });
|
2021-12-13 22:31:18 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-01 19:59:06 +00:00
|
|
|
run();
|