mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 05:42:19 +00:00
Every browser test iframe is named "vitest-iframe" and the Playwright provider looks the frame up by that name. Once a page runs a second file, the first file's iframe can still be found until its detach event arrives, so the second file's first click lands in a frame that is going away and fails with "Frame was detached". With fifteen browser files and at most twelve pages, three pages now run two files each, and a full local run failed this way in four of five tries. The setup now waits until the frame found by name is its own.
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
/**
|
|
* Setup for the `browser` project (`*.browser.test.tsx`, headless Chromium).
|
|
*
|
|
* - The app stylesheet, compiled by Vite through the project's PostCSS
|
|
* config, so components lay out and hide as they do in the app, under the
|
|
* theme class the boot script sets for a first visit (`dark`, see
|
|
* `src/lib/pwa/theme-color.ts`); without one no colour token resolves.
|
|
* - The EN catalog, the fallback floor of every `t()` chain, loaded through
|
|
* the production loader. `renderWithApp` loads any other locale it is
|
|
* asked for.
|
|
* - After every test: the real `fetch`, the real clock, the page's starting
|
|
* address and an empty `localStorage` come back, so a stub, a pinned date,
|
|
* a URL write or a remembered preference never reaches the next test. Rendered
|
|
* trees are unmounted by `vitest-browser-react` itself.
|
|
*/
|
|
import "@/app/globals.css";
|
|
|
|
import { afterEach, beforeAll, beforeEach, vi } from "vitest";
|
|
import { commands } from "vitest/browser";
|
|
|
|
import { loadMessages } from "@/lib/i18n/load-locale";
|
|
|
|
import { restoreFetch } from "./fetch-stub";
|
|
import { rememberAddress, restoreAddress } from "./url";
|
|
|
|
document.documentElement.classList.add("dark");
|
|
|
|
declare module "vitest/browser" {
|
|
interface BrowserCommands {
|
|
/** Waits until the provider's frame lookup finds this file's iframe. */
|
|
awaitOwnFrame: () => Promise<void>;
|
|
}
|
|
}
|
|
|
|
beforeAll(async () => {
|
|
// See `awaitOwnFrame` in vitest.config.mts.
|
|
await commands.awaitOwnFrame();
|
|
await loadMessages("en");
|
|
});
|
|
|
|
beforeEach(() => {
|
|
rememberAddress();
|
|
});
|
|
|
|
afterEach(() => {
|
|
restoreFetch();
|
|
vi.useRealTimers();
|
|
restoreAddress();
|
|
window.localStorage.clear();
|
|
});
|