@vitest/browser-playwright 4.0.0-beta.14

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.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # @vitest/browser-playwright
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/@vitest/browser-playwright?color=a1b858&label=)](https://www.npmjs.com/package/@vitest/browser-playwright)
4
+
5
+ Run your Vitest [browser tests](https://vitest.dev/guide/browser/) using [playwright](https://playwright.dev/docs/api/class-playwright) API. Note that Vitest does not use playwright as a test runner, but only as a browser provider.
6
+
7
+ We recommend using this package if you are already using playwright in your project or if you do not have any E2E tests yet.
8
+
9
+ ## Installation
10
+
11
+ Install the package with your favorite package manager:
12
+
13
+ ```sh
14
+ npm install -D @vitest/browser-playwright
15
+ # or
16
+ yarn add -D @vitest/browser-playwright
17
+ # or
18
+ pnpm add -D @vitest/browser-playwright
19
+ ```
20
+
21
+ Then specify it in the `browser.provider` field of your Vitest configuration:
22
+
23
+ ```ts
24
+ // vitest.config.ts
25
+ import { defineConfig } from 'vitest/config'
26
+ import { playwright } from '@vitest/browser-playwright'
27
+
28
+ export default defineConfig({
29
+ test: {
30
+ browser: {
31
+ provider: playwright({
32
+ // ...custom playwright options
33
+ }),
34
+ instances: [
35
+ { name: 'chromium' },
36
+ ],
37
+ },
38
+ },
39
+ })
40
+ ```
41
+
42
+ Then run Vitest in the browser mode:
43
+
44
+ ```sh
45
+ npx vitest --browser
46
+ ```
47
+
48
+ [GitHub](https://github.com/vitest-dev/vitest/tree/main/packages/browser-playwright) | [Documentation](https://vitest.dev/guide/browser/playwright)
package/context.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '@vitest/browser/context'
@@ -0,0 +1,110 @@
1
+ import { Page, Frame, FrameLocator, BrowserContext, LaunchOptions, ConnectOptions, BrowserContextOptions, Browser } from 'playwright';
2
+ import { Protocol } from 'playwright-core/types/protocol';
3
+ import { ScreenshotMatcherOptions, ScreenshotComparatorRegistry, Locator } from 'vitest/browser';
4
+ import { BrowserProviderOption, BrowserProvider, BrowserModuleMocker, TestProject, CDPSession } from 'vitest/node';
5
+ export { defineBrowserCommand } from '@vitest/browser';
6
+
7
+ declare const playwrightBrowsers: readonly ["firefox", "webkit", "chromium"];
8
+ type PlaywrightBrowser = (typeof playwrightBrowsers)[number];
9
+ interface PlaywrightProviderOptions {
10
+ /**
11
+ * The options passed down to [`playwright.connect`](https://playwright.dev/docs/api/class-browsertype#browser-type-launch) method.
12
+ * @see {@link https://playwright.dev/docs/api/class-browsertype#browser-type-launch}
13
+ */
14
+ launchOptions?: Omit<LaunchOptions, "tracesDir">;
15
+ /**
16
+ * The options passed down to [`playwright.connect`](https://playwright.dev/docs/api/class-browsertype#browser-type-connect) method.
17
+ *
18
+ * This is used only if you connect remotely to the playwright instance via a WebSocket connection.
19
+ * @see {@link https://playwright.dev/docs/api/class-browsertype#browser-type-connect}
20
+ */
21
+ connectOptions?: ConnectOptions & {
22
+ wsEndpoint: string;
23
+ };
24
+ /**
25
+ * The options passed down to [`browser.newContext`](https://playwright.dev/docs/api/class-browser#browser-new-context) method.
26
+ * @see {@link https://playwright.dev/docs/api/class-browser#browser-new-context}
27
+ */
28
+ contextOptions?: Omit<BrowserContextOptions, "ignoreHTTPSErrors" | "serviceWorkers">;
29
+ /**
30
+ * The maximum time in milliseconds to wait for `userEvent` action to complete.
31
+ * @default 0 (no timeout)
32
+ */
33
+ actionTimeout?: number;
34
+ }
35
+ declare function playwright(options?: PlaywrightProviderOptions): BrowserProviderOption<PlaywrightProviderOptions>;
36
+ declare class PlaywrightBrowserProvider implements BrowserProvider {
37
+ private project;
38
+ private options;
39
+ name: "playwright";
40
+ supportsParallelism: boolean;
41
+ browser: Browser | null;
42
+ contexts: Map<string, BrowserContext>;
43
+ pages: Map<string, Page>;
44
+ mocker: BrowserModuleMocker;
45
+ browserName: PlaywrightBrowser;
46
+ private browserPromise;
47
+ private closing;
48
+ tracingContexts: Set<string>;
49
+ pendingTraces: Map<string, string>;
50
+ initScripts: string[];
51
+ constructor(project: TestProject, options: PlaywrightProviderOptions);
52
+ private openBrowser;
53
+ private createMocker;
54
+ private createContext;
55
+ getPage(sessionId: string): Page;
56
+ getCommandsContext(sessionId: string): {
57
+ page: Page;
58
+ context: BrowserContext;
59
+ frame: () => Promise<Frame>;
60
+ readonly iframe: FrameLocator;
61
+ };
62
+ private openBrowserPage;
63
+ openPage(sessionId: string, url: string): Promise<void>;
64
+ private _throwIfClosing;
65
+ getCDPSession(sessionid: string): Promise<CDPSession>;
66
+ close(): Promise<void>;
67
+ }
68
+ declare module "vitest/node" {
69
+ interface BrowserCommandContext {
70
+ page: Page;
71
+ frame(): Promise<Frame>;
72
+ iframe: FrameLocator;
73
+ context: BrowserContext;
74
+ }
75
+ interface _BrowserNames {
76
+ playwright: PlaywrightBrowser;
77
+ }
78
+ interface ToMatchScreenshotOptions extends Omit<ScreenshotMatcherOptions, "comparatorName" | "comparatorOptions"> {}
79
+ interface ToMatchScreenshotComparators extends ScreenshotComparatorRegistry {}
80
+ }
81
+ type PWHoverOptions = NonNullable<Parameters<Page["hover"]>[1]>;
82
+ type PWClickOptions = NonNullable<Parameters<Page["click"]>[1]>;
83
+ type PWDoubleClickOptions = NonNullable<Parameters<Page["dblclick"]>[1]>;
84
+ type PWFillOptions = NonNullable<Parameters<Page["fill"]>[2]>;
85
+ type PWScreenshotOptions = NonNullable<Parameters<Page["screenshot"]>[0]>;
86
+ type PWSelectOptions = NonNullable<Parameters<Page["selectOption"]>[2]>;
87
+ type PWDragAndDropOptions = NonNullable<Parameters<Page["dragAndDrop"]>[2]>;
88
+ type PWSetInputFiles = NonNullable<Parameters<Page["setInputFiles"]>[2]>;
89
+ declare module "vitest/browser" {
90
+ interface UserEventHoverOptions extends PWHoverOptions {}
91
+ interface UserEventClickOptions extends PWClickOptions {}
92
+ interface UserEventDoubleClickOptions extends PWDoubleClickOptions {}
93
+ interface UserEventTripleClickOptions extends PWClickOptions {}
94
+ interface UserEventFillOptions extends PWFillOptions {}
95
+ interface UserEventSelectOptions extends PWSelectOptions {}
96
+ interface UserEventDragAndDropOptions extends PWDragAndDropOptions {}
97
+ interface UserEventUploadOptions extends PWSetInputFiles {}
98
+ interface ScreenshotOptions extends Omit<PWScreenshotOptions, "mask"> {
99
+ mask?: ReadonlyArray<Element | Locator> | undefined;
100
+ }
101
+ interface CDPSession {
102
+ send<T extends keyof Protocol.CommandParameters>(method: T, params?: Protocol.CommandParameters[T]): Promise<Protocol.CommandReturnValues[T]>;
103
+ on<T extends keyof Protocol.Events>(event: T, listener: (payload: Protocol.Events[T]) => void): this;
104
+ once<T extends keyof Protocol.Events>(event: T, listener: (payload: Protocol.Events[T]) => void): this;
105
+ off<T extends keyof Protocol.Events>(event: T, listener: (payload: Protocol.Events[T]) => void): this;
106
+ }
107
+ }
108
+
109
+ export { PlaywrightBrowserProvider, playwright };
110
+ export type { PlaywrightProviderOptions };