Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/TrackPicker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 { timeoutAtLeast } from "../testHelpers";

describe("TrackPicker", () => {
const tracks = {
Expand Down Expand Up @@ -184,7 +185,7 @@ describe("TrackPicker", () => {

expect(fakeOnChange).toHaveBeenCalledTimes(2);
expect(fakeOnChange).toHaveBeenCalledWith(newTracks);
}, 50000);
}, timeoutAtLeast(50000));

it("should close when the exit button is pressed", async () => {
const fakeOnChange = jest.fn();
Expand Down
5 changes: 3 additions & 2 deletions src/end-to-end.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 { timeoutAtLeast } from "./testHelpers";

const getRegionInput = () => {
// Helper function to select the Region input box
Expand Down Expand Up @@ -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&region=ref%3A1-100&dataType=built-in&simplify=false&removeSequences=false";
// Make sure link has changed after pressing go
expect(fakeClipboard).toEqual(expectedLinkCactus);
}, 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
Expand Down Expand Up @@ -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.
}, 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?
3 changes: 2 additions & 1 deletion src/scripts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import "./config-server.mjs";

import { find_vg } from "./vg.mjs";
import { timeoutAtLeast } from "./testHelpers";

import { mkdtemp, rm, cp, open, access } from 'node:fs/promises';
import { join } from 'node:path';
Expand Down Expand Up @@ -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);
}, timeoutAtLeast(30000));


33 changes: 33 additions & 0 deletions src/testHelpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.
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.
//
// 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(
(s) => s.description === "JEST_STATE_SYMBOL"
);
return stateSymbol && globalThis[stateSymbol];
}

// Get a per-test timeout of at least ms, or longer if Jest's default is
// longer.
export function timeoutAtLeast(ms) {
// Use the configured Jest test timeout, or a default value if it is
// unavailable.
return Math.max(ms, findJestState()?.testTimeout || JEST_BUILTIN_TIMEOUT);
}
Loading