@vitest/browser 3.1.1 → 3.1.3

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 (30) hide show
  1. package/dist/client/.vite/manifest.json +6 -6
  2. package/dist/client/__vitest__/assets/index-Cv3XDLXs.js +52 -0
  3. package/dist/client/__vitest__/assets/{index-B0KEk_KY.css → index-D6BhetW8.css} +1 -1
  4. package/dist/client/__vitest__/index.html +2 -2
  5. package/dist/client/__vitest_browser__/orchestrator-CuTjqoE1.js +287 -0
  6. package/dist/client/__vitest_browser__/{tester-DiLSqOx4.js → tester-D8qCxA_3.js} +3172 -3084
  7. package/dist/client/__vitest_browser__/{utils-CNTxSNQV.js → utils-Owv5OOOf.js} +2 -2
  8. package/dist/client/error-catcher.js +1 -14
  9. package/dist/client/esm-client-injector.js +0 -1
  10. package/dist/client/orchestrator.html +2 -2
  11. package/dist/client/tester/tester.html +2 -2
  12. package/dist/client.js +63 -23
  13. package/dist/context.js +4 -4
  14. package/dist/expect-element.js +1 -1
  15. package/dist/index-C3ICQ6zz.js +1 -0
  16. package/dist/index.d.ts +8 -8
  17. package/dist/index.js +364 -244
  18. package/dist/locators/index.js +1 -1
  19. package/dist/locators/playwright.js +1 -1
  20. package/dist/locators/preview.js +1 -1
  21. package/dist/locators/webdriverio.js +1 -1
  22. package/dist/providers.js +2 -1
  23. package/dist/{public-utils-xf4CCUzp.js → public-utils-DUr23h1p.js} +2 -2
  24. package/dist/state.js +2 -67
  25. package/dist/utils.js +1 -1
  26. package/dist/{webdriver-2iYWIzBv.js → webdriver-BH7t2pDp.js} +63 -9
  27. package/package.json +16 -16
  28. package/dist/client/__vitest__/assets/index-BLZJq7cG.js +0 -52
  29. package/dist/client/__vitest_browser__/orchestrator-CqPXjvQE.js +0 -241
  30. package/dist/index-DjDyxzt8.js +0 -1
@@ -1,5 +1,7 @@
1
1
  import { createManualModuleSource } from '@vitest/mocker/node';
2
+ import { createDebugger } from 'vitest/node';
2
3
 
4
+ const debug$1 = createDebugger("vitest:browser:playwright");
3
5
  const playwrightBrowsers = [
4
6
  "firefox",
5
7
  "webkit",
@@ -16,20 +18,25 @@ class PlaywrightBrowserProvider {
16
18
  pages = new Map();
17
19
  browserPromise = null;
18
20
  mocker;
21
+ closing = false;
19
22
  getSupportedBrowsers() {
20
23
  return playwrightBrowsers;
21
24
  }
22
25
  initialize(project, { browser, options }) {
26
+ this.closing = false;
23
27
  this.project = project;
24
28
  this.browserName = browser;
25
29
  this.options = options;
26
30
  this.mocker = this.createMocker();
27
31
  }
28
32
  async openBrowser() {
33
+ await this._throwIfClosing();
29
34
  if (this.browserPromise) {
35
+ debug$1?.("[%s] the browser is resolving, reusing the promise", this.browserName);
30
36
  return this.browserPromise;
31
37
  }
32
38
  if (this.browser) {
39
+ debug$1?.("[%s] the browser is resolved, reusing it", this.browserName);
33
40
  return this.browser;
34
41
  }
35
42
  this.browserPromise = (async () => {
@@ -55,8 +62,8 @@ class PlaywrightBrowserProvider {
55
62
  launchOptions.args.push("--start-maximized");
56
63
  }
57
64
  }
58
- const browser = await playwright[this.browserName].launch(launchOptions);
59
- this.browser = browser;
65
+ debug$1?.("[%s] initializing the browser with launch options: %O", this.browserName, launchOptions);
66
+ this.browser = await playwright[this.browserName].launch(launchOptions);
60
67
  this.browserPromise = null;
61
68
  return this.browser;
62
69
  })();
@@ -166,10 +173,13 @@ class PlaywrightBrowserProvider {
166
173
  };
167
174
  }
168
175
  async createContext(sessionId) {
176
+ await this._throwIfClosing();
169
177
  if (this.contexts.has(sessionId)) {
178
+ debug$1?.("[%s][%s] the context already exists, reusing it", sessionId, this.browserName);
170
179
  return this.contexts.get(sessionId);
171
180
  }
172
181
  const browser = await this.openBrowser();
182
+ await this._throwIfClosing(browser);
173
183
  const { actionTimeout,...contextOptions } = this.options?.context ?? {};
174
184
  const options = {
175
185
  ...contextOptions,
@@ -179,9 +189,11 @@ class PlaywrightBrowserProvider {
179
189
  options.viewport = null;
180
190
  }
181
191
  const context = await browser.newContext(options);
192
+ await this._throwIfClosing(context);
182
193
  if (actionTimeout) {
183
194
  context.setDefaultTimeout(actionTimeout);
184
195
  }
196
+ debug$1?.("[%s][%s] the context is ready", sessionId, this.browserName);
185
197
  this.contexts.set(sessionId, context);
186
198
  return context;
187
199
  }
@@ -219,29 +231,43 @@ class PlaywrightBrowserProvider {
219
231
  };
220
232
  }
221
233
  async openBrowserPage(sessionId) {
234
+ await this._throwIfClosing();
222
235
  if (this.pages.has(sessionId)) {
236
+ debug$1?.("[%s][%s] the page already exists, closing the old one", sessionId, this.browserName);
223
237
  const page = this.pages.get(sessionId);
224
238
  await page.close();
225
239
  this.pages.delete(sessionId);
226
240
  }
227
241
  const context = await this.createContext(sessionId);
228
242
  const page = await context.newPage();
243
+ debug$1?.("[%s][%s] the page is ready", sessionId, this.browserName);
244
+ await this._throwIfClosing(page);
229
245
  this.pages.set(sessionId, page);
230
246
  if (process.env.VITEST_PW_DEBUG) {
231
247
  page.on("requestfailed", (request) => {
232
248
  console.error("[PW Error]", request.resourceType(), "request failed for", request.url(), "url:", request.failure()?.errorText);
233
249
  });
234
250
  }
235
- page.on("crash", () => {
236
- const session = this.project.vitest._browserSessions.getSession(sessionId);
237
- session?.reject(new Error("Page crashed when executing tests"));
238
- });
239
251
  return page;
240
252
  }
241
253
  async openPage(sessionId, url, beforeNavigate) {
254
+ debug$1?.("[%s][%s] creating the browser page for %s", sessionId, this.browserName, url);
242
255
  const browserPage = await this.openBrowserPage(sessionId);
243
256
  await beforeNavigate?.();
257
+ debug$1?.("[%s][%s] browser page is created, opening %s", sessionId, this.browserName, url);
244
258
  await browserPage.goto(url, { timeout: 0 });
259
+ await this._throwIfClosing(browserPage);
260
+ }
261
+ async _throwIfClosing(disposable) {
262
+ if (this.closing) {
263
+ debug$1?.("[%s] provider was closed, cannot perform the action on %s", this.browserName, String(disposable));
264
+ await disposable?.close();
265
+ this.pages.clear();
266
+ this.contexts.clear();
267
+ this.browser = null;
268
+ this.browserPromise = null;
269
+ throw new Error(`[vitest] The provider was closed.`);
270
+ }
245
271
  }
246
272
  async getCDPSession(sessionid) {
247
273
  const page = this.getPage(sessionid);
@@ -263,13 +289,20 @@ class PlaywrightBrowserProvider {
263
289
  };
264
290
  }
265
291
  async close() {
292
+ debug$1?.("[%s] closing provider", this.browserName);
293
+ this.closing = true;
266
294
  const browser = this.browser;
267
295
  this.browser = null;
296
+ if (this.browserPromise) {
297
+ await this.browserPromise;
298
+ this.browserPromise = null;
299
+ }
268
300
  await Promise.all([...this.pages.values()].map((p) => p.close()));
269
301
  this.pages.clear();
270
302
  await Promise.all([...this.contexts.values()].map((c) => c.close()));
271
303
  this.contexts.clear();
272
304
  await browser?.close();
305
+ debug$1?.("[%s] provider is closed", this.browserName);
273
306
  }
274
307
  }
275
308
  function getHeaders(config) {
@@ -299,6 +332,7 @@ function isDirectCSSRequest(request) {
299
332
  return CSS_LANGS_RE.test(request) && directRequestRE.test(request);
300
333
  }
301
334
 
335
+ const debug = createDebugger("vitest:browser:wdio");
302
336
  const webdriverBrowsers = [
303
337
  "firefox",
304
338
  "chrome",
@@ -312,10 +346,12 @@ class WebdriverBrowserProvider {
312
346
  browserName;
313
347
  project;
314
348
  options;
349
+ closing = false;
315
350
  getSupportedBrowsers() {
316
351
  return webdriverBrowsers;
317
352
  }
318
353
  async initialize(ctx, { browser, options }) {
354
+ this.closing = false;
319
355
  this.project = ctx;
320
356
  this.browserName = browser;
321
357
  this.options = options;
@@ -341,7 +377,9 @@ class WebdriverBrowserProvider {
341
377
  return { browser: this.browser };
342
378
  }
343
379
  async openBrowser() {
380
+ await this._throwIfClosing("opening the browser");
344
381
  if (this.browser) {
382
+ debug?.("[%s] the browser is already opened, reusing it", this.browserName);
345
383
  return this.browser;
346
384
  }
347
385
  const options = this.project.config.browser;
@@ -351,11 +389,14 @@ class WebdriverBrowserProvider {
351
389
  }
352
390
  }
353
391
  const { remote } = await import('webdriverio');
354
- this.browser = await remote({
392
+ const remoteOptions = {
355
393
  ...this.options,
356
394
  logLevel: "error",
357
395
  capabilities: this.buildCapabilities()
358
- });
396
+ };
397
+ debug?.("[%s] opening the browser with options: %O", this.browserName, remoteOptions);
398
+ this.browser = await remote(remoteOptions);
399
+ await this._throwIfClosing();
359
400
  return this.browser;
360
401
  }
361
402
  buildCapabilities() {
@@ -390,11 +431,24 @@ class WebdriverBrowserProvider {
390
431
  }
391
432
  return capabilities;
392
433
  }
393
- async openPage(_sessionId, url) {
434
+ async openPage(sessionId, url) {
435
+ await this._throwIfClosing("creating the browser");
436
+ debug?.("[%s][%s] creating the browser page for %s", sessionId, this.browserName, url);
394
437
  const browserInstance = await this.openBrowser();
438
+ debug?.("[%s][%s] browser page is created, opening %s", sessionId, this.browserName, url);
395
439
  await browserInstance.url(url);
440
+ await this._throwIfClosing("opening the url");
441
+ }
442
+ async _throwIfClosing(action) {
443
+ if (this.closing) {
444
+ debug?.(`[%s] provider was closed, cannot perform the action${action ? ` ${action}` : ""}`, this.browserName);
445
+ await (this.browser?.sessionId ? this.browser?.deleteSession?.() : null);
446
+ throw new Error(`[vitest] The provider was closed.`);
447
+ }
396
448
  }
397
449
  async close() {
450
+ debug?.("[%s] closing provider", this.browserName);
451
+ this.closing = true;
398
452
  await Promise.all([this.browser?.sessionId ? this.browser?.deleteSession?.() : null]);
399
453
  process.exit();
400
454
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/browser",
3
3
  "type": "module",
4
- "version": "3.1.1",
4
+ "version": "3.1.3",
5
5
  "description": "Browser running for Vitest",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -66,7 +66,7 @@
66
66
  "peerDependencies": {
67
67
  "playwright": "*",
68
68
  "webdriverio": "^7.0.0 || ^8.0.0 || ^9.0.0",
69
- "vitest": "3.1.1"
69
+ "vitest": "3.1.3"
70
70
  },
71
71
  "peerDependenciesMeta": {
72
72
  "playwright": {
@@ -86,27 +86,27 @@
86
86
  "sirv": "^3.0.1",
87
87
  "tinyrainbow": "^2.0.0",
88
88
  "ws": "^8.18.1",
89
- "@vitest/mocker": "3.1.1",
90
- "@vitest/utils": "3.1.1"
89
+ "@vitest/utils": "3.1.3",
90
+ "@vitest/mocker": "3.1.3"
91
91
  },
92
92
  "devDependencies": {
93
- "@types/ws": "^8.18.0",
94
- "@wdio/protocols": "^9.7.0",
95
- "@wdio/types": "^9.10.1",
96
- "birpc": "0.2.19",
93
+ "@types/ws": "^8.18.1",
94
+ "@wdio/protocols": "^9.12.5",
95
+ "@wdio/types": "^9.12.6",
96
+ "birpc": "2.3.0",
97
97
  "flatted": "^3.3.3",
98
98
  "ivya": "^1.6.0",
99
- "mime": "^4.0.6",
99
+ "mime": "^4.0.7",
100
100
  "pathe": "^2.0.3",
101
101
  "periscopic": "^4.0.2",
102
- "playwright": "^1.51.1",
103
- "playwright-core": "^1.51.1",
102
+ "playwright": "^1.52.0",
103
+ "playwright-core": "^1.52.0",
104
104
  "safaridriver": "^1.0.0",
105
- "webdriverio": "^9.12.1",
106
- "@vitest/runner": "3.1.1",
107
- "@vitest/ui": "3.1.1",
108
- "vitest": "3.1.1",
109
- "@vitest/ws-client": "3.1.1"
105
+ "webdriverio": "^9.12.7",
106
+ "@vitest/runner": "3.1.3",
107
+ "@vitest/ui": "3.1.3",
108
+ "vitest": "3.1.3",
109
+ "@vitest/ws-client": "3.1.3"
110
110
  },
111
111
  "scripts": {
112
112
  "build": "rimraf dist && pnpm build:node && pnpm build:client",