@vitest/browser 5.0.0-beta.6 → 5.0.0-rc.1

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,33 +1,33 @@
1
1
  {
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",
2
+ "../../../../node_modules/.pnpm/rrweb-snapshot@2.1.1_patch_hash=0b0dbc551d27a6f24438e9582c41a0ec34fd444760d383a4172013031d73c4e7/node_modules/rrweb-snapshot/dist/rrweb-snapshot.js": {
3
+ "file": "__vitest_browser__/rrweb-snapshot-g5vjbXoV.js",
4
4
  "name": "rrweb-snapshot",
5
- "src": "../../../../node_modules/.pnpm/rrweb-snapshot@2.0.1_patch_hash=9e976b2c55a5c2ed589c41b8f46cc44b6fe6f528ebb4d3780a44b1ca8cbb17a4/node_modules/rrweb-snapshot/dist/rrweb-snapshot.js",
5
+ "src": "../../../../node_modules/.pnpm/rrweb-snapshot@2.1.1_patch_hash=0b0dbc551d27a6f24438e9582c41a0ec34fd444760d383a4172013031d73c4e7/node_modules/rrweb-snapshot/dist/rrweb-snapshot.js",
6
6
  "isDynamicEntry": true
7
7
  },
8
- "_defineProperty-WHpdAQXR.js": {
9
- "file": "__vitest_browser__/defineProperty-WHpdAQXR.js",
8
+ "_defineProperty-BOtRrjRA.js": {
9
+ "file": "__vitest_browser__/defineProperty-BOtRrjRA.js",
10
10
  "name": "defineProperty"
11
11
  },
12
12
  "orchestrator.html": {
13
- "file": "__vitest_browser__/orchestrator-pKob2Z-i.js",
13
+ "file": "__vitest_browser__/orchestrator-DJgIeTMM.js",
14
14
  "name": "orchestrator",
15
15
  "src": "orchestrator.html",
16
16
  "isEntry": true,
17
17
  "imports": [
18
- "_defineProperty-WHpdAQXR.js"
18
+ "_defineProperty-BOtRrjRA.js"
19
19
  ]
20
20
  },
21
21
  "tester/tester.html": {
22
- "file": "__vitest_browser__/tester-DdZeFrjo.js",
22
+ "file": "__vitest_browser__/tester-Ck66x6M6.js",
23
23
  "name": "tester",
24
24
  "src": "tester/tester.html",
25
25
  "isEntry": true,
26
26
  "imports": [
27
- "_defineProperty-WHpdAQXR.js"
27
+ "_defineProperty-BOtRrjRA.js"
28
28
  ],
29
29
  "dynamicImports": [
30
- "../../../../node_modules/.pnpm/rrweb-snapshot@2.0.1_patch_hash=9e976b2c55a5c2ed589c41b8f46cc44b6fe6f528ebb4d3780a44b1ca8cbb17a4/node_modules/rrweb-snapshot/dist/rrweb-snapshot.js"
30
+ "../../../../node_modules/.pnpm/rrweb-snapshot@2.1.1_patch_hash=0b0dbc551d27a6f24438e9582c41a0ec34fd444760d383a4172013031d73c4e7/node_modules/rrweb-snapshot/dist/rrweb-snapshot.js"
31
31
  ]
32
32
  }
33
33
  }
@@ -121,6 +121,18 @@ var relative = function(from, to) {
121
121
  }
122
122
  return [..._from.map(() => ".."), ..._to].join("/");
123
123
  };
124
+ var basename = function(p, extension) {
125
+ const segments = normalizeWindowsPath(p).split("/");
126
+ let lastSegment = "";
127
+ for (let i = segments.length - 1; i >= 0; i--) {
128
+ const val = segments[i];
129
+ if (val) {
130
+ lastSegment = val;
131
+ break;
132
+ }
133
+ }
134
+ return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
135
+ };
124
136
 
125
137
  //#endregion
126
138
  //#region ../vitest/src/utils/tasks.ts
@@ -307,4 +319,4 @@ function _defineProperty(e, r, t) {
307
319
  }
308
320
 
309
321
  //#endregion
310
- export { moduleRunner as a, generateFileHash as c, resolve as d, getWorkerState as i, getTestName as l, getBrowserState as n, now as o, getConfig as r, __vitePreload as s, _defineProperty as t, relative as u };
322
+ export { moduleRunner as a, generateFileHash as c, relative as d, resolve as f, getWorkerState as i, getTestName as l, getBrowserState as n, now as o, getConfig as r, __vitePreload as s, _defineProperty as t, basename as u };
@@ -1,4 +1,4 @@
1
- import { c as generateFileHash, n as getBrowserState, r as getConfig, t as _defineProperty, u as relative } from "./defineProperty-WHpdAQXR.js";
1
+ import { c as generateFileHash, d as relative, n as getBrowserState, r as getConfig, t as _defineProperty } from "./defineProperty-BOtRrjRA.js";
2
2
  import { channel, client, globalChannel } from "@vitest/browser/client";
3
3
  import { Traces } from "vitest/internal/traces";
4
4
 
@@ -53,7 +53,7 @@ var IframeOrchestrator = class {
53
53
  container.setAttribute("data-ready", "true");
54
54
  if (container.textContent) container.textContent = "";
55
55
  }
56
- if (config.browser.isolate === false) {
56
+ if (config.isolate === false) {
57
57
  await this.runNonIsolatedTests(container, options, startTime, orchestratorSpan.context);
58
58
  await endSpan();
59
59
  return;
@@ -74,7 +74,7 @@ var IframeOrchestrator = class {
74
74
  await endSpan();
75
75
  }
76
76
  async cleanupTesters() {
77
- if (getConfig().browser.isolate) {
77
+ if (getConfig().isolate) {
78
78
  const files = Array.from(this.iframes.keys());
79
79
  const ui = /* @__PURE__ */ getUiAPI();
80
80
  if (ui && files[0]) {
@@ -372,16 +372,23 @@ function generateFileId(file) {
372
372
  __vitest_label__: config.mergeReportsLabel
373
373
  });
374
374
  }
375
+ var currentViewport;
375
376
  async function setIframeViewport(width, height) {
376
377
  const ui = /* @__PURE__ */ getUiAPI();
377
378
  if (ui) await ui.setIframeViewport(width, height);
378
379
  else {
379
380
  document.body.style.setProperty("--viewport-width", `${width}px`);
380
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;
381
384
  await client.rpc.triggerCommand((/* @__PURE__ */ getBrowserState()).sessionId, "__vitest_viewport", void 0, [{
382
385
  width,
383
386
  height
384
387
  }]);
388
+ currentViewport = cacheable ? {
389
+ width,
390
+ height
391
+ } : void 0;
385
392
  }
386
393
  }
387
394
  function debug(...args) {
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/.pnpm/rrweb-snapshot@2.0.1_patch_hash=9e976b2c55a5c2ed589c41b8f46cc44b6fe6f528ebb4d3780a44b1ca8cbb17a4/node_modules/rrweb-snapshot/dist/rrweb-snapshot.js
1
+ //#region ../../node_modules/.pnpm/rrweb-snapshot@2.1.1_patch_hash=0b0dbc551d27a6f24438e9582c41a0ec34fd444760d383a4172013031d73c4e7/node_modules/rrweb-snapshot/dist/rrweb-snapshot.js
2
2
  var __defProp = Object.defineProperty;
3
3
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
4
4
  enumerable: true,
@@ -358,13 +358,15 @@ function absolutifyURLs(cssText, href) {
358
358
  if (URL_PROTOCOL_MATCH.test(filePath) || URL_WWW_MATCH.test(filePath)) return `url(${maybeQuote}${filePath}${maybeQuote})`;
359
359
  if (DATA_URI.test(filePath)) return `url(${maybeQuote}${filePath}${maybeQuote})`;
360
360
  if (filePath[0] === "/") return `url(${maybeQuote}${extractOrigin(href) + filePath}${maybeQuote})`;
361
- const stack = href.split("/");
362
- const parts = filePath.split("/");
361
+ const filePathNoHash = filePath.split("#")[0];
362
+ const maybeHash = filePath.substring(filePathNoHash.length);
363
+ const stack = href.split("#")[0].split("/");
364
+ const parts = filePathNoHash.split("/");
363
365
  stack.pop();
364
366
  for (const part of parts) if (part === ".") continue;
365
367
  else if (part === "..") stack.pop();
366
368
  else stack.push(part);
367
- return `url(${maybeQuote}${stack.join("/")}${maybeQuote})`;
369
+ return `url(${maybeQuote}${stack.join("/")}${maybeHash}${maybeQuote})`;
368
370
  });
369
371
  }
370
372
  function normalizeCssString(cssText, _testNoPxNorm = false) {
@@ -1,8 +1,8 @@
1
- import { a as moduleRunner, d as resolve, i as getWorkerState, l as getTestName, n as getBrowserState, o as now$1, r as getConfig, s as __vitePreload, t as _defineProperty } from "./defineProperty-WHpdAQXR.js";
1
+ import { a as moduleRunner, f as resolve, i as getWorkerState, l as getTestName, n as getBrowserState, o as now$1, r as getConfig, s as __vitePreload, t as _defineProperty, u as basename } from "./defineProperty-BOtRrjRA.js";
2
2
  import { channel, client, globalChannel, onCancel, registerPageMarkHandler } from "@vitest/browser/client";
3
3
  import { Traces } from "vitest/internal/traces";
4
4
  import { page, server, userEvent } from "vitest/browser";
5
- import { DecodedMap, SpyModule, collectTests, format, getOriginalPosition, getSafeTimers, loadDiffConfig, loadSnapshotSerializers, setupCommonEnv, startCoverageInsideWorker, startTests, stopCoverageInsideWorker, takeCoverageInsideWorker } from "vitest/internal/browser";
5
+ import { DecodedMap, SpyModule, collectTests, format, getOriginalPosition, getSafeTimers, loadDiffConfig, loadSnapshotSerializers, setupCommonEnv, setupEnv, startCoverageInsideWorker, startTests, stopCoverageInsideWorker, takeCoverageInsideWorker } from "vitest/internal/browser";
6
6
  import { TestRunner, recordArtifact } from "vitest";
7
7
 
8
8
  //#region \0rolldown/runtime.js
@@ -33,7 +33,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
33
33
  }) : target, mod));
34
34
 
35
35
  //#endregion
36
- //#region ../../node_modules/.pnpm/flatted@3.4.2/node_modules/flatted/esm/index.js
36
+ //#region ../../node_modules/.pnpm/flatted@3.4.4/node_modules/flatted/esm/index.js
37
37
  var { parse: $parse, stringify: $stringify } = JSON;
38
38
  var { keys } = Object;
39
39
  var Primitive = String;
@@ -106,6 +106,7 @@ expect(${name}).toHaveBeenCalledWith(${formattedParams})
106
106
  function setupDialogsSpy() {
107
107
  globalThis.alert = showPopupWarning("alert", void 0);
108
108
  globalThis.confirm = showPopupWarning("confirm", false, true);
109
+ globalThis.print = showPopupWarning("print", void 0);
109
110
  globalThis.prompt = showPopupWarning("prompt", null, "your value");
110
111
  }
111
112
 
@@ -545,7 +546,8 @@ var stackIgnorePatterns = [
545
546
  /__vitest_test__/,
546
547
  /__vitest_browser__/,
547
548
  "/@id/__x00__vitest/browser",
548
- /\/deps\/vitest_/
549
+ /\/deps\/vitest_/,
550
+ "/deps/vitest.js"
549
551
  ];
550
552
  var NOW_LENGTH$1 = Date.now().toString().length;
551
553
  var REGEXP_VITEST$1 = new RegExp(`vitest=\\d{${NOW_LENGTH$1}}`);
@@ -638,7 +640,12 @@ function parseStacktrace(stack, options = {}) {
638
640
  if (options.getUrlId) stack.file = options.getUrlId(stack.file);
639
641
  const map = (_options$getSourceMap = options.getSourceMap) === null || _options$getSourceMap === void 0 ? void 0 : _options$getSourceMap.call(options, stack.file);
640
642
  if (!map || typeof map !== "object" || !map.version) return shouldFilter(ignoreStackEntries, stack.file) ? null : stack;
641
- const position = getOriginalPosition$1(new DecodedMap$1(map, stack.file), stack);
643
+ const traceMap = new DecodedMap$1(map, stack.file);
644
+ if (stack.line <= 0 || stack.column <= 0) return stack;
645
+ const position = getOriginalPosition$1(traceMap, {
646
+ line: stack.line,
647
+ column: stack.column - 1
648
+ });
642
649
  if (!position) return stack;
643
650
  const { line, column, source, name } = position;
644
651
  let file = source || stack.file;
@@ -646,7 +653,7 @@ function parseStacktrace(stack, options = {}) {
646
653
  if (shouldFilter(ignoreStackEntries, file)) return null;
647
654
  if (line != null && column != null) return {
648
655
  line,
649
- column,
656
+ column: column + 1,
650
657
  file,
651
658
  method: name || stack.method
652
659
  };
@@ -833,6 +840,7 @@ function createBrowserRunner(mocker, state, coverageModule) {
833
840
  _defineProperty(this, "config", void 0);
834
841
  _defineProperty(this, "hashMap", browserHashMap);
835
842
  _defineProperty(this, "sourceMapCache", /* @__PURE__ */ new Map());
843
+ _defineProperty(this, "sourceMapPrefetches", /* @__PURE__ */ new Map());
836
844
  _defineProperty(this, "method", "run");
837
845
  _defineProperty(this, "commands", void 0);
838
846
  _defineProperty(this, "traces", /* @__PURE__ */ new Map());
@@ -890,10 +898,10 @@ function createBrowserRunner(mocker, state, coverageModule) {
890
898
  const lastErrorContext = (_task$result3 = task.result) === null || _task$result3 === void 0 || (_task$result3 = _task$result3.errors) === null || _task$result3 === void 0 || (_task$result3 = _task$result3.at(-1)) === null || _task$result3 === void 0 ? void 0 : _task$result3.__vitest_error_context__;
891
899
  if (this.config.browser.screenshotFailures && document.body.clientHeight > 0 && ((_task$result4 = task.result) === null || _task$result4 === void 0 ? void 0 : _task$result4.state) === "fail" && task.type === "test" && !(lastErrorContext && Reflect.get(lastErrorContext, "assertionName") === "toMatchScreenshot" && ((_Reflect$get = Reflect.get(lastErrorContext, "meta")) === null || _Reflect$get === void 0 ? void 0 : _Reflect$get.outcome) !== "unstable-screenshot")) {
892
900
  var _this$config$browser$;
893
- const screenshot = await page.screenshot(
894
- { timeout: ((_this$config$browser$ = this.config.browser.providerOptions) === null || _this$config$browser$ === void 0 ? void 0 : _this$config$browser$.actionTimeout) ?? 5e3 }
895
- /** TODO */
896
- ).catch((err) => {
901
+ const screenshot = await page.screenshot({
902
+ timeout: ((_this$config$browser$ = this.config.browser.providerOptions) === null || _this$config$browser$ === void 0 ? void 0 : _this$config$browser$.actionTimeout) ?? 5e3,
903
+ path: resolve(this.config.attachmentsDir, "failure-screenshots", basename(task.file.filepath), `${task.fullTestName.replace(/\W/g, "-")}.png`)
904
+ }).catch((err) => {
897
905
  console.error("[vitest] Failed to take a screenshot", err);
898
906
  });
899
907
  if (screenshot) await recordArtifact(task, {
@@ -918,7 +926,8 @@ function createBrowserRunner(mocker, state, coverageModule) {
918
926
  var _super$onBeforeRunSui;
919
927
  await Promise.all([(_super$onBeforeRunSui = super.onBeforeRunSuite) === null || _super$onBeforeRunSui === void 0 ? void 0 : _super$onBeforeRunSui.call(this, suite), (async () => {
920
928
  if (!("filepath" in suite)) return;
921
- const map = await rpc$2().getBrowserFileSourceMap(suite.filepath);
929
+ const map = await (this.sourceMapPrefetches.get(suite.filepath) ?? rpc$2().getBrowserFileSourceMap(suite.filepath));
930
+ this.sourceMapPrefetches.delete(suite.filepath);
922
931
  this.sourceMapCache.set(suite.filepath, map);
923
932
  const snapshotEnvironment = this.config.snapshotOptions.snapshotEnvironment;
924
933
  if (snapshotEnvironment instanceof VitestBrowserSnapshotEnvironment) snapshotEnvironment.addSourceMap(suite.filepath, map);
@@ -930,7 +939,7 @@ function createBrowserRunner(mocker, state, coverageModule) {
930
939
  if (coverage) await rpc$2().onAfterSuiteRun({
931
940
  coverage,
932
941
  testFiles: files.map((file) => file.name),
933
- environment: "__browser__",
942
+ environment: "client",
934
943
  projectName: this.config.name
935
944
  });
936
945
  });
@@ -995,6 +1004,7 @@ function createBrowserRunner(mocker, state, coverageModule) {
995
1004
  } catch (err) {
996
1005
  throw new Error(`Failed to import test file ${filepath}`, { cause: err });
997
1006
  }
1007
+ if (mode === "collect" && !this.sourceMapPrefetches.has(filepath)) this.sourceMapPrefetches.set(filepath, rpc$2().getBrowserFileSourceMap(filepath).catch(() => void 0));
998
1008
  });
999
1009
  _defineProperty(this, "trace", (name, attributes, cb) => {
1000
1010
  const options = typeof attributes === "object" ? { attributes } : {};
@@ -1002,7 +1012,7 @@ function createBrowserRunner(mocker, state, coverageModule) {
1002
1012
  });
1003
1013
  this.config = options.config;
1004
1014
  this.commands = (/* @__PURE__ */ getBrowserState()).commands;
1005
- this.viteEnvironment = "__browser__";
1015
+ this.viteEnvironment = "client";
1006
1016
  this._otel = (/* @__PURE__ */ getBrowserState()).traces;
1007
1017
  }
1008
1018
  setMethod(method) {
@@ -1022,7 +1032,7 @@ function createBrowserRunner(mocker, state, coverageModule) {
1022
1032
  return;
1023
1033
  }
1024
1034
  if (shouldTraceView) {
1025
- (/* @__PURE__ */ getBrowserState()).browserTraceDomSnapshot = await __vitePreload(() => import("./rrweb-snapshot-DkFyu2W8.js"), []);
1035
+ (/* @__PURE__ */ getBrowserState()).browserTraceDomSnapshot = await __vitePreload(() => import("./rrweb-snapshot-g5vjbXoV.js"), []);
1026
1036
  (/* @__PURE__ */ getBrowserState()).browserTraceAttempts.set(test.id, {
1027
1037
  retry,
1028
1038
  repeats,
@@ -1266,6 +1276,9 @@ var MockerRegistry = class {
1266
1276
  };
1267
1277
  var AutomockedModule = class AutomockedModule {
1268
1278
  constructor(raw, id, url) {
1279
+ _defineProperty(this, "raw", void 0);
1280
+ _defineProperty(this, "id", void 0);
1281
+ _defineProperty(this, "url", void 0);
1269
1282
  _defineProperty(this, "type", "automock");
1270
1283
  this.raw = raw;
1271
1284
  this.id = id;
@@ -1285,6 +1298,9 @@ var AutomockedModule = class AutomockedModule {
1285
1298
  };
1286
1299
  var AutospiedModule = class AutospiedModule {
1287
1300
  constructor(raw, id, url) {
1301
+ _defineProperty(this, "raw", void 0);
1302
+ _defineProperty(this, "id", void 0);
1303
+ _defineProperty(this, "url", void 0);
1288
1304
  _defineProperty(this, "type", "autospy");
1289
1305
  this.raw = raw;
1290
1306
  this.id = id;
@@ -1304,6 +1320,10 @@ var AutospiedModule = class AutospiedModule {
1304
1320
  };
1305
1321
  var RedirectedModule = class RedirectedModule {
1306
1322
  constructor(raw, id, url, redirect) {
1323
+ _defineProperty(this, "raw", void 0);
1324
+ _defineProperty(this, "id", void 0);
1325
+ _defineProperty(this, "url", void 0);
1326
+ _defineProperty(this, "redirect", void 0);
1307
1327
  _defineProperty(this, "type", "redirect");
1308
1328
  this.raw = raw;
1309
1329
  this.id = id;
@@ -1325,6 +1345,10 @@ var RedirectedModule = class RedirectedModule {
1325
1345
  };
1326
1346
  var ManualMockedModule = class ManualMockedModule {
1327
1347
  constructor(raw, id, url, factory) {
1348
+ _defineProperty(this, "raw", void 0);
1349
+ _defineProperty(this, "id", void 0);
1350
+ _defineProperty(this, "url", void 0);
1351
+ _defineProperty(this, "factory", void 0);
1328
1352
  _defineProperty(this, "cache", void 0);
1329
1353
  _defineProperty(this, "type", "manual");
1330
1354
  this.raw = raw;
@@ -1334,20 +1358,20 @@ var ManualMockedModule = class ManualMockedModule {
1334
1358
  }
1335
1359
  resolve() {
1336
1360
  if (this.cache) return this.cache;
1337
- let exports$1;
1361
+ let exports;
1338
1362
  try {
1339
- exports$1 = this.factory();
1363
+ exports = this.factory();
1340
1364
  } catch (err) {
1341
1365
  throw createHelpfulError(err);
1342
1366
  }
1343
- if (typeof exports$1 === "object" && typeof (exports$1 === null || exports$1 === void 0 ? void 0 : exports$1.then) === "function") return exports$1.then((result) => {
1367
+ if (typeof exports === "object" && typeof (exports === null || exports === void 0 ? void 0 : exports.then) === "function") return exports.then((result) => {
1344
1368
  assertValidExports(this.raw, result);
1345
1369
  return this.cache = result;
1346
1370
  }, (error) => {
1347
1371
  throw createHelpfulError(error);
1348
1372
  });
1349
- assertValidExports(this.raw, exports$1);
1350
- return this.cache = exports$1;
1373
+ assertValidExports(this.raw, exports);
1374
+ return this.cache = exports;
1351
1375
  }
1352
1376
  static fromJSON(data, factory) {
1353
1377
  return new ManualMockedModule(data.raw, data.id, data.url, factory);
@@ -1366,8 +1390,8 @@ function createHelpfulError(cause) {
1366
1390
  error.cause = cause;
1367
1391
  return error;
1368
1392
  }
1369
- function assertValidExports(raw, exports$1) {
1370
- if (exports$1 === null || typeof exports$1 !== "object" || Array.isArray(exports$1)) throw new TypeError(`[vitest] vi.mock("${raw}", factory?: () => unknown) is not returning an object. Did you mean to return an object with a "default" key?`);
1393
+ function assertValidExports(raw, exports) {
1394
+ if (exports === null || typeof exports !== "object" || Array.isArray(exports)) throw new TypeError(`[vitest] vi.mock("${raw}", factory?: () => unknown) is not returning an object. Did you mean to return an object with a "default" key?`);
1371
1395
  }
1372
1396
 
1373
1397
  //#endregion
@@ -1436,14 +1460,14 @@ function mockObject(options, object, mockExports = {}) {
1436
1460
  continue;
1437
1461
  }
1438
1462
  if (options.type === "autospy" && type === "Module") {
1439
- const exports$1 = Object.create(null);
1440
- Object.defineProperty(exports$1, Symbol.toStringTag, {
1463
+ const exports = Object.create(null);
1464
+ Object.defineProperty(exports, Symbol.toStringTag, {
1441
1465
  value: "Module",
1442
1466
  configurable: true,
1443
1467
  writable: true
1444
1468
  });
1445
1469
  try {
1446
- newContainer[property] = exports$1;
1470
+ newContainer[property] = exports;
1447
1471
  } catch {
1448
1472
  continue;
1449
1473
  }
@@ -1642,6 +1666,10 @@ var REGEXP_VITEST = new RegExp(`vitest=\\d{${NOW_LENGTH}}`);
1642
1666
  var { now } = Date;
1643
1667
  var ModuleMocker = class {
1644
1668
  constructor(interceptor, rpc, createMockInstance, config) {
1669
+ _defineProperty(this, "interceptor", void 0);
1670
+ _defineProperty(this, "rpc", void 0);
1671
+ _defineProperty(this, "createMockInstance", void 0);
1672
+ _defineProperty(this, "config", void 0);
1645
1673
  _defineProperty(this, "registry", new MockerRegistry());
1646
1674
  _defineProperty(this, "queue", /* @__PURE__ */ new Set());
1647
1675
  _defineProperty(this, "mockedIds", /* @__PURE__ */ new Set());
@@ -1932,8 +1960,10 @@ var traces = new Traces({
1932
1960
  });
1933
1961
  var rootTesterSpan;
1934
1962
  (/* @__PURE__ */ getBrowserState()).traces = traces;
1963
+ var isEmbedded = window.self !== window.top;
1935
1964
  channel.addEventListener("message", async (e) => {
1936
1965
  const data = e.data;
1966
+ if (!isEmbedded) return;
1937
1967
  if (!isEvent(data)) {
1938
1968
  await client.waitForConnection();
1939
1969
  unhandledError(/* @__PURE__ */ new Error(`Unknown message: ${JSON.stringify(e.data)}`), "Unknown Iframe Message");
@@ -2000,7 +2030,7 @@ var commands = new CommandsManager();
2000
2030
  (/* @__PURE__ */ getBrowserState()).browserTraceAttempts = /* @__PURE__ */ new Map();
2001
2031
  (/* @__PURE__ */ getBrowserState()).iframeId = iframeId;
2002
2032
  registerPageMarkHandler((name, options) => page.mark(name, options));
2003
- channel.postMessage({
2033
+ if (isEmbedded) channel.postMessage({
2004
2034
  event: "ready",
2005
2035
  iframeId
2006
2036
  });
@@ -2067,9 +2097,10 @@ async function prepare(options) {
2067
2097
  const { config, state } = preparedData;
2068
2098
  state.durations.prepare = performance.now() - state.durations.prepare;
2069
2099
  debug === null || debug === void 0 || debug("prepare time", state.durations.prepare, "ms");
2100
+ setupEnv(config.env, state.metaEnv);
2070
2101
  await Promise.all([
2071
2102
  setupCommonEnv(config),
2072
- startCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.browser.isolate }),
2103
+ startCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate }),
2073
2104
  (async () => {
2074
2105
  const VitestIndex = await __vitePreload(() => import("vitest"), []);
2075
2106
  Object.defineProperty(window, "__vitest_index__", {
@@ -2093,7 +2124,7 @@ async function cleanup() {
2093
2124
  await userEvent.cleanup().catch((error) => unhandledError(error, "Cleanup Error"));
2094
2125
  await Promise.all((/* @__PURE__ */ getBrowserState()).cleanups.map((fn) => fn())).catch((error) => unhandledError(error, "Cleanup Error"));
2095
2126
  if (contextSwitched) await rpc.wdioSwitchContext("parent").catch((error) => unhandledError(error, "Cleanup Error"));
2096
- await stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.browser.isolate }).catch((error) => {
2127
+ await stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate }).catch((error) => {
2097
2128
  return unhandledError(error, "Coverage Error");
2098
2129
  });
2099
2130
  }
@@ -26,8 +26,8 @@
26
26
  {__VITEST_INJECTOR__}
27
27
  {__VITEST_ERROR_CATCHER__}
28
28
  {__VITEST_SCRIPTS__}
29
- <script type="module" crossorigin src="/__vitest_browser__/orchestrator-pKob2Z-i.js"></script>
30
- <link rel="modulepreload" crossorigin href="/__vitest_browser__/defineProperty-WHpdAQXR.js">
29
+ <script type="module" crossorigin src="/__vitest_browser__/orchestrator-DJgIeTMM.js"></script>
30
+ <link rel="modulepreload" crossorigin href="/__vitest_browser__/defineProperty-BOtRrjRA.js">
31
31
  </head>
32
32
  <body>
33
33
  <div id="vitest-tester"></div>
@@ -5,8 +5,8 @@
5
5
  <link rel="icon" href="{__VITEST_FAVICON__}" type="image/svg+xml">
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>Vitest Browser Tester</title>
8
- <script type="module" crossorigin src="/__vitest_browser__/tester-DdZeFrjo.js"></script>
9
- <link rel="modulepreload" crossorigin href="/__vitest_browser__/defineProperty-WHpdAQXR.js">
8
+ <script type="module" crossorigin src="/__vitest_browser__/tester-Ck66x6M6.js"></script>
9
+ <link rel="modulepreload" crossorigin href="/__vitest_browser__/defineProperty-BOtRrjRA.js">
10
10
  </head>
11
11
  <body>
12
12
  </body>
@@ -8,9 +8,9 @@ export interface BrowserTraceData {
8
8
  entries: BrowserTraceEntry[];
9
9
  }
10
10
  export type BrowserTraceEntryStatus = "pass" | "fail";
11
- export type BrowserTraceEntryRangePhase = "start" | "end";
12
- export type BrowserTraceSelectorResolution = "matched" | "missing" | "error";
13
- export interface BrowserTraceEntryRange {
11
+ type BrowserTraceEntryRangePhase = "start" | "end";
12
+ type BrowserTraceSelectorResolution = "matched" | "missing" | "error";
13
+ interface BrowserTraceEntryRange {
14
14
  id: string;
15
15
  phase: BrowserTraceEntryRangePhase;
16
16
  }
package/dist/client.js CHANGED
@@ -1,8 +1,3 @@
1
- //#region src/messages.ts
2
- const TYPE_REQUEST = "q";
3
- const TYPE_RESPONSE = "s";
4
-
5
- //#endregion
6
1
  //#region src/utils.ts
7
2
  function createPromiseWithResolvers() {
8
3
  let resolve;
@@ -25,7 +20,6 @@ function nanoid(size = 21) {
25
20
  return id;
26
21
  }
27
22
 
28
- //#endregion
29
23
  //#region src/main.ts
30
24
  const DEFAULT_TIMEOUT = 6e4;
31
25
  const defaultSerialize = (i) => i;
@@ -42,7 +36,7 @@ function createBirpc($functions, options) {
42
36
  const req = {
43
37
  m: method,
44
38
  a: args,
45
- t: TYPE_REQUEST
39
+ t: "q"
46
40
  };
47
41
  if (optional) req.o = true;
48
42
  const send = async (_req) => post(serialize(_req));
@@ -96,7 +90,7 @@ function createBirpc($functions, options) {
96
90
  $call: (method, ...args) => _call(method, args, false),
97
91
  $callOptional: (method, ...args) => _call(method, args, false, true),
98
92
  $callEvent: (method, ...args) => _call(method, args, true),
99
- $callRaw: (options$1) => _call(options$1.method, options$1.args, options$1.event, options$1.optional),
93
+ $callRaw: (options) => _call(options.method, options.args, options.event, options.optional),
100
94
  $rejectPendingCalls,
101
95
  get $closed() {
102
96
  return $closed;
@@ -108,7 +102,7 @@ function createBirpc($functions, options) {
108
102
  $functions
109
103
  };
110
104
  if (proxify) rpc = new Proxy({}, { get(_, method) {
111
- if (Object.prototype.hasOwnProperty.call(builtinMethods, method)) return builtinMethods[method];
105
+ if (Object.hasOwn(builtinMethods, method)) return builtinMethods[method];
112
106
  if (method === "then" && !eventNames.includes("then") && !("then" in $functions)) return void 0;
113
107
  const sendEvent = (...args) => _call(method, args, true);
114
108
  if (eventNames.includes(method)) {
@@ -152,7 +146,7 @@ function createBirpc($functions, options) {
152
146
  if (options.onGeneralError?.call(rpc, e) !== true) throw e;
153
147
  return;
154
148
  }
155
- if (msg.t === TYPE_REQUEST) {
149
+ if (msg.t === "q") {
156
150
  const { m: method, a: args, o: optional } = msg;
157
151
  let result, error;
158
152
  let fn = await (resolver ? resolver.call(rpc, method, $functions[method]) : $functions[method]);
@@ -169,7 +163,7 @@ function createBirpc($functions, options) {
169
163
  }
170
164
  if (!error) try {
171
165
  await post(serialize({
172
- t: TYPE_RESPONSE,
166
+ t: "s",
173
167
  i: msg.i,
174
168
  r: result
175
169
  }), ...extra);
@@ -180,7 +174,7 @@ function createBirpc($functions, options) {
180
174
  }
181
175
  try {
182
176
  await post(serialize({
183
- t: TYPE_RESPONSE,
177
+ t: "s",
184
178
  i: msg.i,
185
179
  e: error
186
180
  }), ...extra);
@@ -336,6 +330,12 @@ const ENTRY_URL = `${location.protocol === "https:" ? "wss:" : "ws:"}//${HOST}/_
336
330
  const onCancelCallbacks = [];
337
331
  function onCancel(callback) {
338
332
  onCancelCallbacks.push(callback);
333
+ return () => {
334
+ const index = onCancelCallbacks.indexOf(callback);
335
+ if (index !== -1) {
336
+ onCancelCallbacks.splice(index, 1);
337
+ }
338
+ };
339
339
  }
340
340
  let pageMarkHandler = null;
341
341
  function registerPageMarkHandler(handler) {
@@ -405,8 +405,8 @@ function createClient() {
405
405
  responseId
406
406
  };
407
407
  }
408
- const exports$1 = await mocker.resolveFactoryModule(url);
409
- const keys = Object.keys(exports$1);
408
+ const exports = await mocker.resolveFactoryModule(url);
409
+ const keys = Object.keys(exports);
410
410
  return {
411
411
  url,
412
412
  keys,
package/dist/context.js CHANGED
@@ -247,8 +247,10 @@ function processTimeoutOptions(options_) {
247
247
  const remainingTime = Math.floor(endTime - currentTime);
248
248
  // keep some buffer to process the timeout, but always hand the provider a
249
249
  // positive value so it surfaces a descriptive, source-mapped locator error
250
- // instead of letting the task timer win the race with a generic timeout
251
- options_.timeout = Math.max(remainingTime - 100, 1);
250
+ // instead of letting the task timer win the race with a generic timeout;
251
+ // the buffer covers the provider->server->client round-trip of the rejection,
252
+ // which can exceed 100ms on loaded CI machines running several browsers
253
+ options_.timeout = Math.max(remainingTime - 250, 1);
252
254
  return options_;
253
255
  }
254
256
  const provider$1 = getBrowserState().provider;
@@ -370,6 +372,7 @@ function createUserEvent(__tl_user_event_base__, options) {
370
372
  upload(element, files, options) {
371
373
  return convertToLocator(element).upload(files, options);
372
374
  },
375
+ // non userEvent events, but still useful
373
376
  fill(element, text, options) {
374
377
  return convertToLocator(element).fill(text, options);
375
378
  },
@@ -378,6 +381,7 @@ function createUserEvent(__tl_user_event_base__, options) {
378
381
  const targetLocator = convertToLocator(target);
379
382
  return sourceLocator.dropTo(targetLocator, options);
380
383
  },
384
+ // testing-library user-event
381
385
  type(element, text, options) {
382
386
  return ensureAwaited(async (error) => {
383
387
  const serializedElement = await serializeElement(element, options);