// 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");