diff options
author | 2024-01-25 16:17:31 +0000 | |
---|---|---|
committer | 2024-01-25 16:17:31 +0000 | |
commit | fc21a3c306f552a3048b0a0899b5f21c1c9269c1 (patch) | |
tree | ba619951f09147eb2893ec5b5f113014ee3f746e /scripts/cmd/test.js | |
parent | d688954c5adba75b0d676694fbf5fb0da1c0af13 (diff) | |
download | astro-fc21a3c306f552a3048b0a0899b5f21c1c9269c1.tar.gz astro-fc21a3c306f552a3048b0a0899b5f21c1c9269c1.tar.zst astro-fc21a3c306f552a3048b0a0899b5f21c1c9269c1.zip |
chore(@astrojs/node): use Node.js for testing (#9758)
* chore(@astrojs/node): use Node.js for testing
* revert file
* address feedback
* feedback
* Run tests in a single process (#9823)
* Run tests in a single process
* Make test less flaky
* chore: remove module
---------
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
Diffstat (limited to 'scripts/cmd/test.js')
-rw-r--r-- | scripts/cmd/test.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/scripts/cmd/test.js b/scripts/cmd/test.js index 84f6d9742..4e3b6c6ca 100644 --- a/scripts/cmd/test.js +++ b/scripts/cmd/test.js @@ -1,5 +1,8 @@ import { run } from 'node:test'; import { spec } from 'node:test/reporters'; +import fs from 'node:fs/promises'; +import path from 'node:path'; +import { pathToFileURL } from 'node:url'; import arg from 'arg'; import glob from 'tiny-glob'; @@ -36,6 +39,20 @@ export default async function test() { process.env.NODE_OPTIONS += ' --test-only'; } + if (!args['--parallel']) { + // If not parallel, we create a temporary file that imports all the test files + // so that it all runs in a single process. + const tempTestFile = path.resolve('./node_modules/.astro/test.mjs'); + await fs.mkdir(path.dirname(tempTestFile), { recursive: true }); + await fs.writeFile( + tempTestFile, + files.map((f) => `import ${JSON.stringify(pathToFileURL(f).toString())};`).join('\n') + ); + + files.length = 0; + files.push(tempTestFile); + } + // https://nodejs.org/api/test.html#runoptions run({ files, |