@vitest/browser 2.0.0-beta.3 → 2.0.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,102 +0,0 @@
1
- import { c as client, g as getConfig, a as getBrowserState, b as channel, r as rpcDone } from "./rpc-Hw6RY18C.js";
2
- const url = new URL(location.href);
3
- const ID_ALL = "__vitest_all__";
4
- const iframes = /* @__PURE__ */ new Map();
5
- function debug(...args) {
6
- const debug2 = getConfig().env.VITEST_BROWSER_DEBUG;
7
- if (debug2 && debug2 !== "false")
8
- client.rpc.debug(...args.map(String));
9
- }
10
- function createIframe(container, file) {
11
- if (iframes.has(file)) {
12
- container.removeChild(iframes.get(file));
13
- iframes.delete(file);
14
- }
15
- const iframe = document.createElement("iframe");
16
- iframe.setAttribute("loading", "eager");
17
- iframe.setAttribute("src", `${url.pathname}__vitest_test__/__test__/${encodeURIComponent(file)}`);
18
- iframes.set(file, iframe);
19
- container.appendChild(iframe);
20
- return iframe;
21
- }
22
- async function done() {
23
- await rpcDone();
24
- await client.rpc.finishBrowserTests();
25
- }
26
- client.ws.addEventListener("open", async () => {
27
- const config = getConfig();
28
- const container = document.querySelector("#vitest-tester");
29
- const testFiles = getBrowserState().files;
30
- debug("test files", testFiles.join(", "));
31
- if (!testFiles.length) {
32
- await done();
33
- return;
34
- }
35
- const runningFiles = new Set(testFiles);
36
- channel.addEventListener("message", async (e) => {
37
- var _a;
38
- debug("channel event", JSON.stringify(e.data));
39
- switch (e.data.type) {
40
- case "done": {
41
- const filenames = e.data.filenames;
42
- filenames.forEach((filename) => runningFiles.delete(filename));
43
- const iframeId = filenames.length > 1 ? ID_ALL : filenames[0];
44
- (_a = iframes.get(iframeId)) == null ? void 0 : _a.remove();
45
- iframes.delete(iframeId);
46
- if (!runningFiles.size)
47
- await done();
48
- break;
49
- }
50
- case "error": {
51
- const iframeId = e.data.files.length > 1 ? ID_ALL : e.data.files[0];
52
- iframes.delete(iframeId);
53
- await client.rpc.onUnhandledError(e.data.error, e.data.errorType);
54
- if (iframeId === ID_ALL)
55
- runningFiles.clear();
56
- else
57
- runningFiles.delete(iframeId);
58
- if (!runningFiles.size)
59
- await done();
60
- break;
61
- }
62
- default: {
63
- await client.rpc.onUnhandledError({
64
- name: "Unexpected Event",
65
- message: `Unexpected event: ${e.data.type}`
66
- }, "Unexpected Event");
67
- await done();
68
- }
69
- }
70
- });
71
- const fileParallelism = config.browser.fileParallelism ?? config.fileParallelism;
72
- if (config.isolate === false) {
73
- createIframe(
74
- container,
75
- ID_ALL
76
- );
77
- } else {
78
- if (fileParallelism) {
79
- for (const file of testFiles) {
80
- createIframe(
81
- container,
82
- file
83
- );
84
- }
85
- } else {
86
- for (const file of testFiles) {
87
- createIframe(
88
- container,
89
- file
90
- );
91
- await new Promise((resolve) => {
92
- channel.addEventListener("message", function handler(e) {
93
- if (e.data.type === "done" || e.data.type === "error") {
94
- channel.removeEventListener("message", handler);
95
- resolve();
96
- }
97
- });
98
- });
99
- }
100
- }
101
- }
102
- });