-
-
Notifications
You must be signed in to change notification settings - Fork 764
Expand file tree
/
Copy pathcontext.ts
More file actions
47 lines (40 loc) · 1.6 KB
/
Copy pathcontext.ts
File metadata and controls
47 lines (40 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { createUserEvent, page } from "vite-plus/test/browser/context";
// This vite-plus build's `@vitest/browser/context` runtime only exports
// `createUserEvent`, `page`, `cdp`, `locators`, `utils` — there is no default
// `userEvent`, `server`, or `commands` export (the published `.d.ts` lists them,
// but they aren't in the runtime bundle). So we adapt here and re-export a
// single shared API surface for the e2e utils + tests to consume.
/** Shared userEvent instance (preserves keyboard/pointer state across calls). */
export const userEvent = createUserEvent();
export { page };
/**
* Triggers a custom browser command registered in `vite.config.browser.ts`
* (e.g. `positionalMouse`). The public `server.commands` API isn't exported in
* this build, so we go through the browser runner directly.
*/
export function triggerCommand<T = unknown>(
name: string,
args: unknown[] = [],
): Promise<T> {
return (window as any).__vitest_browser_runner__.commands.triggerCommand(
name,
args,
);
}
const ua = navigator.userAgent;
/** The browser instance the current test is running in. */
export const browserName: "chromium" | "firefox" | "webkit" = /Firefox/.test(ua)
? "firefox"
: /Chrome|Chromium|HeadlessChrome/.test(ua)
? "chromium"
: "webkit";
/**
* Platform modifier for `userEvent.keyboard` (Cmd on macOS, Ctrl elsewhere) —
* the equivalent of Playwright's `ControlOrMeta`. Derived from the browser the
* test runs in, since `server.platform` isn't available.
*/
export const MOD: "Meta" | "Control" = /Mac|iPhone|iPad/i.test(
navigator.platform || ua,
)
? "Meta"
: "Control";