@vitest/browser 2.1.0-beta.5 → 2.1.0-beta.7

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,301 +0,0 @@
1
- (function polyfill() {
2
- const relList = document.createElement("link").relList;
3
- if (relList && relList.supports && relList.supports("modulepreload")) {
4
- return;
5
- }
6
- for (const link of document.querySelectorAll('link[rel="modulepreload"]')) {
7
- processPreload(link);
8
- }
9
- new MutationObserver((mutations) => {
10
- for (const mutation of mutations) {
11
- if (mutation.type !== "childList") {
12
- continue;
13
- }
14
- for (const node of mutation.addedNodes) {
15
- if (node.tagName === "LINK" && node.rel === "modulepreload")
16
- processPreload(node);
17
- }
18
- }
19
- }).observe(document, { childList: true, subtree: true });
20
- function getFetchOpts(link) {
21
- const fetchOpts = {};
22
- if (link.integrity) fetchOpts.integrity = link.integrity;
23
- if (link.referrerPolicy) fetchOpts.referrerPolicy = link.referrerPolicy;
24
- if (link.crossOrigin === "use-credentials")
25
- fetchOpts.credentials = "include";
26
- else if (link.crossOrigin === "anonymous") fetchOpts.credentials = "omit";
27
- else fetchOpts.credentials = "same-origin";
28
- return fetchOpts;
29
- }
30
- function processPreload(link) {
31
- if (link.ep)
32
- return;
33
- link.ep = true;
34
- const fetchOpts = getFetchOpts(link);
35
- fetch(link.href, fetchOpts);
36
- }
37
- })();
38
- const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
39
- function normalizeWindowsPath(input = "") {
40
- if (!input) {
41
- return input;
42
- }
43
- return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
44
- }
45
- const _UNC_REGEX = /^[/\\]{2}/;
46
- const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
47
- const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
48
- const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
49
- const normalize = function(path) {
50
- if (path.length === 0) {
51
- return ".";
52
- }
53
- path = normalizeWindowsPath(path);
54
- const isUNCPath = path.match(_UNC_REGEX);
55
- const isPathAbsolute = isAbsolute(path);
56
- const trailingSeparator = path[path.length - 1] === "/";
57
- path = normalizeString(path, !isPathAbsolute);
58
- if (path.length === 0) {
59
- if (isPathAbsolute) {
60
- return "/";
61
- }
62
- return trailingSeparator ? "./" : ".";
63
- }
64
- if (trailingSeparator) {
65
- path += "/";
66
- }
67
- if (_DRIVE_LETTER_RE.test(path)) {
68
- path += "/";
69
- }
70
- if (isUNCPath) {
71
- if (!isPathAbsolute) {
72
- return `//./${path}`;
73
- }
74
- return `//${path}`;
75
- }
76
- return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
77
- };
78
- const join = function(...arguments_) {
79
- if (arguments_.length === 0) {
80
- return ".";
81
- }
82
- let joined;
83
- for (const argument of arguments_) {
84
- if (argument && argument.length > 0) {
85
- if (joined === void 0) {
86
- joined = argument;
87
- } else {
88
- joined += `/${argument}`;
89
- }
90
- }
91
- }
92
- if (joined === void 0) {
93
- return ".";
94
- }
95
- return normalize(joined.replace(/\/\/+/g, "/"));
96
- };
97
- function cwd() {
98
- if (typeof process !== "undefined" && typeof process.cwd === "function") {
99
- return process.cwd().replace(/\\/g, "/");
100
- }
101
- return "/";
102
- }
103
- const resolve = function(...arguments_) {
104
- arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
105
- let resolvedPath = "";
106
- let resolvedAbsolute = false;
107
- for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
108
- const path = index >= 0 ? arguments_[index] : cwd();
109
- if (!path || path.length === 0) {
110
- continue;
111
- }
112
- resolvedPath = `${path}/${resolvedPath}`;
113
- resolvedAbsolute = isAbsolute(path);
114
- }
115
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
116
- if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
117
- return `/${resolvedPath}`;
118
- }
119
- return resolvedPath.length > 0 ? resolvedPath : ".";
120
- };
121
- function normalizeString(path, allowAboveRoot) {
122
- let res = "";
123
- let lastSegmentLength = 0;
124
- let lastSlash = -1;
125
- let dots = 0;
126
- let char = null;
127
- for (let index = 0; index <= path.length; ++index) {
128
- if (index < path.length) {
129
- char = path[index];
130
- } else if (char === "/") {
131
- break;
132
- } else {
133
- char = "/";
134
- }
135
- if (char === "/") {
136
- if (lastSlash === index - 1 || dots === 1) ;
137
- else if (dots === 2) {
138
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
139
- if (res.length > 2) {
140
- const lastSlashIndex = res.lastIndexOf("/");
141
- if (lastSlashIndex === -1) {
142
- res = "";
143
- lastSegmentLength = 0;
144
- } else {
145
- res = res.slice(0, lastSlashIndex);
146
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
147
- }
148
- lastSlash = index;
149
- dots = 0;
150
- continue;
151
- } else if (res.length > 0) {
152
- res = "";
153
- lastSegmentLength = 0;
154
- lastSlash = index;
155
- dots = 0;
156
- continue;
157
- }
158
- }
159
- if (allowAboveRoot) {
160
- res += res.length > 0 ? "/.." : "..";
161
- lastSegmentLength = 2;
162
- }
163
- } else {
164
- if (res.length > 0) {
165
- res += `/${path.slice(lastSlash + 1, index)}`;
166
- } else {
167
- res = path.slice(lastSlash + 1, index);
168
- }
169
- lastSegmentLength = index - lastSlash - 1;
170
- }
171
- lastSlash = index;
172
- dots = 0;
173
- } else if (char === "." && dots !== -1) {
174
- ++dots;
175
- } else {
176
- dots = -1;
177
- }
178
- }
179
- return res;
180
- }
181
- const isAbsolute = function(p) {
182
- return _IS_ABSOLUTE_RE.test(p);
183
- };
184
- const _EXTNAME_RE = /.(\.[^./]+)$/;
185
- const extname = function(p) {
186
- const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
187
- return match && match[1] || "";
188
- };
189
- const relative = function(from, to) {
190
- const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
191
- const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
192
- if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
193
- return _to.join("/");
194
- }
195
- const _fromCopy = [..._from];
196
- for (const segment of _fromCopy) {
197
- if (_to[0] !== segment) {
198
- break;
199
- }
200
- _from.shift();
201
- _to.shift();
202
- }
203
- return [..._from.map(() => ".."), ..._to].join("/");
204
- };
205
- async function importId(id) {
206
- const name = `/@id/${id}`.replace(/\\/g, "/");
207
- return (/* @__PURE__ */ getBrowserState()).wrapModule(() => import(
208
- /* @vite-ignore */
209
- name
210
- ));
211
- }
212
- async function importFs(id) {
213
- const name = `/@fs/${id}`.replace(/\\/g, "/");
214
- return (/* @__PURE__ */ getBrowserState()).wrapModule(() => import(
215
- /* @vite-ignore */
216
- name
217
- ));
218
- }
219
- function getConfig() {
220
- return (/* @__PURE__ */ getBrowserState()).config;
221
- }
222
- // @__NO_SIDE_EFFECTS__
223
- function getBrowserState() {
224
- return window.__vitest_browser_runner__;
225
- }
226
- // @__NO_SIDE_EFFECTS__
227
- function getWorkerState() {
228
- const state = window.__vitest_worker__;
229
- if (!state) {
230
- throw new Error("Worker state is not found. This is an issue with Vitest. Please, open an issue.");
231
- }
232
- return state;
233
- }
234
- const scriptRel = "modulepreload";
235
- const assetsURL = function(dep) {
236
- return "/" + dep;
237
- };
238
- const seen = {};
239
- const __vitePreload = function preload(baseModule, deps, importerUrl) {
240
- let promise = Promise.resolve();
241
- if (deps && deps.length > 0) {
242
- document.getElementsByTagName("link");
243
- const cspNonceMeta = document.querySelector(
244
- "meta[property=csp-nonce]"
245
- );
246
- const cspNonce = (cspNonceMeta == null ? void 0 : cspNonceMeta.nonce) || (cspNonceMeta == null ? void 0 : cspNonceMeta.getAttribute("nonce"));
247
- promise = Promise.all(
248
- deps.map((dep) => {
249
- dep = assetsURL(dep);
250
- if (dep in seen) return;
251
- seen[dep] = true;
252
- const isCss = dep.endsWith(".css");
253
- const cssSelector = isCss ? '[rel="stylesheet"]' : "";
254
- if (document.querySelector(`link[href="${dep}"]${cssSelector}`)) {
255
- return;
256
- }
257
- const link = document.createElement("link");
258
- link.rel = isCss ? "stylesheet" : scriptRel;
259
- if (!isCss) {
260
- link.as = "script";
261
- link.crossOrigin = "";
262
- }
263
- link.href = dep;
264
- if (cspNonce) {
265
- link.setAttribute("nonce", cspNonce);
266
- }
267
- document.head.appendChild(link);
268
- if (isCss) {
269
- return new Promise((res, rej) => {
270
- link.addEventListener("load", res);
271
- link.addEventListener(
272
- "error",
273
- () => rej(new Error(`Unable to preload CSS for ${dep}`))
274
- );
275
- });
276
- }
277
- })
278
- );
279
- }
280
- return promise.then(() => baseModule()).catch((err) => {
281
- const e = new Event("vite:preloadError", {
282
- cancelable: true
283
- });
284
- e.payload = err;
285
- window.dispatchEvent(e);
286
- if (!e.defaultPrevented) {
287
- throw err;
288
- }
289
- });
290
- };
291
- export {
292
- __vitePreload as _,
293
- getConfig as a,
294
- importId as b,
295
- getWorkerState as c,
296
- extname as e,
297
- getBrowserState as g,
298
- importFs as i,
299
- join as j,
300
- relative as r
301
- };