fix: more vitest speedup

This commit is contained in:
Julian Sommer
2026-08-19 11:46:17 +10:00
parent bc2da9cdf0
commit 4e36b4ee6c
2 changed files with 15 additions and 0 deletions
@@ -1,3 +1,4 @@
import type * as TestingLibraryReact from "@testing-library/react"
import { cleanup } from "@testing-library/react"
import "@testing-library/jest-dom/vitest"
import { afterEach, vi } from "vitest"
@@ -8,6 +9,19 @@ afterEach(() => {
cleanup()
})
// waitFor wakes on DOM mutations, otherwise it polls every 50ms. renderHook
// tests settle without touching the DOM, so each one pays a full tick.
vi.mock("@testing-library/react", async (importOriginal) => {
const actual = await importOriginal<typeof TestingLibraryReact>()
return {
...actual,
waitFor: async (
callback: Parameters<typeof actual.waitFor>[0],
options?: Parameters<typeof actual.waitFor>[1],
) => await actual.waitFor(callback, { interval: 1, ...options }),
}
})
// Components sign requests with the region the server reports, which the app
// normally loads before rendering. Seed it through the real code path so every
// component test has one without stubbing fetch itself.
@@ -42,6 +42,7 @@ export default defineConfig(({ mode }) => ({
environment: "happy-dom",
setupFiles: "./src/test/setup.ts",
clearMocks: true,
pool: "threads",
coverage: {
include: ["src/**/*.{ts,tsx}"],
exclude: [