summaryrefslogtreecommitdiff
path: root/scripts/smoke/cleanup.js
diff options
context:
space:
mode:
authorGravatar Jonathan Neal <jonathantneal@hotmail.com> 2022-02-15 10:51:12 -0500
committerGravatar GitHub <noreply@github.com> 2022-02-15 10:51:12 -0500
commitfb9a77b77f276f712dae3354bb2e1f8948c72a76 (patch)
treeb38bcd410462e7ca840eea0e459f8143e4283c11 /scripts/smoke/cleanup.js
parentacc92431d63578fe53469d52ae18a3e3ea9006bc (diff)
downloadastro-fb9a77b77f276f712dae3354bb2e1f8948c72a76.tar.gz
astro-fb9a77b77f276f712dae3354bb2e1f8948c72a76.tar.zst
astro-fb9a77b77f276f712dae3354bb2e1f8948c72a76.zip
Update smoke tests to include external docs and www (#2557)
* Update smoke tests * nit: remove old comment * chore: have smoketests use workspace * nit: re-order application and execution
Diffstat (limited to 'scripts/smoke/cleanup.js')
-rw-r--r--scripts/smoke/cleanup.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/scripts/smoke/cleanup.js b/scripts/smoke/cleanup.js
new file mode 100644
index 000000000..291083540
--- /dev/null
+++ b/scripts/smoke/cleanup.js
@@ -0,0 +1,65 @@
+/** @file Remove all smoke tests and may remove extra smoke-test dependencies from `yarn.lock`. */
+
+// @ts-check
+
+import { execa } from 'execa';
+import { polyfill } from '@astropub/webapi';
+import { fileURLToPath } from 'node:url';
+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);
+
+/* Application
+/* ========================================================================== */
+
+/** Runs all smoke tests. */
+async function run() {
+ const dirs = await getChildDirectories(scriptDir)
+
+ if (dirs.length) {
+ console.log()
+
+ for (const dir of await getChildDirectories(scriptDir)) {
+ console.log('🤖', 'Removing', dir.pathname.split('/').at(-1));
+
+ fs.rm(dir, { force: true, recursive: true })
+ }
+ }
+
+ console.log()
+
+ console.log('🤖', 'Resetting', 'yarn');
+
+ await execa('yarn', [], { cwd: fileURLToPath(rootDir), stdout: 'inherit', stderr: 'inherit' });
+}
+
+/* Functionality
+/* ========================================================================== */
+
+/** 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();