@vitest/browser 4.1.0-beta.2 → 4.1.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.
- package/context.d.ts +1 -2
- package/dist/client/.vite/manifest.json +6 -6
- package/dist/client/__vitest__/assets/index-C71EXv4T.css +1 -0
- package/dist/client/__vitest__/assets/index-CPanfHPD.js +63 -0
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
- package/dist/client/__vitest_browser__/{tester-C47xeQbT.js → tester-CgiVtoKi.js} +20 -10
- package/dist/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/tester/tester.html +2 -2
- 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 +45 -79
- package/dist/locators.js +1 -1
- package/package.json +7 -7
- package/dist/client/__vitest__/assets/index-CR4OJGrW.js +0 -59
- package/dist/client/__vitest__/assets/index-Dyh_kUYQ.css +0 -1
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
})();
|
|
24
24
|
</script>
|
|
25
25
|
<!-- !LOAD_METADATA! -->
|
|
26
|
-
<script type="module" src="./assets/index-
|
|
27
|
-
<link rel="stylesheet" href="./assets/index-
|
|
26
|
+
<script type="module" src="./assets/index-CPanfHPD.js"></script>
|
|
27
|
+
<link rel="stylesheet" href="./assets/index-C71EXv4T.css">
|
|
28
28
|
</head>
|
|
29
29
|
<body>
|
|
30
30
|
<div id="app"></div>
|
package/dist/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as getBrowserState, a as getConfig, r as relative, b as generateFileHash } from "./utils-
|
|
1
|
+
import { g as getBrowserState, a as getConfig, r as relative, b as generateFileHash } from "./utils-C2ISqq1C.js";
|
|
2
2
|
import { channel, globalChannel, client } from "@vitest/browser/client";
|
|
3
3
|
import { Traces } from "vitest/internal/browser";
|
|
4
4
|
// @__NO_SIDE_EFFECTS__
|
|
@@ -95,7 +95,7 @@ class IframeOrchestrator {
|
|
|
95
95
|
if (!iframe) {
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
98
|
-
await sendEventToIframe({
|
|
98
|
+
await this.sendEventToIframe({
|
|
99
99
|
event: "cleanup",
|
|
100
100
|
iframeId: ID_ALL
|
|
101
101
|
});
|
|
@@ -117,7 +117,7 @@ class IframeOrchestrator {
|
|
|
117
117
|
const iframe = this.iframes.get(ID_ALL);
|
|
118
118
|
await setIframeViewport(iframe, width, height);
|
|
119
119
|
debug("run non-isolated tests", options.files.join(", "));
|
|
120
|
-
await sendEventToIframe({
|
|
120
|
+
await this.sendEventToIframe({
|
|
121
121
|
event: "execute",
|
|
122
122
|
iframeId: ID_ALL,
|
|
123
123
|
files: options.files,
|
|
@@ -141,14 +141,14 @@ class IframeOrchestrator {
|
|
|
141
141
|
otelContext
|
|
142
142
|
);
|
|
143
143
|
await setIframeViewport(iframe, width, height);
|
|
144
|
-
await sendEventToIframe({
|
|
144
|
+
await this.sendEventToIframe({
|
|
145
145
|
event: "execute",
|
|
146
146
|
files: [spec],
|
|
147
147
|
method: options.method,
|
|
148
148
|
iframeId: file,
|
|
149
149
|
context: options.providedContext
|
|
150
150
|
});
|
|
151
|
-
await sendEventToIframe({
|
|
151
|
+
await this.sendEventToIframe({
|
|
152
152
|
event: "cleanup",
|
|
153
153
|
iframeId: file
|
|
154
154
|
});
|
|
@@ -169,12 +169,19 @@ class IframeOrchestrator {
|
|
|
169
169
|
reject(this.dispatchIframeError(new Error(
|
|
170
170
|
`Cannot connect to the iframe. Did you change the location or submitted a form? If so, don't forget to call \`event.preventDefault()\` to avoid reloading the page.
|
|
171
171
|
|
|
172
|
-
Received URL: ${href || "unknown"}
|
|
172
|
+
Received URL: ${href || "unknown due to CORS"}
|
|
173
173
|
Expected: ${iframe.src}`
|
|
174
174
|
)));
|
|
175
|
+
} else if (this.iframes.has(iframeId)) {
|
|
176
|
+
const events = this.iframeEvents.get(iframe);
|
|
177
|
+
if (events == null ? void 0 : events.size) {
|
|
178
|
+
this.dispatchIframeError(new Error(this.createWarningMessage(iframeId, "during a test")));
|
|
179
|
+
} else {
|
|
180
|
+
this.warnReload(iframe, iframeId);
|
|
181
|
+
}
|
|
175
182
|
} else {
|
|
176
183
|
this.iframes.set(iframeId, iframe);
|
|
177
|
-
sendEventToIframe({
|
|
184
|
+
this.sendEventToIframe({
|
|
178
185
|
event: "prepare",
|
|
179
186
|
iframeId,
|
|
180
187
|
startTime,
|
|
@@ -194,6 +201,28 @@ Expected: ${iframe.src}`
|
|
|
194
201
|
});
|
|
195
202
|
return iframe;
|
|
196
203
|
}
|
|
204
|
+
loggedIframe = /* @__PURE__ */ new WeakSet();
|
|
205
|
+
createWarningMessage(iframeId, location) {
|
|
206
|
+
return `The iframe${iframeId === ID_ALL ? "" : ` for "${iframeId}"`} was reloaded ${location}. This can lead to unexpected behavior during tests, duplicated test results or tests hanging.
|
|
207
|
+
|
|
208
|
+
Make sure that your test code does not change window's location, submit forms without preventing default behavior, or imports unoptimized dependencies.
|
|
209
|
+
If you are using a framework that manipulates browser history (like React Router), consider using memory-based routing for tests. If you think this is a false positive, open an issue with a reproduction: https://github.com/vitest-dev/vitest/issues/new`;
|
|
210
|
+
}
|
|
211
|
+
warnReload(iframe, iframeId) {
|
|
212
|
+
if (this.loggedIframe.has(iframe)) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
this.loggedIframe.add(iframe);
|
|
216
|
+
const message = `\x1B[41m WARNING \x1B[49m ${this.createWarningMessage(iframeId, "multiple times")}`;
|
|
217
|
+
client.rpc.sendLog("run", {
|
|
218
|
+
type: "stderr",
|
|
219
|
+
time: Date.now(),
|
|
220
|
+
content: message,
|
|
221
|
+
size: message.length,
|
|
222
|
+
taskId: iframeId === ID_ALL ? void 0 : generateFileId(iframeId)
|
|
223
|
+
}).catch(() => {
|
|
224
|
+
});
|
|
225
|
+
}
|
|
197
226
|
getIframeHref(iframe) {
|
|
198
227
|
var _a;
|
|
199
228
|
try {
|
|
@@ -265,6 +294,40 @@ Expected: ${iframe.src}`
|
|
|
265
294
|
}
|
|
266
295
|
}
|
|
267
296
|
}
|
|
297
|
+
iframeEvents = /* @__PURE__ */ new WeakMap();
|
|
298
|
+
async sendEventToIframe(event) {
|
|
299
|
+
const iframe = this.iframes.get(event.iframeId);
|
|
300
|
+
if (!iframe) {
|
|
301
|
+
throw new Error(`Cannot find iframe with id ${event.iframeId}`);
|
|
302
|
+
}
|
|
303
|
+
let events = this.iframeEvents.get(iframe);
|
|
304
|
+
if (!events) {
|
|
305
|
+
events = /* @__PURE__ */ new Set();
|
|
306
|
+
this.iframeEvents.set(iframe, events);
|
|
307
|
+
}
|
|
308
|
+
events.add(event.event);
|
|
309
|
+
channel.postMessage(event);
|
|
310
|
+
return new Promise((resolve, reject) => {
|
|
311
|
+
const cleanupEvents = () => {
|
|
312
|
+
channel.removeEventListener("message", onReceived);
|
|
313
|
+
this.eventTarget.removeEventListener("iframeerror", onError);
|
|
314
|
+
};
|
|
315
|
+
function onReceived(e) {
|
|
316
|
+
if (e.data.iframeId === event.iframeId && e.data.event === `response:${event.event}`) {
|
|
317
|
+
resolve();
|
|
318
|
+
cleanupEvents();
|
|
319
|
+
events.delete(event.event);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function onError(e) {
|
|
323
|
+
reject(e.detail);
|
|
324
|
+
cleanupEvents();
|
|
325
|
+
events.delete(event.event);
|
|
326
|
+
}
|
|
327
|
+
this.eventTarget.addEventListener("iframeerror", onError);
|
|
328
|
+
channel.addEventListener("message", onReceived);
|
|
329
|
+
});
|
|
330
|
+
}
|
|
268
331
|
}
|
|
269
332
|
const orchestrator = new IframeOrchestrator();
|
|
270
333
|
getBrowserState().orchestrator = orchestrator;
|
|
@@ -282,27 +345,6 @@ async function getContainer(config) {
|
|
|
282
345
|
}
|
|
283
346
|
return document.querySelector("#vitest-tester");
|
|
284
347
|
}
|
|
285
|
-
async function sendEventToIframe(event) {
|
|
286
|
-
channel.postMessage(event);
|
|
287
|
-
return new Promise((resolve, reject) => {
|
|
288
|
-
function cleanupEvents() {
|
|
289
|
-
channel.removeEventListener("message", onReceived);
|
|
290
|
-
orchestrator.eventTarget.removeEventListener("iframeerror", onError);
|
|
291
|
-
}
|
|
292
|
-
function onReceived(e) {
|
|
293
|
-
if (e.data.iframeId === event.iframeId && e.data.event === `response:${event.event}`) {
|
|
294
|
-
resolve();
|
|
295
|
-
cleanupEvents();
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
function onError(e) {
|
|
299
|
-
reject(e.detail);
|
|
300
|
-
cleanupEvents();
|
|
301
|
-
}
|
|
302
|
-
orchestrator.eventTarget.addEventListener("iframeerror", onError);
|
|
303
|
-
channel.addEventListener("message", onReceived);
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
348
|
function generateFileId(file) {
|
|
307
349
|
const config = getConfig();
|
|
308
350
|
const path = relative(config.root, file);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { c as resolve, m as moduleRunner, d as getWorkerState, g as getBrowserState, e as getTestName, a as getConfig } from "./utils-
|
|
1
|
+
import { c as resolve, m as moduleRunner, d as getWorkerState, g as getBrowserState, e as getTestName, a as getConfig } from "./utils-C2ISqq1C.js";
|
|
2
2
|
import { onCancel, globalChannel, channel, client } from "@vitest/browser/client";
|
|
3
3
|
import { userEvent, page, server } from "vitest/browser";
|
|
4
4
|
import { getSafeTimers, DecodedMap as DecodedMap$1, getOriginalPosition as getOriginalPosition$1, loadDiffConfig, loadSnapshotSerializers, takeCoverageInsideWorker, browserFormat, Traces, setupCommonEnv, startCoverageInsideWorker, stopCoverageInsideWorker, startTests, collectTests, SpyModule } from "vitest/internal/browser";
|
|
5
|
-
import { TestRunner, BenchmarkRunner } from "vitest";
|
|
5
|
+
import { TestRunner, BenchmarkRunner, recordArtifact } from "vitest";
|
|
6
6
|
const scriptRel = "modulepreload";
|
|
7
7
|
const assetsURL = function(dep) {
|
|
8
8
|
return "/" + dep;
|
|
@@ -562,6 +562,7 @@ 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
|
];
|
|
567
568
|
const NOW_LENGTH = Date.now().toString().length;
|
|
@@ -663,7 +664,7 @@ function parseSingleV8Stack(raw) {
|
|
|
663
664
|
}
|
|
664
665
|
file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve(file);
|
|
665
666
|
if (method) {
|
|
666
|
-
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, "");
|
|
667
668
|
}
|
|
668
669
|
return {
|
|
669
670
|
method,
|
|
@@ -683,7 +684,11 @@ function createStackString(stacks) {
|
|
|
683
684
|
}
|
|
684
685
|
function parseStacktrace(stack, options = {}) {
|
|
685
686
|
const { ignoreStackEntries = stackIgnorePatterns } = options;
|
|
686
|
-
|
|
687
|
+
let stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
|
|
688
|
+
const helperIndex = stacks.findLastIndex((s) => s.method === "__VITEST_HELPER__" || s.method === "async*__VITEST_HELPER__");
|
|
689
|
+
if (helperIndex >= 0) {
|
|
690
|
+
stacks = stacks.slice(helperIndex + 1);
|
|
691
|
+
}
|
|
687
692
|
return stacks.map((stack2) => {
|
|
688
693
|
var _a;
|
|
689
694
|
if (options.getUrlId) {
|
|
@@ -736,7 +741,7 @@ class DecodedMap {
|
|
|
736
741
|
this._decodedMemo = memoizedState();
|
|
737
742
|
this.url = from;
|
|
738
743
|
this.resolvedSources = (sources || []).map(
|
|
739
|
-
(s) => resolve(s || ""
|
|
744
|
+
(s) => resolve(from, "..", s || "")
|
|
740
745
|
);
|
|
741
746
|
}
|
|
742
747
|
_encoded;
|
|
@@ -908,7 +913,9 @@ function createBrowserRunner(runnerClass, mocker, state, coverageModule) {
|
|
|
908
913
|
};
|
|
909
914
|
onTaskFinished = async (task) => {
|
|
910
915
|
var _a, _b;
|
|
911
|
-
if (this.config.browser.screenshotFailures && document.body.clientHeight > 0 && ((_a = task.result) == null ? void 0 : _a.state) === "fail"
|
|
916
|
+
if (this.config.browser.screenshotFailures && document.body.clientHeight > 0 && ((_a = task.result) == null ? void 0 : _a.state) === "fail" && task.type === "test" && task.artifacts.every(
|
|
917
|
+
(artifact) => artifact.type !== "internal:toMatchScreenshot"
|
|
918
|
+
)) {
|
|
912
919
|
const screenshot = await page.screenshot(
|
|
913
920
|
{
|
|
914
921
|
timeout: ((_b = this.config.browser.providerOptions) == null ? void 0 : _b.actionTimeout) ?? 5e3
|
|
@@ -918,7 +925,10 @@ function createBrowserRunner(runnerClass, mocker, state, coverageModule) {
|
|
|
918
925
|
console.error("[vitest] Failed to take a screenshot", err);
|
|
919
926
|
});
|
|
920
927
|
if (screenshot) {
|
|
921
|
-
task
|
|
928
|
+
await recordArtifact(task, {
|
|
929
|
+
type: "internal:failureScreenshot",
|
|
930
|
+
attachments: [{ contentType: "image/png", path: screenshot, originalPath: screenshot }]
|
|
931
|
+
});
|
|
922
932
|
}
|
|
923
933
|
}
|
|
924
934
|
};
|
|
@@ -1392,7 +1402,7 @@ class ManualMockedModule {
|
|
|
1392
1402
|
} catch (err) {
|
|
1393
1403
|
throw createHelpfulError(err);
|
|
1394
1404
|
}
|
|
1395
|
-
if (typeof exports$1 === "object" && typeof (exports$1
|
|
1405
|
+
if (typeof exports$1 === "object" && typeof (exports$1 == null ? void 0 : exports$1.then) === "function") {
|
|
1396
1406
|
return exports$1.then((result) => {
|
|
1397
1407
|
assertValidExports(this.raw, result);
|
|
1398
1408
|
return this.cache = result;
|
|
@@ -1799,7 +1809,7 @@ class ModuleMocker {
|
|
|
1799
1809
|
return mod;
|
|
1800
1810
|
}
|
|
1801
1811
|
const m = mod.default;
|
|
1802
|
-
return (m
|
|
1812
|
+
return (m == null ? void 0 : m.__esModule) ? m : {
|
|
1803
1813
|
...typeof m === "object" && !Array.isArray(m) || typeof m === "function" ? m : {},
|
|
1804
1814
|
default: m
|
|
1805
1815
|
};
|
|
@@ -1856,7 +1866,7 @@ class ModuleMocker {
|
|
|
1856
1866
|
return { callstack: null };
|
|
1857
1867
|
}
|
|
1858
1868
|
queueMock(rawId, importer, factoryOrOptions) {
|
|
1859
|
-
const promise = this.rpc.resolveMock(rawId, importer, { mock: typeof factoryOrOptions === "function" ? "factory" : (factoryOrOptions
|
|
1869
|
+
const promise = this.rpc.resolveMock(rawId, importer, { mock: typeof factoryOrOptions === "function" ? "factory" : (factoryOrOptions == null ? void 0 : factoryOrOptions.spy) ? "spy" : "auto" }).then(async ({ redirectUrl, resolvedId, resolvedUrl, needsInterop, mockType }) => {
|
|
1860
1870
|
const mockUrl = this.resolveMockPath(cleanVersion(resolvedUrl));
|
|
1861
1871
|
this.mockedIds.add(resolvedId);
|
|
1862
1872
|
const factory = typeof factoryOrOptions === "function" ? async () => {
|
|
@@ -159,9 +159,9 @@ function generateFileHash(file, projectName) {
|
|
|
159
159
|
function getNames(task) {
|
|
160
160
|
const names = [task.name];
|
|
161
161
|
let current = task;
|
|
162
|
-
while (current
|
|
162
|
+
while (current == null ? void 0 : current.suite) {
|
|
163
163
|
current = current.suite;
|
|
164
|
-
if (current
|
|
164
|
+
if (current == null ? void 0 : current.name) {
|
|
165
165
|
names.unshift(current.name);
|
|
166
166
|
}
|
|
167
167
|
}
|
|
@@ -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-
|
|
30
|
-
<link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-
|
|
29
|
+
<script type="module" crossorigin src="/__vitest_browser__/orchestrator-CXs6qrFe.js"></script>
|
|
30
|
+
<link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-C2ISqq1C.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-
|
|
9
|
-
<link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-
|
|
8
|
+
<script type="module" crossorigin src="/__vitest_browser__/tester-CgiVtoKi.js"></script>
|
|
9
|
+
<link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-C2ISqq1C.js">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
12
12
|
</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(`
|