@vitest/browser 2.1.0-beta.6 → 2.1.0
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/context.d.ts +11 -0
- package/dist/client/.vite/manifest.json +6 -6
- package/dist/client/__vitest__/assets/{index-BevOiAy-.css → index-D5rK8X7L.css} +1 -1
- package/dist/client/__vitest__/assets/index-DsWp6aFQ.js +52 -0
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/{orchestrator-CoMoQEYq.js → orchestrator-qtq9EW1J.js} +243 -91
- package/dist/client/__vitest_browser__/preload-helper-D-WYp1PK.js +317 -0
- package/dist/client/__vitest_browser__/{tester-C7y_vb57.js → tester-Bm6k0JOu.js} +585 -371
- package/dist/client/esm-client-injector.js +1 -0
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/tester/tester.html +2 -2
- package/dist/context.js +39 -23
- package/dist/{index-DcU_z8HM.js → index-Cgg35wOd.js} +19 -0
- package/dist/index.d.ts +7 -13
- package/dist/index.js +272 -287
- package/dist/locators/index.d.ts +1 -0
- package/dist/locators/index.js +1 -1
- package/dist/locators/playwright.js +1 -1
- package/dist/locators/preview.js +15 -2
- package/dist/locators/webdriverio.js +1 -1
- package/dist/providers.js +1 -1
- package/dist/state.js +1 -1
- package/dist/{webdriver-BdVqnfdE.js → webdriver-Cv9wga63.js} +10 -1
- package/package.json +10 -7
- package/dist/client/__vitest__/assets/index-D7jfm8wn.js +0 -52
- package/dist/client/__vitest_browser__/preload-helper-YsBSwBkS.js +0 -310
package/dist/locators/index.d.ts
CHANGED
|
@@ -230,6 +230,7 @@ declare abstract class Locator {
|
|
|
230
230
|
hover(options: UserEventHoverOptions): Promise<void>;
|
|
231
231
|
unhover(options: UserEventHoverOptions): Promise<void>;
|
|
232
232
|
fill(text: string, options?: UserEventFillOptions): Promise<void>;
|
|
233
|
+
upload(files: string | string[] | File | File[]): Promise<void>;
|
|
233
234
|
dropTo(target: Locator, options?: UserEventDragAndDropOptions): Promise<void>;
|
|
234
235
|
selectOptions(value: HTMLElement | HTMLElement[] | Locator | Locator[] | string | string[]): Promise<void>;
|
|
235
236
|
screenshot(options: Omit<LocatorScreenshotOptions, 'base64'> & {
|
package/dist/locators/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { page, server } from '@vitest/browser/context';
|
|
2
2
|
import { g as getByLabelSelector, a as getByRoleSelector, b as getByTestIdSelector, c as getByAltTextSelector, d as getByPlaceholderSelector, e as getByTextSelector, f as getByTitleSelector } from '../public-utils-D6S2-5kI.js';
|
|
3
|
-
import { s as selectorEngine, L as Locator } from '../index-
|
|
3
|
+
import { s as selectorEngine, L as Locator } from '../index-Cgg35wOd.js';
|
|
4
4
|
import 'vitest/utils';
|
|
5
5
|
|
|
6
6
|
page.extend({
|
package/dist/locators/preview.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { page, server } from '@vitest/browser/context';
|
|
2
2
|
import { userEvent } from '@testing-library/user-event';
|
|
3
3
|
import { g as getByLabelSelector, a as getByRoleSelector, b as getByTestIdSelector, c as getByAltTextSelector, d as getByPlaceholderSelector, e as getByTextSelector, f as getByTitleSelector, h as getElementError } from '../public-utils-D6S2-5kI.js';
|
|
4
|
-
import { s as selectorEngine, L as Locator, c as convertElementToCssSelector } from '../index-
|
|
4
|
+
import { s as selectorEngine, L as Locator, c as convertElementToCssSelector } from '../index-Cgg35wOd.js';
|
|
5
5
|
import 'vitest/utils';
|
|
6
6
|
|
|
7
7
|
page.extend({
|
|
@@ -61,9 +61,22 @@ class PreviewLocator extends Locator {
|
|
|
61
61
|
unhover() {
|
|
62
62
|
return userEvent.unhover(this.element());
|
|
63
63
|
}
|
|
64
|
-
fill(text) {
|
|
64
|
+
async fill(text) {
|
|
65
|
+
await this.clear();
|
|
65
66
|
return userEvent.type(this.element(), text);
|
|
66
67
|
}
|
|
68
|
+
async upload(file) {
|
|
69
|
+
const uploadPromise = (Array.isArray(file) ? file : [file]).map(async (file2) => {
|
|
70
|
+
if (typeof file2 !== "string") {
|
|
71
|
+
return file2;
|
|
72
|
+
}
|
|
73
|
+
const { content: base64, basename, mime } = await this.triggerCommand("__vitest_fileInfo", file2, "base64");
|
|
74
|
+
const fileInstance = fetch(base64).then((r) => r.blob()).then((blob) => new File([blob], basename, { type: mime }));
|
|
75
|
+
return fileInstance;
|
|
76
|
+
});
|
|
77
|
+
const uploadFiles = await Promise.all(uploadPromise);
|
|
78
|
+
return userEvent.upload(this.element(), uploadFiles);
|
|
79
|
+
}
|
|
67
80
|
selectOptions(options_) {
|
|
68
81
|
const options = (Array.isArray(options_) ? options_ : [options_]).map((option) => {
|
|
69
82
|
if (typeof option !== "string" && "element" in option) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { page, server } from '@vitest/browser/context';
|
|
2
2
|
import { g as getByLabelSelector, a as getByRoleSelector, b as getByTestIdSelector, c as getByAltTextSelector, d as getByPlaceholderSelector, e as getByTextSelector, f as getByTitleSelector, h as getElementError } from '../public-utils-D6S2-5kI.js';
|
|
3
|
-
import { s as selectorEngine, L as Locator, c as convertElementToCssSelector } from '../index-
|
|
3
|
+
import { s as selectorEngine, L as Locator, c as convertElementToCssSelector } from '../index-Cgg35wOd.js';
|
|
4
4
|
import 'vitest/utils';
|
|
5
5
|
|
|
6
6
|
page.extend({
|
package/dist/providers.js
CHANGED
package/dist/state.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const{parse:$parse,stringify:$stringify}=JSON;const{keys}=Object;const Primitive=String;const primitive="string";const ignore={};const object="object";const noop=(_,value)=>value;const primitives=value=>value instanceof Primitive?Primitive(value):value;const Primitives=(_,value)=>typeof value===primitive?new Primitive(value):value;const revive=(input,parsed,output,$)=>{const lazy=[];for(let ke=keys(output),{length}=ke,y=0;y<length;y++){const k=ke[y];const value=output[k];if(value instanceof Primitive){const tmp=input[value];if(typeof tmp===object&&!parsed.has(tmp)){parsed.add(tmp);output[k]=ignore;lazy.push({k,a:[input,parsed,tmp,$]})}else output[k]=$.call(output,k,tmp)}else if(output[k]!==ignore)output[k]=$.call(output,k,value)}for(let{length}=lazy,i=0;i<length;i++){const{k,a}=lazy[i];output[k]=$.call(output,k,revive.apply(null,a))}return output};const parse=(text,reviver)=>{const input=$parse(text,Primitives).map(primitives);const value=input[0];const $=noop;const tmp=typeof value===object&&value?revive(input,new Set,value,$):value;return $.call({"":tmp},"",tmp)};function getBrowserState(){return window.__vitest_browser_runner__}const config=getBrowserState().config;const contextId=getBrowserState().contextId;const providedContext=parse(getBrowserState().providedContext);const state={ctx:{pool:"browser",worker:"./browser.js",workerId:1,config,projectName:config.name||"",files:[],environment:{name:"browser",options:null},providedContext,invalidates:[]},onCancel:null,
|
|
1
|
+
const{parse:$parse,stringify:$stringify}=JSON;const{keys}=Object;const Primitive=String;const primitive="string";const ignore={};const object="object";const noop=(_,value)=>value;const primitives=value=>value instanceof Primitive?Primitive(value):value;const Primitives=(_,value)=>typeof value===primitive?new Primitive(value):value;const revive=(input,parsed,output,$)=>{const lazy=[];for(let ke=keys(output),{length}=ke,y=0;y<length;y++){const k=ke[y];const value=output[k];if(value instanceof Primitive){const tmp=input[value];if(typeof tmp===object&&!parsed.has(tmp)){parsed.add(tmp);output[k]=ignore;lazy.push({k,a:[input,parsed,tmp,$]})}else output[k]=$.call(output,k,tmp)}else if(output[k]!==ignore)output[k]=$.call(output,k,value)}for(let{length}=lazy,i=0;i<length;i++){const{k,a}=lazy[i];output[k]=$.call(output,k,revive.apply(null,a))}return output};const parse=(text,reviver)=>{const input=$parse(text,Primitives).map(primitives);const value=input[0];const $=noop;const tmp=typeof value===object&&value?revive(input,new Set,value,$):value;return $.call({"":tmp},"",tmp)};function getBrowserState(){return window.__vitest_browser_runner__}const config=getBrowserState().config;const contextId=getBrowserState().contextId;const providedContext=parse(getBrowserState().providedContext);const state={ctx:{pool:"browser",worker:"./browser.js",workerId:1,config,projectName:config.name||"",files:[],environment:{name:"browser",options:null},providedContext,invalidates:[]},onCancel:null,config,environment:{name:"browser",transformMode:"web",setup(){throw new Error("Not called in the browser")}},moduleCache:getBrowserState().moduleCache,rpc:null,durations:{environment:0,prepare:performance.now()},providedContext};globalThis.__vitest_browser__=true;globalThis.__vitest_worker__=state;getBrowserState().cdp=createCdp();function rpc(){return state.rpc}function createCdp(){const listenersMap=new WeakMap;function getId(listener){const id=listenersMap.get(listener)||crypto.randomUUID();listenersMap.set(listener,id);return id}const listeners={};const cdp={send(method,params){return rpc().sendCdpEvent(contextId,method,params)},on(event,listener){const listenerId=getId(listener);listeners[event]=listeners[event]||[];listeners[event].push(listener);rpc().trackCdpEvent(contextId,"on",event,listenerId).catch(error);return cdp},once(event,listener){const listenerId=getId(listener);const handler=data=>{listener(data);cdp.off(event,listener)};listeners[event]=listeners[event]||[];listeners[event].push(handler);rpc().trackCdpEvent(contextId,"once",event,listenerId).catch(error);return cdp},off(event,listener){const listenerId=getId(listener);if(listeners[event]){listeners[event]=listeners[event].filter(l=>l!==listener)}rpc().trackCdpEvent(contextId,"off",event,listenerId).catch(error);return cdp},emit(event,payload){if(listeners[event]){listeners[event].forEach(l=>{try{l(payload)}catch(err){error(err)}})}}};return cdp}function error(err){window.dispatchEvent(new ErrorEvent("error",{error:err}))}
|
|
@@ -31,6 +31,14 @@ class PlaywrightBrowserProvider {
|
|
|
31
31
|
...this.options?.launch,
|
|
32
32
|
headless: options.headless
|
|
33
33
|
};
|
|
34
|
+
if (this.ctx.config.inspector.enabled) {
|
|
35
|
+
const port = this.ctx.config.inspector.port || 9229;
|
|
36
|
+
const host = this.ctx.config.inspector.host || "127.0.0.1";
|
|
37
|
+
launchOptions.args ||= [];
|
|
38
|
+
launchOptions.args.push(`--remote-debugging-port=${port}`);
|
|
39
|
+
launchOptions.args.push(`--remote-debugging-address=${host}`);
|
|
40
|
+
this.ctx.logger.log(`Debugger listening on ws://${host}:${port}`);
|
|
41
|
+
}
|
|
34
42
|
if (this.ctx.config.browser.ui && this.browserName === "chromium") {
|
|
35
43
|
if (!launchOptions.args) {
|
|
36
44
|
launchOptions.args = [];
|
|
@@ -119,8 +127,9 @@ class PlaywrightBrowserProvider {
|
|
|
119
127
|
}
|
|
120
128
|
return page;
|
|
121
129
|
}
|
|
122
|
-
async openPage(contextId, url) {
|
|
130
|
+
async openPage(contextId, url, beforeNavigate) {
|
|
123
131
|
const browserPage = await this.openBrowserPage(contextId);
|
|
132
|
+
await beforeNavigate?.();
|
|
124
133
|
await browserPage.goto(url);
|
|
125
134
|
}
|
|
126
135
|
async getCDPSession(contextId) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.1.0
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"description": "Browser running for Vitest",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"playwright": "*",
|
|
64
64
|
"webdriverio": "*",
|
|
65
|
-
"vitest": "2.1.0
|
|
65
|
+
"vitest": "2.1.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependenciesMeta": {
|
|
68
68
|
"playwright": {
|
|
@@ -81,8 +81,10 @@
|
|
|
81
81
|
"magic-string": "^0.30.11",
|
|
82
82
|
"msw": "^2.3.5",
|
|
83
83
|
"sirv": "^2.0.4",
|
|
84
|
+
"tinyrainbow": "^1.2.0",
|
|
84
85
|
"ws": "^8.18.0",
|
|
85
|
-
"@vitest/utils": "2.1.0
|
|
86
|
+
"@vitest/utils": "2.1.0",
|
|
87
|
+
"@vitest/mocker": "2.1.0"
|
|
86
88
|
},
|
|
87
89
|
"devDependencies": {
|
|
88
90
|
"@testing-library/jest-dom": "^6.4.8",
|
|
@@ -91,16 +93,17 @@
|
|
|
91
93
|
"birpc": "0.2.17",
|
|
92
94
|
"flatted": "^3.3.1",
|
|
93
95
|
"ivya": "^1.1.1",
|
|
96
|
+
"mime": "^4.0.4",
|
|
94
97
|
"pathe": "^1.1.2",
|
|
95
98
|
"periscopic": "^4.0.2",
|
|
96
99
|
"playwright": "^1.46.0",
|
|
97
100
|
"playwright-core": "^1.46.0",
|
|
98
101
|
"safaridriver": "^0.1.2",
|
|
99
102
|
"webdriverio": "^8.40.2",
|
|
100
|
-
"@vitest/runner": "2.1.0
|
|
101
|
-
"@vitest/
|
|
102
|
-
"
|
|
103
|
-
"vitest": "2.1.0
|
|
103
|
+
"@vitest/runner": "2.1.0",
|
|
104
|
+
"@vitest/ws-client": "2.1.0",
|
|
105
|
+
"vitest": "2.1.0",
|
|
106
|
+
"@vitest/ui": "2.1.0"
|
|
104
107
|
},
|
|
105
108
|
"scripts": {
|
|
106
109
|
"build": "rimraf dist && pnpm build:node && pnpm build:client",
|