Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f4ca5c73e |
+1
-2
@@ -153,8 +153,7 @@ module.exports = [
|
||||
},
|
||||
},
|
||||
|
||||
// The helpers the script/ entrypoints call: plain node programs too, run
|
||||
// from a shell script rather than from yarn, and never bundled.
|
||||
// The files in script/lib/ run on plain node too, and are never bundled.
|
||||
{
|
||||
files: ["script/lib/**/*.js"],
|
||||
languageOptions: {
|
||||
|
||||
+26
-19
@@ -1,33 +1,40 @@
|
||||
// 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.
|
||||
// force-stop the worker process that ran a test file. 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.
|
||||
//
|
||||
// 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";
|
||||
|
||||
const { spawn } = require("child_process");
|
||||
|
||||
// The start of the warning that jest prints on stderr after it force-stops a
|
||||
// worker.
|
||||
// worker process.
|
||||
const WORKER_WARNING = "A worker process has failed to exit gracefully";
|
||||
|
||||
const jest = spawn("jest", process.argv.slice(2), {
|
||||
stdio: ["inherit", "inherit", "pipe"],
|
||||
});
|
||||
let forceStopped = false;
|
||||
|
||||
let stderr = "";
|
||||
jest.stderr.on("data", (chunk) => {
|
||||
process.stderr.write(chunk);
|
||||
stderr += chunk;
|
||||
});
|
||||
const writeStderr = process.stderr.write.bind(process.stderr);
|
||||
process.stderr.write = (chunk, ...rest) => {
|
||||
if (String(chunk).includes(WORKER_WARNING)) {
|
||||
forceStopped = true;
|
||||
}
|
||||
return writeStderr(chunk, ...rest);
|
||||
};
|
||||
|
||||
jest.on("close", (code) => {
|
||||
if (stderr.includes(WORKER_WARNING)) {
|
||||
// Runs after jest has finished, as the process exits.
|
||||
process.on("exit", () => {
|
||||
if (forceStopped) {
|
||||
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.",
|
||||
"a worker process. A test left a timer or another open " +
|
||||
"handle running.",
|
||||
);
|
||||
process.exit(1);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
process.exit(code ?? 1);
|
||||
});
|
||||
|
||||
// Jest's own command-line program. It reads its arguments from process.argv.
|
||||
require("jest/bin/jest");
|
||||
|
||||
Reference in New Issue
Block a user