From e08b15206efc70c420b50f051b527e6051e2ea97 Mon Sep 17 00:00:00 2001 From: Automated Commit Date: Wed, 25 Nov 2026 14:41:26 -0500 Subject: [PATCH 1/7] Let --testTimeout raise per-test timeouts but never lower them Co-authored-by: Adam Novak Assisted-by: Claude Code:claude-opus-5-5 --- src/components/TrackPicker.test.js | 3 ++- src/end-to-end.test.js | 5 +++-- src/scripts.test.js | 3 ++- src/testTimeout.js | 31 ++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 src/testTimeout.js diff --git a/src/components/TrackPicker.test.js b/src/components/TrackPicker.test.js index 839ee1da..ac92d4b6 100644 --- a/src/components/TrackPicker.test.js +++ b/src/components/TrackPicker.test.js @@ -5,6 +5,7 @@ import "@testing-library/jest-dom"; import "../config-client.js"; import { config } from "../config-global.mjs"; import { defaultTrackColors } from "../common.mjs"; +import { atLeast } from "../testTimeout"; describe("TrackPicker", () => { const tracks = { @@ -184,7 +185,7 @@ describe("TrackPicker", () => { expect(fakeOnChange).toHaveBeenCalledTimes(2); expect(fakeOnChange).toHaveBeenCalledWith(newTracks); - }, 50000); + }, atLeast(50000)); it("should close when the exit button is pressed", async () => { const fakeOnChange = jest.fn(); diff --git a/src/end-to-end.test.js b/src/end-to-end.test.js index 5aee54ad..991e5001 100644 --- a/src/end-to-end.test.js +++ b/src/end-to-end.test.js @@ -23,6 +23,7 @@ import "@testing-library/jest-dom/extend-expect"; import userEvent from "@testing-library/user-event"; import selectEvent from "react-select-event"; import App from "./App"; +import { atLeast } from "./testTimeout"; const getRegionInput = () => { // Helper function to select the Region input box @@ -376,7 +377,7 @@ it("produces correct link for view before & after go is pressed", async () => { "http://localhost/?tracks[0][trackFile]=exampleData%2Fcactus.vg.xg&tracks[0][trackType]=graph&tracks[1][trackFile]=exampleData%2Fcactus-NA12879.sorted.gam&tracks[1][trackType]=read&bedFile=exampleData%2Fcactus.bed&name=cactus®ion=ref%3A1-100&dataType=built-in&simplify=false&removeSequences=false"; // Make sure link has changed after pressing go expect(fakeClipboard).toEqual(expectedLinkCactus); -}, 20000); +}, atLeast(20000)); it("can retrieve the list of mounted graph files", async () => { // Wait for everything to settle so we don't stop the server while it is thinking @@ -527,5 +528,5 @@ it("can accept uploaded files", async () => { expect(svg.getElementsByTagName("title").length).toEqual(5); console.log("Test over"); -}, 50000); // We need to allow a long time for the slow vg test machines. +}, atLeast(50000)); // We need to allow a long time for the slow vg test machines. // TODO: Is this slow because of unnecessary re-renders caused by the new color schemes taking effect and being rendered with the old data, before the new data downloads? diff --git a/src/scripts.test.js b/src/scripts.test.js index b9fd97eb..88b4c4bd 100644 --- a/src/scripts.test.js +++ b/src/scripts.test.js @@ -3,6 +3,7 @@ import "./config-server.mjs"; import { find_vg } from "./vg.mjs"; +import { atLeast } from "./testTimeout"; import { mkdtemp, rm, cp, open, access } from 'node:fs/promises'; import { join } from 'node:path'; @@ -57,6 +58,6 @@ it("can run prepare_vg.sh", async () => { console.log("stderr:", stderr); await access(join(workDir, "x.vg.xg")); await access(join(workDir, "x.vg.gbwt")); -}, 30000); +}, atLeast(30000)); diff --git a/src/testTimeout.js b/src/testTimeout.js new file mode 100644 index 00000000..55cd8d08 --- /dev/null +++ b/src/testTimeout.js @@ -0,0 +1,31 @@ +// Test timeouts that respect Jest's configured default. +// +// A per-test timeout passed to it() or test() replaces Jest's default (from +// --testTimeout or the 5000 ms built-in) rather than combining with it. Pass +// atLeast(ms) instead of a bare number so that a slow environment can raise +// every limit from the command line. + +// Jest's built-in default per-test timeout. +const JEST_BUILTIN_TIMEOUT = 5000; + +// Get the default per-test timeout Jest is running with. +// +// Jest has no public API for this. jest-circus keeps it as testTimeout on a +// state object stored on the global under an unregistered symbol. +// TODO: This is Jest-internal and may break on a Jest upgrade, in which case +// we fall back to the built-in default and command-line increases are ignored. +function configuredTimeout() { + const stateSymbol = Object.getOwnPropertySymbols(globalThis).find( + (s) => s.description === "JEST_STATE_SYMBOL" + ); + const timeout = stateSymbol && globalThis[stateSymbol]?.testTimeout; + return typeof timeout === "number" ? timeout : JEST_BUILTIN_TIMEOUT; +} + +// Get a timeout of at least ms, or longer if Jest's default is longer. +// +// Must be called while tests are being defined, after Jest has applied its +// configuration, which is the case when used as an it()/test() argument. +export function atLeast(ms) { + return Math.max(ms, configuredTimeout()); +} From 94837b2db712a365638857dc6f46adea19e15fb2 Mon Sep 17 00:00:00 2001 From: Automated Commit Date: Wed, 25 Nov 2026 14:54:07 -0500 Subject: [PATCH 2/7] Move timeout helper to testHelpers and cite Jest source for it Co-authored-by: Adam Novak Assisted-by: Claude Code:claude-opus-5-5 --- src/components/TrackPicker.test.js | 4 +-- src/end-to-end.test.js | 6 ++--- src/scripts.test.js | 4 +-- src/testHelpers.js | 41 ++++++++++++++++++++++++++++++ src/testTimeout.js | 31 ---------------------- 5 files changed, 48 insertions(+), 38 deletions(-) create mode 100644 src/testHelpers.js delete mode 100644 src/testTimeout.js diff --git a/src/components/TrackPicker.test.js b/src/components/TrackPicker.test.js index ac92d4b6..bb3b657c 100644 --- a/src/components/TrackPicker.test.js +++ b/src/components/TrackPicker.test.js @@ -5,7 +5,7 @@ import "@testing-library/jest-dom"; import "../config-client.js"; import { config } from "../config-global.mjs"; import { defaultTrackColors } from "../common.mjs"; -import { atLeast } from "../testTimeout"; +import { timeoutAtLeast } from "../testHelpers"; describe("TrackPicker", () => { const tracks = { @@ -185,7 +185,7 @@ describe("TrackPicker", () => { expect(fakeOnChange).toHaveBeenCalledTimes(2); expect(fakeOnChange).toHaveBeenCalledWith(newTracks); - }, atLeast(50000)); + }, timeoutAtLeast(50000)); it("should close when the exit button is pressed", async () => { const fakeOnChange = jest.fn(); diff --git a/src/end-to-end.test.js b/src/end-to-end.test.js index 991e5001..95ddd4d2 100644 --- a/src/end-to-end.test.js +++ b/src/end-to-end.test.js @@ -23,7 +23,7 @@ import "@testing-library/jest-dom/extend-expect"; import userEvent from "@testing-library/user-event"; import selectEvent from "react-select-event"; import App from "./App"; -import { atLeast } from "./testTimeout"; +import { timeoutAtLeast } from "./testHelpers"; const getRegionInput = () => { // Helper function to select the Region input box @@ -377,7 +377,7 @@ it("produces correct link for view before & after go is pressed", async () => { "http://localhost/?tracks[0][trackFile]=exampleData%2Fcactus.vg.xg&tracks[0][trackType]=graph&tracks[1][trackFile]=exampleData%2Fcactus-NA12879.sorted.gam&tracks[1][trackType]=read&bedFile=exampleData%2Fcactus.bed&name=cactus®ion=ref%3A1-100&dataType=built-in&simplify=false&removeSequences=false"; // Make sure link has changed after pressing go expect(fakeClipboard).toEqual(expectedLinkCactus); -}, atLeast(20000)); +}, timeoutAtLeast(20000)); it("can retrieve the list of mounted graph files", async () => { // Wait for everything to settle so we don't stop the server while it is thinking @@ -528,5 +528,5 @@ it("can accept uploaded files", async () => { expect(svg.getElementsByTagName("title").length).toEqual(5); console.log("Test over"); -}, atLeast(50000)); // We need to allow a long time for the slow vg test machines. +}, timeoutAtLeast(50000)); // We need to allow a long time for the slow vg test machines. // TODO: Is this slow because of unnecessary re-renders caused by the new color schemes taking effect and being rendered with the old data, before the new data downloads? diff --git a/src/scripts.test.js b/src/scripts.test.js index 88b4c4bd..60aea99a 100644 --- a/src/scripts.test.js +++ b/src/scripts.test.js @@ -3,7 +3,7 @@ import "./config-server.mjs"; import { find_vg } from "./vg.mjs"; -import { atLeast } from "./testTimeout"; +import { timeoutAtLeast } from "./testHelpers"; import { mkdtemp, rm, cp, open, access } from 'node:fs/promises'; import { join } from 'node:path'; @@ -58,6 +58,6 @@ it("can run prepare_vg.sh", async () => { console.log("stderr:", stderr); await access(join(workDir, "x.vg.xg")); await access(join(workDir, "x.vg.gbwt")); -}, atLeast(30000)); +}, timeoutAtLeast(30000)); diff --git a/src/testHelpers.js b/src/testHelpers.js new file mode 100644 index 00000000..ef6a5708 --- /dev/null +++ b/src/testHelpers.js @@ -0,0 +1,41 @@ +// Helpers shared by test files. + +// Jest's built-in default per-test timeout. +const JEST_BUILTIN_TIMEOUT = 5000; + +// Find jest-circus's internal state object, or undefined if it can't be found. +// +// jest-circus stores this on the test file's global under an unregistered +// symbol named JEST_STATE_SYMBOL, and applies the Jest configuration to it +// before loading setup and test files. See Jest v27.5.1: +// https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-circus/src/types.ts#L12-L14 +// https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-circus/src/state.ts#L33-L46 +// https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts#L67-L69 +// https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts#L26-L85 +// TODO: This is not a public Jest API and may break on a Jest upgrade. +export function findJestState() { + const stateSymbol = Object.getOwnPropertySymbols(globalThis).find( + (s) => s.description === "JEST_STATE_SYMBOL" + ); + return stateSymbol && globalThis[stateSymbol]; +} + +// Get the default per-test timeout Jest is running with, from --testTimeout +// or the built-in default. +// +// Jest has no public API for this. If Jest's internal state can't be found, +// return the built-in default, ignoring any --testTimeout. +function configuredTimeout() { + const timeout = findJestState()?.testTimeout; + return typeof timeout === "number" ? timeout : JEST_BUILTIN_TIMEOUT; +} + +// Get a per-test timeout of at least ms, or longer if Jest's default is +// longer. +// +// Pass this to it() or test() instead of a bare number. A bare number replaces +// Jest's default instead of combining with it, so --testTimeout could not +// raise it for a slow environment. +export function timeoutAtLeast(ms) { + return Math.max(ms, configuredTimeout()); +} diff --git a/src/testTimeout.js b/src/testTimeout.js deleted file mode 100644 index 55cd8d08..00000000 --- a/src/testTimeout.js +++ /dev/null @@ -1,31 +0,0 @@ -// Test timeouts that respect Jest's configured default. -// -// A per-test timeout passed to it() or test() replaces Jest's default (from -// --testTimeout or the 5000 ms built-in) rather than combining with it. Pass -// atLeast(ms) instead of a bare number so that a slow environment can raise -// every limit from the command line. - -// Jest's built-in default per-test timeout. -const JEST_BUILTIN_TIMEOUT = 5000; - -// Get the default per-test timeout Jest is running with. -// -// Jest has no public API for this. jest-circus keeps it as testTimeout on a -// state object stored on the global under an unregistered symbol. -// TODO: This is Jest-internal and may break on a Jest upgrade, in which case -// we fall back to the built-in default and command-line increases are ignored. -function configuredTimeout() { - const stateSymbol = Object.getOwnPropertySymbols(globalThis).find( - (s) => s.description === "JEST_STATE_SYMBOL" - ); - const timeout = stateSymbol && globalThis[stateSymbol]?.testTimeout; - return typeof timeout === "number" ? timeout : JEST_BUILTIN_TIMEOUT; -} - -// Get a timeout of at least ms, or longer if Jest's default is longer. -// -// Must be called while tests are being defined, after Jest has applied its -// configuration, which is the case when used as an it()/test() argument. -export function atLeast(ms) { - return Math.max(ms, configuredTimeout()); -} From 28332a6f81e871812b669a46320753ee77541563 Mon Sep 17 00:00:00 2001 From: Automated Commit Date: Wed, 25 Nov 2026 14:58:46 -0500 Subject: [PATCH 3/7] Move Jest internals notes inside findJestState and trim comments Co-authored-by: Adam Novak Assisted-by: Claude Code:claude-opus-5-5 --- src/testHelpers.js | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/testHelpers.js b/src/testHelpers.js index ef6a5708..019e049e 100644 --- a/src/testHelpers.js +++ b/src/testHelpers.js @@ -4,27 +4,23 @@ const JEST_BUILTIN_TIMEOUT = 5000; // Find jest-circus's internal state object, or undefined if it can't be found. -// -// jest-circus stores this on the test file's global under an unregistered -// symbol named JEST_STATE_SYMBOL, and applies the Jest configuration to it -// before loading setup and test files. See Jest v27.5.1: -// https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-circus/src/types.ts#L12-L14 -// https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-circus/src/state.ts#L33-L46 -// https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts#L67-L69 -// https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts#L26-L85 -// TODO: This is not a public Jest API and may break on a Jest upgrade. export function findJestState() { + // jest-circus stores this on the test file's global under an unregistered + // symbol named JEST_STATE_SYMBOL, and applies the Jest configuration to it + // before loading setup and test files. See Jest v27.5.1: + // https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-circus/src/types.ts#L12-L14 + // https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-circus/src/state.ts#L33-L46 + // https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts#L67-L69 + // https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts#L26-L85 + // TODO: This is not a public Jest API and may break on a Jest upgrade. const stateSymbol = Object.getOwnPropertySymbols(globalThis).find( (s) => s.description === "JEST_STATE_SYMBOL" ); return stateSymbol && globalThis[stateSymbol]; } -// Get the default per-test timeout Jest is running with, from --testTimeout -// or the built-in default. -// -// Jest has no public API for this. If Jest's internal state can't be found, -// return the built-in default, ignoring any --testTimeout. +// Get the configured Jest test timeout, or a default value if it is +// unavailable. function configuredTimeout() { const timeout = findJestState()?.testTimeout; return typeof timeout === "number" ? timeout : JEST_BUILTIN_TIMEOUT; @@ -32,10 +28,6 @@ function configuredTimeout() { // Get a per-test timeout of at least ms, or longer if Jest's default is // longer. -// -// Pass this to it() or test() instead of a bare number. A bare number replaces -// Jest's default instead of combining with it, so --testTimeout could not -// raise it for a slow environment. export function timeoutAtLeast(ms) { return Math.max(ms, configuredTimeout()); } From 13f2eefd8fc8f04c32ea8162e01d8e705d0821b8 Mon Sep 17 00:00:00 2001 From: Automated Commit Date: Wed, 25 Nov 2026 15:00:25 -0500 Subject: [PATCH 4/7] Explain why findJestState can't use jest-circus's getState Co-authored-by: Adam Novak Assisted-by: Claude Code:claude-opus-5-5 --- src/testHelpers.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/testHelpers.js b/src/testHelpers.js index 019e049e..18a79dcf 100644 --- a/src/testHelpers.js +++ b/src/testHelpers.js @@ -13,6 +13,15 @@ export function findJestState() { // https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts#L67-L69 // https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts#L26-L85 // TODO: This is not a public Jest API and may break on a Jest upgrade. + // + // Importing getState() from jest-circus would get the wrong state. Jest + // loads its own copy of jest-circus from an internal module registry, and + // test code that imports jest-circus gets a second copy from the normal + // registry, which makes its own symbol and state with none of the Jest + // configuration applied. The runner's symbol is found here because it is + // added to the global first. See: + // https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-runtime/src/index.ts#L803-L811 + // https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-runtime/src/index.ts#L849-L870 const stateSymbol = Object.getOwnPropertySymbols(globalThis).find( (s) => s.description === "JEST_STATE_SYMBOL" ); From 3b6e35bfd5b0279d6581fcfa7b03a212fe76c728 Mon Sep 17 00:00:00 2001 From: Automated Commit Date: Wed, 25 Nov 2026 15:02:30 -0500 Subject: [PATCH 5/7] Shorten comment on why findJestState can't import jest-circus Co-authored-by: Adam Novak Assisted-by: Claude Code:claude-opus-5-5 --- src/testHelpers.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/testHelpers.js b/src/testHelpers.js index 18a79dcf..a8513282 100644 --- a/src/testHelpers.js +++ b/src/testHelpers.js @@ -14,12 +14,8 @@ export function findJestState() { // https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts#L26-L85 // TODO: This is not a public Jest API and may break on a Jest upgrade. // - // Importing getState() from jest-circus would get the wrong state. Jest - // loads its own copy of jest-circus from an internal module registry, and - // test code that imports jest-circus gets a second copy from the normal - // registry, which makes its own symbol and state with none of the Jest - // configuration applied. The runner's symbol is found here because it is - // added to the global first. See: + // Jest gives the code under test its own isolated module registry, so we + // can't get at the real Jest state by importing jest-circus. See: // https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-runtime/src/index.ts#L803-L811 // https://github.com/jestjs/jest/blob/67c1aa20c5fec31366d733e901fee2b981cb1850/packages/jest-runtime/src/index.ts#L849-L870 const stateSymbol = Object.getOwnPropertySymbols(globalThis).find( From f142cb10e10f059868845aa5385958a1882f75ea Mon Sep 17 00:00:00 2001 From: Automated Commit Date: Wed, 25 Nov 2026 15:16:33 -0500 Subject: [PATCH 6/7] Fold configuredTimeout into timeoutAtLeast Co-authored-by: Adam Novak Assisted-by: Claude Code:claude-opus-5-5 --- src/testHelpers.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/testHelpers.js b/src/testHelpers.js index a8513282..a441a58e 100644 --- a/src/testHelpers.js +++ b/src/testHelpers.js @@ -24,15 +24,14 @@ export function findJestState() { return stateSymbol && globalThis[stateSymbol]; } -// Get the configured Jest test timeout, or a default value if it is -// unavailable. -function configuredTimeout() { - const timeout = findJestState()?.testTimeout; - return typeof timeout === "number" ? timeout : JEST_BUILTIN_TIMEOUT; -} - // Get a per-test timeout of at least ms, or longer if Jest's default is // longer. export function timeoutAtLeast(ms) { - return Math.max(ms, configuredTimeout()); + // Use the configured Jest test timeout, or a default value if it is + // unavailable. + let configured = findJestState()?.testTimeout; + if (typeof configured !== "number") { + configured = JEST_BUILTIN_TIMEOUT; + } + return Math.max(ms, configured); } From f6781951d0ce9b119e6088975bdf9680bcedcc55 Mon Sep 17 00:00:00 2001 From: Automated Commit Date: Wed, 25 Nov 2026 15:18:35 -0500 Subject: [PATCH 7/7] Use || for the timeoutAtLeast fallback Co-authored-by: Adam Novak Assisted-by: Claude Code:claude-opus-5-5 --- src/testHelpers.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/testHelpers.js b/src/testHelpers.js index a441a58e..7f8c1a59 100644 --- a/src/testHelpers.js +++ b/src/testHelpers.js @@ -29,9 +29,5 @@ export function findJestState() { export function timeoutAtLeast(ms) { // Use the configured Jest test timeout, or a default value if it is // unavailable. - let configured = findJestState()?.testTimeout; - if (typeof configured !== "number") { - configured = JEST_BUILTIN_TIMEOUT; - } - return Math.max(ms, configured); + return Math.max(ms, findJestState()?.testTimeout || JEST_BUILTIN_TIMEOUT); }