@vitest/browser 4.1.0 → 4.1.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.
@@ -1,223 +0,0 @@
1
- (function polyfill() {
2
- const relList = document.createElement("link").relList;
3
- if (relList && relList.supports && relList.supports("modulepreload")) return;
4
- for (const link of document.querySelectorAll('link[rel="modulepreload"]')) processPreload(link);
5
- new MutationObserver((mutations) => {
6
- for (const mutation of mutations) {
7
- if (mutation.type !== "childList") continue;
8
- for (const node of mutation.addedNodes) if (node.tagName === "LINK" && node.rel === "modulepreload") processPreload(node);
9
- }
10
- }).observe(document, {
11
- childList: true,
12
- subtree: true
13
- });
14
- function getFetchOpts(link) {
15
- const fetchOpts = {};
16
- if (link.integrity) fetchOpts.integrity = link.integrity;
17
- if (link.referrerPolicy) fetchOpts.referrerPolicy = link.referrerPolicy;
18
- if (link.crossOrigin === "use-credentials") fetchOpts.credentials = "include";
19
- else if (link.crossOrigin === "anonymous") fetchOpts.credentials = "omit";
20
- else fetchOpts.credentials = "same-origin";
21
- return fetchOpts;
22
- }
23
- function processPreload(link) {
24
- if (link.ep) return;
25
- link.ep = true;
26
- const fetchOpts = getFetchOpts(link);
27
- fetch(link.href, fetchOpts);
28
- }
29
- })();
30
- const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
31
- function normalizeWindowsPath(input = "") {
32
- if (!input) {
33
- return input;
34
- }
35
- return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
36
- }
37
- const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
38
- const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
39
- function cwd() {
40
- if (typeof process !== "undefined" && typeof process.cwd === "function") {
41
- return process.cwd().replace(/\\/g, "/");
42
- }
43
- return "/";
44
- }
45
- const resolve = function(...arguments_) {
46
- arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
47
- let resolvedPath = "";
48
- let resolvedAbsolute = false;
49
- for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
50
- const path = index >= 0 ? arguments_[index] : cwd();
51
- if (!path || path.length === 0) {
52
- continue;
53
- }
54
- resolvedPath = `${path}/${resolvedPath}`;
55
- resolvedAbsolute = isAbsolute(path);
56
- }
57
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
58
- if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
59
- return `/${resolvedPath}`;
60
- }
61
- return resolvedPath.length > 0 ? resolvedPath : ".";
62
- };
63
- function normalizeString(path, allowAboveRoot) {
64
- let res = "";
65
- let lastSegmentLength = 0;
66
- let lastSlash = -1;
67
- let dots = 0;
68
- let char = null;
69
- for (let index = 0; index <= path.length; ++index) {
70
- if (index < path.length) {
71
- char = path[index];
72
- } else if (char === "/") {
73
- break;
74
- } else {
75
- char = "/";
76
- }
77
- if (char === "/") {
78
- if (lastSlash === index - 1 || dots === 1) ;
79
- else if (dots === 2) {
80
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
81
- if (res.length > 2) {
82
- const lastSlashIndex = res.lastIndexOf("/");
83
- if (lastSlashIndex === -1) {
84
- res = "";
85
- lastSegmentLength = 0;
86
- } else {
87
- res = res.slice(0, lastSlashIndex);
88
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
89
- }
90
- lastSlash = index;
91
- dots = 0;
92
- continue;
93
- } else if (res.length > 0) {
94
- res = "";
95
- lastSegmentLength = 0;
96
- lastSlash = index;
97
- dots = 0;
98
- continue;
99
- }
100
- }
101
- if (allowAboveRoot) {
102
- res += res.length > 0 ? "/.." : "..";
103
- lastSegmentLength = 2;
104
- }
105
- } else {
106
- if (res.length > 0) {
107
- res += `/${path.slice(lastSlash + 1, index)}`;
108
- } else {
109
- res = path.slice(lastSlash + 1, index);
110
- }
111
- lastSegmentLength = index - lastSlash - 1;
112
- }
113
- lastSlash = index;
114
- dots = 0;
115
- } else if (char === "." && dots !== -1) {
116
- ++dots;
117
- } else {
118
- dots = -1;
119
- }
120
- }
121
- return res;
122
- }
123
- const isAbsolute = function(p) {
124
- return _IS_ABSOLUTE_RE.test(p);
125
- };
126
- const relative = function(from, to) {
127
- const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
128
- const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
129
- if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
130
- return _to.join("/");
131
- }
132
- const _fromCopy = [..._from];
133
- for (const segment of _fromCopy) {
134
- if (_to[0] !== segment) {
135
- break;
136
- }
137
- _from.shift();
138
- _to.shift();
139
- }
140
- return [..._from.map(() => ".."), ..._to].join("/");
141
- };
142
- // @__NO_SIDE_EFFECTS__
143
- function generateHash(str) {
144
- let hash = 0;
145
- if (str.length === 0) {
146
- return `${hash}`;
147
- }
148
- for (let i = 0; i < str.length; i++) {
149
- const char = str.charCodeAt(i);
150
- hash = (hash << 5) - hash + char;
151
- hash = hash & hash;
152
- }
153
- return `${hash}`;
154
- }
155
- // @__NO_SIDE_EFFECTS__
156
- function generateFileHash(file, projectName) {
157
- return /* @__PURE__ */ generateHash(`${file}${projectName || ""}`);
158
- }
159
- function getNames(task) {
160
- const names = [task.name];
161
- let current = task;
162
- while (current == null ? void 0 : current.suite) {
163
- current = current.suite;
164
- if (current == null ? void 0 : current.name) {
165
- names.unshift(current.name);
166
- }
167
- }
168
- if (current !== task.file) {
169
- names.unshift(task.file.name);
170
- }
171
- return names;
172
- }
173
- function getTestName(task, separator = " > ") {
174
- return getNames(task).slice(1).join(separator);
175
- }
176
- async function importId(id) {
177
- const name = `/@id/${id}`.replace(/\\/g, "/");
178
- return (/* @__PURE__ */ getBrowserState()).wrapModule(() => import(
179
- /* @vite-ignore */
180
- name
181
- ));
182
- }
183
- async function importFs(id) {
184
- const name = `/@fs/${id}`.replace(/\\/g, "/");
185
- return (/* @__PURE__ */ getBrowserState()).wrapModule(() => import(
186
- /* @vite-ignore */
187
- name
188
- ));
189
- }
190
- const moduleRunner = {
191
- isBrowser: true,
192
- import: (id) => {
193
- if (id[0] === "/" || id[1] === ":") {
194
- return importFs(id);
195
- }
196
- return importId(id);
197
- }
198
- };
199
- function getConfig() {
200
- return (/* @__PURE__ */ getBrowserState()).config;
201
- }
202
- // @__NO_SIDE_EFFECTS__
203
- function getBrowserState() {
204
- return window.__vitest_browser_runner__;
205
- }
206
- // @__NO_SIDE_EFFECTS__
207
- function getWorkerState() {
208
- const state = window.__vitest_worker__;
209
- if (!state) {
210
- throw new Error("Worker state is not found. This is an issue with Vitest. Please, open an issue.");
211
- }
212
- return state;
213
- }
214
- export {
215
- getConfig as a,
216
- generateFileHash as b,
217
- resolve as c,
218
- getWorkerState as d,
219
- getTestName as e,
220
- getBrowserState as g,
221
- moduleRunner as m,
222
- relative as r
223
- };