@vitest/browser 1.2.2 → 1.3.1

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.
@@ -17,8 +17,8 @@
17
17
  })()
18
18
  </script>
19
19
  <!-- !LOAD_METADATA! -->
20
- <script type="module" crossorigin src="./assets/index-0EYobN63.js"></script>
21
- <link rel="stylesheet" crossorigin href="./assets/index-b8y7ovCb.css">
20
+ <script type="module" crossorigin src="./assets/index-pzCGhZhc.js"></script>
21
+ <link rel="stylesheet" crossorigin href="./assets/index-iPSQW1bz.css">
22
22
  </head>
23
23
  <body>
24
24
  <div id="app"></div>
@@ -0,0 +1,98 @@
1
+ import { c as client, g as getConfig, a as getBrowserState, b as channel, r as rpcDone } from "./rpc-wczK3HEm.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
+ debug("channel event", JSON.stringify(e.data));
38
+ switch (e.data.type) {
39
+ case "done": {
40
+ const filenames = e.data.filenames;
41
+ filenames.forEach((filename) => runningFiles.delete(filename));
42
+ if (!runningFiles.size)
43
+ await done();
44
+ break;
45
+ }
46
+ case "error": {
47
+ const iframeId = e.data.files.length > 1 ? ID_ALL : e.data.files[0];
48
+ iframes.delete(iframeId);
49
+ await client.rpc.onUnhandledError(e.data.error, e.data.errorType);
50
+ if (iframeId === ID_ALL)
51
+ runningFiles.clear();
52
+ else
53
+ runningFiles.delete(iframeId);
54
+ if (!runningFiles.size)
55
+ await done();
56
+ break;
57
+ }
58
+ default: {
59
+ await client.rpc.onUnhandledError({
60
+ name: "Unexpected Event",
61
+ message: `Unexpected event: ${e.data.type}`
62
+ }, "Unexpected Event");
63
+ await done();
64
+ }
65
+ }
66
+ });
67
+ const fileParallelism = config.browser.fileParallelism ?? config.fileParallelism;
68
+ if (config.isolate === false) {
69
+ createIframe(
70
+ container,
71
+ ID_ALL
72
+ );
73
+ } else {
74
+ if (fileParallelism) {
75
+ for (const file of testFiles) {
76
+ createIframe(
77
+ container,
78
+ file
79
+ );
80
+ }
81
+ } else {
82
+ for (const file of testFiles) {
83
+ createIframe(
84
+ container,
85
+ file
86
+ );
87
+ await new Promise((resolve) => {
88
+ channel.addEventListener("message", function handler(e) {
89
+ if (e.data.type === "done" || e.data.type === "error") {
90
+ channel.removeEventListener("message", handler);
91
+ resolve();
92
+ }
93
+ });
94
+ });
95
+ }
96
+ }
97
+ }
98
+ });