summaryrefslogtreecommitdiff
path: root/scripts/smoke/index.js
diff options
context:
space:
mode:
authorGravatar Fred K. Schott <fkschott@gmail.com> 2022-02-28 21:38:17 -0800
committerGravatar GitHub <noreply@github.com> 2022-02-28 21:38:17 -0800
commit918f1ea4f72850c650282c134de94548ef2fcad5 (patch)
treecac396f9e7be425b59cdbfea7725b3915acf3406 /scripts/smoke/index.js
parenta217c6608df684ddf3672bbef73bd7efc9a6a191 (diff)
downloadastro-918f1ea4f72850c650282c134de94548ef2fcad5.tar.gz
astro-918f1ea4f72850c650282c134de94548ef2fcad5.tar.zst
astro-918f1ea4f72850c650282c134de94548ef2fcad5.zip
Make smoke tests more deterministic (#2618)
* sync first remote smoke tests * update smoke test scripts
Diffstat (limited to 'scripts/smoke/index.js')
-rw-r--r--scripts/smoke/index.js117
1 files changed, 16 insertions, 101 deletions
diff --git a/scripts/smoke/index.js b/scripts/smoke/index.js
index 69e0c889a..c0600e2b7 100644
--- a/scripts/smoke/index.js
+++ b/scripts/smoke/index.js
@@ -1,8 +1,6 @@
/** @file Runs all smoke tests and may add extra smoke-test dependencies to `yarn.lock`. */
-
// @ts-check
-import Zip from 'adm-zip';
import { execa } from 'execa';
import { polyfill } from '@astropub/webapi';
import { fileURLToPath } from 'node:url';
@@ -10,38 +8,32 @@ import { promises as fs } from 'node:fs';
polyfill(globalThis, { exclude: 'window document' });
-/* Configuration
-/* -------------------------------------------------------------------------- */
-
-/** URL directory containing this current script. */
-const scriptDir = new URL('./', import.meta.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);
-/** URL directory containing the Astro package. */
-const astroDir = new URL('packages/astro/', rootDir);
-
-/** GitHub configuration for the external "docs" Astro project. */
-// const docGithubConfig = { org: 'withastro', name: 'docs', branch: 'main' };
+/** Returns all child directories of the given directory. */
+const getChildDirectories = async (/** @type {URL} */ dir) => {
+ /** @type {URL[]} */
+ const dirs = [];
-/** GitHub configuration for the external "astro.build" Astro project. */
-// const wwwGithubConfig = { org: 'withastro', name: 'astro.build', branch: 'main' };
+ for await (const dirent of await fs.opendir(dir)) {
+ if (dirent.isDirectory()) {
+ dirs.push(new URL(dirent.name, dir));
+ }
+ }
-/* Application
-/* -------------------------------------------------------------------------- */
+ return dirs;
+};
/** Runs all smoke tests. */
async function run() {
console.log('');
- const directories = await getChildDirectories(exampleDir);
-
- // TODO Skipped the docs-main test since it is failing at the moment.
- // TODO Skipped the www test since it is failing at the moment.
+ const directories = [...await getChildDirectories(exampleDir), ...await getChildDirectories(smokeDir)];
console.log('🤖', 'Preparing', 'yarn');
@@ -54,13 +46,11 @@ async function run() {
await execa('yarn', ['run', 'build'], { cwd: fileURLToPath(directory), stdio: 'inherit' });
} catch (err) {
console.log(err);
-
process.exit(1);
}
- // Run with the static build too
- if (directory.pathname.includes('astro.build')) {
- // astro.build uses the static build, so rerunning with the flag actually negates it.
+ // Run with the static build too (skip for remote repos)
+ if (directory.pathname.includes(smokeDir.pathname)) {
continue;
}
@@ -68,7 +58,6 @@ async function run() {
await execa('yarn', ['build', '--', '--experimental-static-build'], { cwd: fileURLToPath(directory), stdout: 'inherit', stderr: 'inherit' });
} catch (err) {
console.log(err);
-
process.exit(1);
}
@@ -76,78 +65,4 @@ async function run() {
}
}
-/* Functionality
-/* -------------------------------------------------------------------------- */
-
-/** Returns the URL to the ZIP of the given GitHub project. */
-const getGithubZipURL = (/** @type {GithubOpts} */ opts) => `https://github.com/${opts.org}/${opts.name}/archive/refs/heads/${opts.branch}.zip`;
-
-/** Returns the awaited ZIP Buffer from the given GitHub project. */
-const fetchGithubZip = (/** @type {GithubOpts} */ opts) =>
- fetch(getGithubZipURL(opts))
- .then((response) => response.arrayBuffer())
- .then((arrayBuffer) => Buffer.from(arrayBuffer));
-
-/** Downloads a ZIP from the given GitHub project. */
-const downloadGithubZip = async (/** @type {GithubOpts} */ opts) => {
- /** Expected directory when the zip is downloaded. */
- const githubDir = new URL(`${opts.name}-${opts.branch}`, scriptDir);
-
- console.log('🤖', 'Downloading', `${opts.org}/${opts.name}#${opts.branch}`);
-
- const buffer = await fetchGithubZip(opts);
-
- console.log('🤖', 'Extracting', `${opts.org}/${opts.name}#${opts.branch}`);
-
- new Zip(buffer).extractAllTo(fileURLToPath(scriptDir), true);
-
- console.log('🤖', 'Preparing', `${opts.org}/${opts.name}#${opts.branch}`);
-
- const astroPackage = await readDirectoryPackage(astroDir);
-
- const githubPackage = await readDirectoryPackage(githubDir);
-
- if ('astro' in Object(githubPackage.dependencies)) {
- githubPackage.dependencies['astro'] = astroPackage.version;
- }
-
- if ('astro' in Object(githubPackage.devDependencies)) {
- githubPackage.devDependencies['astro'] = astroPackage.version;
- }
-
- if ('astro' in Object(githubPackage.peerDependencies)) {
- githubPackage.peerDependencies['astro'] = astroPackage.version;
- }
-
- await writeDirectoryPackage(githubDir, githubPackage);
-
- return githubDir;
-};
-
-/** Returns the parsed package.json of the given directory. */
-const readDirectoryPackage = async (/** @type {URL} */ dir) => JSON.parse(await fs.readFile(new URL('package.json', dir + '/'), 'utf-8'));
-
-/** Returns upon completion of writing a package.json to the given directory. */
-const writeDirectoryPackage = async (/** @type {URL} */ dir, /** @type {any} */ data) =>
- await fs.writeFile(new URL('package.json', dir + '/'), JSON.stringify(data, null, ' ') + '\n');
-
-/** 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;
-};
-
-/* Execution
-/* -------------------------------------------------------------------------- */
-
-run();
-
-/** @typedef {{ org: string, name: string, branch: string }} GithubOpts */
+run(); \ No newline at end of file