From ae3540e6ee92edc31a8a259cdb6ad219d2a00f37 Mon Sep 17 00:00:00 2001 From: kipavy Date: Tue, 18 Aug 2026 22:07:03 +0000 Subject: [PATCH] test(titlebar): hoist the TitleBar import out of the sync-state tests The first test imported ./TitleBar dynamically, so vitest cold-transformed the component's whole dependency graph inside that test's 5s timeout. Under load the transform alone exceeded it and the first test failed while the second passed on the warm cache. Import once in beforeAll, which carries its own timeout and is not billed to any single test. --- .../layout/TitleBar.syncState.test.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/components/layout/TitleBar.syncState.test.tsx b/src/components/layout/TitleBar.syncState.test.tsx index de6782a7e..53f7b7eed 100644 --- a/src/components/layout/TitleBar.syncState.test.tsx +++ b/src/components/layout/TitleBar.syncState.test.tsx @@ -1,4 +1,4 @@ -import { describe, test, expect, vi, beforeEach, afterEach } from "vitest"; +import { describe, test, expect, vi, beforeAll, beforeEach, afterEach } from "vitest"; import { render, cleanup } from "@testing-library/react"; import { usePluginStateStore } from "@/stores/pluginStateStore"; import { __resetGistSyncStateWarnings } from "@/services/syncStatus"; @@ -25,6 +25,15 @@ vi.mock("@/utils/icons", () => ({ const PLUGIN_ID = "plugin-gist-sync"; +// TitleBar pulls in a large dependency graph that vitest must cold-transform +// on first import. Under load that transform alone can exceed the default +// 5s test timeout, so it's paid once here in beforeAll (unbounded by any +// single test's timeout) rather than inside each test via a per-test import. +let TitleBar: (typeof import("./TitleBar"))["default"]; +beforeAll(async () => { + ({ default: TitleBar } = await import("./TitleBar")); +}, 20000); + beforeEach(() => { usePluginStateStore.setState({ values: new Map() }); __resetGistSyncStateWarnings(); @@ -37,7 +46,7 @@ afterEach(cleanup); // (root.children dropped to 0). This renders the real TitleBar against that exact // malformed publish and proves it no longer crashes. describe("TitleBar + malformed gist-sync state", () => { - test("renders without throwing when lastSync is published as an ISO string", async () => { + test("renders without throwing when lastSync is published as an ISO string", () => { usePluginStateStore.getState().publish(PLUGIN_ID, "sync-state", { status: "success", lastSync: "2026-01-01T00:00:00.000Z", @@ -46,11 +55,10 @@ describe("TitleBar + malformed gist-sync state", () => { configured: true, }); - const { default: TitleBar } = await import("./TitleBar"); expect(() => render()).not.toThrow(); }); - test("renders without throwing when lastSync is published as unparseable garbage", async () => { + test("renders without throwing when lastSync is published as unparseable garbage", () => { usePluginStateStore.getState().publish(PLUGIN_ID, "sync-state", { status: "success", lastSync: "not-a-date", @@ -59,7 +67,6 @@ describe("TitleBar + malformed gist-sync state", () => { configured: true, }); - const { default: TitleBar } = await import("./TitleBar"); expect(() => render()).not.toThrow(); }); });