0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/scripts/smoke/index.js
Erika 148e61d249 feat: remove webapi in favor of a smaller polyfill (#7840)
* feat: remove webapi in favor of a smaller polyfill

* test: remove old test

* test: 🤦‍♀️

* chore: changeset
2023-08-08 11:01:45 +01:00

56 lines
1.7 KiB
JavaScript

/** @file Runs all smoke tests and may add extra smoke-test dependencies to `pnpm-lock.yaml`. */
// @ts-check
import { execa } from 'execa';
import { promises as fs } from 'node:fs';
import { fileURLToPath } from 'node:url';
/** 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(smokeDir)), ...(await getChildDirectories(exampleDir))];
console.log('🤖', 'Preparing', 'pnpm');
await execa('pnpm', ['install', '--frozen-lockfile=false'], { cwd: fileURLToPath(rootDir), stdio: 'inherit' });
for (const directory of directories) {
const name = directory.pathname.split('/').at(-1) ?? "";
const isExternal = directory.pathname.includes(smokeDir.pathname);
console.log('🤖', 'Testing', name);
try {
await execa('pnpm', ['install', '--ignore-scripts', '--frozen-lockfile=false'].filter(x => x), { cwd: fileURLToPath(directory), stdio: 'inherit' });
await execa('pnpm', ['astro', 'telemetry', 'disable']);
await execa('pnpm', ['run', 'build'], { cwd: fileURLToPath(directory), stdio: 'inherit' });
} catch (err) {
console.log(err);
process.exit(1);
}
}
}
run();