Open History to see the last commit
1import { beforeEach } from "vite-plus/test";
2import { commands } from "vite-plus/test/browser";
3
4import { initializeI18n } from "../src/i18n/initializeI18n";
5
6declare module "vite-plus/test/browser" {
7 interface BrowserCommands {
8 /** Defined in vite.config.ts. Moves Playwright's mouse off the page. */
9 resetPointer: () => Promise<void>;
10 /** Defined in vite.config.ts. Presses the primary button where the mouse is, without releasing. */
11 pointerDown: () => Promise<void>;
12 /** Defined in vite.config.ts. Releases the primary button. */
13 pointerUp: () => Promise<void>;
14 }
15}
16
17// Files in one browser session share an origin, so storage a previous file persisted (a collapsed
18// sidebar folder, say, or a cached server config) would seed this file's stores when they load.
19// Setup runs before those imports.
20localStorage.clear();
21sessionStorage.clear();
22await Promise.all(
23 (await indexedDB.databases()).map(
24 ({ name }) =>
25 new Promise<void>((resolve, reject) => {
26 if (name === undefined) return resolve();
27 const request = indexedDB.deleteDatabase(name);
28 request.onsuccess = () => resolve();
29 request.onerror = () => reject(request.error);
30 }),
31 ),
32);
33
34// Playwright's mouse outlives each test and each file, so whatever the next test mounts
35// under its last position starts hovered. Registered here rather than in render() so tests
36// that mount without it are covered too. Before each test, not after: a timed-out test keeps
37// running and can move the mouse after its own afterEach.
38beforeEach(async () => {
39 await commands.resetPointer();
40});
41
42// The app initializes GT at startup; components using its hooks need the same here.
43initializeI18n();