@vitest/browser 4.0.0-beta.12 → 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.
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 +521 -1472
  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 -383
  30. package/dist/providers/preview.d.ts +0 -16
  31. package/dist/providers/preview.js +0 -43
  32. package/dist/providers/webdriverio.d.ts +0 -50
  33. package/dist/providers/webdriverio.js +0 -171
  34. package/dist/utils.js +0 -1
  35. package/providers.d.ts +0 -7
@@ -1,383 +0,0 @@
1
- import { createManualModuleSource } from '@vitest/mocker/node';
2
- import c from 'tinyrainbow';
3
- import { createDebugger, isCSSRequest } from 'vitest/node';
4
-
5
- const debug = createDebugger("vitest:browser:playwright");
6
- const playwrightBrowsers = [
7
- "firefox",
8
- "webkit",
9
- "chromium"
10
- ];
11
- function playwright(options = {}) {
12
- return {
13
- name: "playwright",
14
- supportedBrowser: playwrightBrowsers,
15
- factory(project) {
16
- return new PlaywrightBrowserProvider(project, options);
17
- },
18
- _cli: true
19
- };
20
- }
21
- class PlaywrightBrowserProvider {
22
- name = "playwright";
23
- supportsParallelism = true;
24
- browser = null;
25
- contexts = new Map();
26
- pages = new Map();
27
- mocker;
28
- browserName;
29
- browserPromise = null;
30
- closing = false;
31
- tracingContexts = new Set();
32
- pendingTraces = new Map();
33
- constructor(project, options) {
34
- this.project = project;
35
- this.options = options;
36
- this.browserName = project.config.browser.name;
37
- this.mocker = this.createMocker();
38
- // make sure the traces are finished if the test hangs
39
- process.on("SIGTERM", () => {
40
- if (!this.browser) {
41
- return;
42
- }
43
- const promises = [];
44
- for (const [trace, contextId] of this.pendingTraces.entries()) {
45
- promises.push(() => {
46
- const context = this.contexts.get(contextId);
47
- return context?.tracing.stopChunk({ path: trace });
48
- });
49
- }
50
- return Promise.allSettled(promises);
51
- });
52
- }
53
- async openBrowser() {
54
- await this._throwIfClosing();
55
- if (this.browserPromise) {
56
- debug?.("[%s] the browser is resolving, reusing the promise", this.browserName);
57
- return this.browserPromise;
58
- }
59
- if (this.browser) {
60
- debug?.("[%s] the browser is resolved, reusing it", this.browserName);
61
- return this.browser;
62
- }
63
- this.browserPromise = (async () => {
64
- const options = this.project.config.browser;
65
- const playwright = await import('playwright');
66
- if (this.options.connectOptions) {
67
- if (this.options.launchOptions) {
68
- 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.
69
- Ignoring ${c.bold(c.italic(c.yellow("launch")))} options and using ${c.bold(c.italic(c.yellow("connect")))} mode.
70
- You probably want to remove one of the two options and keep only the one you want to use.`));
71
- }
72
- const browser = await playwright[this.browserName].connect(this.options.connectOptions.wsEndpoint, this.options.connectOptions);
73
- this.browser = browser;
74
- this.browserPromise = null;
75
- return this.browser;
76
- }
77
- const launchOptions = {
78
- ...this.options.launchOptions,
79
- headless: options.headless
80
- };
81
- if (typeof options.trace === "object" && options.trace.tracesDir) {
82
- launchOptions.tracesDir = options.trace?.tracesDir;
83
- }
84
- if (this.project.config.inspector.enabled) {
85
- // NodeJS equivalent defaults: https://nodejs.org/en/learn/getting-started/debugging#enable-inspector
86
- const port = this.project.config.inspector.port || 9229;
87
- const host = this.project.config.inspector.host || "127.0.0.1";
88
- launchOptions.args ||= [];
89
- launchOptions.args.push(`--remote-debugging-port=${port}`);
90
- launchOptions.args.push(`--remote-debugging-address=${host}`);
91
- this.project.vitest.logger.log(`Debugger listening on ws://${host}:${port}`);
92
- }
93
- // start Vitest UI maximized only on supported browsers
94
- if (this.project.config.browser.ui && this.browserName === "chromium") {
95
- if (!launchOptions.args) {
96
- launchOptions.args = [];
97
- }
98
- if (!launchOptions.args.includes("--start-maximized") && !launchOptions.args.includes("--start-fullscreen")) {
99
- launchOptions.args.push("--start-maximized");
100
- }
101
- }
102
- debug?.("[%s] initializing the browser with launch options: %O", this.browserName, launchOptions);
103
- this.browser = await playwright[this.browserName].launch(launchOptions);
104
- this.browserPromise = null;
105
- return this.browser;
106
- })();
107
- return this.browserPromise;
108
- }
109
- createMocker() {
110
- const idPreficates = new Map();
111
- const sessionIds = new Map();
112
- function createPredicate(sessionId, url) {
113
- const moduleUrl = new URL(url, "http://localhost");
114
- const predicate = (url) => {
115
- if (url.searchParams.has("_vitest_original")) {
116
- return false;
117
- }
118
- // different modules, ignore request
119
- if (url.pathname !== moduleUrl.pathname) {
120
- return false;
121
- }
122
- url.searchParams.delete("t");
123
- url.searchParams.delete("v");
124
- url.searchParams.delete("import");
125
- // different search params, ignore request
126
- if (url.searchParams.size !== moduleUrl.searchParams.size) {
127
- return false;
128
- }
129
- // check that all search params are the same
130
- for (const [param, value] of url.searchParams.entries()) {
131
- if (moduleUrl.searchParams.get(param) !== value) {
132
- return false;
133
- }
134
- }
135
- return true;
136
- };
137
- const ids = sessionIds.get(sessionId) || [];
138
- ids.push(moduleUrl.href);
139
- sessionIds.set(sessionId, ids);
140
- idPreficates.set(predicateKey(sessionId, moduleUrl.href), predicate);
141
- return predicate;
142
- }
143
- function predicateKey(sessionId, url) {
144
- return `${sessionId}:${url}`;
145
- }
146
- return {
147
- register: async (sessionId, module) => {
148
- const page = this.getPage(sessionId);
149
- await page.route(createPredicate(sessionId, module.url), async (route) => {
150
- if (module.type === "manual") {
151
- const exports = Object.keys(await module.resolve());
152
- const body = createManualModuleSource(module.url, exports);
153
- return route.fulfill({
154
- body,
155
- headers: getHeaders(this.project.browser.vite.config)
156
- });
157
- }
158
- // webkit doesn't support redirect responses
159
- // https://github.com/microsoft/playwright/issues/18318
160
- const isWebkit = this.browserName === "webkit";
161
- if (isWebkit) {
162
- let url;
163
- if (module.type === "redirect") {
164
- const redirect = new URL(module.redirect);
165
- url = redirect.href.slice(redirect.origin.length);
166
- } else {
167
- const request = new URL(route.request().url());
168
- request.searchParams.set("mock", module.type);
169
- url = request.href.slice(request.origin.length);
170
- }
171
- const result = await this.project.browser.vite.transformRequest(url).catch(() => null);
172
- if (!result) {
173
- return route.continue();
174
- }
175
- let content = result.code;
176
- if (result.map && "version" in result.map && result.map.mappings) {
177
- const type = isDirectCSSRequest(url) ? "css" : "js";
178
- content = getCodeWithSourcemap(type, content.toString(), result.map);
179
- }
180
- return route.fulfill({
181
- body: content,
182
- headers: getHeaders(this.project.browser.vite.config)
183
- });
184
- }
185
- if (module.type === "redirect") {
186
- return route.fulfill({
187
- status: 302,
188
- headers: { Location: module.redirect }
189
- });
190
- } else if (module.type === "automock" || module.type === "autospy") {
191
- const url = new URL(route.request().url());
192
- url.searchParams.set("mock", module.type);
193
- return route.fulfill({
194
- status: 302,
195
- headers: { Location: url.href }
196
- });
197
- } else ;
198
- });
199
- },
200
- delete: async (sessionId, id) => {
201
- const page = this.getPage(sessionId);
202
- const key = predicateKey(sessionId, id);
203
- const predicate = idPreficates.get(key);
204
- if (predicate) {
205
- await page.unroute(predicate).finally(() => idPreficates.delete(key));
206
- }
207
- },
208
- clear: async (sessionId) => {
209
- const page = this.getPage(sessionId);
210
- const ids = sessionIds.get(sessionId) || [];
211
- const promises = ids.map((id) => {
212
- const key = predicateKey(sessionId, id);
213
- const predicate = idPreficates.get(key);
214
- if (predicate) {
215
- return page.unroute(predicate).finally(() => idPreficates.delete(key));
216
- }
217
- return null;
218
- });
219
- await Promise.all(promises).finally(() => sessionIds.delete(sessionId));
220
- }
221
- };
222
- }
223
- async createContext(sessionId) {
224
- await this._throwIfClosing();
225
- if (this.contexts.has(sessionId)) {
226
- debug?.("[%s][%s] the context already exists, reusing it", sessionId, this.browserName);
227
- return this.contexts.get(sessionId);
228
- }
229
- const browser = await this.openBrowser();
230
- await this._throwIfClosing(browser);
231
- const actionTimeout = this.options.actionTimeout;
232
- const contextOptions = this.options.contextOptions ?? {};
233
- const options = {
234
- ...contextOptions,
235
- ignoreHTTPSErrors: true
236
- };
237
- if (this.project.config.browser.ui) {
238
- options.viewport = null;
239
- }
240
- const context = await browser.newContext(options);
241
- await this._throwIfClosing(context);
242
- if (actionTimeout != null) {
243
- context.setDefaultTimeout(actionTimeout);
244
- }
245
- debug?.("[%s][%s] the context is ready", sessionId, this.browserName);
246
- this.contexts.set(sessionId, context);
247
- return context;
248
- }
249
- getPage(sessionId) {
250
- const page = this.pages.get(sessionId);
251
- if (!page) {
252
- throw new Error(`Page "${sessionId}" not found in ${this.browserName} browser.`);
253
- }
254
- return page;
255
- }
256
- getCommandsContext(sessionId) {
257
- const page = this.getPage(sessionId);
258
- return {
259
- page,
260
- context: this.contexts.get(sessionId),
261
- frame() {
262
- return new Promise((resolve, reject) => {
263
- const frame = page.frame("vitest-iframe");
264
- if (frame) {
265
- return resolve(frame);
266
- }
267
- const timeout = setTimeout(() => {
268
- const err = new Error(`Cannot find "vitest-iframe" on the page. This is a bug in Vitest, please report it.`);
269
- reject(err);
270
- }, 1e3).unref();
271
- page.on("frameattached", (frame) => {
272
- clearTimeout(timeout);
273
- resolve(frame);
274
- });
275
- });
276
- },
277
- get iframe() {
278
- return page.frameLocator("[data-vitest=\"true\"]");
279
- }
280
- };
281
- }
282
- async openBrowserPage(sessionId) {
283
- await this._throwIfClosing();
284
- if (this.pages.has(sessionId)) {
285
- debug?.("[%s][%s] the page already exists, closing the old one", sessionId, this.browserName);
286
- const page = this.pages.get(sessionId);
287
- await page.close();
288
- this.pages.delete(sessionId);
289
- }
290
- const context = await this.createContext(sessionId);
291
- const page = await context.newPage();
292
- debug?.("[%s][%s] the page is ready", sessionId, this.browserName);
293
- await this._throwIfClosing(page);
294
- this.pages.set(sessionId, page);
295
- if (process.env.VITEST_PW_DEBUG) {
296
- page.on("requestfailed", (request) => {
297
- console.error("[PW Error]", request.resourceType(), "request failed for", request.url(), "url:", request.failure()?.errorText);
298
- });
299
- }
300
- return page;
301
- }
302
- async openPage(sessionId, url, beforeNavigate) {
303
- debug?.("[%s][%s] creating the browser page for %s", sessionId, this.browserName, url);
304
- const browserPage = await this.openBrowserPage(sessionId);
305
- await beforeNavigate?.();
306
- debug?.("[%s][%s] browser page is created, opening %s", sessionId, this.browserName, url);
307
- await browserPage.goto(url, { timeout: 0 });
308
- await this._throwIfClosing(browserPage);
309
- }
310
- async _throwIfClosing(disposable) {
311
- if (this.closing) {
312
- debug?.("[%s] provider was closed, cannot perform the action on %s", this.browserName, String(disposable));
313
- await disposable?.close();
314
- this.pages.clear();
315
- this.contexts.clear();
316
- this.browser = null;
317
- this.browserPromise = null;
318
- throw new Error(`[vitest] The provider was closed.`);
319
- }
320
- }
321
- async getCDPSession(sessionid) {
322
- const page = this.getPage(sessionid);
323
- const cdp = await page.context().newCDPSession(page);
324
- return {
325
- async send(method, params) {
326
- const result = await cdp.send(method, params);
327
- return result;
328
- },
329
- on(event, listener) {
330
- cdp.on(event, listener);
331
- },
332
- off(event, listener) {
333
- cdp.off(event, listener);
334
- },
335
- once(event, listener) {
336
- cdp.once(event, listener);
337
- }
338
- };
339
- }
340
- async close() {
341
- debug?.("[%s] closing provider", this.browserName);
342
- this.closing = true;
343
- if (this.browserPromise) {
344
- await this.browserPromise;
345
- this.browserPromise = null;
346
- }
347
- const browser = this.browser;
348
- this.browser = null;
349
- await Promise.all([...this.pages.values()].map((p) => p.close()));
350
- this.pages.clear();
351
- await Promise.all([...this.contexts.values()].map((c) => c.close()));
352
- this.contexts.clear();
353
- await browser?.close();
354
- debug?.("[%s] provider is closed", this.browserName);
355
- }
356
- }
357
- function getHeaders(config) {
358
- const headers = { "Content-Type": "application/javascript" };
359
- for (const name in config.server.headers) {
360
- headers[name] = String(config.server.headers[name]);
361
- }
362
- return headers;
363
- }
364
- function getCodeWithSourcemap(type, code, map) {
365
- if (type === "js") {
366
- code += `\n//# sourceMappingURL=${genSourceMapUrl(map)}`;
367
- } else if (type === "css") {
368
- code += `\n/*# sourceMappingURL=${genSourceMapUrl(map)} */`;
369
- }
370
- return code;
371
- }
372
- function genSourceMapUrl(map) {
373
- if (typeof map !== "string") {
374
- map = JSON.stringify(map);
375
- }
376
- return `data:application/json;base64,${Buffer.from(map).toString("base64")}`;
377
- }
378
- const directRequestRE = /[?&]direct\b/;
379
- function isDirectCSSRequest(request) {
380
- return isCSSRequest(request) && directRequestRE.test(request);
381
- }
382
-
383
- export { PlaywrightBrowserProvider, playwright };
@@ -1,16 +0,0 @@
1
- import { BrowserProviderOption, BrowserProvider, TestProject } from 'vitest/node';
2
-
3
- declare function preview(): BrowserProviderOption;
4
- declare class PreviewBrowserProvider implements BrowserProvider {
5
- name: "preview";
6
- supportsParallelism: boolean;
7
- private project;
8
- private open;
9
- constructor(project: TestProject);
10
- isOpen(): boolean;
11
- getCommandsContext(): {};
12
- openPage(_sessionId: string, url: string): Promise<void>;
13
- close(): Promise<void>;
14
- }
15
-
16
- export { PreviewBrowserProvider, preview };
@@ -1,43 +0,0 @@
1
- function preview() {
2
- return {
3
- name: "preview",
4
- factory(project) {
5
- return new PreviewBrowserProvider(project);
6
- },
7
- _cli: true
8
- };
9
- }
10
- class PreviewBrowserProvider {
11
- name = "preview";
12
- supportsParallelism = false;
13
- project;
14
- open = false;
15
- constructor(project) {
16
- this.project = project;
17
- this.open = false;
18
- if (project.config.browser.headless) {
19
- throw new Error("You've enabled headless mode for \"preview\" provider but it doesn't support it. Use \"playwright\" or \"webdriverio\" instead: https://vitest.dev/guide/browser/#configuration");
20
- }
21
- project.vitest.logger.printBrowserBanner(project);
22
- }
23
- isOpen() {
24
- return this.open;
25
- }
26
- getCommandsContext() {
27
- return {};
28
- }
29
- async openPage(_sessionId, url) {
30
- this.open = true;
31
- if (!this.project.browser) {
32
- throw new Error("Browser is not initialized");
33
- }
34
- const options = this.project.browser.vite.config.server;
35
- const _open = options.open;
36
- options.open = url;
37
- this.project.browser.vite.openBrowser();
38
- options.open = _open;
39
- }
40
- async close() {}
41
- }
42
-
43
- export { PreviewBrowserProvider, preview };
@@ -1,50 +0,0 @@
1
- import { ScreenshotMatcherOptions, ScreenshotComparatorRegistry } from '@vitest/browser/context';
2
- import { BrowserProviderOption, BrowserProvider, TestProject } from 'vitest/node';
3
- import { ClickOptions, DragAndDropOptions, remote } from 'webdriverio';
4
-
5
- interface WebdriverProviderOptions extends Partial<Parameters<typeof remote>[0]> {}
6
- declare function webdriverio(options?: WebdriverProviderOptions): BrowserProviderOption;
7
- declare class WebdriverBrowserProvider implements BrowserProvider {
8
- name: "webdriverio";
9
- supportsParallelism: boolean;
10
- browser: WebdriverIO.Browser | null;
11
- private browserName;
12
- private project;
13
- private options?;
14
- private closing;
15
- private iframeSwitched;
16
- private topLevelContext;
17
- getSupportedBrowsers(): readonly string[];
18
- constructor(project: TestProject, options: WebdriverProviderOptions);
19
- isIframeSwitched(): boolean;
20
- switchToTestFrame(): Promise<void>;
21
- switchToMainFrame(): Promise<void>;
22
- setViewport(options: {
23
- width: number;
24
- height: number;
25
- }): Promise<void>;
26
- getCommandsContext(): {
27
- browser: WebdriverIO.Browser | null;
28
- };
29
- openBrowser(): Promise<WebdriverIO.Browser>;
30
- private buildCapabilities;
31
- openPage(sessionId: string, url: string): Promise<void>;
32
- private _throwIfClosing;
33
- close(): Promise<void>;
34
- }
35
- declare module "vitest/node" {
36
- interface UserEventClickOptions extends ClickOptions {}
37
- interface UserEventDragOptions extends DragAndDropOptions {
38
- sourceX?: number;
39
- sourceY?: number;
40
- targetX?: number;
41
- targetY?: number;
42
- }
43
- interface BrowserCommandContext {
44
- browser: WebdriverIO.Browser;
45
- }
46
- interface ToMatchScreenshotOptions extends Omit<ScreenshotMatcherOptions, "comparatorName" | "comparatorOptions"> {}
47
- interface ToMatchScreenshotComparators extends ScreenshotComparatorRegistry {}
48
- }
49
-
50
- export { WebdriverBrowserProvider, webdriverio };
@@ -1,171 +0,0 @@
1
- import { createDebugger } from 'vitest/node';
2
-
3
- const debug = createDebugger("vitest:browser:wdio");
4
- const webdriverBrowsers = [
5
- "firefox",
6
- "chrome",
7
- "edge",
8
- "safari"
9
- ];
10
- function webdriverio(options = {}) {
11
- return {
12
- name: "webdriverio",
13
- supportedBrowser: webdriverBrowsers,
14
- factory(project) {
15
- return new WebdriverBrowserProvider(project, options);
16
- },
17
- _cli: true
18
- };
19
- }
20
- class WebdriverBrowserProvider {
21
- name = "webdriverio";
22
- supportsParallelism = false;
23
- browser = null;
24
- browserName;
25
- project;
26
- options;
27
- closing = false;
28
- iframeSwitched = false;
29
- topLevelContext;
30
- getSupportedBrowsers() {
31
- return webdriverBrowsers;
32
- }
33
- constructor(project, options) {
34
- // increase shutdown timeout because WDIO takes some extra time to kill the driver
35
- if (!project.vitest.state._data.timeoutIncreased) {
36
- project.vitest.state._data.timeoutIncreased = true;
37
- project.vitest.config.teardownTimeout += 1e4;
38
- }
39
- this.closing = false;
40
- this.project = project;
41
- this.browserName = project.config.browser.name;
42
- this.options = options;
43
- }
44
- isIframeSwitched() {
45
- return this.iframeSwitched;
46
- }
47
- async switchToTestFrame() {
48
- const browser = this.browser;
49
- // support wdio@9
50
- if (browser.switchFrame) {
51
- await browser.switchFrame(browser.$("iframe[data-vitest]"));
52
- } else {
53
- const iframe = await browser.findElement("css selector", "iframe[data-vitest]");
54
- await browser.switchToFrame(iframe);
55
- }
56
- this.iframeSwitched = true;
57
- }
58
- async switchToMainFrame() {
59
- const page = this.browser;
60
- if (page.switchFrame) {
61
- await page.switchFrame(null);
62
- } else {
63
- await page.switchToParentFrame();
64
- }
65
- this.iframeSwitched = false;
66
- }
67
- async setViewport(options) {
68
- if (this.topLevelContext == null || !this.browser) {
69
- throw new Error(`The browser has no open pages.`);
70
- }
71
- await this.browser.send({
72
- method: "browsingContext.setViewport",
73
- params: {
74
- context: this.topLevelContext,
75
- devicePixelRatio: 1,
76
- viewport: options
77
- }
78
- });
79
- }
80
- getCommandsContext() {
81
- return { browser: this.browser };
82
- }
83
- async openBrowser() {
84
- await this._throwIfClosing("opening the browser");
85
- if (this.browser) {
86
- debug?.("[%s] the browser is already opened, reusing it", this.browserName);
87
- return this.browser;
88
- }
89
- const options = this.project.config.browser;
90
- if (this.browserName === "safari") {
91
- if (options.headless) {
92
- throw new Error("You've enabled headless mode for Safari but it doesn't currently support it.");
93
- }
94
- }
95
- const { remote } = await import('webdriverio');
96
- const remoteOptions = {
97
- logLevel: "silent",
98
- ...this.options,
99
- capabilities: this.buildCapabilities()
100
- };
101
- debug?.("[%s] opening the browser with options: %O", this.browserName, remoteOptions);
102
- // TODO: close everything, if browser is closed from the outside
103
- this.browser = await remote(remoteOptions);
104
- await this._throwIfClosing();
105
- return this.browser;
106
- }
107
- buildCapabilities() {
108
- const capabilities = {
109
- ...this.options?.capabilities,
110
- browserName: this.browserName
111
- };
112
- const headlessMap = {
113
- chrome: ["goog:chromeOptions", ["headless", "disable-gpu"]],
114
- firefox: ["moz:firefoxOptions", ["-headless"]],
115
- edge: ["ms:edgeOptions", ["--headless"]]
116
- };
117
- const options = this.project.config.browser;
118
- const browser = this.browserName;
119
- if (browser !== "safari" && options.headless) {
120
- const [key, args] = headlessMap[browser];
121
- const currentValues = (this.options?.capabilities)?.[key] || {};
122
- const newArgs = [...currentValues.args || [], ...args];
123
- capabilities[key] = {
124
- ...currentValues,
125
- args: newArgs
126
- };
127
- }
128
- // start Vitest UI maximized only on supported browsers
129
- if (options.ui && (browser === "chrome" || browser === "edge")) {
130
- const key = browser === "chrome" ? "goog:chromeOptions" : "ms:edgeOptions";
131
- const args = capabilities[key]?.args || [];
132
- if (!args.includes("--start-maximized") && !args.includes("--start-fullscreen")) {
133
- args.push("--start-maximized");
134
- }
135
- capabilities[key] ??= {};
136
- capabilities[key].args = args;
137
- }
138
- return capabilities;
139
- }
140
- async openPage(sessionId, url) {
141
- await this._throwIfClosing("creating the browser");
142
- debug?.("[%s][%s] creating the browser page for %s", sessionId, this.browserName, url);
143
- const browserInstance = await this.openBrowser();
144
- debug?.("[%s][%s] browser page is created, opening %s", sessionId, this.browserName, url);
145
- await browserInstance.url(url);
146
- this.topLevelContext = await browserInstance.getWindowHandle();
147
- await this._throwIfClosing("opening the url");
148
- }
149
- async _throwIfClosing(action) {
150
- if (this.closing) {
151
- debug?.(`[%s] provider was closed, cannot perform the action${action ? ` ${action}` : ""}`, this.browserName);
152
- await (this.browser?.sessionId ? this.browser?.deleteSession?.() : null);
153
- throw new Error(`[vitest] The provider was closed.`);
154
- }
155
- }
156
- async close() {
157
- debug?.("[%s] closing provider", this.browserName);
158
- this.closing = true;
159
- const browser = this.browser;
160
- const sessionId = browser?.sessionId;
161
- if (!browser || !sessionId) {
162
- return;
163
- }
164
- // https://github.com/webdriverio/webdriverio/blob/ab1a2e82b13a9c7d0e275ae87e7357e1b047d8d3/packages/wdio-runner/src/index.ts#L486
165
- await browser.deleteSession();
166
- browser.sessionId = undefined;
167
- this.browser = null;
168
- }
169
- }
170
-
171
- export { WebdriverBrowserProvider, webdriverio };
package/dist/utils.js DELETED
@@ -1 +0,0 @@
1
- import"@vitest/browser/context";export{u as debug,h as getElementError,t as getElementLocatorSelectors,v as prettyDOM}from"./public-utils-B6exS8fl.js";import"vitest/internal/browser";
package/providers.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import type { BrowserProviderModule } from 'vitest/node'
2
-
3
- declare const webdriverio: BrowserProviderModule
4
- declare const playwright: BrowserProviderModule
5
- declare const preview: BrowserProviderModule
6
-
7
- export { webdriverio, playwright, preview }