astro/scripts/smoke/index.js
Nate Moore f18ee36dc0
Add @astrojs/webapi package (#2729)
* chore: add @astrojs/webapi

* chore: update package.json

* fix: update file case

* fix: remove lowercase file

* chore: update tests to use mocha

* chore: update LICENSE
2022-03-07 15:36:22 -06:00

68 lines
1.8 KiB
JavaScript

/** @file Runs all smoke tests and may add extra smoke-test dependencies to `yarn.lock`. */
// @ts-check
import { execa } from 'execa';
import { polyfill } from '@astrojs/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);
const smokeDir = new URL('smoke/', rootDir);
/** Returns all child directories of the given directory. */
const getChildDirectories = async (/** @type {URL} */ dir) => {
/** @type {URL[]} */
const dirs = [];
for await (const dirent of await fs.opendir(dir)) {
if (dirent.isDirectory()) {
dirs.push(new URL(dirent.name, dir));
}
}
return dirs;
};
/** Runs all smoke tests. */
async function run() {
console.log('');
const directories = [...(await getChildDirectories(exampleDir)), ...(await getChildDirectories(smokeDir))];
console.log('🤖', 'Preparing', 'yarn');
await execa('yarn', [], { cwd: fileURLToPath(rootDir), stdio: 'inherit' });
for (const directory of directories) {
console.log('🤖', 'Testing', directory.pathname.split('/').at(-1));
try {
await execa('yarn', ['run', 'build'], { cwd: fileURLToPath(directory), stdio: 'inherit' });
} catch (err) {
console.log(err);
process.exit(1);
}
// Run with the static build too (skip for remote repos)
if (directory.pathname.includes(smokeDir.pathname)) {
continue;
}
try {
await execa('yarn', ['build', '--', '--experimental-static-build'], { cwd: fileURLToPath(directory), stdout: 'inherit', stderr: 'inherit' });
} catch (err) {
console.log(err);
process.exit(1);
}
console.log();
}
}
run();