@voidzero-dev/vite-plus-test 0.1.8 → 0.1.10
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/LICENSE.md +181 -1
- package/dist/@vitest/browser/client/.vite/manifest.json +6 -6
- package/dist/@vitest/browser/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-Di71CKDo.js +63 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.ico +0 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.svg +49 -4
- package/dist/@vitest/browser/client/__vitest__/index.html +2 -2
- package/dist/@vitest/browser/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
- package/dist/@vitest/browser/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
- package/dist/@vitest/browser/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
- package/dist/@vitest/browser/client/favicon.svg +49 -4
- package/dist/@vitest/browser/client/orchestrator.html +2 -2
- package/dist/@vitest/browser/client/tester/tester.html +2 -2
- package/dist/@vitest/browser/client.js +20 -13
- package/dist/@vitest/browser/context.d.ts +160 -10
- package/dist/@vitest/browser/context.js +108 -22
- package/dist/@vitest/browser/expect-element.js +23 -28
- package/dist/@vitest/browser/index-5Pe7X7sp.js +7 -0
- package/dist/@vitest/browser/index.d.ts +20 -2
- package/dist/@vitest/browser/index.js +5706 -159
- package/dist/@vitest/browser/locators.d.ts +14 -3
- package/dist/@vitest/browser/locators.js +1 -1
- package/dist/@vitest/browser-playwright/index.d.ts +22 -5
- package/dist/@vitest/browser-playwright/index.js +169 -61
- package/dist/@vitest/browser-preview/index.d.ts +14 -1
- package/dist/@vitest/browser-preview/locators.js +31 -18
- package/dist/@vitest/browser-webdriverio/index.d.ts +17 -3
- package/dist/@vitest/browser-webdriverio/index.js +22 -2
- package/dist/@vitest/browser-webdriverio/locators.js +84 -7
- package/dist/@vitest/expect/index.d.ts +172 -54
- package/dist/@vitest/expect/index.js +124 -67
- package/dist/@vitest/mocker/auto-register.js +1 -0
- package/dist/@vitest/mocker/automock.d.ts +1 -0
- package/dist/@vitest/mocker/automock.js +5 -0
- package/dist/@vitest/mocker/browser.d.ts +4 -4
- package/dist/@vitest/mocker/browser.js +1 -0
- package/dist/@vitest/mocker/chunk-automock.js +182 -14
- package/dist/@vitest/mocker/chunk-helpers.js +44 -0
- package/dist/@vitest/mocker/chunk-hoistMocks.js +659 -0
- package/dist/@vitest/mocker/chunk-mocker.js +41 -30
- package/dist/@vitest/mocker/chunk-registry.js +21 -7
- package/dist/@vitest/mocker/chunk-utils.js +18 -7
- package/dist/@vitest/mocker/hoistMocks.d-w2ILr1dG.d.ts +739 -0
- package/dist/@vitest/mocker/{index.d-C-sLYZi-.d.ts → index.d-B41z0AuW.d.ts} +1 -1
- package/dist/@vitest/mocker/index.d.ts +2 -2
- package/dist/@vitest/mocker/index.js +18 -3
- package/dist/@vitest/mocker/{mocker.d-TnKRhz7N.d.ts → mocker.d-QEntlm6J.d.ts} +10 -5
- package/dist/@vitest/mocker/node.d.ts +5 -734
- package/dist/@vitest/mocker/node.js +29 -587
- package/dist/@vitest/mocker/redirect.js +4 -4
- package/dist/@vitest/mocker/register.d.ts +3 -3
- package/dist/@vitest/mocker/register.js +1 -0
- package/dist/@vitest/mocker/transforms.d.ts +6 -0
- package/dist/@vitest/mocker/transforms.js +8 -0
- package/dist/@vitest/mocker/{types.d-B8CCKmHt.d.ts → types.d-BjI5eAwu.d.ts} +23 -7
- package/dist/@vitest/pretty-format/index.d.ts +11 -1
- package/dist/@vitest/pretty-format/index.js +33 -4
- package/dist/@vitest/runner/chunk-tasks.js +305 -37
- package/dist/@vitest/runner/index.d.ts +5 -6
- package/dist/@vitest/runner/index.js +1146 -455
- package/dist/@vitest/runner/{tasks.d-C7UxawJ9.d.ts → tasks.d-D2GKpdwQ.d.ts} +726 -55
- package/dist/@vitest/runner/types.d.ts +2 -182
- package/dist/@vitest/runner/utils.d.ts +16 -8
- package/dist/@vitest/runner/utils.js +1 -1
- package/dist/@vitest/snapshot/{environment.d-DHdQ1Csl.d.ts → environment.d-DOJxxZV9.d.ts} +2 -7
- package/dist/@vitest/snapshot/environment.d.ts +2 -1
- package/dist/@vitest/snapshot/environment.js +1 -1
- package/dist/@vitest/snapshot/index.d.ts +4 -3
- package/dist/@vitest/snapshot/index.js +21 -550
- package/dist/@vitest/snapshot/manager.d.ts +3 -2
- package/dist/@vitest/snapshot/manager.js +1 -1
- package/dist/@vitest/snapshot/{rawSnapshot.d-lFsMJFUd.d.ts → rawSnapshot.d-U2kJUxDr.d.ts} +1 -1
- package/dist/@vitest/spy/index.d.ts +34 -4
- package/dist/@vitest/spy/index.js +69 -19
- package/dist/@vitest/utils/diff.js +11 -9
- package/dist/@vitest/utils/display.d.ts +2 -1
- package/dist/@vitest/utils/display.js +38 -5
- package/dist/@vitest/utils/error.d.ts +2 -1
- package/dist/@vitest/utils/error.js +1 -2
- package/dist/@vitest/utils/helpers.d.ts +4 -1
- package/dist/@vitest/utils/helpers.js +43 -1
- package/dist/@vitest/utils/resolver.js +1 -2
- package/dist/@vitest/utils/serialize.js +6 -6
- package/dist/@vitest/utils/source-map/node.d.ts +6 -0
- package/dist/@vitest/utils/source-map/node.js +23 -0
- package/dist/@vitest/utils/source-map.js +15 -5
- package/dist/browser.d.ts +3 -2
- package/dist/browser.js +2 -2
- package/dist/chunks/acorn.B2iPLyUM.js +5958 -0
- package/dist/chunks/{base.CJ0Y4ePK.js → base.DM0-RqVb.js} +54 -16
- package/dist/chunks/{benchmark.B3N2zMcH.js → benchmark.D0SlKNbZ.js} +1 -1
- package/dist/chunks/{browser.d.ChKACdzH.d.ts → browser.d.X3SXoOCV.d.ts} +4 -1
- package/dist/chunks/{cac.DVeoLl0M.js → cac.CWGDZnXT.js} +979 -20
- package/dist/chunks/{cli-api.B7PN_QUv.js → cli-api.DuT9iuvY.js} +8764 -7898
- package/dist/chunks/{config.d.Cy95HiCx.d.ts → config.d.EJLVE3es.d.ts} +30 -15
- package/dist/chunks/{console.Cf-YriPC.js → console.3WNpx0tS.js} +3 -2
- package/dist/chunks/{constants.D_Q9UYh-.js → constants.CPYnjOGj.js} +4 -2
- package/dist/chunks/coverage.Bri33R1t.js +1050 -0
- package/dist/chunks/{creator.DAmOKTvJ.js → creator.DgVhQm5q.js} +35 -4
- package/dist/chunks/{defaults.BOqNVLsY.js → defaults.CdU2lD-q.js} +4 -3
- package/dist/chunks/{global.d.B15mdLcR.d.ts → global.d.x-ILCfAE.d.ts} +1 -2
- package/dist/chunks/{globals.DOayXfHP.js → globals.BXNGLnTL.js} +11 -10
- package/dist/chunks/{coverage.AVPTjMgw.js → index.BCY_7LL2.js} +5 -959
- package/dist/chunks/{index.C5r1PdPD.js → index.CEzQDJGb.js} +1 -1
- package/dist/chunks/{index.D3XRDfWc.js → index.CMESou6r.js} +26 -1
- package/dist/chunks/{index.6Qv1eEA6.js → index.DGNSnENe.js} +95 -9
- package/dist/chunks/{index.M8mOzt4Y.js → index.DXMFO5MJ.js} +3279 -2914
- package/dist/chunks/{index.Z5E_ObnR.js → index.DlDSLQD3.js} +7 -3
- package/dist/chunks/{index.CyBMJtT7.js → index.EY6TCHpo.js} +10 -8
- package/dist/chunks/{index.D4KonVSU.js → index.og1WyBLx.js} +18 -3
- package/dist/chunks/{init-forks._y3TW739.js → init-forks.DeArv0jT.js} +1 -1
- package/dist/chunks/{init-threads.DBO2kn-p.js → init-threads.-2OUl4Nn.js} +1 -1
- package/dist/chunks/{init.B6MLFIaN.js → init.DICorXCo.js} +52 -13
- package/dist/chunks/native.DPzPHdi5.js +148 -0
- package/dist/chunks/nativeModuleMocker.DndvSdL6.js +206 -0
- package/dist/chunks/nativeModuleRunner.BIakptoF.js +36 -0
- package/dist/chunks/{node.Ce0vMQM7.js → node.COQbm6gK.js} +1 -1
- package/dist/chunks/{plugin.d.CtqpEehP.d.ts → plugin.d.BuW-flqo.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CWXNI2jG.d.ts → reporters.d.DVUYHHhe.d.ts} +328 -79
- package/dist/chunks/rpc.MzXet3jl.js +144 -0
- package/dist/chunks/{rpc.d.RH3apGEf.d.ts → rpc.d.BFMWpdph.d.ts} +10 -2
- package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.B41N_kPE.js} +3 -3
- package/dist/chunks/{startModuleRunner.DEj0jb3e.js → startVitestModuleRunner.C3ZR-4J3.js} +265 -405
- package/dist/chunks/{suite.d.BJWk38HB.d.ts → suite.d.udJtyAgw.d.ts} +1 -1
- package/dist/chunks/{vi.2VT5v0um.js → test.CTcmp4Su.js} +538 -181
- package/dist/chunks/{utils.DvEY5TfP.js → utils.BX5Fg8C4.js} +8 -1
- package/dist/chunks/{vm.D3epNOPZ.js → vm.Dh2rTtmP.js} +48 -8
- package/dist/chunks/{worker.d.Dyxm8DEL.d.ts → worker.d.B84sVRy0.d.ts} +2 -2
- package/dist/cli.js +6 -5
- package/dist/client/.vite/manifest.json +6 -6
- package/dist/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
- package/dist/client/__vitest__/assets/index-Di71CKDo.js +63 -0
- package/dist/client/__vitest__/favicon.ico +0 -0
- package/dist/client/__vitest__/favicon.svg +49 -4
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
- package/dist/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
- package/dist/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
- package/dist/client/favicon.svg +49 -4
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/tester/tester.html +2 -2
- package/dist/client.js +20 -13
- package/dist/config.cjs +3 -2
- package/dist/config.d.ts +13 -12
- package/dist/config.js +2 -2
- package/dist/context.js +108 -22
- package/dist/coverage.d.ts +12 -8
- package/dist/coverage.js +8 -5
- package/dist/environments.js +3 -1
- package/dist/expect-element.js +23 -23
- package/dist/index-5Pe7X7sp.js +7 -0
- package/dist/index.d.ts +66 -27
- package/dist/index.js +10 -9
- package/dist/locators.d.ts +14 -3
- package/dist/locators.js +1 -1
- package/dist/module-evaluator.d.ts +11 -1
- package/dist/module-evaluator.js +43 -26
- package/dist/node.d.ts +28 -14
- package/dist/node.js +42 -40
- package/dist/nodejs-worker-loader.js +41 -0
- package/dist/plugins/mocker-transforms.mjs +2 -0
- package/dist/plugins/utils-source-map-node.mjs +2 -0
- package/dist/reporters.d.ts +8 -8
- package/dist/reporters.js +7 -5
- package/dist/runners.d.ts +24 -5
- package/dist/runners.js +6 -6
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.js +35 -0
- package/dist/snapshot.js +4 -2
- package/dist/suite.d.ts +1 -1
- package/dist/suite.js +4 -2
- package/dist/vendor/blazediff_core.d.mts +1 -0
- package/dist/vendor/blazediff_core.mjs +117 -0
- package/dist/vendor/chai.mjs +4 -249
- package/dist/vendor/convert-source-map.d.mts +1 -0
- package/dist/vendor/convert-source-map.mjs +150 -0
- package/dist/vendor/expect-type.d.mts +14 -7
- package/dist/vendor/expect-type.mjs +5 -5
- package/dist/vendor/std-env.d.mts +131 -40
- package/dist/vendor/std-env.mjs +114 -117
- package/dist/worker.d.ts +6 -6
- package/dist/worker.js +27 -21
- package/dist/workers/forks.js +23 -17
- package/dist/workers/runVmTests.js +18 -16
- package/dist/workers/threads.js +23 -17
- package/dist/workers/vmForks.js +15 -12
- package/dist/workers/vmThreads.js +15 -12
- package/globals.d.ts +2 -0
- package/package.json +36 -27
- package/suppress-warnings.cjs +1 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +0 -57
- package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
- package/dist/@vitest/browser/index-D6m36C6U.js +0 -11
- package/dist/@vitest/utils/chunk-_commonjsHelpers.js +0 -5
- package/dist/@vitest/utils/highlight.d.ts +0 -9
- package/dist/@vitest/utils/highlight.js +0 -538
- package/dist/chunks/date.Bq6ZW5rf.js +0 -73
- package/dist/chunks/rpc.BoxB0q7B.js +0 -76
- package/dist/chunks/test.B8ej_ZHS.js +0 -254
- package/dist/client/__vitest__/assets/index-BUCFJtth.js +0 -57
- package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
- package/dist/index-D6m36C6U.js +0 -6
- package/dist/mocker.d.ts +0 -1
- package/dist/mocker.js +0 -1
- package/dist/module-runner.js +0 -17
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserEventClickOptions, UserEventClearOptions, UserEventHoverOptions, UserEventFillOptions, UserEventUploadOptions, UserEventDragAndDropOptions, UserEventSelectOptions, LocatorScreenshotOptions, LocatorByRoleOptions, LocatorOptions } from './index.js';
|
|
1
|
+
import { UserEventClickOptions, UserEventWheelOptions, UserEventClearOptions, UserEventHoverOptions, UserEventFillOptions, UserEventUploadOptions, UserEventDragAndDropOptions, UserEventSelectOptions, LocatorScreenshotOptions, MarkOptions, LocatorByRoleOptions, LocatorOptions, SelectorOptions } from './index.js';
|
|
2
2
|
|
|
3
3
|
type ClauseCombinator = '' | '>' | '+' | '~' | '>=';
|
|
4
4
|
type CSSFunctionArgument = CSSComplexSelector | number | string;
|
|
@@ -299,19 +299,23 @@ interface SelectorEngine {
|
|
|
299
299
|
declare function convertElementToCssSelector(element: Element): string;
|
|
300
300
|
declare function processTimeoutOptions<T extends {
|
|
301
301
|
timeout?: number;
|
|
302
|
-
}>(options_
|
|
302
|
+
}>(options_: T | undefined): T | undefined;
|
|
303
303
|
declare function getIframeScale(): number;
|
|
304
304
|
|
|
305
|
+
declare function ensureAwaited<T>(promise: (error?: Error) => Promise<T>): Promise<T>;
|
|
306
|
+
|
|
305
307
|
declare const selectorEngine: Ivya;
|
|
306
308
|
declare abstract class Locator {
|
|
307
309
|
abstract selector: string;
|
|
308
310
|
private _parsedSelector;
|
|
309
311
|
protected _container?: Element | undefined;
|
|
310
312
|
protected _pwSelector?: string | undefined;
|
|
313
|
+
protected _errorSource?: Error;
|
|
311
314
|
constructor();
|
|
312
315
|
click(options?: UserEventClickOptions): Promise<void>;
|
|
313
316
|
dblClick(options?: UserEventClickOptions): Promise<void>;
|
|
314
317
|
tripleClick(options?: UserEventClickOptions): Promise<void>;
|
|
318
|
+
wheel(options: UserEventWheelOptions): Promise<void>;
|
|
315
319
|
clear(options?: UserEventClearOptions): Promise<void>;
|
|
316
320
|
hover(options?: UserEventHoverOptions): Promise<void>;
|
|
317
321
|
unhover(options?: UserEventHoverOptions): Promise<void>;
|
|
@@ -326,6 +330,7 @@ declare abstract class Locator {
|
|
|
326
330
|
base64: string;
|
|
327
331
|
}>;
|
|
328
332
|
screenshot(options?: LocatorScreenshotOptions): Promise<string>;
|
|
333
|
+
mark(name: string, options?: MarkOptions): Promise<void>;
|
|
329
334
|
protected abstract locator(selector: string): Locator;
|
|
330
335
|
protected abstract elementLocator(element: Element): Locator;
|
|
331
336
|
getByRole(role: string, options?: LocatorByRoleOptions): Locator;
|
|
@@ -348,7 +353,13 @@ declare abstract class Locator {
|
|
|
348
353
|
last(): Locator;
|
|
349
354
|
toString(): string;
|
|
350
355
|
toJSON(): string;
|
|
356
|
+
findElement(options_?: SelectorOptions): Promise<HTMLElement | SVGElement>;
|
|
351
357
|
protected triggerCommand<T>(command: string, ...args: any[]): Promise<T>;
|
|
352
358
|
}
|
|
359
|
+
declare function triggerCommandWithTrace<T>(options: {
|
|
360
|
+
name: string;
|
|
361
|
+
arguments: unknown[];
|
|
362
|
+
errorSource?: Error | undefined;
|
|
363
|
+
}): Promise<T>;
|
|
353
364
|
|
|
354
|
-
export { Locator, convertElementToCssSelector, getByAltTextSelector, getByLabelSelector, getByPlaceholderSelector, getByRoleSelector, getByTestIdSelector, getByTextSelector, getByTitleSelector, getIframeScale, processTimeoutOptions, selectorEngine };
|
|
365
|
+
export { Locator, convertElementToCssSelector, ensureAwaited, getByAltTextSelector, getByLabelSelector, getByPlaceholderSelector, getByRoleSelector, getByTestIdSelector, getByTextSelector, getByTitleSelector, getIframeScale, processTimeoutOptions, selectorEngine, triggerCommandWithTrace };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{L as Locator,
|
|
1
|
+
export{L as Locator,o as convertElementToCssSelector,q as ensureAwaited,r as getByAltTextSelector,s as getByLabelSelector,t as getByPlaceholderSelector,u as getByRoleSelector,v as getByTestIdSelector,w as getByTextSelector,x as getByTitleSelector,y as getIframeScale,p as processTimeoutOptions,z as selectorEngine,A as triggerCommandWithTrace}from"./index-5Pe7X7sp.js";import'../../browser.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CustomComparatorsRegistry } from '../browser/index.js';
|
|
2
2
|
export { defineBrowserCommand } from '../browser/index.js';
|
|
3
|
-
import { Page, Frame, FrameLocator, BrowserContext, CDPSession, LaunchOptions, ConnectOptions, BrowserContextOptions
|
|
3
|
+
import { Page, Frame, FrameLocator, BrowserContext, CDPSession, Browser, LaunchOptions, ConnectOptions, BrowserContextOptions } from 'playwright';
|
|
4
4
|
import { ScreenshotMatcherOptions, ScreenshotComparatorRegistry, Locator } from '../browser/index.js';
|
|
5
|
-
import {
|
|
5
|
+
import { BrowserProvider, BrowserModuleMocker, TestProject, CDPSession as CDPSession$1, BrowserProviderOption } from '../../node.js';
|
|
6
6
|
|
|
7
7
|
declare const playwrightBrowsers: readonly ["firefox", "webkit", "chromium"];
|
|
8
8
|
type PlaywrightBrowser = (typeof playwrightBrowsers)[number];
|
|
@@ -31,6 +31,18 @@ interface PlaywrightProviderOptions {
|
|
|
31
31
|
* @default 0 (no timeout)
|
|
32
32
|
*/
|
|
33
33
|
actionTimeout?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Use a persistent context instead of a regular browser context.
|
|
36
|
+
* This allows browser state (cookies, localStorage, DevTools settings, etc.) to persist between test runs.
|
|
37
|
+
* When set to `true`, the user data is stored in `./node_modules/.cache/vitest-playwright-user-data`.
|
|
38
|
+
* When set to a string, the value is used as the path to the user data directory.
|
|
39
|
+
*
|
|
40
|
+
* Note: This option is ignored when running tests in parallel (e.g. headless with fileParallelism enabled)
|
|
41
|
+
* because persistent context cannot be shared across parallel sessions.
|
|
42
|
+
* @default false
|
|
43
|
+
* @see {@link https://playwright.dev/docs/api/class-browsertype#browser-type-launch-persistent-context}
|
|
44
|
+
*/
|
|
45
|
+
persistentContext?: boolean | string;
|
|
34
46
|
}
|
|
35
47
|
declare function playwright(options?: PlaywrightProviderOptions): BrowserProviderOption<PlaywrightProviderOptions>;
|
|
36
48
|
declare class PlaywrightBrowserProvider implements BrowserProvider {
|
|
@@ -39,6 +51,7 @@ declare class PlaywrightBrowserProvider implements BrowserProvider {
|
|
|
39
51
|
name: "playwright";
|
|
40
52
|
supportsParallelism: boolean;
|
|
41
53
|
browser: Browser | null;
|
|
54
|
+
persistentContext: BrowserContext | null;
|
|
42
55
|
contexts: Map<string, BrowserContext>;
|
|
43
56
|
pages: Map<string, Page>;
|
|
44
57
|
mocker: BrowserModuleMocker;
|
|
@@ -52,6 +65,7 @@ declare class PlaywrightBrowserProvider implements BrowserProvider {
|
|
|
52
65
|
private openBrowser;
|
|
53
66
|
private createMocker;
|
|
54
67
|
private createContext;
|
|
68
|
+
private getContextOptions;
|
|
55
69
|
getPage(sessionId: string): Page;
|
|
56
70
|
getCommandsContext(sessionId: string): {
|
|
57
71
|
page: Page;
|
|
@@ -60,7 +74,9 @@ declare class PlaywrightBrowserProvider implements BrowserProvider {
|
|
|
60
74
|
readonly iframe: FrameLocator;
|
|
61
75
|
};
|
|
62
76
|
private openBrowserPage;
|
|
63
|
-
openPage(sessionId: string, url: string
|
|
77
|
+
openPage(sessionId: string, url: string, options: {
|
|
78
|
+
parallel: boolean;
|
|
79
|
+
}): Promise<void>;
|
|
64
80
|
private _throwIfClosing;
|
|
65
81
|
getCDPSession(sessionid: string): Promise<CDPSession$1>;
|
|
66
82
|
close(): Promise<void>;
|
|
@@ -86,7 +102,8 @@ type PWScreenshotOptions = NonNullable<Parameters<Page["screenshot"]>[0]>;
|
|
|
86
102
|
type PWSelectOptions = NonNullable<Parameters<Page["selectOption"]>[2]>;
|
|
87
103
|
type PWDragAndDropOptions = NonNullable<Parameters<Page["dragAndDrop"]>[2]>;
|
|
88
104
|
type PWSetInputFiles = NonNullable<Parameters<Page["setInputFiles"]>[2]>;
|
|
89
|
-
type PWCDPSession = CDPSession
|
|
105
|
+
type PWCDPSession = Pick<CDPSession, "send" | "on" | "off" | "once">;
|
|
106
|
+
|
|
90
107
|
declare module "vitest/browser" {
|
|
91
108
|
interface UserEventHoverOptions extends PWHoverOptions {}
|
|
92
109
|
interface UserEventClickOptions extends PWClickOptions {}
|
|
@@ -103,4 +120,4 @@ declare module "vitest/browser" {
|
|
|
103
120
|
}
|
|
104
121
|
|
|
105
122
|
export { PlaywrightBrowserProvider, playwright };
|
|
106
|
-
export type { PlaywrightProviderOptions };
|
|
123
|
+
export type { PWCDPSession as CDPSession, PlaywrightProviderOptions };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseKeyDef, resolveScreenshotPath, defineBrowserProvider } from '../browser/index.js';
|
|
1
|
+
import { asLocator, parseKeyDef, resolveScreenshotPath, defineBrowserProvider } from '../browser/index.js';
|
|
2
2
|
export { defineBrowserCommand } from '../browser/index.js';
|
|
3
3
|
import { createManualModuleSource } from '../mocker/node.js';
|
|
4
4
|
import c from '../../vendor/tinyrainbow.mjs';
|
|
@@ -169,23 +169,28 @@ const basename = function(p, extension) {
|
|
|
169
169
|
return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
|
|
170
170
|
};
|
|
171
171
|
|
|
172
|
+
// strip iframe locator part from the trace description e.g.
|
|
173
|
+
// - locator('[data-vitest="true"]').contentFrame().getByRole('button')
|
|
174
|
+
// ⇓
|
|
175
|
+
// - getByRole('button')
|
|
176
|
+
function getDescribedLocator(context, selector) {
|
|
177
|
+
const locator = context.iframe.locator(selector);
|
|
178
|
+
return typeof locator.describe === "function" ? locator.describe(asLocator("javascript", selector)) : locator;
|
|
179
|
+
}
|
|
180
|
+
|
|
172
181
|
const clear = async (context, selector) => {
|
|
173
|
-
const
|
|
174
|
-
const element = iframe.locator(selector);
|
|
182
|
+
const element = getDescribedLocator(context, selector);
|
|
175
183
|
await element.clear();
|
|
176
184
|
};
|
|
177
185
|
|
|
178
186
|
const click = async (context, selector, options = {}) => {
|
|
179
|
-
|
|
180
|
-
await tester.locator(selector).click(options);
|
|
187
|
+
await getDescribedLocator(context, selector).click(options);
|
|
181
188
|
};
|
|
182
189
|
const dblClick = async (context, selector, options = {}) => {
|
|
183
|
-
|
|
184
|
-
await tester.locator(selector).dblclick(options);
|
|
190
|
+
await getDescribedLocator(context, selector).dblclick(options);
|
|
185
191
|
};
|
|
186
192
|
const tripleClick = async (context, selector, options = {}) => {
|
|
187
|
-
|
|
188
|
-
await tester.locator(selector).click({
|
|
193
|
+
await getDescribedLocator(context, selector).click({
|
|
189
194
|
...options,
|
|
190
195
|
clickCount: 3
|
|
191
196
|
});
|
|
@@ -197,13 +202,12 @@ const dragAndDrop = async (context, source, target, options_) => {
|
|
|
197
202
|
};
|
|
198
203
|
|
|
199
204
|
const fill = async (context, selector, text, options = {}) => {
|
|
200
|
-
const
|
|
201
|
-
const element = iframe.locator(selector);
|
|
205
|
+
const element = getDescribedLocator(context, selector);
|
|
202
206
|
await element.fill(text, options);
|
|
203
207
|
};
|
|
204
208
|
|
|
205
209
|
const hover = async (context, selector, options = {}) => {
|
|
206
|
-
await context
|
|
210
|
+
await getDescribedLocator(context, selector).hover(options);
|
|
207
211
|
};
|
|
208
212
|
|
|
209
213
|
const keyboard = async (context, text, state) => {
|
|
@@ -512,10 +516,10 @@ async function takeScreenshot(context, name, options) {
|
|
|
512
516
|
savePath = normalize(path);
|
|
513
517
|
await mkdir(dirname(savePath), { recursive: true });
|
|
514
518
|
}
|
|
515
|
-
const mask = options.mask?.map((selector) => context
|
|
519
|
+
const mask = options.mask?.map((selector) => getDescribedLocator(context, selector));
|
|
516
520
|
if (options.element) {
|
|
517
521
|
const { element: selector, ...config } = options;
|
|
518
|
-
const element = context
|
|
522
|
+
const element = getDescribedLocator(context, selector);
|
|
519
523
|
const buffer = await element.screenshot({
|
|
520
524
|
...config,
|
|
521
525
|
mask,
|
|
@@ -526,7 +530,7 @@ async function takeScreenshot(context, name, options) {
|
|
|
526
530
|
path
|
|
527
531
|
};
|
|
528
532
|
}
|
|
529
|
-
const buffer = await context
|
|
533
|
+
const buffer = await getDescribedLocator(context, "body").screenshot({
|
|
530
534
|
...options,
|
|
531
535
|
mask,
|
|
532
536
|
path: savePath
|
|
@@ -539,13 +543,12 @@ async function takeScreenshot(context, name, options) {
|
|
|
539
543
|
|
|
540
544
|
const selectOptions = async (context, selector, userValues, options = {}) => {
|
|
541
545
|
const value = userValues;
|
|
542
|
-
const
|
|
543
|
-
const selectElement = iframe.locator(selector);
|
|
546
|
+
const selectElement = getDescribedLocator(context, selector);
|
|
544
547
|
const values = await Promise.all(value.map(async (v) => {
|
|
545
548
|
if (typeof v === "string") {
|
|
546
549
|
return v;
|
|
547
550
|
}
|
|
548
|
-
const elementHandler = await
|
|
551
|
+
const elementHandler = await getDescribedLocator(context, v.element).elementHandle();
|
|
549
552
|
if (!elementHandler) {
|
|
550
553
|
throw new Error(`Element not found: ${v.element}`);
|
|
551
554
|
}
|
|
@@ -569,7 +572,7 @@ const startTracing = async ({ context, project, provider, sessionId }) => {
|
|
|
569
572
|
await context.tracing.start({
|
|
570
573
|
screenshots: options.screenshots ?? true,
|
|
571
574
|
snapshots: options.snapshots ?? true,
|
|
572
|
-
sources:
|
|
575
|
+
sources: options.sources ?? true
|
|
573
576
|
}).catch(() => {
|
|
574
577
|
provider.tracingContexts.delete(sessionId);
|
|
575
578
|
});
|
|
@@ -605,6 +608,68 @@ const stopChunkTrace = async (context, { name }) => {
|
|
|
605
608
|
}
|
|
606
609
|
throw new TypeError(`The ${context.provider.name} provider does not support tracing.`);
|
|
607
610
|
};
|
|
611
|
+
const markTrace = async (context, payload) => {
|
|
612
|
+
if (isPlaywrightProvider(context.provider)) {
|
|
613
|
+
// skip if tracing is not active
|
|
614
|
+
// this is only safe guard and this isn't expected to happen since
|
|
615
|
+
// runner already checks if tracing is active before sending this command
|
|
616
|
+
if (!context.provider.tracingContexts.has(context.sessionId)) {
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
const { name, selector, stack } = payload;
|
|
620
|
+
const location = parseLocation(context, stack);
|
|
621
|
+
// mark trace via group/groupEnd with dummy calls to force snapshot.
|
|
622
|
+
// https://github.com/microsoft/playwright/issues/39308
|
|
623
|
+
await context.context.tracing.group(name, { location });
|
|
624
|
+
try {
|
|
625
|
+
if (selector) {
|
|
626
|
+
const locator = getDescribedLocator(context, selector);
|
|
627
|
+
if (typeof locator._expect === "function") {
|
|
628
|
+
await locator._expect("to.be.attached", {
|
|
629
|
+
isNot: false,
|
|
630
|
+
timeout: 1
|
|
631
|
+
});
|
|
632
|
+
} else {
|
|
633
|
+
await context.page.evaluate(() => 0);
|
|
634
|
+
}
|
|
635
|
+
} else {
|
|
636
|
+
await context.page.evaluate(() => 0);
|
|
637
|
+
}
|
|
638
|
+
} catch {}
|
|
639
|
+
await context.context.tracing.groupEnd();
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
throw new TypeError(`The ${context.provider.name} provider does not support tracing.`);
|
|
643
|
+
};
|
|
644
|
+
const groupTraceStart = async (context, payload) => {
|
|
645
|
+
if (isPlaywrightProvider(context.provider)) {
|
|
646
|
+
if (!context.provider.tracingContexts.has(context.sessionId)) {
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
const { name, stack } = payload;
|
|
650
|
+
const location = parseLocation(context, stack);
|
|
651
|
+
await context.context.tracing.group(name, { location });
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
throw new TypeError(`The ${context.provider.name} provider does not support tracing.`);
|
|
655
|
+
};
|
|
656
|
+
const groupTraceEnd = async (context) => {
|
|
657
|
+
if (isPlaywrightProvider(context.provider)) {
|
|
658
|
+
if (!context.provider.tracingContexts.has(context.sessionId)) {
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
await context.context.tracing.groupEnd();
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
throw new TypeError(`The ${context.provider.name} provider does not support tracing.`);
|
|
665
|
+
};
|
|
666
|
+
function parseLocation(context, stack) {
|
|
667
|
+
if (!stack) {
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
const parsedStacks = context.project.browser.parseStacktrace(stack);
|
|
671
|
+
return parsedStacks[0];
|
|
672
|
+
}
|
|
608
673
|
function resolveTracesPath({ testPath, project }, name) {
|
|
609
674
|
if (!testPath) {
|
|
610
675
|
throw new Error(`This command can only be called inside a test file.`);
|
|
@@ -665,8 +730,7 @@ function isPlaywrightProvider(provider) {
|
|
|
665
730
|
const type = async (context, selector, text, options = {}) => {
|
|
666
731
|
const { skipClick = false, skipAutoClose = false } = options;
|
|
667
732
|
const unreleased = new Set(Reflect.get(options, "unreleased") ?? []);
|
|
668
|
-
const
|
|
669
|
-
const element = iframe.locator(selector);
|
|
733
|
+
const element = getDescribedLocator(context, selector);
|
|
670
734
|
if (!skipClick) {
|
|
671
735
|
await element.focus();
|
|
672
736
|
}
|
|
@@ -680,7 +744,6 @@ const upload = async (context, selector, files, options) => {
|
|
|
680
744
|
throw new Error(`Cannot upload files outside of a test`);
|
|
681
745
|
}
|
|
682
746
|
const root = context.project.config.root;
|
|
683
|
-
const { iframe } = context;
|
|
684
747
|
const playwrightFiles = files.map((file) => {
|
|
685
748
|
if (typeof file === "string") {
|
|
686
749
|
return resolve(root, file);
|
|
@@ -691,7 +754,17 @@ const upload = async (context, selector, files, options) => {
|
|
|
691
754
|
buffer: Buffer.from(file.base64, "base64")
|
|
692
755
|
};
|
|
693
756
|
});
|
|
694
|
-
await
|
|
757
|
+
await getDescribedLocator(context, selector).setInputFiles(playwrightFiles, options);
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
const wheel = async (context, selector, options) => {
|
|
761
|
+
await hover(context, selector);
|
|
762
|
+
const times = options.times ?? 1;
|
|
763
|
+
const deltaX = options.delta.x ?? 0;
|
|
764
|
+
const deltaY = options.delta.y ?? 0;
|
|
765
|
+
for (let count = 0; count < times; count += 1) {
|
|
766
|
+
await context.page.mouse.wheel(deltaX, deltaY);
|
|
767
|
+
}
|
|
695
768
|
};
|
|
696
769
|
|
|
697
770
|
var commands = {
|
|
@@ -699,6 +772,7 @@ var commands = {
|
|
|
699
772
|
__vitest_click: click,
|
|
700
773
|
__vitest_dblClick: dblClick,
|
|
701
774
|
__vitest_tripleClick: tripleClick,
|
|
775
|
+
__vitest_wheel: wheel,
|
|
702
776
|
__vitest_takeScreenshot: takeScreenshot,
|
|
703
777
|
__vitest_type: type,
|
|
704
778
|
__vitest_clear: clear,
|
|
@@ -713,7 +787,10 @@ var commands = {
|
|
|
713
787
|
__vitest_startChunkTrace: startChunkTrace,
|
|
714
788
|
__vitest_startTracing: startTracing,
|
|
715
789
|
__vitest_stopChunkTrace: stopChunkTrace,
|
|
716
|
-
__vitest_annotateTraces: annotateTraces
|
|
790
|
+
__vitest_annotateTraces: annotateTraces,
|
|
791
|
+
__vitest_markTrace: markTrace,
|
|
792
|
+
__vitest_groupTraceStart: groupTraceStart,
|
|
793
|
+
__vitest_groupTraceEnd: groupTraceEnd
|
|
717
794
|
};
|
|
718
795
|
|
|
719
796
|
const distRoot = dirname(fileURLToPath(import.meta.url));
|
|
@@ -741,6 +818,7 @@ class PlaywrightBrowserProvider {
|
|
|
741
818
|
name = "playwright";
|
|
742
819
|
supportsParallelism = true;
|
|
743
820
|
browser = null;
|
|
821
|
+
persistentContext = null;
|
|
744
822
|
contexts = new Map();
|
|
745
823
|
pages = new Map();
|
|
746
824
|
mocker;
|
|
@@ -773,7 +851,7 @@ class PlaywrightBrowserProvider {
|
|
|
773
851
|
return Promise.allSettled(promises);
|
|
774
852
|
});
|
|
775
853
|
}
|
|
776
|
-
async openBrowser() {
|
|
854
|
+
async openBrowser(openBrowserOptions) {
|
|
777
855
|
await this._throwIfClosing();
|
|
778
856
|
if (this.browserPromise) {
|
|
779
857
|
debug?.("[%s] the browser is resolving, reusing the promise", this.browserName);
|
|
@@ -786,17 +864,6 @@ class PlaywrightBrowserProvider {
|
|
|
786
864
|
this.browserPromise = (async () => {
|
|
787
865
|
const options = this.project.config.browser;
|
|
788
866
|
const playwright = await import('playwright');
|
|
789
|
-
if (this.options.connectOptions) {
|
|
790
|
-
if (this.options.launchOptions) {
|
|
791
|
-
this.project.vitest.logger.warn(c.yellow(`Found both ${c.bold(c.italic(c.yellow("connect")))} and ${c.bold(c.italic(c.yellow("launch")))} options in browser instance configuration.
|
|
792
|
-
Ignoring ${c.bold(c.italic(c.yellow("launch")))} options and using ${c.bold(c.italic(c.yellow("connect")))} mode.
|
|
793
|
-
You probably want to remove one of the two options and keep only the one you want to use.`));
|
|
794
|
-
}
|
|
795
|
-
const browser = await playwright[this.browserName].connect(this.options.connectOptions.wsEndpoint, this.options.connectOptions);
|
|
796
|
-
this.browser = browser;
|
|
797
|
-
this.browserPromise = null;
|
|
798
|
-
return this.browser;
|
|
799
|
-
}
|
|
800
867
|
const launchOptions = {
|
|
801
868
|
...this.options.launchOptions,
|
|
802
869
|
headless: options.headless
|
|
@@ -811,8 +878,10 @@ class PlaywrightBrowserProvider {
|
|
|
811
878
|
const host = inspector.host || "127.0.0.1";
|
|
812
879
|
launchOptions.args ||= [];
|
|
813
880
|
launchOptions.args.push(`--remote-debugging-port=${port}`);
|
|
814
|
-
|
|
815
|
-
|
|
881
|
+
if (host !== "localhost" && host !== "127.0.0.1" && host !== "::1") {
|
|
882
|
+
this.project.vitest.logger.warn(`Custom inspector host "${host}" will be ignored. Chromium only allows remote debugging on localhost.`);
|
|
883
|
+
}
|
|
884
|
+
this.project.vitest.logger.log(`Debugger listening on ws://127.0.0.1:${port}`);
|
|
816
885
|
}
|
|
817
886
|
// start Vitest UI maximized only on supported browsers
|
|
818
887
|
if (this.project.config.browser.ui && this.browserName === "chromium") {
|
|
@@ -824,7 +893,39 @@ class PlaywrightBrowserProvider {
|
|
|
824
893
|
}
|
|
825
894
|
}
|
|
826
895
|
debug?.("[%s] initializing the browser with launch options: %O", this.browserName, launchOptions);
|
|
827
|
-
|
|
896
|
+
if (this.options.connectOptions) {
|
|
897
|
+
let { wsEndpoint, headers = {}, ...connectOptions } = this.options.connectOptions;
|
|
898
|
+
if ("x-playwright-launch-options" in headers) {
|
|
899
|
+
this.project.vitest.logger.warn(c.yellow("Detected \"x-playwright-launch-options\" in connectOptions.headers. Provider config launchOptions is ignored."));
|
|
900
|
+
} else {
|
|
901
|
+
headers = {
|
|
902
|
+
...headers,
|
|
903
|
+
"x-playwright-launch-options": JSON.stringify(launchOptions)
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
this.browser = await playwright[this.browserName].connect(wsEndpoint, {
|
|
907
|
+
...connectOptions,
|
|
908
|
+
headers
|
|
909
|
+
});
|
|
910
|
+
this.browserPromise = null;
|
|
911
|
+
return this.browser;
|
|
912
|
+
}
|
|
913
|
+
let persistentContextOption = this.options.persistentContext;
|
|
914
|
+
if (persistentContextOption && openBrowserOptions.parallel) {
|
|
915
|
+
persistentContextOption = false;
|
|
916
|
+
this.project.vitest.logger.warn(c.yellow(`The persistentContext option is ignored because tests are running in parallel.`));
|
|
917
|
+
}
|
|
918
|
+
if (persistentContextOption) {
|
|
919
|
+
const userDataDir = typeof this.options.persistentContext === "string" ? this.options.persistentContext : "./node_modules/.cache/vitest-playwright-user-data";
|
|
920
|
+
// TODO: how to avoid default "about" page?
|
|
921
|
+
this.persistentContext = await playwright[this.browserName].launchPersistentContext(userDataDir, {
|
|
922
|
+
...launchOptions,
|
|
923
|
+
...this.getContextOptions()
|
|
924
|
+
});
|
|
925
|
+
this.browser = this.persistentContext.browser();
|
|
926
|
+
} else {
|
|
927
|
+
this.browser = await playwright[this.browserName].launch(launchOptions);
|
|
928
|
+
}
|
|
828
929
|
this.browserPromise = null;
|
|
829
930
|
return this.browser;
|
|
830
931
|
})();
|
|
@@ -944,29 +1045,22 @@ class PlaywrightBrowserProvider {
|
|
|
944
1045
|
}
|
|
945
1046
|
};
|
|
946
1047
|
}
|
|
947
|
-
async createContext(sessionId) {
|
|
1048
|
+
async createContext(sessionId, openBrowserOptions) {
|
|
948
1049
|
await this._throwIfClosing();
|
|
949
1050
|
if (this.contexts.has(sessionId)) {
|
|
950
1051
|
debug?.("[%s][%s] the context already exists, reusing it", sessionId, this.browserName);
|
|
951
1052
|
return this.contexts.get(sessionId);
|
|
952
1053
|
}
|
|
953
|
-
const browser = await this.openBrowser();
|
|
1054
|
+
const browser = await this.openBrowser(openBrowserOptions);
|
|
954
1055
|
await this._throwIfClosing(browser);
|
|
955
1056
|
const actionTimeout = this.options.actionTimeout;
|
|
956
|
-
const
|
|
957
|
-
const options = {
|
|
958
|
-
...contextOptions,
|
|
959
|
-
ignoreHTTPSErrors: true
|
|
960
|
-
};
|
|
961
|
-
if (this.project.config.browser.ui) {
|
|
962
|
-
options.viewport = null;
|
|
963
|
-
}
|
|
1057
|
+
const options = this.getContextOptions();
|
|
964
1058
|
// TODO: investigate the consequences for Vitest 5
|
|
965
1059
|
// else {
|
|
966
1060
|
// if UI is disabled, keep the iframe scale to 1
|
|
967
1061
|
// options.viewport ??= this.project.config.browser.viewport
|
|
968
1062
|
// }
|
|
969
|
-
const context = await browser.newContext(options);
|
|
1063
|
+
const context = this.persistentContext ?? await browser.newContext(options);
|
|
970
1064
|
await this._throwIfClosing(context);
|
|
971
1065
|
if (actionTimeout != null) {
|
|
972
1066
|
context.setDefaultTimeout(actionTimeout);
|
|
@@ -975,6 +1069,17 @@ class PlaywrightBrowserProvider {
|
|
|
975
1069
|
this.contexts.set(sessionId, context);
|
|
976
1070
|
return context;
|
|
977
1071
|
}
|
|
1072
|
+
getContextOptions() {
|
|
1073
|
+
const contextOptions = this.options.contextOptions ?? {};
|
|
1074
|
+
const options = {
|
|
1075
|
+
...contextOptions,
|
|
1076
|
+
ignoreHTTPSErrors: true
|
|
1077
|
+
};
|
|
1078
|
+
if (this.project.config.browser.ui) {
|
|
1079
|
+
options.viewport = null;
|
|
1080
|
+
}
|
|
1081
|
+
return options;
|
|
1082
|
+
}
|
|
978
1083
|
getPage(sessionId) {
|
|
979
1084
|
const page = this.pages.get(sessionId);
|
|
980
1085
|
if (!page) {
|
|
@@ -1008,7 +1113,7 @@ class PlaywrightBrowserProvider {
|
|
|
1008
1113
|
}
|
|
1009
1114
|
};
|
|
1010
1115
|
}
|
|
1011
|
-
async openBrowserPage(sessionId) {
|
|
1116
|
+
async openBrowserPage(sessionId, options) {
|
|
1012
1117
|
await this._throwIfClosing();
|
|
1013
1118
|
if (this.pages.has(sessionId)) {
|
|
1014
1119
|
debug?.("[%s][%s] the page already exists, closing the old one", sessionId, this.browserName);
|
|
@@ -1016,7 +1121,7 @@ class PlaywrightBrowserProvider {
|
|
|
1016
1121
|
await page.close();
|
|
1017
1122
|
this.pages.delete(sessionId);
|
|
1018
1123
|
}
|
|
1019
|
-
const context = await this.createContext(sessionId);
|
|
1124
|
+
const context = await this.createContext(sessionId, options);
|
|
1020
1125
|
const page = await context.newPage();
|
|
1021
1126
|
debug?.("[%s][%s] the page is ready", sessionId, this.browserName);
|
|
1022
1127
|
await this._throwIfClosing(page);
|
|
@@ -1028,9 +1133,9 @@ class PlaywrightBrowserProvider {
|
|
|
1028
1133
|
}
|
|
1029
1134
|
return page;
|
|
1030
1135
|
}
|
|
1031
|
-
async openPage(sessionId, url) {
|
|
1136
|
+
async openPage(sessionId, url, options) {
|
|
1032
1137
|
debug?.("[%s][%s] creating the browser page for %s", sessionId, this.browserName, url);
|
|
1033
|
-
const browserPage = await this.openBrowserPage(sessionId);
|
|
1138
|
+
const browserPage = await this.openBrowserPage(sessionId, options);
|
|
1034
1139
|
debug?.("[%s][%s] browser page is created, opening %s", sessionId, this.browserName, url);
|
|
1035
1140
|
await browserPage.goto(url, { timeout: 0 });
|
|
1036
1141
|
await this._throwIfClosing(browserPage);
|
|
@@ -1050,18 +1155,17 @@ class PlaywrightBrowserProvider {
|
|
|
1050
1155
|
const page = this.getPage(sessionid);
|
|
1051
1156
|
const cdp = await page.context().newCDPSession(page);
|
|
1052
1157
|
return {
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
return result;
|
|
1158
|
+
send(method, params) {
|
|
1159
|
+
return cdp.send(method, params);
|
|
1056
1160
|
},
|
|
1057
1161
|
on(event, listener) {
|
|
1058
|
-
cdp.on(event, listener);
|
|
1162
|
+
return cdp.on(event, listener);
|
|
1059
1163
|
},
|
|
1060
1164
|
off(event, listener) {
|
|
1061
|
-
cdp.off(event, listener);
|
|
1165
|
+
return cdp.off(event, listener);
|
|
1062
1166
|
},
|
|
1063
1167
|
once(event, listener) {
|
|
1064
|
-
cdp.once(event, listener);
|
|
1168
|
+
return cdp.once(event, listener);
|
|
1065
1169
|
}
|
|
1066
1170
|
};
|
|
1067
1171
|
}
|
|
@@ -1076,7 +1180,11 @@ class PlaywrightBrowserProvider {
|
|
|
1076
1180
|
this.browser = null;
|
|
1077
1181
|
await Promise.all([...this.pages.values()].map((p) => p.close()));
|
|
1078
1182
|
this.pages.clear();
|
|
1079
|
-
|
|
1183
|
+
if (this.persistentContext) {
|
|
1184
|
+
await this.persistentContext.close();
|
|
1185
|
+
} else {
|
|
1186
|
+
await Promise.all([...this.contexts.values()].map((c) => c.close()));
|
|
1187
|
+
}
|
|
1080
1188
|
this.contexts.clear();
|
|
1081
1189
|
await browser?.close();
|
|
1082
1190
|
debug?.("[%s] provider is closed", this.browserName);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SelectorOptions } from '../browser/index.js';
|
|
2
|
+
import { BrowserProvider, TestProject, BrowserProviderOption } from '../../node.js';
|
|
2
3
|
export { defineBrowserCommand } from '../browser/index.js';
|
|
3
4
|
|
|
4
5
|
declare function preview(): BrowserProviderOption;
|
|
@@ -15,5 +16,17 @@ declare class PreviewBrowserProvider implements BrowserProvider {
|
|
|
15
16
|
openPage(_sessionId: string, url: string): Promise<void>;
|
|
16
17
|
close(): Promise<void>;
|
|
17
18
|
}
|
|
19
|
+
declare module "vitest/browser" {
|
|
20
|
+
interface UserEventClickOptions extends SelectorOptions {}
|
|
21
|
+
interface UserEventHoverOptions extends SelectorOptions {}
|
|
22
|
+
interface UserEventFillOptions extends SelectorOptions {}
|
|
23
|
+
interface UserEventSelectOptions extends SelectorOptions {}
|
|
24
|
+
interface UserEventClearOptions extends SelectorOptions {}
|
|
25
|
+
interface UserEventDoubleClickOptions extends SelectorOptions {}
|
|
26
|
+
interface UserEventTripleClickOptions extends SelectorOptions {}
|
|
27
|
+
interface UserEventUploadOptions extends SelectorOptions {}
|
|
28
|
+
interface UserEventWheelBaseOptions extends SelectorOptions {}
|
|
29
|
+
interface LocatorScreenshotOptions extends SelectorOptions {}
|
|
30
|
+
}
|
|
18
31
|
|
|
19
32
|
export { PreviewBrowserProvider, preview };
|
|
@@ -16,32 +16,45 @@ class PreviewLocator extends Locator {
|
|
|
16
16
|
}
|
|
17
17
|
return selectors.join(", ");
|
|
18
18
|
}
|
|
19
|
-
click() {
|
|
20
|
-
|
|
19
|
+
async click(options) {
|
|
20
|
+
const element = await this.findElement(options);
|
|
21
|
+
return userEvent.click(element);
|
|
21
22
|
}
|
|
22
|
-
dblClick() {
|
|
23
|
-
|
|
23
|
+
async dblClick(options) {
|
|
24
|
+
const element = await this.findElement(options);
|
|
25
|
+
return userEvent.dblClick(element);
|
|
24
26
|
}
|
|
25
|
-
tripleClick() {
|
|
26
|
-
|
|
27
|
+
async tripleClick(options) {
|
|
28
|
+
const element = await this.findElement(options);
|
|
29
|
+
return userEvent.tripleClick(element);
|
|
27
30
|
}
|
|
28
|
-
hover() {
|
|
29
|
-
|
|
31
|
+
async hover(options) {
|
|
32
|
+
const element = await this.findElement(options);
|
|
33
|
+
return userEvent.hover(element);
|
|
30
34
|
}
|
|
31
|
-
unhover() {
|
|
32
|
-
|
|
35
|
+
async unhover(options) {
|
|
36
|
+
const element = await this.findElement(options);
|
|
37
|
+
return userEvent.unhover(element);
|
|
33
38
|
}
|
|
34
|
-
async fill(text) {
|
|
35
|
-
|
|
39
|
+
async fill(text, options) {
|
|
40
|
+
const element = await this.findElement(options);
|
|
41
|
+
return userEvent.fill(element, text);
|
|
36
42
|
}
|
|
37
|
-
async upload(file) {
|
|
38
|
-
|
|
43
|
+
async upload(file, options) {
|
|
44
|
+
const element = await this.findElement(options);
|
|
45
|
+
return userEvent.upload(element, file);
|
|
39
46
|
}
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
async wheel(options) {
|
|
48
|
+
const element = await this.findElement(options);
|
|
49
|
+
return userEvent.wheel(element, options);
|
|
42
50
|
}
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
async selectOptions(options, settings) {
|
|
52
|
+
const element = await this.findElement(settings);
|
|
53
|
+
return userEvent.selectOptions(element, options);
|
|
54
|
+
}
|
|
55
|
+
async clear(options) {
|
|
56
|
+
const element = await this.findElement(options);
|
|
57
|
+
return userEvent.clear(element);
|
|
45
58
|
}
|
|
46
59
|
locator(selector) {
|
|
47
60
|
return new PreviewLocator(`${this._pwSelector} >> ${selector}`, this._container);
|