diff --git a/changes/mocha-without-npx.internal.md b/changes/mocha-without-npx.internal.md new file mode 100644 index 0000000000..38874a0749 --- /dev/null +++ b/changes/mocha-without-npx.internal.md @@ -0,0 +1 @@ +- Run Mocha in the test scripts without npx, which failed on Windows with Node 26.14.0. diff --git a/lib_dev/process.js b/lib_dev/process.js index 380d144cc4..d050075389 100644 --- a/lib_dev/process.js +++ b/lib_dev/process.js @@ -1,5 +1,6 @@ import * as child_process from "node:child_process"; import * as fs from "node:fs/promises"; +import { createRequire } from "node:module"; import * as path from "node:path"; import { bsc_exe, rescript_exe } from "#cli/bins"; @@ -15,6 +16,8 @@ import { bsc_exe, rescript_exe } from "#cli/bins"; * }} ExecResult */ +const mochaBin = createRequire(import.meta.url).resolve("mocha/bin/mocha.js"); + const signals = { SIGINT: 2, SIGQUIT: 3, @@ -126,9 +129,9 @@ export function setup(cwd = process.cwd()) { * @return {Promise} */ mocha(args = [], options = {}) { - // `yarn mocha` works, but format output differently - // No more efforts here since we're plannig to drop Mocha - return exec("npx", ["mocha", ...args], options); + // Run Mocha's CLI script with Node directly. On Windows, `npx mocha` + // failed with Node 26.14.0 to find the script it should run. + return exec("node", [mochaBin, ...args], options); }, /**