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
|
|
|
|
|
2021-12-13 17:31:18 -05:00
|
|
|
import { execa } from 'execa';
|
2022-03-07 16:36:22 -05:00
|
|
|
import { polyfill } from '@astrojs/webapi';
|
2022-02-15 10:51:12 -05:00
|
|
|
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-22 16:11:05 -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))];
|
2022-02-15 10:51:12 -05:00
|
|
|
|
2022-03-08 16:46:11 -05:00
|
|
|
console.log('🤖', 'Preparing', 'pnpm');
|
2022-02-15 10:51:12 -05:00
|
|
|
|
2022-03-08 16:46:11 -05:00
|
|
|
await execa('pnpm', ['install', '--frozen-lockfile=false'], { cwd: fileURLToPath(rootDir), stdio: 'inherit' });
|
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-22 16:11:05 -05:00
|
|
|
try {
|
2022-09-28 10:13:33 -05:00
|
|
|
await execa('pnpm', ['install', '--ignore-scripts', '--frozen-lockfile=false'].filter(x => x), { cwd: fileURLToPath(directory), stdio: 'inherit' });
|
2022-05-03 08:07:28 -05:00
|
|
|
await execa('pnpm', ['astro', 'telemetry', 'disable']);
|
2022-03-08 16:46:11 -05:00
|
|
|
await execa('pnpm', ['run', 'build'], { cwd: fileURLToPath(directory), stdio: 'inherit' });
|
2021-12-22 16:11:05 -05:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
2021-12-13 17:31:18 -05:00
|
|
|
}
|
|
|
|
|
2022-03-01 14:59:06 -05:00
|
|
|
run();
|