@vitest/browser 3.1.0-beta.1 → 3.1.0-beta.2
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 +22 -0
- package/dist/client/.vite/manifest.json +1 -1
- package/dist/client/__vitest__/assets/{index-CsZqQx26.js → index-C3wX9Cb1.js} +1 -1
- package/dist/client/__vitest__/index.html +1 -1
- package/dist/client/__vitest_browser__/{tester-lo_P6U-u.js → tester-DRF-LncV.js} +1112 -324
- package/dist/client/tester/tester.html +1 -1
- package/dist/client.js +91 -105
- package/dist/context.js +374 -390
- package/dist/index-VvsEiykv.js +327 -0
- package/dist/index.js +1914 -1885
- package/dist/locators/index.d.ts +3 -0
- package/dist/locators/index.js +2 -2
- package/dist/locators/playwright.js +99 -108
- package/dist/locators/preview.js +71 -78
- package/dist/locators/webdriverio.js +135 -138
- package/dist/providers.js +34 -37
- package/dist/{public-utils-J4vwTaki.js → public-utils-4WiYB3_6.js} +38 -40
- package/dist/state.js +170 -1
- package/dist/utils.js +1 -1
- package/dist/webdriver-BP2w_ajA.js +271 -0
- package/package.json +8 -8
- package/dist/index-DrTP5i7N.js +0 -195
- package/dist/utils-VCysLhWp.js +0 -115
- package/dist/webdriver-C5-VI7VH.js +0 -275
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
const playwrightBrowsers = ["firefox", "webkit", "chromium"];
|
|
2
|
-
class PlaywrightBrowserProvider {
|
|
3
|
-
name = "playwright";
|
|
4
|
-
supportsParallelism = true;
|
|
5
|
-
browser = null;
|
|
6
|
-
browserName;
|
|
7
|
-
project;
|
|
8
|
-
options;
|
|
9
|
-
contexts = /* @__PURE__ */ new Map();
|
|
10
|
-
pages = /* @__PURE__ */ new Map();
|
|
11
|
-
browserPromise = null;
|
|
12
|
-
getSupportedBrowsers() {
|
|
13
|
-
return playwrightBrowsers;
|
|
14
|
-
}
|
|
15
|
-
initialize(project, { browser, options }) {
|
|
16
|
-
this.project = project;
|
|
17
|
-
this.browserName = browser;
|
|
18
|
-
this.options = options;
|
|
19
|
-
}
|
|
20
|
-
async openBrowser() {
|
|
21
|
-
if (this.browserPromise) {
|
|
22
|
-
return this.browserPromise;
|
|
23
|
-
}
|
|
24
|
-
if (this.browser) {
|
|
25
|
-
return this.browser;
|
|
26
|
-
}
|
|
27
|
-
this.browserPromise = (async () => {
|
|
28
|
-
const options = this.project.config.browser;
|
|
29
|
-
const playwright = await import('playwright');
|
|
30
|
-
const launchOptions = {
|
|
31
|
-
...this.options?.launch,
|
|
32
|
-
headless: options.headless
|
|
33
|
-
};
|
|
34
|
-
if (this.project.config.inspector.enabled) {
|
|
35
|
-
const port = this.project.config.inspector.port || 9229;
|
|
36
|
-
const host = this.project.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.project.vitest.logger.log(`Debugger listening on ws://${host}:${port}`);
|
|
41
|
-
}
|
|
42
|
-
if (this.project.config.browser.ui && this.browserName === "chromium") {
|
|
43
|
-
if (!launchOptions.args) {
|
|
44
|
-
launchOptions.args = [];
|
|
45
|
-
}
|
|
46
|
-
if (!launchOptions.args.includes("--start-maximized") && !launchOptions.args.includes("--start-fullscreen")) {
|
|
47
|
-
launchOptions.args.push("--start-maximized");
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const browser = await playwright[this.browserName].launch(launchOptions);
|
|
51
|
-
this.browser = browser;
|
|
52
|
-
this.browserPromise = null;
|
|
53
|
-
return this.browser;
|
|
54
|
-
})();
|
|
55
|
-
return this.browserPromise;
|
|
56
|
-
}
|
|
57
|
-
async createContext(sessionId) {
|
|
58
|
-
if (this.contexts.has(sessionId)) {
|
|
59
|
-
return this.contexts.get(sessionId);
|
|
60
|
-
}
|
|
61
|
-
const browser = await this.openBrowser();
|
|
62
|
-
const { actionTimeout, ...contextOptions } = this.options?.context ?? {};
|
|
63
|
-
const options = {
|
|
64
|
-
...contextOptions,
|
|
65
|
-
ignoreHTTPSErrors: true,
|
|
66
|
-
serviceWorkers: "allow"
|
|
67
|
-
};
|
|
68
|
-
if (this.project.config.browser.ui) {
|
|
69
|
-
options.viewport = null;
|
|
70
|
-
}
|
|
71
|
-
const context = await browser.newContext(options);
|
|
72
|
-
if (actionTimeout) {
|
|
73
|
-
context.setDefaultTimeout(actionTimeout);
|
|
74
|
-
}
|
|
75
|
-
this.contexts.set(sessionId, context);
|
|
76
|
-
return context;
|
|
77
|
-
}
|
|
78
|
-
getPage(sessionId) {
|
|
79
|
-
const page = this.pages.get(sessionId);
|
|
80
|
-
if (!page) {
|
|
81
|
-
throw new Error(`Page "${sessionId}" not found in ${this.browserName} browser.`);
|
|
82
|
-
}
|
|
83
|
-
return page;
|
|
84
|
-
}
|
|
85
|
-
getCommandsContext(sessionId) {
|
|
86
|
-
const page = this.getPage(sessionId);
|
|
87
|
-
return {
|
|
88
|
-
page,
|
|
89
|
-
context: this.contexts.get(sessionId),
|
|
90
|
-
frame() {
|
|
91
|
-
return new Promise((resolve, reject) => {
|
|
92
|
-
const frame = page.frame("vitest-iframe");
|
|
93
|
-
if (frame) {
|
|
94
|
-
return resolve(frame);
|
|
95
|
-
}
|
|
96
|
-
const timeout = setTimeout(() => {
|
|
97
|
-
const err = new Error(`Cannot find "vitest-iframe" on the page. This is a bug in Vitest, please report it.`);
|
|
98
|
-
reject(err);
|
|
99
|
-
}, 1e3);
|
|
100
|
-
page.on("frameattached", (frame2) => {
|
|
101
|
-
clearTimeout(timeout);
|
|
102
|
-
resolve(frame2);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
},
|
|
106
|
-
get iframe() {
|
|
107
|
-
return page.frameLocator('[data-vitest="true"]');
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
async openBrowserPage(sessionId) {
|
|
112
|
-
if (this.pages.has(sessionId)) {
|
|
113
|
-
const page2 = this.pages.get(sessionId);
|
|
114
|
-
await page2.close();
|
|
115
|
-
this.pages.delete(sessionId);
|
|
116
|
-
}
|
|
117
|
-
const context = await this.createContext(sessionId);
|
|
118
|
-
const page = await context.newPage();
|
|
119
|
-
this.pages.set(sessionId, page);
|
|
120
|
-
if (process.env.VITEST_PW_DEBUG) {
|
|
121
|
-
page.on("requestfailed", (request) => {
|
|
122
|
-
console.error(
|
|
123
|
-
"[PW Error]",
|
|
124
|
-
request.resourceType(),
|
|
125
|
-
"request failed for",
|
|
126
|
-
request.url(),
|
|
127
|
-
"url:",
|
|
128
|
-
request.failure()?.errorText
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
page.on("crash", () => {
|
|
133
|
-
const session = this.project.vitest._browserSessions.getSession(sessionId);
|
|
134
|
-
session?.reject(new Error("Page crashed when executing tests"));
|
|
135
|
-
});
|
|
136
|
-
return page;
|
|
137
|
-
}
|
|
138
|
-
async openPage(sessionId, url, beforeNavigate) {
|
|
139
|
-
const browserPage = await this.openBrowserPage(sessionId);
|
|
140
|
-
await beforeNavigate?.();
|
|
141
|
-
await browserPage.goto(url, { timeout: 0 });
|
|
142
|
-
}
|
|
143
|
-
async getCDPSession(sessionid) {
|
|
144
|
-
const page = this.getPage(sessionid);
|
|
145
|
-
const cdp = await page.context().newCDPSession(page);
|
|
146
|
-
return {
|
|
147
|
-
async send(method, params) {
|
|
148
|
-
const result = await cdp.send(method, params);
|
|
149
|
-
return result;
|
|
150
|
-
},
|
|
151
|
-
on(event, listener) {
|
|
152
|
-
cdp.on(event, listener);
|
|
153
|
-
},
|
|
154
|
-
off(event, listener) {
|
|
155
|
-
cdp.off(event, listener);
|
|
156
|
-
},
|
|
157
|
-
once(event, listener) {
|
|
158
|
-
cdp.once(event, listener);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
async close() {
|
|
163
|
-
const browser = this.browser;
|
|
164
|
-
this.browser = null;
|
|
165
|
-
await Promise.all([...this.pages.values()].map((p) => p.close()));
|
|
166
|
-
this.pages.clear();
|
|
167
|
-
await Promise.all([...this.contexts.values()].map((c) => c.close()));
|
|
168
|
-
this.contexts.clear();
|
|
169
|
-
await browser?.close();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const webdriverBrowsers = ["firefox", "chrome", "edge", "safari"];
|
|
174
|
-
class WebdriverBrowserProvider {
|
|
175
|
-
name = "webdriverio";
|
|
176
|
-
supportsParallelism = false;
|
|
177
|
-
browser = null;
|
|
178
|
-
browserName;
|
|
179
|
-
project;
|
|
180
|
-
options;
|
|
181
|
-
getSupportedBrowsers() {
|
|
182
|
-
return webdriverBrowsers;
|
|
183
|
-
}
|
|
184
|
-
async initialize(ctx, { browser, options }) {
|
|
185
|
-
this.project = ctx;
|
|
186
|
-
this.browserName = browser;
|
|
187
|
-
this.options = options;
|
|
188
|
-
}
|
|
189
|
-
async switchToTestFrame() {
|
|
190
|
-
const page = this.browser;
|
|
191
|
-
if (page.switchFrame) {
|
|
192
|
-
await page.switchFrame(page.$("iframe[data-vitest]"));
|
|
193
|
-
} else {
|
|
194
|
-
const iframe = await page.findElement(
|
|
195
|
-
"css selector",
|
|
196
|
-
"iframe[data-vitest]"
|
|
197
|
-
);
|
|
198
|
-
await page.switchToFrame(iframe);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
async switchToMainFrame() {
|
|
202
|
-
const page = this.browser;
|
|
203
|
-
if (page.switchFrame) {
|
|
204
|
-
await page.switchFrame(null);
|
|
205
|
-
} else {
|
|
206
|
-
await page.switchToParentFrame();
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
getCommandsContext() {
|
|
210
|
-
return {
|
|
211
|
-
browser: this.browser
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
async openBrowser() {
|
|
215
|
-
if (this.browser) {
|
|
216
|
-
return this.browser;
|
|
217
|
-
}
|
|
218
|
-
const options = this.project.config.browser;
|
|
219
|
-
if (this.browserName === "safari") {
|
|
220
|
-
if (options.headless) {
|
|
221
|
-
throw new Error(
|
|
222
|
-
"You've enabled headless mode for Safari but it doesn't currently support it."
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
const { remote } = await import('webdriverio');
|
|
227
|
-
this.browser = await remote({
|
|
228
|
-
...this.options,
|
|
229
|
-
logLevel: "error",
|
|
230
|
-
capabilities: this.buildCapabilities()
|
|
231
|
-
});
|
|
232
|
-
return this.browser;
|
|
233
|
-
}
|
|
234
|
-
buildCapabilities() {
|
|
235
|
-
const capabilities = {
|
|
236
|
-
...this.options?.capabilities,
|
|
237
|
-
browserName: this.browserName
|
|
238
|
-
};
|
|
239
|
-
const headlessMap = {
|
|
240
|
-
chrome: ["goog:chromeOptions", ["headless", "disable-gpu"]],
|
|
241
|
-
firefox: ["moz:firefoxOptions", ["-headless"]],
|
|
242
|
-
edge: ["ms:edgeOptions", ["--headless"]]
|
|
243
|
-
};
|
|
244
|
-
const options = this.project.config.browser;
|
|
245
|
-
const browser = this.browserName;
|
|
246
|
-
if (browser !== "safari" && options.headless) {
|
|
247
|
-
const [key, args] = headlessMap[browser];
|
|
248
|
-
const currentValues = this.options?.capabilities?.[key] || {};
|
|
249
|
-
const newArgs = [...currentValues.args || [], ...args];
|
|
250
|
-
capabilities[key] = { ...currentValues, args: newArgs };
|
|
251
|
-
}
|
|
252
|
-
if (options.ui && (browser === "chrome" || browser === "edge")) {
|
|
253
|
-
const key = browser === "chrome" ? "goog:chromeOptions" : "ms:edgeOptions";
|
|
254
|
-
const args = capabilities[key]?.args || [];
|
|
255
|
-
if (!args.includes("--start-maximized") && !args.includes("--start-fullscreen")) {
|
|
256
|
-
args.push("--start-maximized");
|
|
257
|
-
}
|
|
258
|
-
capabilities[key] ??= {};
|
|
259
|
-
capabilities[key].args = args;
|
|
260
|
-
}
|
|
261
|
-
return capabilities;
|
|
262
|
-
}
|
|
263
|
-
async openPage(_sessionId, url) {
|
|
264
|
-
const browserInstance = await this.openBrowser();
|
|
265
|
-
await browserInstance.url(url);
|
|
266
|
-
}
|
|
267
|
-
async close() {
|
|
268
|
-
await Promise.all([
|
|
269
|
-
this.browser?.sessionId ? this.browser?.deleteSession?.() : null
|
|
270
|
-
]);
|
|
271
|
-
process.exit();
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
export { PlaywrightBrowserProvider as P, WebdriverBrowserProvider as W };
|