Files
qqq-cli/scripts/run-tests.mjs
T
james.maesandClaude Fable 5.1 5dd5e2d7f1 test: run the package tests without shell globs, for the Windows lane
The cli-windows-x64 lane failed in every package with "Could not find
...\dist\test\*.test.js": npm runs scripts with cmd.exe there, which
does not expand globs, and Node 20 does not glob its own arguments.
Plain "node --test" is no fix on Node 20 either, because its default
patterns run every file under a test directory, helpers such as
harness.js and stub.js included.

scripts/run-tests.mjs lists the *.test.js files directly in dist/test and
spawns node --test with them, so all four packages run the same files on
every platform. Counts on macOS are unchanged: 18, 167, 3 and 100.

Two cheap Windows fixes in the CLI test harness: the sandbox sets
USERPROFILE as well as HOME (os.homedir() reads USERPROFILE on Windows,
so defaults would have escaped into the real profile) and QQQ_STATE_DIR,
and the golden-file normaliser turns backslashes in sandbox paths into /
so export-download-dir.txt matches there too.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-01 04:39:55 -06:00

35 lines
1.4 KiB
JavaScript

#!/usr/bin/env node
/*
* Copyright 2026 QRun.IO, Inc.
* Licensed under the Apache License, Version 2.0 (see LICENSE).
*/
/**
* Runs a package's built tests: `node --test` on every `*.test.js` directly in `dist/test` (or the
* directory given), from the package directory npm runs scripts in. A shell glob such as
* `node --test dist/test/*.test.js` is not expanded by cmd.exe on Windows, and Node 20 does not glob
* its own arguments; `node --test` without arguments would also run helpers such as `test/harness.js`
* (Node 20's default patterns include every file under a `test` directory). So the list is made here.
*
* Usage: node ../../scripts/run-tests.mjs [dir] (extra node --test options may follow the dir)
*/
import { spawnSync } from 'node:child_process'
import { existsSync, readdirSync } from 'node:fs'
import { join, resolve } from 'node:path'
const [dirArg = 'dist/test', ...options] = process.argv.slice(2)
const dir = resolve(dirArg)
if (!existsSync(dir)) {
console.error(`run-tests: ${dir} does not exist; run npm run build first`)
process.exit(1)
}
const files = readdirSync(dir).filter((name) => name.endsWith('.test.js')).sort().map((name) => join(dir, name))
if (!files.length) {
console.error(`run-tests: no *.test.js in ${dir}`)
process.exit(1)
}
const result = spawnSync(process.execPath, ['--test', ...options, ...files], { stdio: 'inherit' })
if (result.error) throw result.error
process.exit(result.status ?? 1)