@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.
- package/context.d.ts +0 -1
- package/dist/client/.vite/manifest.json +2 -2
- package/dist/client/__vitest__/assets/index-BcP0bNv8.js +59 -0
- package/dist/client/__vitest__/assets/index-DC7speYS.css +1 -0
- package/dist/client/__vitest__/favicon.ico +0 -0
- package/dist/client/__vitest__/favicon.svg +49 -4
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-fh7lJzlE.js} +69 -27
- package/dist/client/__vitest_browser__/{tester-cVWT4Xmu.js → tester-CH-bVWK6.js} +56 -18
- package/dist/client/favicon.svg +49 -4
- package/dist/client/orchestrator.html +1 -1
- package/dist/client/tester/tester.html +1 -1
- package/dist/client.js +1 -1
- package/dist/context.js +0 -3
- package/dist/expect-element.js +1 -1
- package/dist/{index-5ZLDAkrH.js → index-Dlkb5vw8.js} +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +40 -10
- package/dist/locators.js +1 -1
- package/package.json +7 -7
- package/dist/client/__vitest__/assets/index-DHXSWiHD.js +0 -57
- package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
|
@@ -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(
|
|
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
|
-
|
|
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 =
|
|
1394
|
+
exports$1 = this.factory();
|
|
1387
1395
|
} catch (err) {
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
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,
|
|
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)),
|
|
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}`,
|
|
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
|
-
|
|
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)),
|
|
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);
|
package/dist/client/favicon.svg
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
|
-
<svg width="
|
|
2
|
-
<path d="
|
|
3
|
-
<
|
|
4
|
-
<path d="
|
|
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-
|
|
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-
|
|
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
package/dist/expect-element.js
CHANGED
|
@@ -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-
|
|
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(`
|