Files
AutistMask/script/lib/jest.js
T
sneak 4cb61d1a10
check / check (push) Waiting to run
e2e / e2e-chrome (push) Waiting to run
e2e / e2e-firefox (push) Waiting to run
test: run jest in one process, fail on an open handle (closes #766)
Jest force-stopped worker processes that could not exit within 500 ms on
a starved CPU, failing runs where every test passed. The test scripts now
pass --runInBand. script/lib/jest.js fails the run at once when jest
warns that it did not exit one second after the run, instead of
hanging. The Dockerfile test stage drops its 90-second timeout.

tests/jestRunner.test.js runs the runner on a fixture that leaves an
interval running and expects exit status 1.

Model: opus-5-5
2026-11-11 05:21:01 +00:00

33 lines
1.3 KiB
JavaScript

// Runs jest with the arguments it is given, and fails the run at once when a
// test left a timer or another open handle running. Such a handle keeps this
// process alive after the last test, so the run would hang. Jest itself only
// prints a warning one second after the run, and then keeps waiting. The test
// scripts in package.json run jest through this file, in this one process.
//
// Jest runs inside this process and writes to the terminal directly, so its
// output looks the same as a plain jest run. This file only checks each write
// to stderr for the warning below.
"use strict";
// The start of the warning that jest prints on stderr when the process has not
// exited one second after the test run.
const OPEN_HANDLE_WARNING =
"Jest did not exit one second after the test run has completed.";
const writeStderr = process.stderr.write.bind(process.stderr);
process.stderr.write = (chunk, ...rest) => {
const written = writeStderr(chunk, ...rest);
if (String(chunk).includes(OPEN_HANDLE_WARNING)) {
writeStderr(
"script/lib/jest.js: failing the run, because a test left a " +
"timer or another open handle running.\n",
);
process.exit(1);
}
return written;
};
// Jest's own command-line program. It reads its arguments from process.argv.
require("jest/bin/jest");