@vitest/browser 3.0.0-beta.2 → 3.0.0-beta.4

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.
@@ -23,7 +23,7 @@
23
23
  })();
24
24
  </script>
25
25
  <!-- !LOAD_METADATA! -->
26
- <script type="module" src="./assets/index-BgsOOCCp.js"></script>
26
+ <script type="module" src="./assets/index-BC8TFRpg.js"></script>
27
27
  <link rel="stylesheet" href="./assets/index-D1v_Nqq1.css">
28
28
  </head>
29
29
  <body>
@@ -1,7 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { g as getBrowserState, a as getConfig, r as relative } from "./utils-Owv5OOOf.js";
4
+ import { g as getBrowserState, a as getConfig, r as relative } from "./utils-CaCTRFti.js";
5
5
  import { client, channel, globalChannel } from "@vitest/browser/client";
6
6
  function generateHash(str) {
7
7
  let hash = 0;
@@ -26,8 +26,7 @@ class IframeOrchestrator {
26
26
  __publicField(this, "runningFiles", /* @__PURE__ */ new Set());
27
27
  __publicField(this, "iframes", /* @__PURE__ */ new Map());
28
28
  }
29
- async init() {
30
- const testFiles = getBrowserState().files;
29
+ async init(testFiles) {
31
30
  debug("test files", testFiles.join(", "));
32
31
  this.runningFiles.clear();
33
32
  testFiles.forEach((file) => this.runningFiles.add(file));
@@ -45,6 +44,7 @@ class IframeOrchestrator {
45
44
  this.runningFiles.clear();
46
45
  testFiles.forEach((file) => this.runningFiles.add(file));
47
46
  const config = getConfig();
47
+ debug("create testers", testFiles.join(", "));
48
48
  const container = await getContainer(config);
49
49
  if (config.browser.ui) {
50
50
  container.className = "absolute origin-top mt-[8px]";
@@ -55,6 +55,7 @@ class IframeOrchestrator {
55
55
  this.iframes.forEach((iframe) => iframe.remove());
56
56
  this.iframes.clear();
57
57
  if (config.isolate === false) {
58
+ debug("create iframe", ID_ALL);
58
59
  const iframe = this.createIframe(container, ID_ALL);
59
60
  await setIframeViewport(iframe, width, height);
60
61
  return;
@@ -64,6 +65,7 @@ class IframeOrchestrator {
64
65
  done();
65
66
  return;
66
67
  }
68
+ debug("create iframe", file);
67
69
  const iframe = this.createIframe(container, file);
68
70
  await setIframeViewport(iframe, width, height);
69
71
  await new Promise((resolve) => {
@@ -88,7 +90,7 @@ class IframeOrchestrator {
88
90
  iframe.setAttribute("loading", "eager");
89
91
  iframe.setAttribute(
90
92
  "src",
91
- `${url.pathname}__vitest_test__/__test__/${getBrowserState().contextId}/${encodeURIComponent(file)}`
93
+ `${url.pathname}__vitest_test__/__test__/${getBrowserState().sessionId}/${encodeURIComponent(file)}`
92
94
  );
93
95
  iframe.setAttribute("data-vitest", "true");
94
96
  iframe.style.border = "none";
@@ -192,7 +194,7 @@ getBrowserState().createTesters = async (files) => {
192
194
  await promiseTesters;
193
195
  };
194
196
  async function done() {
195
- await client.rpc.finishBrowserTests(getBrowserState().contextId);
197
+ await client.rpc.finishBrowserTests(getBrowserState().sessionId);
196
198
  }
197
199
  async function getContainer(config) {
198
200
  if (config.browser.ui) {
@@ -210,7 +212,7 @@ async function getContainer(config) {
210
212
  }
211
213
  client.waitForConnection().then(async () => {
212
214
  const testFiles = getBrowserState().files;
213
- await orchestrator.init();
215
+ await orchestrator.init(testFiles);
214
216
  if (testFiles.length) {
215
217
  await orchestrator.createTesters(testFiles);
216
218
  }
@@ -1,7 +1,8 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { a as getConfig, g as getBrowserState, b as resolve, e as executor, c as getWorkerState } from "./utils-Owv5OOOf.js";
4
+ var _a2;
5
+ import { a as getConfig, g as getBrowserState, b as resolve, e as executor, c as getWorkerState } from "./utils-CaCTRFti.js";
5
6
  import { globalChannel, client, onCancel, channel } from "@vitest/browser/client";
6
7
  import { userEvent, page } from "@vitest/browser/context";
7
8
  import { loadDiffConfig, loadSnapshotSerializers, takeCoverageInsideWorker, setupCommonEnv, startCoverageInsideWorker, startTests, collectTests, stopCoverageInsideWorker, SpyModule } from "vitest/browser";
@@ -67,16 +68,16 @@ const __vitePreload = function preload(baseModule, deps, importerUrl) {
67
68
  };
68
69
  function showPopupWarning(name, value, defaultValue) {
69
70
  return (...params) => {
70
- const formatedParams = params.map((p) => JSON.stringify(p)).join(", ");
71
- console.warn(`Vitest encountered a \`${name}(${formatedParams})\` call that it cannot handle by default, so it returned \`${value}\`. Read more in https://vitest.dev/guide/browser/#thread-blocking-dialogs.
71
+ const formattedParams = params.map((p) => JSON.stringify(p)).join(", ");
72
+ console.warn(`Vitest encountered a \`${name}(${formattedParams})\` call that it cannot handle by default, so it returned \`${value}\`. Read more in https://vitest.dev/guide/browser/#thread-blocking-dialogs.
72
73
  If needed, mock the \`${name}\` call manually like:
73
74
 
74
75
  \`\`\`
75
76
  import { expect, vi } from "vitest"
76
77
 
77
78
  vi.spyOn(window, "${name}")${defaultValue ? `.mockReturnValue(${JSON.stringify(defaultValue)})` : ""}
78
- ${name}(${formatedParams})
79
- expect(${name}).toHaveBeenCalledWith(${formatedParams})
79
+ ${name}(${formattedParams})
80
+ expect(${name}).toHaveBeenCalledWith(${formattedParams})
80
81
  \`\`\``);
81
82
  return value;
82
83
  };
@@ -644,7 +645,7 @@ function _defineProperties(target, props) {
644
645
  }
645
646
  }
646
647
  function _createClass(Constructor, protoProps, staticProps) {
647
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
648
+ _defineProperties(Constructor.prototype, protoProps);
648
649
  Object.defineProperty(Constructor, "prototype", { writable: false });
649
650
  return Constructor;
650
651
  }
@@ -1459,7 +1460,7 @@ Object.defineProperty(iterationDecorator$1, "__esModule", {
1459
1460
  iterationDecorator$1.default = iterationDecorator;
1460
1461
  var _iteratorProxy = _interopRequireDefault$a(iteratorProxy$1);
1461
1462
  function _interopRequireDefault$a(obj) {
1462
- return obj && obj.__esModule ? obj : { default: obj };
1463
+ return obj.__esModule ? obj : { default: obj };
1463
1464
  }
1464
1465
  function _typeof(obj) {
1465
1466
  "@babel/helpers - typeof";
@@ -1483,7 +1484,7 @@ Object.defineProperty(ariaPropsMap$1, "__esModule", {
1483
1484
  ariaPropsMap$1.default = void 0;
1484
1485
  var _iterationDecorator$4 = _interopRequireDefault$9(iterationDecorator$1);
1485
1486
  function _interopRequireDefault$9(obj) {
1486
- return obj && obj.__esModule ? obj : { default: obj };
1487
+ return obj.__esModule ? obj : { default: obj };
1487
1488
  }
1488
1489
  function _slicedToArray$4(arr, i) {
1489
1490
  return _arrayWithHoles$4(arr) || _iterableToArrayLimit$4(arr, i) || _unsupportedIterableToArray$4(arr, i) || _nonIterableRest$4();
@@ -1733,7 +1734,7 @@ Object.defineProperty(domMap$1, "__esModule", {
1733
1734
  domMap$1.default = void 0;
1734
1735
  var _iterationDecorator$3 = _interopRequireDefault$8(iterationDecorator$1);
1735
1736
  function _interopRequireDefault$8(obj) {
1736
- return obj && obj.__esModule ? obj : { default: obj };
1737
+ return obj.__esModule ? obj : { default: obj };
1737
1738
  }
1738
1739
  function _slicedToArray$3(arr, i) {
1739
1740
  return _arrayWithHoles$3(arr) || _iterableToArrayLimit$3(arr, i) || _unsupportedIterableToArray$3(arr, i) || _nonIterableRest$3();
@@ -10295,7 +10296,7 @@ function toHaveAccessibleDescription(htmlElement, expectedAccessibleDescription)
10295
10296
  const ariaInvalidName = "aria-invalid";
10296
10297
  const validStates = ["false"];
10297
10298
  function toHaveAccessibleErrorMessage(htmlElement, expectedAccessibleErrorMessage) {
10298
- var _a;
10299
+ var _a3;
10299
10300
  checkHtmlElement(htmlElement, toHaveAccessibleErrorMessage, this);
10300
10301
  const to = this.isNot ? "not to" : "to";
10301
10302
  const method = this.isNot ? ".not.toHaveAccessibleErrorMessage" : ".toHaveAccessibleErrorMessage";
@@ -10334,7 +10335,7 @@ function toHaveAccessibleErrorMessage(htmlElement, expectedAccessibleErrorMessag
10334
10335
  };
10335
10336
  }
10336
10337
  const error = normalize$1(
10337
- ((_a = htmlElement.ownerDocument.getElementById(errormessageId)) == null ? void 0 : _a.textContent) ?? ""
10338
+ ((_a3 = htmlElement.ownerDocument.getElementById(errormessageId)) == null ? void 0 : _a3.textContent) ?? ""
10338
10339
  );
10339
10340
  return {
10340
10341
  pass: expectedAccessibleErrorMessage === void 0 ? Boolean(error) : expectedAccessibleErrorMessage instanceof RegExp ? expectedAccessibleErrorMessage.test(error) : this.equals(error, expectedAccessibleErrorMessage),
@@ -11078,8 +11079,8 @@ function supportedRoles() {
11078
11079
  return roles_1.keys().filter(roleSupportsChecked);
11079
11080
  }
11080
11081
  function roleSupportsChecked(role) {
11081
- var _a;
11082
- return ((_a = roles_1.get(role)) == null ? void 0 : _a.props["aria-checked"]) !== void 0;
11082
+ var _a3;
11083
+ return ((_a3 = roles_1.get(role)) == null ? void 0 : _a3.props["aria-checked"]) !== void 0;
11083
11084
  }
11084
11085
  function toBePartiallyChecked(element) {
11085
11086
  checkHtmlElement(element, toBePartiallyChecked, this);
@@ -11316,10 +11317,18 @@ async function setupExpectDom() {
11316
11317
  chai.util.flag(this, "_poll.element", true);
11317
11318
  const isNot = chai.util.flag(this, "negate");
11318
11319
  const name = chai.util.flag(this, "_name");
11320
+ const isLastPollAttempt = chai.util.flag(this, "_isLastPollAttempt");
11319
11321
  if (isNot && name === "toBeInTheDocument") {
11320
11322
  return elementOrLocator.query();
11321
11323
  }
11322
- return elementOrLocator.element();
11324
+ if (isLastPollAttempt) {
11325
+ return elementOrLocator.element();
11326
+ }
11327
+ const result = elementOrLocator.query();
11328
+ if (!result) {
11329
+ throw new Error(`Cannot find element with locator: ${JSON.stringify(elementOrLocator)}`);
11330
+ }
11331
+ return result;
11323
11332
  }, options);
11324
11333
  };
11325
11334
  }
@@ -11400,11 +11409,11 @@ function setupConsoleLogSpy() {
11400
11409
  sendLog("stdout", processLog(args));
11401
11410
  };
11402
11411
  console$1.trace = (...args) => {
11403
- var _a;
11412
+ var _a3;
11404
11413
  trace(...args);
11405
11414
  const content = processLog(args);
11406
11415
  const error2 = new Error("$$Trace");
11407
- const processor = ((_a = globalThis.__vitest_worker__) == null ? void 0 : _a.onFilterStackTrace) || ((s) => s || "");
11416
+ const processor = ((_a3 = globalThis.__vitest_worker__) == null ? void 0 : _a3.onFilterStackTrace) || ((s) => s || "");
11408
11417
  const stack = processor(error2.stack || "");
11409
11418
  sendLog("stderr", `${content}
11410
11419
  ${stack}`, true);
@@ -11471,12 +11480,12 @@ function processLog(args) {
11471
11480
  return args.map(formatInput).join(" ");
11472
11481
  }
11473
11482
  function sendLog(type, content, disableStack) {
11474
- var _a, _b, _c;
11483
+ var _a3, _b, _c;
11475
11484
  if (content.startsWith("[vite]")) {
11476
11485
  return;
11477
11486
  }
11478
11487
  const unknownTestId = "__vitest__unknown_test__";
11479
- const taskId = ((_b = (_a = globalThis.__vitest_worker__) == null ? void 0 : _a.current) == null ? void 0 : _b.id) ?? unknownTestId;
11488
+ const taskId = ((_b = (_a3 = globalThis.__vitest_worker__) == null ? void 0 : _a3.current) == null ? void 0 : _b.id) ?? unknownTestId;
11480
11489
  const origin = getConfig().printConsoleTrace && !disableStack ? (_c = new Error("STACK_TRACE").stack) == null ? void 0 : _c.split("\n").slice(1).join("\n") : void 0;
11481
11490
  rpc$1().sendLog({
11482
11491
  origin,
@@ -11827,6 +11836,8 @@ function normalizeWindowsPath(input = "") {
11827
11836
  const _UNC_REGEX = /^[/\\]{2}/;
11828
11837
  const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
11829
11838
  const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
11839
+ const _EXTNAME_RE = /.(\.[^./]+)$/;
11840
+ ((_a2 = globalThis.process) == null ? void 0 : _a2.platform) === "win32" ? ";" : ":";
11830
11841
  const normalize = function(path) {
11831
11842
  if (path.length === 0) {
11832
11843
  return ".";
@@ -11856,24 +11867,26 @@ const normalize = function(path) {
11856
11867
  }
11857
11868
  return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
11858
11869
  };
11859
- const join = function(...arguments_) {
11860
- if (arguments_.length === 0) {
11861
- return ".";
11862
- }
11863
- let joined;
11864
- for (const argument of arguments_) {
11865
- if (argument && argument.length > 0) {
11866
- if (joined === void 0) {
11867
- joined = argument;
11870
+ const join = function(...segments) {
11871
+ let path = "";
11872
+ for (const seg of segments) {
11873
+ if (!seg) {
11874
+ continue;
11875
+ }
11876
+ if (path.length > 0) {
11877
+ const pathTrailing = path[path.length - 1] === "/";
11878
+ const segLeading = seg[0] === "/";
11879
+ const both = pathTrailing && segLeading;
11880
+ if (both) {
11881
+ path += seg.slice(1);
11868
11882
  } else {
11869
- joined += `/${argument}`;
11883
+ path += pathTrailing || segLeading ? seg : `/${seg}`;
11870
11884
  }
11885
+ } else {
11886
+ path += seg;
11871
11887
  }
11872
11888
  }
11873
- if (joined === void 0) {
11874
- return ".";
11875
- }
11876
- return normalize(joined.replace(/\/\/+/g, "/"));
11889
+ return normalize(path);
11877
11890
  };
11878
11891
  function normalizeString(path, allowAboveRoot) {
11879
11892
  let res = "";
@@ -11938,11 +11951,11 @@ function normalizeString(path, allowAboveRoot) {
11938
11951
  const isAbsolute = function(p) {
11939
11952
  return _IS_ABSOLUTE_RE.test(p);
11940
11953
  };
11941
- const _EXTNAME_RE = /.(\.[^./]+)$/;
11942
11954
  const extname = function(p) {
11943
11955
  const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
11944
11956
  return match && match[1] || "";
11945
11957
  };
11958
+ var _a;
11946
11959
  const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
11947
11960
  const intToChar = new Uint8Array(64);
11948
11961
  const charToInt = new Uint8Array(128);
@@ -11961,6 +11974,7 @@ var UrlType;
11961
11974
  UrlType2[UrlType2["SchemeRelative"] = 6] = "SchemeRelative";
11962
11975
  UrlType2[UrlType2["Absolute"] = 7] = "Absolute";
11963
11976
  })(UrlType || (UrlType = {}));
11977
+ ((_a = globalThis.process) == null ? void 0 : _a.platform) === "win32" ? ";" : ":";
11964
11978
  const { now } = Date;
11965
11979
  class ModuleMocker {
11966
11980
  constructor(interceptor, rpc2, spyOn, config) {
@@ -12140,9 +12154,9 @@ class ModuleMocker {
12140
12154
  return path;
12141
12155
  }
12142
12156
  }
12143
- const versionRegexp$1 = /(\?|&)v=\w{8}/;
12157
+ const versionRegexp = /(\?|&)v=\w{8}/;
12144
12158
  function cleanVersion(url2) {
12145
- return url2.replace(versionRegexp$1, "");
12159
+ return url2.replace(versionRegexp, "");
12146
12160
  }
12147
12161
  const postfixRE = /[?#].*$/;
12148
12162
  function cleanUrl(url2) {
@@ -12231,10 +12245,11 @@ ${keys7}`;
12231
12245
  return await this.startPromise;
12232
12246
  }
12233
12247
  }
12234
- const timestampRegexp = /(\?|&)t=\d{13}/;
12235
- const versionRegexp = /(\?|&)v=\w{8}/;
12248
+ const trailingSeparatorRE = /[?&]$/;
12249
+ const timestampRE = /\bt=\d{13}&?\b/;
12250
+ const versionRE = /\bv=\w{8}&?\b/;
12236
12251
  function cleanQuery(url2) {
12237
- return url2.replace(timestampRegexp, "").replace(versionRegexp, "");
12252
+ return url2.replace(timestampRE, "").replace(versionRE, "").replace(trailingSeparatorRE, "");
12238
12253
  }
12239
12254
  function passthrough() {
12240
12255
  return new Response(null, {
@@ -13167,13 +13182,13 @@ function requireResolveUri_umd() {
13167
13182
  return map;
13168
13183
  }
13169
13184
  function encodedMappings(map) {
13170
- var _a;
13185
+ var _a3;
13171
13186
  var _b;
13172
- return (_a = (_b = cast(map))._encoded) !== null && _a !== void 0 ? _a : _b._encoded = sourcemapCodec.encode(cast(map)._decoded);
13187
+ return (_a3 = (_b = cast(map))._encoded) !== null && _a3 !== void 0 ? _a3 : _b._encoded = sourcemapCodec.encode(cast(map)._decoded);
13173
13188
  }
13174
13189
  function decodedMappings(map) {
13175
- var _a;
13176
- return (_a = cast(map))._decoded || (_a._decoded = sourcemapCodec.decode(cast(map)._encoded));
13190
+ var _a3;
13191
+ return (_a3 = cast(map))._decoded || (_a3._decoded = sourcemapCodec.decode(cast(map)._encoded));
13177
13192
  }
13178
13193
  function traceSegment(map, line, column) {
13179
13194
  const decoded = decodedMappings(map);
@@ -13320,7 +13335,7 @@ function requireResolveUri_umd() {
13320
13335
  return result;
13321
13336
  }
13322
13337
  function generatedPosition(map, source2, line, column, bias, all) {
13323
- var _a;
13338
+ var _a3;
13324
13339
  line--;
13325
13340
  if (line < 0)
13326
13341
  throw new Error(LINE_GTR_ZERO);
@@ -13332,7 +13347,7 @@ function requireResolveUri_umd() {
13332
13347
  sourceIndex2 = resolvedSources.indexOf(source2);
13333
13348
  if (sourceIndex2 === -1)
13334
13349
  return all ? [] : GMapping(null, null);
13335
- const generated = (_a = cast(map))._bySources || (_a._bySources = buildBySources(decodedMappings(map), cast(map)._bySourceMemos = sources.map(memoizedState)));
13350
+ const generated = (_a3 = cast(map))._bySources || (_a3._bySources = buildBySources(decodedMappings(map), cast(map)._bySourceMemos = sources.map(memoizedState)));
13336
13351
  const segments = generated[sourceIndex2][line];
13337
13352
  if (segments == null)
13338
13353
  return all ? [] : GMapping(null, null);
@@ -13497,11 +13512,11 @@ function parseStacktrace(stack, options = {}) {
13497
13512
  );
13498
13513
  }
13499
13514
  return stacks.map((stack2) => {
13500
- var _a;
13515
+ var _a3;
13501
13516
  if (options.getFileName) {
13502
13517
  stack2.file = options.getFileName(stack2.file);
13503
13518
  }
13504
- const map = (_a = options.getSourceMap) == null ? void 0 : _a.call(options, stack2.file);
13519
+ const map = (_a3 = options.getSourceMap) == null ? void 0 : _a3.call(options, stack2.file);
13505
13520
  if (!map || typeof map !== "object" || !map.version) {
13506
13521
  return stack2;
13507
13522
  }
@@ -13577,13 +13592,13 @@ function createBrowserRunner(runnerClass, mocker, state, coverageModule) {
13577
13592
  __publicField(this, "hashMap", browserHashMap);
13578
13593
  __publicField(this, "sourceMapCache", /* @__PURE__ */ new Map());
13579
13594
  __publicField(this, "onBeforeTryTask", async (...args) => {
13580
- var _a;
13595
+ var _a3;
13581
13596
  await userEvent.cleanup();
13582
- await ((_a = super.onBeforeTryTask) == null ? void 0 : _a.call(this, ...args));
13597
+ await ((_a3 = super.onBeforeTryTask) == null ? void 0 : _a3.call(this, ...args));
13583
13598
  });
13584
13599
  __publicField(this, "onAfterRunTask", async (task) => {
13585
- var _a, _b;
13586
- await ((_a = super.onAfterRunTask) == null ? void 0 : _a.call(this, task));
13600
+ var _a3, _b;
13601
+ await ((_a3 = super.onAfterRunTask) == null ? void 0 : _a3.call(this, task));
13587
13602
  if (this.config.bail && ((_b = task.result) == null ? void 0 : _b.state) === "fail") {
13588
13603
  const previousFailures = await rpc$1().getCountOfFailedTests();
13589
13604
  const currentFailures = 1 + previousFailures;
@@ -13594,20 +13609,25 @@ function createBrowserRunner(runnerClass, mocker, state, coverageModule) {
13594
13609
  }
13595
13610
  });
13596
13611
  __publicField(this, "onTaskFinished", async (task) => {
13597
- var _a;
13598
- if (this.config.browser.screenshotFailures && ((_a = task.result) == null ? void 0 : _a.state) === "fail") {
13599
- task.meta.failScreenshotPath = await page.screenshot();
13612
+ var _a3;
13613
+ if (this.config.browser.screenshotFailures && document.body.clientHeight > 0 && ((_a3 = task.result) == null ? void 0 : _a3.state) === "fail") {
13614
+ const screenshot = await page.screenshot().catch((err) => {
13615
+ console.error("[vitest] Failed to take a screenshot", err);
13616
+ });
13617
+ if (screenshot) {
13618
+ task.meta.failScreenshotPath = screenshot;
13619
+ }
13600
13620
  }
13601
13621
  });
13602
13622
  __publicField(this, "onCancel", (reason) => {
13603
- var _a;
13604
- (_a = super.onCancel) == null ? void 0 : _a.call(this, reason);
13623
+ var _a3;
13624
+ (_a3 = super.onCancel) == null ? void 0 : _a3.call(this, reason);
13605
13625
  globalChannel.postMessage({ type: "cancel", reason });
13606
13626
  });
13607
13627
  __publicField(this, "onBeforeRunSuite", async (suite) => {
13608
- var _a;
13628
+ var _a3;
13609
13629
  await Promise.all([
13610
- (_a = super.onBeforeRunSuite) == null ? void 0 : _a.call(this, suite),
13630
+ (_a3 = super.onBeforeRunSuite) == null ? void 0 : _a3.call(this, suite),
13611
13631
  (async () => {
13612
13632
  if ("filepath" in suite) {
13613
13633
  const map = await rpc$1().getBrowserFileSourceMap(suite.filepath);
@@ -13621,9 +13641,9 @@ function createBrowserRunner(runnerClass, mocker, state, coverageModule) {
13621
13641
  ]);
13622
13642
  });
13623
13643
  __publicField(this, "onAfterRunFiles", async (files) => {
13624
- var _a, _b;
13644
+ var _a3, _b;
13625
13645
  const [coverage] = await Promise.all([
13626
- (_a = coverageModule == null ? void 0 : coverageModule.takeCoverage) == null ? void 0 : _a.call(coverageModule),
13646
+ (_a3 = coverageModule == null ? void 0 : coverageModule.takeCoverage) == null ? void 0 : _a3.call(coverageModule),
13627
13647
  mocker.invalidate(),
13628
13648
  (_b = super.onAfterRunFiles) == null ? void 0 : _b.call(this, files)
13629
13649
  ]);
@@ -13636,6 +13656,9 @@ function createBrowserRunner(runnerClass, mocker, state, coverageModule) {
13636
13656
  });
13637
13657
  }
13638
13658
  });
13659
+ __publicField(this, "onCollectStart", (file) => {
13660
+ return rpc$1().onQueued(file);
13661
+ });
13639
13662
  __publicField(this, "onCollected", async (files) => {
13640
13663
  files.forEach((file) => {
13641
13664
  file.prepareDuration = state.durations.prepare;
@@ -13765,8 +13788,8 @@ async function prepareTestEnvironment(files) {
13765
13788
  }
13766
13789
  });
13767
13790
  onCancel.then((reason) => {
13768
- var _a;
13769
- (_a = runner.onCancel) == null ? void 0 : _a.call(runner, reason);
13791
+ var _a3;
13792
+ (_a3 = runner.onCancel) == null ? void 0 : _a3.call(runner, reason);
13770
13793
  });
13771
13794
  return {
13772
13795
  runner,
@@ -1,3 +1,4 @@
1
+ var _a;
1
2
  (function polyfill() {
2
3
  const relList = document.createElement("link").relList;
3
4
  if (relList && relList.supports && relList.supports("modulepreload")) {
@@ -44,6 +45,7 @@ function normalizeWindowsPath(input = "") {
44
45
  }
45
46
  const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
46
47
  const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
48
+ ((_a = globalThis.process) == null ? void 0 : _a.platform) === "win32" ? ";" : ":";
47
49
  function cwd() {
48
50
  if (typeof process !== "undefined" && typeof process.cwd === "function") {
49
51
  return process.cwd().replace(/\\/g, "/");
@@ -24,7 +24,7 @@
24
24
  viteConfig: { __VITEST_VITE_CONFIG__ },
25
25
  files: { __VITEST_FILES__ },
26
26
  type: { __VITEST_TYPE__ },
27
- contextId: { __VITEST_CONTEXT_ID__ },
27
+ sessionId: { __VITEST_SESSION_ID__ },
28
28
  testerId: { __VITEST_TESTER_ID__ },
29
29
  provider: { __VITEST_PROVIDER__ },
30
30
  providedContext: { __VITEST_PROVIDED_CONTEXT__ },
@@ -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-DnP17K36.js"></script>
30
- <link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-Owv5OOOf.js">
29
+ <script type="module" crossorigin src="/__vitest_browser__/orchestrator-Cv-bzUFk.js"></script>
30
+ <link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-CaCTRFti.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-BdwA4c5U.js"></script>
9
- <link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-Owv5OOOf.js">
8
+ <script type="module" crossorigin src="/__vitest_browser__/tester-DreAh6ar.js"></script>
9
+ <link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-CaCTRFti.js">
10
10
  </head>
11
11
  <body>
12
12
  </body>
package/dist/client.js CHANGED
@@ -201,9 +201,9 @@ const parse = (text, reviver) => {
201
201
  * @returns {string}
202
202
  */
203
203
  const stringify = (value, replacer, space) => {
204
- const $ = replacer && typeof replacer === object ?
204
+ const $ = typeof replacer === object ?
205
205
  (k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
206
- (replacer || noop);
206
+ (replacer);
207
207
  const known = new Map;
208
208
  const input = [];
209
209
  const output = [];
@@ -236,7 +236,7 @@ function getBrowserState() {
236
236
  }
237
237
 
238
238
  const channel = new BroadcastChannel(
239
- `vitest:${getBrowserState().contextId}`
239
+ `vitest:${getBrowserState().sessionId}`
240
240
  );
241
241
  const globalChannel = new BroadcastChannel("vitest:global");
242
242
  function waitForChannel(event) {
@@ -256,8 +256,8 @@ function waitForChannel(event) {
256
256
  const PAGE_TYPE = getBrowserState().type;
257
257
  const PORT = location.port;
258
258
  const HOST = [location.hostname, PORT].filter(Boolean).join(":");
259
- const SESSION_ID = PAGE_TYPE === "orchestrator" ? getBrowserState().contextId : getBrowserState().testerId;
260
- const ENTRY_URL = `${location.protocol === "https:" ? "wss:" : "ws:"}//${HOST}/__vitest_browser_api__?type=${PAGE_TYPE}&sessionId=${SESSION_ID}`;
259
+ const RPC_ID = PAGE_TYPE === "orchestrator" ? getBrowserState().sessionId : getBrowserState().testerId;
260
+ const ENTRY_URL = `${location.protocol === "https:" ? "wss:" : "ws:"}//${HOST}/__vitest_browser_api__?type=${PAGE_TYPE}&rpcId=${RPC_ID}&sessionId=${getBrowserState().sessionId}&projectName=${getBrowserState().config.name || ""}`;
261
261
  let setCancel = (_) => {
262
262
  };
263
263
  const onCancel = new Promise((resolve) => {
@@ -353,4 +353,4 @@ function createClient() {
353
353
  }
354
354
  const client = createClient();
355
355
 
356
- export { ENTRY_URL, HOST, PORT, SESSION_ID, channel, client, globalChannel, onCancel, waitForChannel };
356
+ export { ENTRY_URL, HOST, PORT, RPC_ID, channel, client, globalChannel, onCancel, waitForChannel };
package/dist/context.js CHANGED
@@ -117,10 +117,10 @@ function filepath() {
117
117
  return getWorkerState().filepath || getWorkerState().current?.file?.filepath || void 0;
118
118
  }
119
119
  const rpc = () => getWorkerState().rpc;
120
- const contextId = getBrowserState().contextId;
121
- const channel = new BroadcastChannel(`vitest:${contextId}`);
120
+ const sessionId = getBrowserState().sessionId;
121
+ const channel = new BroadcastChannel(`vitest:${sessionId}`);
122
122
  function triggerCommand(command, ...args) {
123
- return rpc().triggerCommand(contextId, command, filepath(), args);
123
+ return rpc().triggerCommand(sessionId, command, filepath(), args);
124
124
  }
125
125
  function createUserEvent(__tl_user_event_base__, options) {
126
126
  if (__tl_user_event_base__) {
@@ -129,7 +129,8 @@ function createUserEvent(__tl_user_event_base__, options) {
129
129
  const keyboard = {
130
130
  unreleased: []
131
131
  };
132
- return {
132
+ const modifier = provider === `playwright` ? "ControlOrMeta" : provider === "webdriverio" ? "Ctrl" : "Control";
133
+ const userEvent = {
133
134
  setup() {
134
135
  return createUserEvent();
135
136
  },
@@ -199,11 +200,22 @@ function createUserEvent(__tl_user_event_base__, options) {
199
200
  );
200
201
  keyboard.unreleased = unreleased;
201
202
  });
203
+ },
204
+ async copy() {
205
+ await userEvent.keyboard(`{${modifier}>}{c}{/${modifier}}`);
206
+ },
207
+ async cut() {
208
+ await userEvent.keyboard(`{${modifier}>}{x}{/${modifier}}`);
209
+ },
210
+ async paste() {
211
+ await userEvent.keyboard(`{${modifier}>}{v}{/${modifier}}`);
202
212
  }
203
213
  };
214
+ return userEvent;
204
215
  }
205
216
  function createPreviewUserEvent(userEventBase, options) {
206
217
  let userEvent = userEventBase.setup(options);
218
+ let clipboardData;
207
219
  function toElement(element) {
208
220
  return element instanceof Element ? element : element.element();
209
221
  }
@@ -271,6 +283,15 @@ function createPreviewUserEvent(userEventBase, options) {
271
283
  },
272
284
  async keyboard(text) {
273
285
  await userEvent.keyboard(text);
286
+ },
287
+ async copy() {
288
+ clipboardData = await userEvent.copy();
289
+ },
290
+ async cut() {
291
+ clipboardData = await userEvent.cut();
292
+ },
293
+ async paste() {
294
+ await userEvent.paste(clipboardData);
274
295
  }
275
296
  };
276
297
  for (const [name, fn] of Object.entries(vitestUserEvent)) {
@@ -235,6 +235,15 @@ class Locator {
235
235
  all() {
236
236
  return this.elements().map((element) => this.elementLocator(element));
237
237
  }
238
+ nth(index) {
239
+ return this.locator(`nth=${index}`);
240
+ }
241
+ first() {
242
+ return this.nth(0);
243
+ }
244
+ last() {
245
+ return this.nth(-1);
246
+ }
238
247
  toString() {
239
248
  return this.selector;
240
249
  }
@@ -253,7 +262,7 @@ class Locator {
253
262
  triggerCommand(command, ...args) {
254
263
  const filepath = this.worker.filepath || this.worker.current?.file?.filepath || void 0;
255
264
  return ensureAwaited(() => this.rpc.triggerCommand(
256
- this.state.contextId,
265
+ this.state.sessionId,
257
266
  command,
258
267
  filepath,
259
268
  args