@vitest/browser 5.0.0-beta.5 → 5.0.0-beta.7

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.
@@ -1,8 +1,8 @@
1
1
  {
2
- "../../../../node_modules/.pnpm/rrweb-snapshot@2.0.0-alpha.20_patch_hash=d11ec9bd9b66247ba493ab5fd117fbf0b4cb6e5d0a6a7c600d1d844bfa3d3044/node_modules/rrweb-snapshot/dist/rrweb-snapshot.js": {
3
- "file": "__vitest_browser__/rrweb-snapshot-iZCFA2to.js",
2
+ "../../../../node_modules/.pnpm/rrweb-snapshot@2.0.1_patch_hash=9e976b2c55a5c2ed589c41b8f46cc44b6fe6f528ebb4d3780a44b1ca8cbb17a4/node_modules/rrweb-snapshot/dist/rrweb-snapshot.js": {
3
+ "file": "__vitest_browser__/rrweb-snapshot-DkFyu2W8.js",
4
4
  "name": "rrweb-snapshot",
5
- "src": "../../../../node_modules/.pnpm/rrweb-snapshot@2.0.0-alpha.20_patch_hash=d11ec9bd9b66247ba493ab5fd117fbf0b4cb6e5d0a6a7c600d1d844bfa3d3044/node_modules/rrweb-snapshot/dist/rrweb-snapshot.js",
5
+ "src": "../../../../node_modules/.pnpm/rrweb-snapshot@2.0.1_patch_hash=9e976b2c55a5c2ed589c41b8f46cc44b6fe6f528ebb4d3780a44b1ca8cbb17a4/node_modules/rrweb-snapshot/dist/rrweb-snapshot.js",
6
6
  "isDynamicEntry": true
7
7
  },
8
8
  "_defineProperty-WHpdAQXR.js": {
@@ -10,7 +10,7 @@
10
10
  "name": "defineProperty"
11
11
  },
12
12
  "orchestrator.html": {
13
- "file": "__vitest_browser__/orchestrator-bDJB3Bid.js",
13
+ "file": "__vitest_browser__/orchestrator-Bdv4lWwV.js",
14
14
  "name": "orchestrator",
15
15
  "src": "orchestrator.html",
16
16
  "isEntry": true,
@@ -19,7 +19,7 @@
19
19
  ]
20
20
  },
21
21
  "tester/tester.html": {
22
- "file": "__vitest_browser__/tester-C1kIlbPd.js",
22
+ "file": "__vitest_browser__/tester-CREI5Ivt.js",
23
23
  "name": "tester",
24
24
  "src": "tester/tester.html",
25
25
  "isEntry": true,
@@ -27,7 +27,7 @@
27
27
  "_defineProperty-WHpdAQXR.js"
28
28
  ],
29
29
  "dynamicImports": [
30
- "../../../../node_modules/.pnpm/rrweb-snapshot@2.0.0-alpha.20_patch_hash=d11ec9bd9b66247ba493ab5fd117fbf0b4cb6e5d0a6a7c600d1d844bfa3d3044/node_modules/rrweb-snapshot/dist/rrweb-snapshot.js"
30
+ "../../../../node_modules/.pnpm/rrweb-snapshot@2.0.1_patch_hash=9e976b2c55a5c2ed589c41b8f46cc44b6fe6f528ebb4d3780a44b1ca8cbb17a4/node_modules/rrweb-snapshot/dist/rrweb-snapshot.js"
31
31
  ]
32
32
  }
33
33
  }
@@ -18,6 +18,7 @@ var IframeOrchestrator = class {
18
18
  _defineProperty(this, "iframes", /* @__PURE__ */ new Map());
19
19
  _defineProperty(this, "readyIframes", /* @__PURE__ */ new Set());
20
20
  _defineProperty(this, "readyWaiters", /* @__PURE__ */ new Map());
21
+ _defineProperty(this, "messageId", 0);
21
22
  _defineProperty(this, "eventTarget", new EventTarget());
22
23
  _defineProperty(this, "traces", void 0);
23
24
  _defineProperty(this, "loggedIframe", /* @__PURE__ */ new WeakSet());
@@ -52,7 +53,7 @@ var IframeOrchestrator = class {
52
53
  container.setAttribute("data-ready", "true");
53
54
  if (container.textContent) container.textContent = "";
54
55
  }
55
- if (config.browser.isolate === false) {
56
+ if (config.isolate === false) {
56
57
  await this.runNonIsolatedTests(container, options, startTime, orchestratorSpan.context);
57
58
  await endSpan();
58
59
  return;
@@ -73,7 +74,7 @@ var IframeOrchestrator = class {
73
74
  await endSpan();
74
75
  }
75
76
  async cleanupTesters() {
76
- if (getConfig().browser.isolate) {
77
+ if (getConfig().isolate) {
77
78
  const files = Array.from(this.iframes.keys());
78
79
  const ui = /* @__PURE__ */ getUiAPI();
79
80
  if (ui && files[0]) {
@@ -175,20 +176,38 @@ Received URL: ${href || "unknown due to CORS"}\nExpected: ${iframe.src}`)));
175
176
  const waiter = this.readyWaiters.get(iframeId);
176
177
  if (waiter) {
177
178
  this.readyWaiters.delete(iframeId);
178
- waiter();
179
+ waiter.resolve();
179
180
  }
180
181
  }
181
182
  waitForReady(iframeId) {
182
183
  if (this.readyIframes.has(iframeId)) return Promise.resolve();
183
- return new Promise((resolve) => {
184
- this.readyWaiters.set(iframeId, resolve);
184
+ return new Promise((resolve, reject) => {
185
+ const timeout = getIframeTimeout();
186
+ const timer = setTimeout(() => {
187
+ this.readyWaiters.delete(iframeId);
188
+ reject(/* @__PURE__ */ new Error(`The iframe "${iframeId}" did not become ready within ${timeout}ms. The tester likely failed to initialize, check the browser console for errors.`));
189
+ }, timeout);
190
+ this.readyWaiters.set(iframeId, {
191
+ resolve: () => {
192
+ clearTimeout(timer);
193
+ resolve();
194
+ },
195
+ reject: (error) => {
196
+ clearTimeout(timer);
197
+ reject(error);
198
+ }
199
+ });
185
200
  });
186
201
  }
187
202
  removeIframe(iframeId) {
188
203
  const iframe = this.iframes.get(iframeId);
189
204
  this.iframes.delete(iframeId);
190
205
  this.readyIframes.delete(iframeId);
191
- this.readyWaiters.delete(iframeId);
206
+ const waiter = this.readyWaiters.get(iframeId);
207
+ if (waiter) {
208
+ this.readyWaiters.delete(iframeId);
209
+ waiter.reject(/* @__PURE__ */ new Error(`The iframe "${iframeId}" was removed before it became ready.`));
210
+ }
192
211
  iframe === null || iframe === void 0 || iframe.remove();
193
212
  }
194
213
  createWarningMessage(iframeId, location) {
@@ -275,12 +294,14 @@ Received URL: ${href || "unknown due to CORS"}\nExpected: ${iframe.src}`)));
275
294
  });
276
295
  break;
277
296
  }
278
- default:
279
- if (typeof e.data.event === "string" && e.data.event.startsWith("response:")) break;
297
+ default: {
298
+ const event = e.data.event;
299
+ if (typeof event === "string" && (event.startsWith("response:") || event.startsWith("ack:"))) break;
280
300
  await client.rpc.onUnhandledError({
281
301
  name: "Unexpected Event",
282
302
  message: `Unexpected event: ${e.data.event}`
283
303
  }, "Unexpected Event");
304
+ }
284
305
  }
285
306
  }
286
307
  async sendEventToIframe(event) {
@@ -292,23 +313,38 @@ Received URL: ${href || "unknown due to CORS"}\nExpected: ${iframe.src}`)));
292
313
  this.iframeEvents.set(iframe, events);
293
314
  }
294
315
  events.add(event.event);
295
- channel.postMessage(event);
316
+ const messageId = this.messageId++;
317
+ channel.postMessage({
318
+ ...event,
319
+ messageId
320
+ });
296
321
  return new Promise((resolve, reject) => {
322
+ let ackTimer;
297
323
  const cleanupEvents = () => {
324
+ clearTimeout(ackTimer);
298
325
  channel.removeEventListener("message", onReceived);
299
326
  this.eventTarget.removeEventListener("iframeerror", onError);
327
+ events.delete(event.event);
300
328
  };
329
+ const timeout = getIframeTimeout();
330
+ ackTimer = setTimeout(() => {
331
+ cleanupEvents();
332
+ reject(/* @__PURE__ */ new Error(`The iframe "${event.iframeId}" did not acknowledge the "${event.event}" message within ${timeout}ms. The tester might have crashed, been removed, or be blocked by a long synchronous task.`));
333
+ }, timeout);
301
334
  function onReceived(e) {
302
- if (e.data.iframeId === event.iframeId && e.data.event === `response:${event.event}`) {
303
- resolve();
335
+ if (e.data.iframeId !== event.iframeId || e.data.messageId !== messageId) return;
336
+ if (e.data.event === `ack:${event.event}`) {
337
+ clearTimeout(ackTimer);
338
+ return;
339
+ }
340
+ if (e.data.event === `response:${event.event}`) {
304
341
  cleanupEvents();
305
- events.delete(event.event);
342
+ resolve();
306
343
  }
307
344
  }
308
345
  function onError(e) {
309
- reject(e.detail);
310
346
  cleanupEvents();
311
- events.delete(event.event);
347
+ reject(e.detail);
312
348
  }
313
349
  this.eventTarget.addEventListener("iframeerror", onError);
314
350
  channel.addEventListener("message", onReceived);
@@ -336,21 +372,31 @@ function generateFileId(file) {
336
372
  __vitest_label__: config.mergeReportsLabel
337
373
  });
338
374
  }
375
+ var currentViewport;
339
376
  async function setIframeViewport(width, height) {
340
377
  const ui = /* @__PURE__ */ getUiAPI();
341
378
  if (ui) await ui.setIframeViewport(width, height);
342
379
  else {
343
380
  document.body.style.setProperty("--viewport-width", `${width}px`);
344
381
  document.body.style.setProperty("--viewport-height", `${height}px`);
382
+ const cacheable = (/* @__PURE__ */ getBrowserState()).provider === "playwright";
383
+ if (cacheable && (currentViewport === null || currentViewport === void 0 ? void 0 : currentViewport.width) === width && (currentViewport === null || currentViewport === void 0 ? void 0 : currentViewport.height) === height) return;
345
384
  await client.rpc.triggerCommand((/* @__PURE__ */ getBrowserState()).sessionId, "__vitest_viewport", void 0, [{
346
385
  width,
347
386
  height
348
387
  }]);
388
+ currentViewport = cacheable ? {
389
+ width,
390
+ height
391
+ } : void 0;
349
392
  }
350
393
  }
351
394
  function debug(...args) {
352
395
  const debug = getConfig().env.VITEST_BROWSER_DEBUG;
353
396
  if (debug && debug !== "false") client.rpc.debug(...args.map(String));
354
397
  }
398
+ function getIframeTimeout() {
399
+ return Number(getConfig().env.VITEST_BROWSER_IFRAME_TIMEOUT) || 6e4;
400
+ }
355
401
 
356
402
  //#endregion