test: make test fails when jest force-stops a worker (closes #711)
When a test leaves a timer running, jest force-stops that worker, prints a warning, and the run still passes. Jest has no option that fails the run instead. Both test scripts in package.json now run jest through script/lib/jest.js. It passes jest's output through and exits 1 when jest printed that warning. Model: opus-5-5
This commit is contained in:
+2
-2
@@ -6,8 +6,8 @@
|
|||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest --maxWorkers=3",
|
"test": "node script/lib/jest.js --maxWorkers=3",
|
||||||
"test:verbose": "jest --maxWorkers=3 --verbose",
|
"test:verbose": "node script/lib/jest.js --maxWorkers=3 --verbose",
|
||||||
"build": "node build.js",
|
"build": "node build.js",
|
||||||
"lint": "eslint . && prettier --check .",
|
"lint": "eslint . && prettier --check .",
|
||||||
"fmt": "prettier --write .",
|
"fmt": "prettier --write .",
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
// Runs jest with the arguments it is given, and fails the run when jest had to
|
||||||
|
// force-stop a worker. Jest itself only prints a warning when that happens, and
|
||||||
|
// its run still passes. The warning means a test left a timer or another open
|
||||||
|
// handle running. The test scripts in package.json run jest through this file.
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const { spawn } = require("child_process");
|
||||||
|
|
||||||
|
// The start of the warning that jest prints on stderr after it force-stops a
|
||||||
|
// worker.
|
||||||
|
const WORKER_WARNING = "A worker process has failed to exit gracefully";
|
||||||
|
|
||||||
|
const jest = spawn("jest", process.argv.slice(2), {
|
||||||
|
stdio: ["inherit", "inherit", "pipe"],
|
||||||
|
});
|
||||||
|
|
||||||
|
let stderr = "";
|
||||||
|
jest.stderr.on("data", (chunk) => {
|
||||||
|
process.stderr.write(chunk);
|
||||||
|
stderr += chunk;
|
||||||
|
});
|
||||||
|
|
||||||
|
jest.on("close", (code) => {
|
||||||
|
if (stderr.includes(WORKER_WARNING)) {
|
||||||
|
console.error(
|
||||||
|
"script/lib/jest.js: failing the run, because jest force-stopped " +
|
||||||
|
"a worker. A test left a timer or another open handle running.",
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
process.exit(code ?? 1);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user