2022-02-15 15:51:12 +00:00
|
|
|
/** @file Runs all smoke tests and may add extra smoke-test dependencies to `yarn.lock`. */
|
|
|
|
// @ts-check
|
|
|
|
|
2021-12-13 22:31:18 +00:00
|
|
|
import { execa } from 'execa';
|
2022-03-07 21:36:22 +00:00
|
|
|
import { polyfill } from '@astrojs/webapi';
|
2022-02-15 15:51:12 +00: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 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-01 19:59:06 +00:00
|
|
|
const directories = [...(await getChildDirectories(exampleDir)), ...(await getChildDirectories(smokeDir))];
|
2022-02-15 15:51:12 +00:00
|
|
|
|
|
|
|
console.log('🤖', 'Preparing', 'yarn');
|
|
|
|
|
2022-02-18 21:40:03 +00:00
|
|
|
await execa('yarn', [], { cwd: fileURLToPath(rootDir), stdio: 'inherit' });
|
2022-02-15 15:51:12 +00:00
|
|
|
|
|
|
|
for (const directory of directories) {
|
|
|
|
console.log('🤖', 'Testing', directory.pathname.split('/').at(-1));
|
|
|
|
|
2021-12-13 22:31:18 +00:00
|
|
|
try {
|
2022-02-18 21:40:03 +00:00
|
|
|
await execa('yarn', ['run', 'build'], { cwd: fileURLToPath(directory), stdio: 'inherit' });
|
2021-12-13 22:31:18 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2022-02-15 15:51:12 +00:00
|
|
|
|
2022-03-01 05:38:17 +00:00
|
|
|
// Run with the static build too (skip for remote repos)
|
|
|
|
if (directory.pathname.includes(smokeDir.pathname)) {
|
2022-02-23 13:41:10 +00: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 15:51:12 +00:00
|
|
|
console.log();
|
2021-12-13 22:31:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-01 19:59:06 +00:00
|
|
|
run();
|