@vitest/browser 4.1.0-beta.1 → 4.1.0-beta.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.
@@ -562,8 +562,11 @@ const stackIgnorePatterns = [
562
562
  /node:\w+/,
563
563
  /__vitest_test__/,
564
564
  /__vitest_browser__/,
565
+ "/@id/__x00__vitest/browser",
565
566
  /\/deps\/vitest_/
566
567
  ];
568
+ const NOW_LENGTH = Date.now().toString().length;
569
+ const REGEXP_VITEST = new RegExp(`vitest=\\d{${NOW_LENGTH}}`);
567
570
  function extractLocation(urlLike) {
568
571
  if (!urlLike.includes(":")) {
569
572
  return [urlLike];
@@ -587,6 +590,9 @@ function extractLocation(urlLike) {
587
590
  const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url2);
588
591
  url2 = url2.slice(isWindows ? 5 : 4);
589
592
  }
593
+ if (url2.includes("vitest=")) {
594
+ url2 = url2.replace(REGEXP_VITEST, "").replace(/[?&]$/, "");
595
+ }
590
596
  return [url2, parts[2] || void 0, parts[3] || void 0];
591
597
  }
592
598
  function parseSingleFFOrSafariStack(raw) {
@@ -658,7 +664,7 @@ function parseSingleV8Stack(raw) {
658
664
  }
659
665
  file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve(file);
660
666
  if (method) {
661
- method = method.replace(/__vite_ssr_import_\d+__\./g, "").replace(/(Object\.)?__vite_ssr_export_default__\s?/g, "");
667
+ method = method.replace(/\(0\s?,\s?__vite_ssr_import_\d+__.(\w+)\)/g, "$1").replace(/__(vite_ssr_import|vi_import)_\d+__\./g, "").replace(/(Object\.)?__vite_ssr_export_default__\s?/g, "");
662
668
  }
663
669
  return {
664
670
  method,
@@ -903,7 +909,9 @@ function createBrowserRunner(runnerClass, mocker, state, coverageModule) {
903
909
  };
904
910
  onTaskFinished = async (task) => {
905
911
  var _a, _b;
906
- if (this.config.browser.screenshotFailures && document.body.clientHeight > 0 && ((_a = task.result) == null ? void 0 : _a.state) === "fail") {
912
+ if (this.config.browser.screenshotFailures && document.body.clientHeight > 0 && ((_a = task.result) == null ? void 0 : _a.state) === "fail" && task.type === "test" && task.artifacts.every(
913
+ (artifact) => artifact.type !== "internal:toMatchScreenshot"
914
+ )) {
907
915
  const screenshot = await page.screenshot(
908
916
  {
909
917
  timeout: ((_b = this.config.browser.providerOptions) == null ? void 0 : _b.actionTimeout) ?? 5e3
@@ -1377,21 +1385,25 @@ class ManualMockedModule {
1377
1385
  this.url = url2;
1378
1386
  this.factory = factory;
1379
1387
  }
1380
- async resolve() {
1388
+ resolve() {
1381
1389
  if (this.cache) {
1382
1390
  return this.cache;
1383
1391
  }
1384
1392
  let exports$1;
1385
1393
  try {
1386
- exports$1 = await this.factory();
1394
+ exports$1 = this.factory();
1387
1395
  } catch (err) {
1388
- const vitestError = new Error('[vitest] There was an error when mocking a module. If you are using "vi.mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api/vi.html#vi-mock');
1389
- vitestError.cause = err;
1390
- throw vitestError;
1391
- }
1392
- if (exports$1 === null || typeof exports$1 !== "object" || Array.isArray(exports$1)) {
1393
- throw new TypeError(`[vitest] vi.mock("${this.raw}", factory?: () => unknown) is not returning an object. Did you mean to return an object with a "default" key?`);
1396
+ throw createHelpfulError(err);
1397
+ }
1398
+ if (typeof exports$1 === "object" && typeof (exports$1 === null || exports$1 === void 0 ? void 0 : exports$1.then) === "function") {
1399
+ return exports$1.then((result) => {
1400
+ assertValidExports(this.raw, result);
1401
+ return this.cache = result;
1402
+ }, (error) => {
1403
+ throw createHelpfulError(error);
1404
+ });
1394
1405
  }
1406
+ assertValidExports(this.raw, exports$1);
1395
1407
  return this.cache = exports$1;
1396
1408
  }
1397
1409
  static fromJSON(data, factory) {
@@ -1406,6 +1418,16 @@ class ManualMockedModule {
1406
1418
  };
1407
1419
  }
1408
1420
  }
1421
+ function createHelpfulError(cause) {
1422
+ const error = new Error('[vitest] There was an error when mocking a module. If you are using "vi.mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api/vi.html#vi-mock');
1423
+ error.cause = cause;
1424
+ return error;
1425
+ }
1426
+ function assertValidExports(raw, exports$1) {
1427
+ if (exports$1 === null || typeof exports$1 !== "object" || Array.isArray(exports$1)) {
1428
+ 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?`);
1429
+ }
1430
+ }
1409
1431
  function mockObject(options, object2, mockExports = {}) {
1410
1432
  const finalizers = new Array();
1411
1433
  const refs = new RefTracker();
@@ -1718,6 +1740,7 @@ for (let i = 0; i < chars.length; i++) {
1718
1740
  intToChar[i] = c;
1719
1741
  charToInt[c] = i;
1720
1742
  }
1743
+ Date.now().toString().length;
1721
1744
  const { now } = Date;
1722
1745
  class ModuleMocker {
1723
1746
  registry = new MockerRegistry();
@@ -1768,7 +1791,7 @@ class ModuleMocker {
1768
1791
  throw new Error(`[vitest] Cannot resolve "${id}" imported from "${importer}"`);
1769
1792
  }
1770
1793
  const ext = extname(resolved.id);
1771
- const url2 = new URL(resolved.url, location.href);
1794
+ const url2 = new URL(resolved.url, this.getBaseUrl());
1772
1795
  const query = `_vitest_original&ext${ext}`;
1773
1796
  const actualUrl = `${url2.pathname}${url2.search ? `${url2.search}&${query}` : `?${query}`}${url2.hash}`;
1774
1797
  return this.wrapDynamicImport(() => import(
@@ -1785,6 +1808,9 @@ class ModuleMocker {
1785
1808
  };
1786
1809
  });
1787
1810
  }
1811
+ getBaseUrl() {
1812
+ return location.href;
1813
+ }
1788
1814
  async importMock(rawId, importer) {
1789
1815
  await this.prepare();
1790
1816
  const { resolvedId, resolvedUrl, redirectUrl } = await this.rpc.resolveMock(rawId, importer, { mock: "auto" });
@@ -1792,7 +1818,7 @@ class ModuleMocker {
1792
1818
  let mock = this.registry.get(mockUrl);
1793
1819
  if (!mock) {
1794
1820
  if (redirectUrl) {
1795
- const resolvedRedirect = new URL(this.resolveMockPath(cleanVersion(redirectUrl)), location.href).toString();
1821
+ const resolvedRedirect = new URL(this.resolveMockPath(cleanVersion(redirectUrl)), this.getBaseUrl()).toString();
1796
1822
  mock = new RedirectedModule(rawId, resolvedId, mockUrl, resolvedRedirect);
1797
1823
  } else {
1798
1824
  mock = new AutomockedModule(rawId, resolvedId, mockUrl);
@@ -1802,21 +1828,21 @@ class ModuleMocker {
1802
1828
  return await mock.resolve();
1803
1829
  }
1804
1830
  if (mock.type === "automock" || mock.type === "autospy") {
1805
- const url2 = new URL(`/@id/${resolvedId}`, location.href);
1831
+ const url2 = new URL(`/@id/${resolvedId}`, this.getBaseUrl());
1806
1832
  const query = url2.search ? `${url2.search}&t=${now()}` : `?t=${now()}`;
1807
1833
  const moduleObject = await __vitePreload(() => import(
1808
1834
  /* @vite-ignore */
1809
1835
  `${url2.pathname}${query}&mock=${mock.type}${url2.hash}`
1810
1836
  ), true ? [] : void 0);
1811
- return this.mockObject(moduleObject, mock.type);
1837
+ return this.mockObject(moduleObject, void 0, mock.type);
1812
1838
  }
1813
1839
  return import(
1814
1840
  /* @vite-ignore */
1815
1841
  mock.redirect
1816
1842
  );
1817
1843
  }
1818
- mockObject(object2, moduleType = "automock") {
1819
- return mockObject({
1844
+ mockObject(object2, mockExports, moduleType = "automock") {
1845
+ const result = mockObject({
1820
1846
  globalConstructors: {
1821
1847
  Object,
1822
1848
  Function,
@@ -1826,7 +1852,11 @@ class ModuleMocker {
1826
1852
  },
1827
1853
  createMockInstance: this.createMockInstance,
1828
1854
  type: moduleType
1829
- }, object2);
1855
+ }, object2, mockExports);
1856
+ return result;
1857
+ }
1858
+ getMockContext() {
1859
+ return { callstack: null };
1830
1860
  }
1831
1861
  queueMock(rawId, importer, factoryOrOptions) {
1832
1862
  const promise = this.rpc.resolveMock(rawId, importer, { mock: typeof factoryOrOptions === "function" ? "factory" : (factoryOrOptions === null || factoryOrOptions === void 0 ? void 0 : factoryOrOptions.spy) ? "spy" : "auto" }).then(async ({ redirectUrl, resolvedId, resolvedUrl, needsInterop, mockType }) => {
@@ -1836,7 +1866,7 @@ class ModuleMocker {
1836
1866
  const data = await factoryOrOptions();
1837
1867
  return needsInterop ? { default: data } : data;
1838
1868
  } : void 0;
1839
- const mockRedirect = typeof redirectUrl === "string" ? new URL(this.resolveMockPath(cleanVersion(redirectUrl)), location.href).toString() : null;
1869
+ const mockRedirect = typeof redirectUrl === "string" ? new URL(this.resolveMockPath(cleanVersion(redirectUrl)), this.getBaseUrl()).toString() : null;
1840
1870
  let module;
1841
1871
  if (mockType === "manual") {
1842
1872
  module = this.registry.register("manual", rawId, resolvedId, mockUrl, factory);
@@ -1880,6 +1910,14 @@ class ModuleMocker {
1880
1910
  }
1881
1911
  return moduleFactory;
1882
1912
  }
1913
+ getMockedModuleById(id) {
1914
+ return this.registry.getById(id);
1915
+ }
1916
+ reset() {
1917
+ this.registry.clear();
1918
+ this.mockedIds.clear();
1919
+ this.queue.clear();
1920
+ }
1883
1921
  resolveMockPath(path) {
1884
1922
  const config = this.config;
1885
1923
  const fsRoot = join("/@fs/", config.root);
@@ -1,5 +1,50 @@
1
- <svg width="165" height="165" viewBox="0 0 165 165" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <path d="M120.831 57.2543L84.693 109.505C84.3099 110.059 83.7558 110.474 83.1148 110.687C82.4738 110.9 81.7809 110.898 81.1412 110.684C80.5015 110.469 79.95 110.052 79.5702 109.497C79.1905 108.941 79.0032 108.277 79.037 107.606L80.4833 78.7582L57.1343 73.8064C56.6353 73.7007 56.1704 73.474 55.7807 73.1465C55.391 72.8191 55.0885 72.4009 54.9001 71.929C54.7117 71.4571 54.6432 70.9461 54.7006 70.4412C54.758 69.9364 54.9395 69.4532 55.2291 69.0345L91.3675 16.7837C91.7507 16.2294 92.3048 15.8145 92.9458 15.6018C93.5869 15.3891 94.2798 15.3902 94.9196 15.6051C95.5593 15.8199 96.1109 16.2367 96.4906 16.7923C96.8703 17.3478 97.0575 18.0117 97.0236 18.6833L95.5773 47.5314L118.926 52.4828C119.425 52.5885 119.89 52.8152 120.28 53.1426C120.67 53.4701 120.972 53.8883 121.16 54.3602C121.349 54.8321 121.417 55.3431 121.36 55.8479C121.303 56.3528 121.121 56.836 120.831 57.2547L120.831 57.2543Z" fill="#FCC72B"/>
3
- <path d="M82.9866 153.343C82.0254 153.344 81.0735 153.156 80.1855 152.788C79.2975 152.42 78.4909 151.88 77.8122 151.2L43.6658 117.056C42.2998 115.683 41.5341 113.824 41.5366 111.887C41.5392 109.95 42.3098 108.092 43.6796 106.723C45.0493 105.353 46.9064 104.582 48.8435 104.579C50.7807 104.577 52.6399 105.342 54.0134 106.708L82.9866 135.678L146.105 72.5626C147.481 71.2088 149.336 70.4536 151.266 70.4615C153.197 70.4693 155.046 71.2396 156.41 72.6045C157.775 73.9695 158.546 75.8184 158.554 77.7487C158.561 79.679 157.806 81.5342 156.452 82.9101L88.1597 151.2C87.4811 151.881 86.6747 152.42 85.7869 152.788C84.8992 153.156 83.9475 153.344 82.9866 153.343Z" fill="#729B1B"/>
4
- <path d="M82.9572 153.343C83.9184 153.344 84.8703 153.156 85.7583 152.788C86.6463 152.42 87.4528 151.88 88.1316 151.2L122.278 117.056C123.644 115.683 124.41 113.824 124.407 111.887C124.405 109.95 123.634 108.092 122.264 106.723C120.894 105.353 119.037 104.582 117.1 104.579C115.163 104.577 113.304 105.342 111.93 106.708L82.9572 135.678L19.8389 72.5626C18.4629 71.2088 16.6077 70.4536 14.6775 70.4615C12.7472 70.4693 10.8982 71.2396 9.53331 72.6045C8.16839 73.9695 7.39811 75.8184 7.39025 77.7487C7.38239 79.679 8.13759 81.5342 9.49135 82.9101L77.784 151.2C78.4627 151.881 79.2691 152.42 80.1568 152.788C81.0446 153.156 81.9963 153.344 82.9572 153.343Z" fill="#729B1B" fill-opacity="0.5"/>
1
+ <svg width="45" height="43" viewBox="0 0 45 43" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M21.2659 42.2067C20.9342 42.797 20.163 42.965 19.6137 42.5665L0.465308 28.6398C0.172341 28.4265 0 28.0862 0 27.7243V10.939C0 10.0148 1.04907 9.48061 1.79657 10.0235L13.5088 18.541C14.6031 19.3381 16.1476 18.9999 16.8111 17.8215L26.5113 0.577439C26.7117 0.222001 27.0887 0.00012207 27.498 0.00012207H43.0726C43.9385 0.00012207 44.4836 0.932876 44.0592 1.68683L21.2659 42.2046V42.2067Z" fill="#22FF84"/>
3
+ <mask id="mask0_2002_17204" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="45" height="43">
4
+ <path d="M21.2659 42.2066C20.9342 42.7968 20.163 42.9649 19.6137 42.5663L0.465308 28.6397C0.172341 28.4264 0 28.086 0 27.7241V10.9389C0 10.0147 1.04907 9.48049 1.79657 10.0233L13.5088 18.5409C14.6031 19.338 16.1476 18.9998 16.8111 17.8214L26.5113 0.577317C26.7117 0.221879 27.0887 0 27.498 0H43.0726C43.9385 0 44.4836 0.932754 44.0592 1.68671L21.2659 42.2044V42.2066Z" fill="black"/>
5
+ </mask>
6
+ <g mask="url(#mask0_2002_17204)">
7
+ <g filter="url(#filter0_f_2002_17204)">
8
+ <ellipse cx="14.0313" cy="3.39062" rx="14.0313" ry="3.39062" transform="matrix(-0.650066 0.759878 0.759879 0.650065 32.5093 -3.61884)" fill="#00CCC6"/>
9
+ </g>
10
+ <g filter="url(#filter1_f_2002_17204)">
11
+ <ellipse cx="14.0313" cy="6.0868" rx="14.0313" ry="6.0868" transform="matrix(-0.588245 -0.808682 -0.808682 0.588246 16.1094 37.5068)" fill="#00CCC6"/>
12
+ </g>
13
+ <g filter="url(#filter2_f_2002_17204)">
14
+ <ellipse cx="6.44313" cy="12.1953" rx="6.37416" ry="5.55082" transform="rotate(23.1293 6.44313 12.1953)" fill="#77FF00"/>
15
+ </g>
16
+ <g filter="url(#filter3_f_2002_17204)">
17
+ <ellipse cx="40.7746" cy="15.9509" rx="5.61461" ry="24.5343" transform="rotate(23.1293 40.7746 15.9509)" fill="#77FF00"/>
18
+ </g>
19
+ <g filter="url(#filter4_f_2002_17204)">
20
+ <ellipse cx="4.98534" cy="10.0691" rx="4.98534" ry="10.0691" transform="matrix(0.707107 -0.707107 -0.707107 -0.707107 39.4482 10.9414)" fill="#97FFE2"/>
21
+ </g>
22
+ </g>
23
+ <defs>
24
+ <filter id="filter0_f_2002_17204" x="7.29277" y="-10.8334" width="37.3432" height="40.1616" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
25
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
26
+ <feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
27
+ <feGaussianBlur stdDeviation="4.59556" result="effect1_foregroundBlur_2002_17204"/>
28
+ </filter>
29
+ <filter id="filter1_f_2002_17204" x="-15.8693" y="8.64781" width="37.6054" height="42.1854" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
30
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
31
+ <feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
32
+ <feGaussianBlur stdDeviation="4.59556" result="effect1_foregroundBlur_2002_17204"/>
33
+ </filter>
34
+ <filter id="filter2_f_2002_17204" x="-9.0041" y="-2.68275" width="30.8944" height="29.7561" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
35
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
36
+ <feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
37
+ <feGaussianBlur stdDeviation="4.59556" result="effect1_foregroundBlur_2002_17204"/>
38
+ </filter>
39
+ <filter id="filter3_f_2002_17204" x="20.6482" y="-15.9117" width="40.2528" height="63.7251" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
40
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
41
+ <feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
42
+ <feGaussianBlur stdDeviation="4.59556" result="effect1_foregroundBlur_2002_17204"/>
43
+ </filter>
44
+ <filter id="filter4_f_2002_17204" x="18.7156" y="-16.8414" width="34.2758" height="34.2754" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
45
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
46
+ <feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
47
+ <feGaussianBlur stdDeviation="4.59556" result="effect1_foregroundBlur_2002_17204"/>
48
+ </filter>
49
+ </defs>
5
50
  </svg>
@@ -26,7 +26,7 @@
26
26
  {__VITEST_INJECTOR__}
27
27
  {__VITEST_ERROR_CATCHER__}
28
28
  {__VITEST_SCRIPTS__}
29
- <script type="module" crossorigin src="/__vitest_browser__/orchestrator-S_3e_uzt.js"></script>
29
+ <script type="module" crossorigin src="/__vitest_browser__/orchestrator-fh7lJzlE.js"></script>
30
30
  <link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-uxqdqUz8.js">
31
31
  </head>
32
32
  <body>
@@ -5,7 +5,7 @@
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-cVWT4Xmu.js"></script>
8
+ <script type="module" crossorigin src="/__vitest_browser__/tester-CH-bVWK6.js"></script>
9
9
  <link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-uxqdqUz8.js">
10
10
  </head>
11
11
  <body>
package/dist/client.js CHANGED
@@ -324,7 +324,7 @@ const PORT = location.port;
324
324
  const HOST = [location.hostname, PORT].filter(Boolean).join(":");
325
325
  const RPC_ID = PAGE_TYPE === "orchestrator" ? getBrowserState().sessionId : getBrowserState().testerId;
326
326
  const METHOD = getBrowserState().method;
327
- 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 || ""}&method=${METHOD}&token=${window.VITEST_API_TOKEN || "0"}`;
327
+ const ENTRY_URL = `${location.protocol === "https:" ? "wss:" : "ws:"}//${HOST}/__vitest_browser_api__?type=${PAGE_TYPE}&rpcId=${RPC_ID}&sessionId=${getBrowserState().sessionId}&projectName=${encodeURIComponent(getBrowserState().config.name || "")}&method=${METHOD}&token=${window.VITEST_API_TOKEN || "0"}`;
328
328
  const onCancelCallbacks = [];
329
329
  function onCancel(callback) {
330
330
  onCancelCallbacks.push(callback);
package/dist/context.js CHANGED
@@ -577,9 +577,6 @@ function getElementError(selector, container) {
577
577
  error.name = "VitestBrowserElementError";
578
578
  return error;
579
579
  }
580
- /**
581
- * @experimental
582
- */
583
580
  function configurePrettyDOM(options) {
584
581
  defaultOptions = options;
585
582
  }
@@ -1,4 +1,4 @@
1
- import{recordArtifact,expect,chai}from"vitest";import{getType}from"vitest/internal/browser";import{k as kAriaCheckedRoles,L as Locator,g as getAriaChecked,a as getAriaRole,b as getAriaDisabled,c as beginAriaCaches,e as endAriaCaches,i as isElementVisible$1,d as getElementAccessibleDescription,f as getElementAccessibleErrorMessage,h as getElementAccessibleName,j as cssEscape,l as convertToSelector,m as getBrowserState,p as processTimeoutOptions}from"./index-5ZLDAkrH.js";import{server}from"vitest/browser";function getAriaCheckedRoles(){return[...kAriaCheckedRoles]}function queryElementFromUserInput(_,K,q){return _ instanceof Locator&&(_=_.query()),_==null?null:getElementFromUserInput(_,K,q)}function getElementFromUserInput(_,K,q){_ instanceof Locator&&(_=_.element());let J=_?.ownerDocument?.defaultView||window;if(_ instanceof J.HTMLElement||_ instanceof J.SVGElement)return _;throw new UserInputElementTypeError(_,K,q)}function getNodeFromUserInput(_,K,q){_ instanceof Locator&&(_=_.element());let J=_.ownerDocument?.defaultView||window;if(_ instanceof J.Node)return _;throw new UserInputNodeTypeError(_,K,q)}function getMessage(_,K,q,J,Y,X){return[`${K}\n`,`${q}:\n${_.utils.EXPECTED_COLOR(redent(display(_,J),2))}`,`${Y}:\n${_.utils.RECEIVED_COLOR(redent(display(_,X),2))}`].join(`
1
+ import{recordArtifact,expect,chai}from"vitest";import{getType}from"vitest/internal/browser";import{k as kAriaCheckedRoles,L as Locator,g as getAriaChecked,a as getAriaRole,b as getAriaDisabled,c as beginAriaCaches,e as endAriaCaches,i as isElementVisible$1,d as getElementAccessibleDescription,f as getElementAccessibleErrorMessage,h as getElementAccessibleName,j as cssEscape,l as convertToSelector,m as getBrowserState,p as processTimeoutOptions}from"./index-Dlkb5vw8.js";import{server}from"vitest/browser";function getAriaCheckedRoles(){return[...kAriaCheckedRoles]}function queryElementFromUserInput(_,K,q){return _ instanceof Locator&&(_=_.query()),_==null?null:getElementFromUserInput(_,K,q)}function getElementFromUserInput(_,K,q){_ instanceof Locator&&(_=_.element());let J=_?.ownerDocument?.defaultView||window;if(_ instanceof J.HTMLElement||_ instanceof J.SVGElement)return _;throw new UserInputElementTypeError(_,K,q)}function getNodeFromUserInput(_,K,q){_ instanceof Locator&&(_=_.element());let J=_.ownerDocument?.defaultView||window;if(_ instanceof J.Node)return _;throw new UserInputNodeTypeError(_,K,q)}function getMessage(_,K,q,J,Y,X){return[`${K}\n`,`${q}:\n${_.utils.EXPECTED_COLOR(redent(display(_,J),2))}`,`${Y}:\n${_.utils.RECEIVED_COLOR(redent(display(_,X),2))}`].join(`
2
2
  `)}function redent(_,K){return indentString(stripIndent(_),K)}function indentString(_,K){return _.replace(/^(?!\s*$)/gm,` `.repeat(K))}function minIndent(_){let K=_.match(/^[ \t]*(?=\S)/gm);return K?K.reduce((_,K)=>Math.min(_,K.length),1/0):0}function stripIndent(_){let K=minIndent(_);if(K===0)return _;let q=RegExp(`^[ \\t]{${K}}`,`gm`);return _.replace(q,``)}function display(_,K){return typeof K==`string`?K:_.utils.stringify(K)}function toSentence(_,{wordConnector:K=`, `,lastWordConnector:q=` and `}={}){return[_.slice(0,-1).join(K),_.at(-1)].join(_.length>1?q:``)}class GenericTypeError extends Error{constructor(_,K,q,J){super(),Error.captureStackTrace&&Error.captureStackTrace(this,q);let Y=``;try{Y=J.utils.printWithType(`Received`,K,J.utils.printReceived)}catch{}this.message=[J.utils.matcherHint(`${J.isNot?`.not`:``}.${q.name}`,`received`,``),``,`${J.utils.RECEIVED_COLOR(`received`)} value must ${_} or a Locator that returns ${_}.`,Y].join(`
3
3
  `)}}class UserInputElementTypeError extends GenericTypeError{constructor(_,K,q){super(`an HTMLElement or an SVGElement`,_,K,q)}}class UserInputNodeTypeError extends GenericTypeError{constructor(_,K,q){super(`a Node`,_,K,q)}}function getTag(_){return _ instanceof HTMLFormElement?`FORM`:_.tagName.toUpperCase()}function isInputElement(_){return getTag(_)===`INPUT`}function getSingleElementValue(_){if(_)switch(getTag(_)){case`INPUT`:return getInputValue(_);case`SELECT`:return getSelectValue(_);default:return _.value??getAccessibleValue(_)}}function getSelectValue({multiple:_,options:K}){let q=[...K].filter(_=>_.selected);if(_)return[...q].map(_=>_.value);if(q.length!==0)return q[0].value}function getInputValue(_){switch(_.type){case`number`:return _.value===``?null:Number(_.value);case`checkbox`:return _.checked;default:return _.value}}const rolesSupportingValues=[`meter`,`progressbar`,`slider`,`spinbutton`];function getAccessibleValue(_){if(rolesSupportingValues.includes(_.getAttribute(`role`)||``))return Number(_.getAttribute(`aria-valuenow`))}function normalize(_){return _.replace(/\s+/g,` `).trim()}function matches(_,K){return K instanceof RegExp?K.test(_):_.includes(String(K))}function arrayAsSetComparison(_,K){if(Array.isArray(_)&&Array.isArray(K)){let q=new Set(K);for(let K of new Set(_))if(!q.has(K))return!1;return!0}}const supportedRoles=getAriaCheckedRoles();function toBeChecked(_){let K=getElementFromUserInput(_,toBeChecked,this);if(!(isInputElement(K)&&[`checkbox`,`radio`].includes(K.type))&&!(supportedRoles.includes(getAriaRole(K)||``)&&[`true`,`false`].includes(K.getAttribute(`aria-checked`)||``)))return{pass:!1,message:()=>`only inputs with type="checkbox" or type="radio" or elements with ${supportedRolesSentence()} and a valid aria-checked attribute can be used with .toBeChecked(). Use .toHaveValue() instead`};let q=getAriaChecked(K)===!0;return{pass:q,message:()=>{let _=q?`is`:`is not`;return[this.utils.matcherHint(`${this.isNot?`.not`:``}.toBeChecked`,`element`,``),``,`Received element ${_} checked:`,` ${this.utils.printReceived(K.cloneNode(!1))}`].join(`
4
4
  `)}}}function supportedRolesSentence(){return toSentence(supportedRoles.map(_=>`role="${_}"`),{lastWordConnector:` or `})}function toBeEmptyDOMElement(_){let K=getElementFromUserInput(_,toBeEmptyDOMElement,this);return{pass:isEmptyElement(K),message:()=>[this.utils.matcherHint(`${this.isNot?`.not`:``}.toBeEmptyDOMElement`,`element`,``),``,`Received:`,` ${this.utils.printReceived(K.innerHTML)}`].join(`