@vitest/browser 4.0.0-beta.13 → 4.0.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/context.d.ts +50 -9
  2. package/context.js +3 -2
  3. package/dist/client/.vite/manifest.json +2 -2
  4. package/dist/client/__vitest__/assets/{index-C15NF4dG.js → index-CKAjAT2u.js} +1 -1
  5. package/dist/client/__vitest__/index.html +1 -1
  6. package/dist/client/__vitest_browser__/{orchestrator-Pdu7HCGX.js → orchestrator-Ce7D5fGP.js} +8 -6
  7. package/dist/client/__vitest_browser__/{tester-DYNLfPFH.js → tester-Vm4ppAv-.js} +4 -1
  8. package/dist/client/orchestrator.html +1 -1
  9. package/dist/client/tester/tester.html +1 -1
  10. package/dist/client.js +1 -1
  11. package/dist/context.js +70 -12
  12. package/dist/expect-element.js +1 -1
  13. package/dist/{public-utils-B6exS8fl.js → index-BnLTaCRv.js} +3 -3
  14. package/dist/index.d.ts +36 -172
  15. package/dist/index.js +515 -1487
  16. package/dist/{locators/index.d.ts → locators.d.ts} +25 -2
  17. package/dist/locators.js +1 -0
  18. package/jest-dom.d.ts +5 -5
  19. package/matchers.d.ts +1 -1
  20. package/package.json +11 -33
  21. package/utils.d.ts +5 -5
  22. package/dist/index-BPDFwkoW.js +0 -1
  23. package/dist/index-CwoiDq7G.js +0 -6
  24. package/dist/locators/index.js +0 -1
  25. package/dist/locators/playwright.js +0 -1
  26. package/dist/locators/preview.js +0 -1
  27. package/dist/locators/webdriverio.js +0 -1
  28. package/dist/providers/playwright.d.ts +0 -105
  29. package/dist/providers/playwright.js +0 -385
  30. package/dist/providers/preview.d.ts +0 -16
  31. package/dist/providers/preview.js +0 -44
  32. package/dist/providers/webdriverio.d.ts +0 -51
  33. package/dist/providers/webdriverio.js +0 -206
  34. package/dist/utils.js +0 -1
  35. package/providers.d.ts +0 -7
package/dist/index.d.ts CHANGED
@@ -1,172 +1,36 @@
1
- import { Plugin } from 'vitest/config';
2
- import { CDPSession, BrowserServerState as BrowserServerState$1, ProjectBrowser as ProjectBrowser$1, TestProject, BrowserProvider, Vitest, ResolvedConfig, Vite, BrowserCommand, BrowserScript, ProcessPool } from 'vitest/node';
3
- import { StackTraceParserOptions } from '@vitest/utils/source-map';
4
- import { ViteDevServer, HtmlTagDescriptor } from 'vite';
5
- import { CancelReason, BrowserTesterOptions, TestExecutionMethod, RunnerTestFile, AfterSuiteRunMeta, UserConsoleLog, SnapshotResult, SerializedConfig, TestError, ParsedStack } from 'vitest';
6
- import { ServerIdResolution, ServerMockResolution, MockedModuleSerialized } from '@vitest/mocker';
7
- import { TestAnnotation, TaskResultPack, TaskEventPack } from '@vitest/runner';
8
-
9
- type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never;
10
- type ReturnType<T> = T extends (...args: any) => infer R ? R : never;
11
- type PromisifyFn<T> = ReturnType<T> extends Promise<any> ? T : (...args: ArgumentsType<T>) => Promise<Awaited<ReturnType<T>>>;
12
- type BirpcFn<T> = PromisifyFn<T> & {
13
- /**
14
- * Send event without asking for response
15
- */
16
- asEvent: (...args: ArgumentsType<T>) => void;
17
- };
18
- type BirpcReturn<RemoteFunctions, LocalFunctions = Record<string, never>> = {
19
- [K in keyof RemoteFunctions]: BirpcFn<RemoteFunctions[K]>;
20
- } & {
21
- $functions: LocalFunctions;
22
- $close: (error?: Error) => void;
23
- $closed: boolean;
24
- $rejectPendingCalls: (handler?: PendingCallHandler) => Promise<void>[];
25
- };
26
- type PendingCallHandler = (options: Pick<PromiseEntry, 'method' | 'reject'>) => void | Promise<void>;
27
- interface PromiseEntry {
28
- resolve: (arg: any) => void;
29
- reject: (error: any) => void;
30
- method: string;
31
- timeoutId?: ReturnType<typeof setTimeout>;
32
- }
33
- declare const setTimeout: typeof globalThis.setTimeout;
34
-
35
- interface WebSocketBrowserHandlers {
36
- resolveSnapshotPath: (testPath: string) => string;
37
- resolveSnapshotRawPath: (testPath: string, rawPath: string) => string;
38
- onUnhandledError: (error: unknown, type: string) => Promise<void>;
39
- onQueued: (method: TestExecutionMethod, file: RunnerTestFile) => void;
40
- onCollected: (method: TestExecutionMethod, files: RunnerTestFile[]) => Promise<void>;
41
- onTaskAnnotate: (testId: string, annotation: TestAnnotation) => Promise<TestAnnotation>;
42
- onTaskUpdate: (method: TestExecutionMethod, packs: TaskResultPack[], events: TaskEventPack[]) => void;
43
- onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void;
44
- cancelCurrentRun: (reason: CancelReason) => void;
45
- getCountOfFailedTests: () => number;
46
- readSnapshotFile: (id: string) => Promise<string | null>;
47
- saveSnapshotFile: (id: string, content: string) => Promise<void>;
48
- removeSnapshotFile: (id: string) => Promise<void>;
49
- sendLog: (method: TestExecutionMethod, log: UserConsoleLog) => void;
50
- snapshotSaved: (snapshot: SnapshotResult) => void;
51
- debug: (...args: string[]) => void;
52
- resolveId: (id: string, importer?: string) => Promise<ServerIdResolution | null>;
53
- triggerCommand: <T>(sessionId: string, command: string, testPath: string | undefined, payload: unknown[]) => Promise<T>;
54
- resolveMock: (id: string, importer: string, options: {
55
- mock: "spy" | "factory" | "auto";
56
- }) => Promise<ServerMockResolution>;
57
- invalidate: (ids: string[]) => void;
58
- getBrowserFileSourceMap: (id: string) => SourceMap | null | {
59
- mappings: "";
60
- } | undefined;
61
- wdioSwitchContext: (direction: "iframe" | "parent") => void;
62
- registerMock: (sessionId: string, mock: MockedModuleSerialized) => void;
63
- unregisterMock: (sessionId: string, id: string) => void;
64
- clearMocks: (sessionId: string) => void;
65
- sendCdpEvent: (sessionId: string, event: string, payload?: Record<string, unknown>) => unknown;
66
- trackCdpEvent: (sessionId: string, type: "on" | "once" | "off", event: string, listenerId: string) => void;
67
- }
68
- interface WebSocketBrowserEvents {
69
- onCancel: (reason: CancelReason) => void;
70
- createTesters: (options: BrowserTesterOptions) => Promise<void>;
71
- cleanupTesters: () => Promise<void>;
72
- cdpEvent: (event: string, payload: unknown) => void;
73
- resolveManualMock: (url: string) => Promise<{
74
- url: string;
75
- keys: string[];
76
- responseId: string;
77
- }>;
78
- }
79
- type WebSocketBrowserRPC = BirpcReturn<WebSocketBrowserEvents, WebSocketBrowserHandlers>;
80
- interface SourceMap {
81
- file: string;
82
- mappings: string;
83
- names: string[];
84
- sources: string[];
85
- sourcesContent?: string[];
86
- version: number;
87
- toString: () => string;
88
- toUrl: () => string;
89
- }
90
-
91
- declare class BrowserServerCDPHandler {
92
- private session;
93
- private tester;
94
- private listenerIds;
95
- private listeners;
96
- constructor(session: CDPSession, tester: WebSocketBrowserRPC);
97
- send(method: string, params?: Record<string, unknown>): Promise<unknown>;
98
- on(event: string, id: string, once?: boolean): void;
99
- off(event: string, id: string): void;
100
- once(event: string, listener: string): void;
101
- }
102
-
103
- declare class BrowserServerState implements BrowserServerState$1 {
104
- readonly orchestrators: Map<string, WebSocketBrowserRPC>;
105
- readonly testers: Map<string, WebSocketBrowserRPC>;
106
- }
107
-
108
- declare class ProjectBrowser implements ProjectBrowser$1 {
109
- project: TestProject;
110
- base: string;
111
- testerHtml: Promise<string> | string;
112
- testerFilepath: string;
113
- provider: BrowserProvider;
114
- vitest: Vitest;
115
- config: ResolvedConfig;
116
- children: Set<ProjectBrowser>;
117
- parent: ParentBrowserProject;
118
- state: BrowserServerState;
119
- constructor(project: TestProject, base: string);
120
- get vite(): ViteDevServer;
121
- wrapSerializedConfig(): SerializedConfig;
122
- initBrowserProvider(project: TestProject): Promise<void>;
123
- parseErrorStacktrace(e: TestError, options?: StackTraceParserOptions): ParsedStack[];
124
- parseStacktrace(trace: string, options?: StackTraceParserOptions): ParsedStack[];
125
- close(): Promise<void>;
126
- }
127
-
128
- declare class ParentBrowserProject {
129
- project: TestProject;
130
- base: string;
131
- orchestratorScripts: string | undefined;
132
- faviconUrl: string;
133
- prefixOrchestratorUrl: string;
134
- prefixTesterUrl: string;
135
- manifest: Promise<Vite.Manifest> | Vite.Manifest;
136
- vite: Vite.ViteDevServer;
137
- private stackTraceOptions;
138
- orchestratorHtml: Promise<string> | string;
139
- injectorJs: Promise<string> | string;
140
- errorCatcherUrl: string;
141
- locatorsUrl: string | undefined;
142
- matchersUrl: string;
143
- stateJs: Promise<string> | string;
144
- commands: Record<string, BrowserCommand<any>>;
145
- children: Set<ProjectBrowser>;
146
- vitest: Vitest;
147
- config: ResolvedConfig;
148
- private sourceMapCache;
149
- constructor(project: TestProject, base: string);
150
- setServer(vite: Vite.ViteDevServer): void;
151
- spawn(project: TestProject): ProjectBrowser;
152
- parseErrorStacktrace(e: TestError, options?: StackTraceParserOptions): ParsedStack[];
153
- parseStacktrace(trace: string, options?: StackTraceParserOptions): ParsedStack[];
154
- readonly cdps: Map<string, BrowserServerCDPHandler>;
155
- private cdpSessionsPromises;
156
- ensureCDPHandler(sessionId: string, rpcId: string): Promise<BrowserServerCDPHandler>;
157
- removeCDPHandler(sessionId: string): void;
158
- formatScripts(scripts: BrowserScript[] | undefined): Promise<HtmlTagDescriptor[]>;
159
- resolveTesterUrl(pathname: string): {
160
- sessionId: string;
161
- testFile: string;
162
- };
163
- private retrieveSourceMapURL;
164
- }
165
-
166
- declare const distRoot: string;
167
-
168
- declare function createBrowserPool(vitest: Vitest): ProcessPool;
169
-
170
- declare function createBrowserServer(project: TestProject, configFile: string | undefined, prePlugins?: Plugin[], postPlugins?: Plugin[]): Promise<ParentBrowserProject>;
171
-
172
- export { ProjectBrowser, createBrowserPool, createBrowserServer, distRoot };
1
+ import { ResolvedConfig, BrowserCommand, BrowserServerFactory, BrowserProviderOption } from 'vitest/node';
2
+
3
+ declare enum DOM_KEY_LOCATION {
4
+ STANDARD = 0,
5
+ LEFT = 1,
6
+ RIGHT = 2,
7
+ NUMPAD = 3
8
+ }
9
+ interface keyboardKey {
10
+ /** Physical location on a keyboard */
11
+ code?: string;
12
+ /** Character or functional key descriptor */
13
+ key?: string;
14
+ /** Location on the keyboard for keys with multiple representation */
15
+ location?: DOM_KEY_LOCATION;
16
+ /** Does the character in `key` require/imply AltRight to be pressed? */
17
+ altGr?: boolean;
18
+ /** Does the character in `key` require/imply a shiftKey to be pressed? */
19
+ shift?: boolean;
20
+ }
21
+ declare function parseKeyDef(text: string): {
22
+ keyDef: keyboardKey;
23
+ releasePrevious: boolean;
24
+ releaseSelf: boolean;
25
+ repeat: number;
26
+ }[];
27
+ declare function resolveScreenshotPath(testPath: string, name: string, config: ResolvedConfig, customPath: string | undefined): string;
28
+
29
+ declare function defineBrowserCommand<T extends unknown[]>(fn: BrowserCommand<T>): BrowserCommand<T>;
30
+
31
+ declare const createBrowserServer: BrowserServerFactory;
32
+ declare function defineBrowserProvider<T extends object = object>(options: Omit<BrowserProviderOption<T>, "serverFactory" | "options"> & {
33
+ options?: T;
34
+ }): BrowserProviderOption;
35
+
36
+ export { createBrowserServer, defineBrowserCommand, defineBrowserProvider, parseKeyDef, resolveScreenshotPath };