@vitest/browser 2.1.3 → 2.1.5
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/README.md +7 -21
- package/context.d.ts +6 -0
- package/dist/client/.vite/manifest.json +7 -7
- package/dist/client/__vitest__/assets/index-CGSAdLIf.css +1 -0
- package/dist/client/__vitest__/assets/index-DWjHzG4O.js +52 -0
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/orchestrator-DnP17K36.js +238 -0
- package/dist/client/__vitest_browser__/{tester-DZCtFstH.js → tester-BaiNqOPw.js} +7749 -6109
- package/dist/client/__vitest_browser__/utils-Owv5OOOf.js +195 -0
- package/dist/client/error-catcher.js +3 -1
- package/dist/client/esm-client-injector.js +50 -48
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/tester/tester.html +3 -19
- package/dist/client.js +28 -5
- package/dist/context.js +96 -47
- package/dist/{index-Cgg35wOd.js → index-CKtADM3n.js} +35 -3
- package/dist/index.d.ts +10 -6
- package/dist/index.js +2016 -1825
- package/dist/locators/index.js +1 -1
- package/dist/locators/playwright.js +1 -1
- package/dist/locators/preview.js +11 -11
- package/dist/locators/webdriverio.js +1 -1
- package/dist/providers.js +8 -7
- package/dist/state.js +1 -1
- package/dist/utils.js +1 -1
- package/package.json +18 -18
- package/dist/client/__vitest__/assets/index-CADIw8eX.js +0 -52
- package/dist/client/__vitest__/assets/index-D5rK8X7L.css +0 -1
- package/dist/client/__vitest_browser__/orchestrator-BCPid0xo.js +0 -1099
- package/dist/client/__vitest_browser__/preload-helper-D-WYp1PK.js +0 -317
|
@@ -1,1099 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import { M as MockerRegistry, _ as __vitePreload, a as ManualMockedModule, g as getBrowserState, b as getConfig } from "./preload-helper-D-WYp1PK.js";
|
|
5
|
-
import { channel, client, globalChannel } from "@vitest/browser/client";
|
|
6
|
-
var f = {
|
|
7
|
-
reset: [0, 0],
|
|
8
|
-
bold: [1, 22, "\x1B[22m\x1B[1m"],
|
|
9
|
-
dim: [2, 22, "\x1B[22m\x1B[2m"],
|
|
10
|
-
italic: [3, 23],
|
|
11
|
-
underline: [4, 24],
|
|
12
|
-
inverse: [7, 27],
|
|
13
|
-
hidden: [8, 28],
|
|
14
|
-
strikethrough: [9, 29],
|
|
15
|
-
black: [30, 39],
|
|
16
|
-
red: [31, 39],
|
|
17
|
-
green: [32, 39],
|
|
18
|
-
yellow: [33, 39],
|
|
19
|
-
blue: [34, 39],
|
|
20
|
-
magenta: [35, 39],
|
|
21
|
-
cyan: [36, 39],
|
|
22
|
-
white: [37, 39],
|
|
23
|
-
gray: [90, 39],
|
|
24
|
-
bgBlack: [40, 49],
|
|
25
|
-
bgRed: [41, 49],
|
|
26
|
-
bgGreen: [42, 49],
|
|
27
|
-
bgYellow: [43, 49],
|
|
28
|
-
bgBlue: [44, 49],
|
|
29
|
-
bgMagenta: [45, 49],
|
|
30
|
-
bgCyan: [46, 49],
|
|
31
|
-
bgWhite: [47, 49],
|
|
32
|
-
blackBright: [90, 39],
|
|
33
|
-
redBright: [91, 39],
|
|
34
|
-
greenBright: [92, 39],
|
|
35
|
-
yellowBright: [93, 39],
|
|
36
|
-
blueBright: [94, 39],
|
|
37
|
-
magentaBright: [95, 39],
|
|
38
|
-
cyanBright: [96, 39],
|
|
39
|
-
whiteBright: [97, 39],
|
|
40
|
-
bgBlackBright: [100, 49],
|
|
41
|
-
bgRedBright: [101, 49],
|
|
42
|
-
bgGreenBright: [102, 49],
|
|
43
|
-
bgYellowBright: [103, 49],
|
|
44
|
-
bgBlueBright: [104, 49],
|
|
45
|
-
bgMagentaBright: [105, 49],
|
|
46
|
-
bgCyanBright: [106, 49],
|
|
47
|
-
bgWhiteBright: [107, 49]
|
|
48
|
-
}, h = Object.entries(f);
|
|
49
|
-
function a(n) {
|
|
50
|
-
return String(n);
|
|
51
|
-
}
|
|
52
|
-
a.open = "";
|
|
53
|
-
a.close = "";
|
|
54
|
-
function C(n = false) {
|
|
55
|
-
let e = typeof process != "undefined" ? process : void 0, i = (e == null ? void 0 : e.env) || {}, g = (e == null ? void 0 : e.argv) || [];
|
|
56
|
-
return !("NO_COLOR" in i || g.includes("--no-color")) && ("FORCE_COLOR" in i || g.includes("--color") || (e == null ? void 0 : e.platform) === "win32" || n && i.TERM !== "dumb" || "CI" in i) || typeof window != "undefined" && !!window.chrome;
|
|
57
|
-
}
|
|
58
|
-
function p(n = false) {
|
|
59
|
-
let e = C(n), i = (r, t, c, o) => {
|
|
60
|
-
let l = "", s = 0;
|
|
61
|
-
do
|
|
62
|
-
l += r.substring(s, o) + c, s = o + t.length, o = r.indexOf(t, s);
|
|
63
|
-
while (~o);
|
|
64
|
-
return l + r.substring(s);
|
|
65
|
-
}, g = (r, t, c = r) => {
|
|
66
|
-
let o = (l) => {
|
|
67
|
-
let s = String(l), b = s.indexOf(t, r.length);
|
|
68
|
-
return ~b ? r + i(s, t, c, b) + t : r + s + t;
|
|
69
|
-
};
|
|
70
|
-
return o.open = r, o.close = t, o;
|
|
71
|
-
}, u = {
|
|
72
|
-
isColorSupported: e
|
|
73
|
-
}, d = (r) => `\x1B[${r}m`;
|
|
74
|
-
for (let [r, t] of h)
|
|
75
|
-
u[r] = e ? g(
|
|
76
|
-
d(t[0]),
|
|
77
|
-
d(t[1]),
|
|
78
|
-
t[2]
|
|
79
|
-
) : a;
|
|
80
|
-
return u;
|
|
81
|
-
}
|
|
82
|
-
p(false);
|
|
83
|
-
let getPromiseValue = () => "Promise{…}";
|
|
84
|
-
try {
|
|
85
|
-
const { getPromiseDetails, kPending, kRejected } = process.binding("util");
|
|
86
|
-
if (Array.isArray(getPromiseDetails(Promise.resolve()))) {
|
|
87
|
-
getPromiseValue = (value, options) => {
|
|
88
|
-
const [state, innerValue] = getPromiseDetails(value);
|
|
89
|
-
if (state === kPending) {
|
|
90
|
-
return "Promise{<pending>}";
|
|
91
|
-
}
|
|
92
|
-
return `Promise${state === kRejected ? "!" : ""}{${options.inspect(innerValue, options)}}`;
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
} catch (notNode) {
|
|
96
|
-
}
|
|
97
|
-
let nodeInspect = false;
|
|
98
|
-
try {
|
|
99
|
-
const nodeUtil = require("util");
|
|
100
|
-
nodeInspect = nodeUtil.inspect ? nodeUtil.inspect.custom : false;
|
|
101
|
-
} catch (noNodeInspect) {
|
|
102
|
-
nodeInspect = false;
|
|
103
|
-
}
|
|
104
|
-
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
105
|
-
function normalizeWindowsPath(input = "") {
|
|
106
|
-
if (!input) {
|
|
107
|
-
return input;
|
|
108
|
-
}
|
|
109
|
-
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
110
|
-
}
|
|
111
|
-
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
112
|
-
const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
|
|
113
|
-
function cwd() {
|
|
114
|
-
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
115
|
-
return process.cwd().replace(/\\/g, "/");
|
|
116
|
-
}
|
|
117
|
-
return "/";
|
|
118
|
-
}
|
|
119
|
-
const resolve = function(...arguments_) {
|
|
120
|
-
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
121
|
-
let resolvedPath = "";
|
|
122
|
-
let resolvedAbsolute = false;
|
|
123
|
-
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
124
|
-
const path = index >= 0 ? arguments_[index] : cwd();
|
|
125
|
-
if (!path || path.length === 0) {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
resolvedPath = `${path}/${resolvedPath}`;
|
|
129
|
-
resolvedAbsolute = isAbsolute(path);
|
|
130
|
-
}
|
|
131
|
-
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
132
|
-
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
133
|
-
return `/${resolvedPath}`;
|
|
134
|
-
}
|
|
135
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
136
|
-
};
|
|
137
|
-
function normalizeString(path, allowAboveRoot) {
|
|
138
|
-
let res = "";
|
|
139
|
-
let lastSegmentLength = 0;
|
|
140
|
-
let lastSlash = -1;
|
|
141
|
-
let dots = 0;
|
|
142
|
-
let char = null;
|
|
143
|
-
for (let index = 0; index <= path.length; ++index) {
|
|
144
|
-
if (index < path.length) {
|
|
145
|
-
char = path[index];
|
|
146
|
-
} else if (char === "/") {
|
|
147
|
-
break;
|
|
148
|
-
} else {
|
|
149
|
-
char = "/";
|
|
150
|
-
}
|
|
151
|
-
if (char === "/") {
|
|
152
|
-
if (lastSlash === index - 1 || dots === 1) ;
|
|
153
|
-
else if (dots === 2) {
|
|
154
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
155
|
-
if (res.length > 2) {
|
|
156
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
157
|
-
if (lastSlashIndex === -1) {
|
|
158
|
-
res = "";
|
|
159
|
-
lastSegmentLength = 0;
|
|
160
|
-
} else {
|
|
161
|
-
res = res.slice(0, lastSlashIndex);
|
|
162
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
163
|
-
}
|
|
164
|
-
lastSlash = index;
|
|
165
|
-
dots = 0;
|
|
166
|
-
continue;
|
|
167
|
-
} else if (res.length > 0) {
|
|
168
|
-
res = "";
|
|
169
|
-
lastSegmentLength = 0;
|
|
170
|
-
lastSlash = index;
|
|
171
|
-
dots = 0;
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (allowAboveRoot) {
|
|
176
|
-
res += res.length > 0 ? "/.." : "..";
|
|
177
|
-
lastSegmentLength = 2;
|
|
178
|
-
}
|
|
179
|
-
} else {
|
|
180
|
-
if (res.length > 0) {
|
|
181
|
-
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
182
|
-
} else {
|
|
183
|
-
res = path.slice(lastSlash + 1, index);
|
|
184
|
-
}
|
|
185
|
-
lastSegmentLength = index - lastSlash - 1;
|
|
186
|
-
}
|
|
187
|
-
lastSlash = index;
|
|
188
|
-
dots = 0;
|
|
189
|
-
} else if (char === "." && dots !== -1) {
|
|
190
|
-
++dots;
|
|
191
|
-
} else {
|
|
192
|
-
dots = -1;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return res;
|
|
196
|
-
}
|
|
197
|
-
const isAbsolute = function(p2) {
|
|
198
|
-
return _IS_ABSOLUTE_RE.test(p2);
|
|
199
|
-
};
|
|
200
|
-
const relative = function(from, to) {
|
|
201
|
-
const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
202
|
-
const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
203
|
-
if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
|
|
204
|
-
return _to.join("/");
|
|
205
|
-
}
|
|
206
|
-
const _fromCopy = [..._from];
|
|
207
|
-
for (const segment of _fromCopy) {
|
|
208
|
-
if (_to[0] !== segment) {
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
_from.shift();
|
|
212
|
-
_to.shift();
|
|
213
|
-
}
|
|
214
|
-
return [..._from.map(() => ".."), ..._to].join("/");
|
|
215
|
-
};
|
|
216
|
-
var jsTokens_1;
|
|
217
|
-
var hasRequiredJsTokens;
|
|
218
|
-
function requireJsTokens() {
|
|
219
|
-
if (hasRequiredJsTokens) return jsTokens_1;
|
|
220
|
-
hasRequiredJsTokens = 1;
|
|
221
|
-
var Identifier, JSXIdentifier, JSXPunctuator, JSXString, JSXText, KeywordsWithExpressionAfter, KeywordsWithNoLineTerminatorAfter, LineTerminatorSequence, MultiLineComment, Newline, NumericLiteral, Punctuator, RegularExpressionLiteral, SingleLineComment, StringLiteral, Template, TokensNotPrecedingObjectLiteral, TokensPrecedingExpression, WhiteSpace;
|
|
222
|
-
RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\\]).|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/yu;
|
|
223
|
-
Punctuator = /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/y;
|
|
224
|
-
Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/yu;
|
|
225
|
-
StringLiteral = /(['"])(?:(?!\1)[^\\\n\r]|\\(?:\r\n|[^]))*(\1)?/y;
|
|
226
|
-
NumericLiteral = /(?:0[xX][\da-fA-F](?:_?[\da-fA-F])*|0[oO][0-7](?:_?[0-7])*|0[bB][01](?:_?[01])*)n?|0n|[1-9](?:_?\d)*n|(?:(?:0(?!\d)|0\d*[89]\d*|[1-9](?:_?\d)*)(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:[eE][+-]?\d(?:_?\d)*)?|0[0-7]+/y;
|
|
227
|
-
Template = /[`}](?:[^`\\$]|\\[^]|\$(?!\{))*(`|\$\{)?/y;
|
|
228
|
-
WhiteSpace = /[\t\v\f\ufeff\p{Zs}]+/yu;
|
|
229
|
-
LineTerminatorSequence = /\r?\n|[\r\u2028\u2029]/y;
|
|
230
|
-
MultiLineComment = /\/\*(?:[^*]|\*(?!\/))*(\*\/)?/y;
|
|
231
|
-
SingleLineComment = /\/\/.*/y;
|
|
232
|
-
JSXPunctuator = /[<>.:={}]|\/(?![\/*])/y;
|
|
233
|
-
JSXIdentifier = /[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}-]*/yu;
|
|
234
|
-
JSXString = /(['"])(?:(?!\1)[^])*(\1)?/y;
|
|
235
|
-
JSXText = /[^<>{}]+/y;
|
|
236
|
-
TokensPrecedingExpression = /^(?:[\/+-]|\.{3}|\?(?:InterpolationIn(?:JSX|Template)|NoLineTerminatorHere|NonExpressionParenEnd|UnaryIncDec))?$|[{}([,;<>=*%&|^!~?:]$/;
|
|
237
|
-
TokensNotPrecedingObjectLiteral = /^(?:=>|[;\]){}]|else|\?(?:NoLineTerminatorHere|NonExpressionParenEnd))?$/;
|
|
238
|
-
KeywordsWithExpressionAfter = /^(?:await|case|default|delete|do|else|instanceof|new|return|throw|typeof|void|yield)$/;
|
|
239
|
-
KeywordsWithNoLineTerminatorAfter = /^(?:return|throw|yield)$/;
|
|
240
|
-
Newline = RegExp(LineTerminatorSequence.source);
|
|
241
|
-
jsTokens_1 = function* (input, { jsx = false } = {}) {
|
|
242
|
-
var braces, firstCodePoint, isExpression, lastIndex, lastSignificantToken, length, match, mode, nextLastIndex, nextLastSignificantToken, parenNesting, postfixIncDec, punctuator, stack;
|
|
243
|
-
({ length } = input);
|
|
244
|
-
lastIndex = 0;
|
|
245
|
-
lastSignificantToken = "";
|
|
246
|
-
stack = [
|
|
247
|
-
{ tag: "JS" }
|
|
248
|
-
];
|
|
249
|
-
braces = [];
|
|
250
|
-
parenNesting = 0;
|
|
251
|
-
postfixIncDec = false;
|
|
252
|
-
while (lastIndex < length) {
|
|
253
|
-
mode = stack[stack.length - 1];
|
|
254
|
-
switch (mode.tag) {
|
|
255
|
-
case "JS":
|
|
256
|
-
case "JSNonExpressionParen":
|
|
257
|
-
case "InterpolationInTemplate":
|
|
258
|
-
case "InterpolationInJSX":
|
|
259
|
-
if (input[lastIndex] === "/" && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
|
|
260
|
-
RegularExpressionLiteral.lastIndex = lastIndex;
|
|
261
|
-
if (match = RegularExpressionLiteral.exec(input)) {
|
|
262
|
-
lastIndex = RegularExpressionLiteral.lastIndex;
|
|
263
|
-
lastSignificantToken = match[0];
|
|
264
|
-
postfixIncDec = true;
|
|
265
|
-
yield {
|
|
266
|
-
type: "RegularExpressionLiteral",
|
|
267
|
-
value: match[0],
|
|
268
|
-
closed: match[1] !== void 0 && match[1] !== "\\"
|
|
269
|
-
};
|
|
270
|
-
continue;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
Punctuator.lastIndex = lastIndex;
|
|
274
|
-
if (match = Punctuator.exec(input)) {
|
|
275
|
-
punctuator = match[0];
|
|
276
|
-
nextLastIndex = Punctuator.lastIndex;
|
|
277
|
-
nextLastSignificantToken = punctuator;
|
|
278
|
-
switch (punctuator) {
|
|
279
|
-
case "(":
|
|
280
|
-
if (lastSignificantToken === "?NonExpressionParenKeyword") {
|
|
281
|
-
stack.push({
|
|
282
|
-
tag: "JSNonExpressionParen",
|
|
283
|
-
nesting: parenNesting
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
parenNesting++;
|
|
287
|
-
postfixIncDec = false;
|
|
288
|
-
break;
|
|
289
|
-
case ")":
|
|
290
|
-
parenNesting--;
|
|
291
|
-
postfixIncDec = true;
|
|
292
|
-
if (mode.tag === "JSNonExpressionParen" && parenNesting === mode.nesting) {
|
|
293
|
-
stack.pop();
|
|
294
|
-
nextLastSignificantToken = "?NonExpressionParenEnd";
|
|
295
|
-
postfixIncDec = false;
|
|
296
|
-
}
|
|
297
|
-
break;
|
|
298
|
-
case "{":
|
|
299
|
-
Punctuator.lastIndex = 0;
|
|
300
|
-
isExpression = !TokensNotPrecedingObjectLiteral.test(lastSignificantToken) && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken));
|
|
301
|
-
braces.push(isExpression);
|
|
302
|
-
postfixIncDec = false;
|
|
303
|
-
break;
|
|
304
|
-
case "}":
|
|
305
|
-
switch (mode.tag) {
|
|
306
|
-
case "InterpolationInTemplate":
|
|
307
|
-
if (braces.length === mode.nesting) {
|
|
308
|
-
Template.lastIndex = lastIndex;
|
|
309
|
-
match = Template.exec(input);
|
|
310
|
-
lastIndex = Template.lastIndex;
|
|
311
|
-
lastSignificantToken = match[0];
|
|
312
|
-
if (match[1] === "${") {
|
|
313
|
-
lastSignificantToken = "?InterpolationInTemplate";
|
|
314
|
-
postfixIncDec = false;
|
|
315
|
-
yield {
|
|
316
|
-
type: "TemplateMiddle",
|
|
317
|
-
value: match[0]
|
|
318
|
-
};
|
|
319
|
-
} else {
|
|
320
|
-
stack.pop();
|
|
321
|
-
postfixIncDec = true;
|
|
322
|
-
yield {
|
|
323
|
-
type: "TemplateTail",
|
|
324
|
-
value: match[0],
|
|
325
|
-
closed: match[1] === "`"
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
break;
|
|
331
|
-
case "InterpolationInJSX":
|
|
332
|
-
if (braces.length === mode.nesting) {
|
|
333
|
-
stack.pop();
|
|
334
|
-
lastIndex += 1;
|
|
335
|
-
lastSignificantToken = "}";
|
|
336
|
-
yield {
|
|
337
|
-
type: "JSXPunctuator",
|
|
338
|
-
value: "}"
|
|
339
|
-
};
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
postfixIncDec = braces.pop();
|
|
344
|
-
nextLastSignificantToken = postfixIncDec ? "?ExpressionBraceEnd" : "}";
|
|
345
|
-
break;
|
|
346
|
-
case "]":
|
|
347
|
-
postfixIncDec = true;
|
|
348
|
-
break;
|
|
349
|
-
case "++":
|
|
350
|
-
case "--":
|
|
351
|
-
nextLastSignificantToken = postfixIncDec ? "?PostfixIncDec" : "?UnaryIncDec";
|
|
352
|
-
break;
|
|
353
|
-
case "<":
|
|
354
|
-
if (jsx && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
|
|
355
|
-
stack.push({ tag: "JSXTag" });
|
|
356
|
-
lastIndex += 1;
|
|
357
|
-
lastSignificantToken = "<";
|
|
358
|
-
yield {
|
|
359
|
-
type: "JSXPunctuator",
|
|
360
|
-
value: punctuator
|
|
361
|
-
};
|
|
362
|
-
continue;
|
|
363
|
-
}
|
|
364
|
-
postfixIncDec = false;
|
|
365
|
-
break;
|
|
366
|
-
default:
|
|
367
|
-
postfixIncDec = false;
|
|
368
|
-
}
|
|
369
|
-
lastIndex = nextLastIndex;
|
|
370
|
-
lastSignificantToken = nextLastSignificantToken;
|
|
371
|
-
yield {
|
|
372
|
-
type: "Punctuator",
|
|
373
|
-
value: punctuator
|
|
374
|
-
};
|
|
375
|
-
continue;
|
|
376
|
-
}
|
|
377
|
-
Identifier.lastIndex = lastIndex;
|
|
378
|
-
if (match = Identifier.exec(input)) {
|
|
379
|
-
lastIndex = Identifier.lastIndex;
|
|
380
|
-
nextLastSignificantToken = match[0];
|
|
381
|
-
switch (match[0]) {
|
|
382
|
-
case "for":
|
|
383
|
-
case "if":
|
|
384
|
-
case "while":
|
|
385
|
-
case "with":
|
|
386
|
-
if (lastSignificantToken !== "." && lastSignificantToken !== "?.") {
|
|
387
|
-
nextLastSignificantToken = "?NonExpressionParenKeyword";
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
lastSignificantToken = nextLastSignificantToken;
|
|
391
|
-
postfixIncDec = !KeywordsWithExpressionAfter.test(match[0]);
|
|
392
|
-
yield {
|
|
393
|
-
type: match[1] === "#" ? "PrivateIdentifier" : "IdentifierName",
|
|
394
|
-
value: match[0]
|
|
395
|
-
};
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
StringLiteral.lastIndex = lastIndex;
|
|
399
|
-
if (match = StringLiteral.exec(input)) {
|
|
400
|
-
lastIndex = StringLiteral.lastIndex;
|
|
401
|
-
lastSignificantToken = match[0];
|
|
402
|
-
postfixIncDec = true;
|
|
403
|
-
yield {
|
|
404
|
-
type: "StringLiteral",
|
|
405
|
-
value: match[0],
|
|
406
|
-
closed: match[2] !== void 0
|
|
407
|
-
};
|
|
408
|
-
continue;
|
|
409
|
-
}
|
|
410
|
-
NumericLiteral.lastIndex = lastIndex;
|
|
411
|
-
if (match = NumericLiteral.exec(input)) {
|
|
412
|
-
lastIndex = NumericLiteral.lastIndex;
|
|
413
|
-
lastSignificantToken = match[0];
|
|
414
|
-
postfixIncDec = true;
|
|
415
|
-
yield {
|
|
416
|
-
type: "NumericLiteral",
|
|
417
|
-
value: match[0]
|
|
418
|
-
};
|
|
419
|
-
continue;
|
|
420
|
-
}
|
|
421
|
-
Template.lastIndex = lastIndex;
|
|
422
|
-
if (match = Template.exec(input)) {
|
|
423
|
-
lastIndex = Template.lastIndex;
|
|
424
|
-
lastSignificantToken = match[0];
|
|
425
|
-
if (match[1] === "${") {
|
|
426
|
-
lastSignificantToken = "?InterpolationInTemplate";
|
|
427
|
-
stack.push({
|
|
428
|
-
tag: "InterpolationInTemplate",
|
|
429
|
-
nesting: braces.length
|
|
430
|
-
});
|
|
431
|
-
postfixIncDec = false;
|
|
432
|
-
yield {
|
|
433
|
-
type: "TemplateHead",
|
|
434
|
-
value: match[0]
|
|
435
|
-
};
|
|
436
|
-
} else {
|
|
437
|
-
postfixIncDec = true;
|
|
438
|
-
yield {
|
|
439
|
-
type: "NoSubstitutionTemplate",
|
|
440
|
-
value: match[0],
|
|
441
|
-
closed: match[1] === "`"
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
continue;
|
|
445
|
-
}
|
|
446
|
-
break;
|
|
447
|
-
case "JSXTag":
|
|
448
|
-
case "JSXTagEnd":
|
|
449
|
-
JSXPunctuator.lastIndex = lastIndex;
|
|
450
|
-
if (match = JSXPunctuator.exec(input)) {
|
|
451
|
-
lastIndex = JSXPunctuator.lastIndex;
|
|
452
|
-
nextLastSignificantToken = match[0];
|
|
453
|
-
switch (match[0]) {
|
|
454
|
-
case "<":
|
|
455
|
-
stack.push({ tag: "JSXTag" });
|
|
456
|
-
break;
|
|
457
|
-
case ">":
|
|
458
|
-
stack.pop();
|
|
459
|
-
if (lastSignificantToken === "/" || mode.tag === "JSXTagEnd") {
|
|
460
|
-
nextLastSignificantToken = "?JSX";
|
|
461
|
-
postfixIncDec = true;
|
|
462
|
-
} else {
|
|
463
|
-
stack.push({ tag: "JSXChildren" });
|
|
464
|
-
}
|
|
465
|
-
break;
|
|
466
|
-
case "{":
|
|
467
|
-
stack.push({
|
|
468
|
-
tag: "InterpolationInJSX",
|
|
469
|
-
nesting: braces.length
|
|
470
|
-
});
|
|
471
|
-
nextLastSignificantToken = "?InterpolationInJSX";
|
|
472
|
-
postfixIncDec = false;
|
|
473
|
-
break;
|
|
474
|
-
case "/":
|
|
475
|
-
if (lastSignificantToken === "<") {
|
|
476
|
-
stack.pop();
|
|
477
|
-
if (stack[stack.length - 1].tag === "JSXChildren") {
|
|
478
|
-
stack.pop();
|
|
479
|
-
}
|
|
480
|
-
stack.push({ tag: "JSXTagEnd" });
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
lastSignificantToken = nextLastSignificantToken;
|
|
484
|
-
yield {
|
|
485
|
-
type: "JSXPunctuator",
|
|
486
|
-
value: match[0]
|
|
487
|
-
};
|
|
488
|
-
continue;
|
|
489
|
-
}
|
|
490
|
-
JSXIdentifier.lastIndex = lastIndex;
|
|
491
|
-
if (match = JSXIdentifier.exec(input)) {
|
|
492
|
-
lastIndex = JSXIdentifier.lastIndex;
|
|
493
|
-
lastSignificantToken = match[0];
|
|
494
|
-
yield {
|
|
495
|
-
type: "JSXIdentifier",
|
|
496
|
-
value: match[0]
|
|
497
|
-
};
|
|
498
|
-
continue;
|
|
499
|
-
}
|
|
500
|
-
JSXString.lastIndex = lastIndex;
|
|
501
|
-
if (match = JSXString.exec(input)) {
|
|
502
|
-
lastIndex = JSXString.lastIndex;
|
|
503
|
-
lastSignificantToken = match[0];
|
|
504
|
-
yield {
|
|
505
|
-
type: "JSXString",
|
|
506
|
-
value: match[0],
|
|
507
|
-
closed: match[2] !== void 0
|
|
508
|
-
};
|
|
509
|
-
continue;
|
|
510
|
-
}
|
|
511
|
-
break;
|
|
512
|
-
case "JSXChildren":
|
|
513
|
-
JSXText.lastIndex = lastIndex;
|
|
514
|
-
if (match = JSXText.exec(input)) {
|
|
515
|
-
lastIndex = JSXText.lastIndex;
|
|
516
|
-
lastSignificantToken = match[0];
|
|
517
|
-
yield {
|
|
518
|
-
type: "JSXText",
|
|
519
|
-
value: match[0]
|
|
520
|
-
};
|
|
521
|
-
continue;
|
|
522
|
-
}
|
|
523
|
-
switch (input[lastIndex]) {
|
|
524
|
-
case "<":
|
|
525
|
-
stack.push({ tag: "JSXTag" });
|
|
526
|
-
lastIndex++;
|
|
527
|
-
lastSignificantToken = "<";
|
|
528
|
-
yield {
|
|
529
|
-
type: "JSXPunctuator",
|
|
530
|
-
value: "<"
|
|
531
|
-
};
|
|
532
|
-
continue;
|
|
533
|
-
case "{":
|
|
534
|
-
stack.push({
|
|
535
|
-
tag: "InterpolationInJSX",
|
|
536
|
-
nesting: braces.length
|
|
537
|
-
});
|
|
538
|
-
lastIndex++;
|
|
539
|
-
lastSignificantToken = "?InterpolationInJSX";
|
|
540
|
-
postfixIncDec = false;
|
|
541
|
-
yield {
|
|
542
|
-
type: "JSXPunctuator",
|
|
543
|
-
value: "{"
|
|
544
|
-
};
|
|
545
|
-
continue;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
WhiteSpace.lastIndex = lastIndex;
|
|
549
|
-
if (match = WhiteSpace.exec(input)) {
|
|
550
|
-
lastIndex = WhiteSpace.lastIndex;
|
|
551
|
-
yield {
|
|
552
|
-
type: "WhiteSpace",
|
|
553
|
-
value: match[0]
|
|
554
|
-
};
|
|
555
|
-
continue;
|
|
556
|
-
}
|
|
557
|
-
LineTerminatorSequence.lastIndex = lastIndex;
|
|
558
|
-
if (match = LineTerminatorSequence.exec(input)) {
|
|
559
|
-
lastIndex = LineTerminatorSequence.lastIndex;
|
|
560
|
-
postfixIncDec = false;
|
|
561
|
-
if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
|
|
562
|
-
lastSignificantToken = "?NoLineTerminatorHere";
|
|
563
|
-
}
|
|
564
|
-
yield {
|
|
565
|
-
type: "LineTerminatorSequence",
|
|
566
|
-
value: match[0]
|
|
567
|
-
};
|
|
568
|
-
continue;
|
|
569
|
-
}
|
|
570
|
-
MultiLineComment.lastIndex = lastIndex;
|
|
571
|
-
if (match = MultiLineComment.exec(input)) {
|
|
572
|
-
lastIndex = MultiLineComment.lastIndex;
|
|
573
|
-
if (Newline.test(match[0])) {
|
|
574
|
-
postfixIncDec = false;
|
|
575
|
-
if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
|
|
576
|
-
lastSignificantToken = "?NoLineTerminatorHere";
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
yield {
|
|
580
|
-
type: "MultiLineComment",
|
|
581
|
-
value: match[0],
|
|
582
|
-
closed: match[1] !== void 0
|
|
583
|
-
};
|
|
584
|
-
continue;
|
|
585
|
-
}
|
|
586
|
-
SingleLineComment.lastIndex = lastIndex;
|
|
587
|
-
if (match = SingleLineComment.exec(input)) {
|
|
588
|
-
lastIndex = SingleLineComment.lastIndex;
|
|
589
|
-
postfixIncDec = false;
|
|
590
|
-
yield {
|
|
591
|
-
type: "SingleLineComment",
|
|
592
|
-
value: match[0]
|
|
593
|
-
};
|
|
594
|
-
continue;
|
|
595
|
-
}
|
|
596
|
-
firstCodePoint = String.fromCodePoint(input.codePointAt(lastIndex));
|
|
597
|
-
lastIndex += firstCodePoint.length;
|
|
598
|
-
lastSignificantToken = firstCodePoint;
|
|
599
|
-
postfixIncDec = false;
|
|
600
|
-
yield {
|
|
601
|
-
type: mode.tag.startsWith("JSX") ? "JSXInvalid" : "Invalid",
|
|
602
|
-
value: firstCodePoint
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
return void 0;
|
|
606
|
-
};
|
|
607
|
-
return jsTokens_1;
|
|
608
|
-
}
|
|
609
|
-
requireJsTokens();
|
|
610
|
-
var reservedWords = {
|
|
611
|
-
keyword: [
|
|
612
|
-
"break",
|
|
613
|
-
"case",
|
|
614
|
-
"catch",
|
|
615
|
-
"continue",
|
|
616
|
-
"debugger",
|
|
617
|
-
"default",
|
|
618
|
-
"do",
|
|
619
|
-
"else",
|
|
620
|
-
"finally",
|
|
621
|
-
"for",
|
|
622
|
-
"function",
|
|
623
|
-
"if",
|
|
624
|
-
"return",
|
|
625
|
-
"switch",
|
|
626
|
-
"throw",
|
|
627
|
-
"try",
|
|
628
|
-
"var",
|
|
629
|
-
"const",
|
|
630
|
-
"while",
|
|
631
|
-
"with",
|
|
632
|
-
"new",
|
|
633
|
-
"this",
|
|
634
|
-
"super",
|
|
635
|
-
"class",
|
|
636
|
-
"extends",
|
|
637
|
-
"export",
|
|
638
|
-
"import",
|
|
639
|
-
"null",
|
|
640
|
-
"true",
|
|
641
|
-
"false",
|
|
642
|
-
"in",
|
|
643
|
-
"instanceof",
|
|
644
|
-
"typeof",
|
|
645
|
-
"void",
|
|
646
|
-
"delete"
|
|
647
|
-
],
|
|
648
|
-
strict: [
|
|
649
|
-
"implements",
|
|
650
|
-
"interface",
|
|
651
|
-
"let",
|
|
652
|
-
"package",
|
|
653
|
-
"private",
|
|
654
|
-
"protected",
|
|
655
|
-
"public",
|
|
656
|
-
"static",
|
|
657
|
-
"yield"
|
|
658
|
-
]
|
|
659
|
-
};
|
|
660
|
-
new Set(reservedWords.keyword);
|
|
661
|
-
new Set(reservedWords.strict);
|
|
662
|
-
const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
663
|
-
function nanoid(size = 21) {
|
|
664
|
-
let id = "";
|
|
665
|
-
let i = size;
|
|
666
|
-
while (i--) {
|
|
667
|
-
id += urlAlphabet[Math.random() * 64 | 0];
|
|
668
|
-
}
|
|
669
|
-
return id;
|
|
670
|
-
}
|
|
671
|
-
function generateHash(str) {
|
|
672
|
-
let hash = 0;
|
|
673
|
-
if (str.length === 0) {
|
|
674
|
-
return `${hash}`;
|
|
675
|
-
}
|
|
676
|
-
for (let i = 0; i < str.length; i++) {
|
|
677
|
-
const char = str.charCodeAt(i);
|
|
678
|
-
hash = (hash << 5) - hash + char;
|
|
679
|
-
hash = hash & hash;
|
|
680
|
-
}
|
|
681
|
-
return `${hash}`;
|
|
682
|
-
}
|
|
683
|
-
function getUiAPI() {
|
|
684
|
-
return window.__vitest_ui_api__;
|
|
685
|
-
}
|
|
686
|
-
const postfixRE = /[?#].*$/;
|
|
687
|
-
function cleanUrl(url2) {
|
|
688
|
-
return url2.replace(postfixRE, "");
|
|
689
|
-
}
|
|
690
|
-
class ModuleMockerMSWInterceptor {
|
|
691
|
-
constructor(options = {}) {
|
|
692
|
-
__publicField(this, "mocks", new MockerRegistry());
|
|
693
|
-
__publicField(this, "started", false);
|
|
694
|
-
__publicField(this, "startPromise");
|
|
695
|
-
this.options = options;
|
|
696
|
-
if (!options.globalThisAccessor) {
|
|
697
|
-
options.globalThisAccessor = '"__vitest_mocker__"';
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
async register(module) {
|
|
701
|
-
await this.init();
|
|
702
|
-
this.mocks.add(module);
|
|
703
|
-
}
|
|
704
|
-
async delete(url2) {
|
|
705
|
-
await this.init();
|
|
706
|
-
this.mocks.delete(url2);
|
|
707
|
-
}
|
|
708
|
-
invalidate() {
|
|
709
|
-
this.mocks.clear();
|
|
710
|
-
}
|
|
711
|
-
async resolveManualMock(mock) {
|
|
712
|
-
const exports = Object.keys(await mock.resolve());
|
|
713
|
-
const module = `const module = globalThis[${this.options.globalThisAccessor}].getFactoryModule("${mock.url}");`;
|
|
714
|
-
const keys = exports.map((name) => {
|
|
715
|
-
if (name === "default") {
|
|
716
|
-
return `export default module["default"];`;
|
|
717
|
-
}
|
|
718
|
-
return `export const ${name} = module["${name}"];`;
|
|
719
|
-
}).join("\n");
|
|
720
|
-
const text = `${module}
|
|
721
|
-
${keys}`;
|
|
722
|
-
return new Response(text, {
|
|
723
|
-
headers: {
|
|
724
|
-
"Content-Type": "application/javascript"
|
|
725
|
-
}
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
async init() {
|
|
729
|
-
if (this.started) {
|
|
730
|
-
return;
|
|
731
|
-
}
|
|
732
|
-
if (this.startPromise) {
|
|
733
|
-
return this.startPromise;
|
|
734
|
-
}
|
|
735
|
-
const worker = this.options.mswWorker;
|
|
736
|
-
this.startPromise = Promise.all([
|
|
737
|
-
worker ? {
|
|
738
|
-
setupWorker(handler) {
|
|
739
|
-
worker.use(handler);
|
|
740
|
-
return worker;
|
|
741
|
-
}
|
|
742
|
-
} : __vitePreload(() => import("msw/browser"), true ? [] : void 0),
|
|
743
|
-
__vitePreload(() => import("msw/core/http"), true ? [] : void 0)
|
|
744
|
-
]).then(([{ setupWorker }, { http }]) => {
|
|
745
|
-
const worker2 = setupWorker(
|
|
746
|
-
http.get(/.+/, async ({ request }) => {
|
|
747
|
-
const path = cleanQuery(request.url.slice(location.origin.length));
|
|
748
|
-
if (!this.mocks.has(path)) {
|
|
749
|
-
if (path.includes("/deps/")) {
|
|
750
|
-
return fetch(bypass(request));
|
|
751
|
-
}
|
|
752
|
-
return passthrough();
|
|
753
|
-
}
|
|
754
|
-
const mock = this.mocks.get(path);
|
|
755
|
-
switch (mock.type) {
|
|
756
|
-
case "manual":
|
|
757
|
-
return this.resolveManualMock(mock);
|
|
758
|
-
case "automock":
|
|
759
|
-
case "autospy":
|
|
760
|
-
return Response.redirect(injectQuery(path, `mock=${mock.type}`));
|
|
761
|
-
case "redirect":
|
|
762
|
-
return Response.redirect(mock.redirect);
|
|
763
|
-
default:
|
|
764
|
-
throw new Error(`Unknown mock type: ${mock.type}`);
|
|
765
|
-
}
|
|
766
|
-
})
|
|
767
|
-
);
|
|
768
|
-
return worker2.start(this.options.mswOptions);
|
|
769
|
-
}).finally(() => {
|
|
770
|
-
this.started = true;
|
|
771
|
-
this.startPromise = void 0;
|
|
772
|
-
});
|
|
773
|
-
await this.startPromise;
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
const timestampRegexp = /(\?|&)t=\d{13}/;
|
|
777
|
-
const versionRegexp = /(\?|&)v=\w{8}/;
|
|
778
|
-
function cleanQuery(url2) {
|
|
779
|
-
return url2.replace(timestampRegexp, "").replace(versionRegexp, "");
|
|
780
|
-
}
|
|
781
|
-
function passthrough() {
|
|
782
|
-
return new Response(null, {
|
|
783
|
-
status: 302,
|
|
784
|
-
statusText: "Passthrough",
|
|
785
|
-
headers: {
|
|
786
|
-
"x-msw-intention": "passthrough"
|
|
787
|
-
}
|
|
788
|
-
});
|
|
789
|
-
}
|
|
790
|
-
function bypass(request) {
|
|
791
|
-
const clonedRequest = request.clone();
|
|
792
|
-
clonedRequest.headers.set("x-msw-intention", "bypass");
|
|
793
|
-
const cacheControl = clonedRequest.headers.get("cache-control");
|
|
794
|
-
if (cacheControl) {
|
|
795
|
-
clonedRequest.headers.set(
|
|
796
|
-
"cache-control",
|
|
797
|
-
// allow reinvalidation of the cache so mocks can be updated
|
|
798
|
-
cacheControl.replace(", immutable", "")
|
|
799
|
-
);
|
|
800
|
-
}
|
|
801
|
-
return clonedRequest;
|
|
802
|
-
}
|
|
803
|
-
const replacePercentageRE = /%/g;
|
|
804
|
-
function injectQuery(url2, queryToInject) {
|
|
805
|
-
const resolvedUrl = new URL(
|
|
806
|
-
url2.replace(replacePercentageRE, "%25"),
|
|
807
|
-
location.href
|
|
808
|
-
);
|
|
809
|
-
const { search, hash } = resolvedUrl;
|
|
810
|
-
const pathname = cleanUrl(url2);
|
|
811
|
-
return `${pathname}?${queryToInject}${search ? `&${search.slice(1)}` : ""}${hash ?? ""}`;
|
|
812
|
-
}
|
|
813
|
-
class VitestBrowserModuleMockerInterceptor extends ModuleMockerMSWInterceptor {
|
|
814
|
-
async register(event) {
|
|
815
|
-
if (event.type === "manual") {
|
|
816
|
-
const module = ManualMockedModule.fromJSON(event, async () => {
|
|
817
|
-
const keys = await getFactoryExports(event.url);
|
|
818
|
-
return Object.fromEntries(keys.map((key) => [key, null]));
|
|
819
|
-
});
|
|
820
|
-
await super.register(module);
|
|
821
|
-
} else {
|
|
822
|
-
await this.init();
|
|
823
|
-
this.mocks.register(event);
|
|
824
|
-
}
|
|
825
|
-
channel.postMessage({ type: "mock:done" });
|
|
826
|
-
}
|
|
827
|
-
async delete(url2) {
|
|
828
|
-
await super.delete(url2);
|
|
829
|
-
channel.postMessage({ type: "unmock:done" });
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
function createModuleMockerInterceptor() {
|
|
833
|
-
return new VitestBrowserModuleMockerInterceptor({
|
|
834
|
-
globalThisAccessor: '"__vitest_mocker__"',
|
|
835
|
-
mswOptions: {
|
|
836
|
-
serviceWorker: {
|
|
837
|
-
url: "/mockServiceWorker.js",
|
|
838
|
-
options: {
|
|
839
|
-
scope: "/"
|
|
840
|
-
}
|
|
841
|
-
},
|
|
842
|
-
quiet: true
|
|
843
|
-
}
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
function getFactoryExports(id) {
|
|
847
|
-
const eventId = nanoid();
|
|
848
|
-
channel.postMessage({
|
|
849
|
-
type: "mock-factory:request",
|
|
850
|
-
eventId,
|
|
851
|
-
id
|
|
852
|
-
});
|
|
853
|
-
return new Promise((resolve2, reject) => {
|
|
854
|
-
channel.addEventListener(
|
|
855
|
-
"message",
|
|
856
|
-
function onMessage(e) {
|
|
857
|
-
if (e.data.type === "mock-factory:response" && e.data.eventId === eventId) {
|
|
858
|
-
resolve2(e.data.exports);
|
|
859
|
-
channel.removeEventListener("message", onMessage);
|
|
860
|
-
}
|
|
861
|
-
if (e.data.type === "mock-factory:error" && e.data.eventId === eventId) {
|
|
862
|
-
reject(e.data.error);
|
|
863
|
-
channel.removeEventListener("message", onMessage);
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
);
|
|
867
|
-
});
|
|
868
|
-
}
|
|
869
|
-
const url = new URL(location.href);
|
|
870
|
-
const ID_ALL = "__vitest_all__";
|
|
871
|
-
class IframeOrchestrator {
|
|
872
|
-
constructor() {
|
|
873
|
-
__publicField(this, "cancelled", false);
|
|
874
|
-
__publicField(this, "runningFiles", /* @__PURE__ */ new Set());
|
|
875
|
-
__publicField(this, "interceptor", createModuleMockerInterceptor());
|
|
876
|
-
__publicField(this, "iframes", /* @__PURE__ */ new Map());
|
|
877
|
-
}
|
|
878
|
-
async init() {
|
|
879
|
-
const testFiles = getBrowserState().files;
|
|
880
|
-
debug("test files", testFiles.join(", "));
|
|
881
|
-
this.runningFiles.clear();
|
|
882
|
-
testFiles.forEach((file) => this.runningFiles.add(file));
|
|
883
|
-
channel.addEventListener(
|
|
884
|
-
"message",
|
|
885
|
-
(e) => this.onIframeEvent(e)
|
|
886
|
-
);
|
|
887
|
-
globalChannel.addEventListener(
|
|
888
|
-
"message",
|
|
889
|
-
(e) => this.onGlobalChannelEvent(e)
|
|
890
|
-
);
|
|
891
|
-
}
|
|
892
|
-
async createTesters(testFiles) {
|
|
893
|
-
this.cancelled = false;
|
|
894
|
-
this.runningFiles.clear();
|
|
895
|
-
testFiles.forEach((file) => this.runningFiles.add(file));
|
|
896
|
-
const config = getConfig();
|
|
897
|
-
const container = await getContainer(config);
|
|
898
|
-
if (config.browser.ui) {
|
|
899
|
-
container.className = "absolute origin-top mt-[8px]";
|
|
900
|
-
container.parentElement.setAttribute("data-ready", "true");
|
|
901
|
-
container.textContent = "";
|
|
902
|
-
}
|
|
903
|
-
const { width, height } = config.browser.viewport;
|
|
904
|
-
this.iframes.forEach((iframe) => iframe.remove());
|
|
905
|
-
this.iframes.clear();
|
|
906
|
-
if (config.isolate === false) {
|
|
907
|
-
const iframe = this.createIframe(container, ID_ALL);
|
|
908
|
-
await setIframeViewport(iframe, width, height);
|
|
909
|
-
return;
|
|
910
|
-
}
|
|
911
|
-
for (const file of testFiles) {
|
|
912
|
-
if (this.cancelled) {
|
|
913
|
-
done();
|
|
914
|
-
return;
|
|
915
|
-
}
|
|
916
|
-
const iframe = this.createIframe(container, file);
|
|
917
|
-
await setIframeViewport(iframe, width, height);
|
|
918
|
-
await new Promise((resolve2) => {
|
|
919
|
-
channel.addEventListener(
|
|
920
|
-
"message",
|
|
921
|
-
function handler(e) {
|
|
922
|
-
if (e.data.type === "done" || e.data.type === "error") {
|
|
923
|
-
channel.removeEventListener("message", handler);
|
|
924
|
-
resolve2();
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
);
|
|
928
|
-
});
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
createIframe(container, file) {
|
|
932
|
-
if (this.iframes.has(file)) {
|
|
933
|
-
this.iframes.get(file).remove();
|
|
934
|
-
this.iframes.delete(file);
|
|
935
|
-
}
|
|
936
|
-
const iframe = document.createElement("iframe");
|
|
937
|
-
iframe.setAttribute("loading", "eager");
|
|
938
|
-
iframe.setAttribute(
|
|
939
|
-
"src",
|
|
940
|
-
`${url.pathname}__vitest_test__/__test__/${getBrowserState().contextId}/${encodeURIComponent(file)}`
|
|
941
|
-
);
|
|
942
|
-
iframe.setAttribute("data-vitest", "true");
|
|
943
|
-
iframe.style.border = "none";
|
|
944
|
-
iframe.style.width = "100%";
|
|
945
|
-
iframe.style.height = "100%";
|
|
946
|
-
iframe.setAttribute("allowfullscreen", "true");
|
|
947
|
-
iframe.setAttribute("allow", "clipboard-write;");
|
|
948
|
-
iframe.setAttribute("name", "vitest-iframe");
|
|
949
|
-
this.iframes.set(file, iframe);
|
|
950
|
-
container.appendChild(iframe);
|
|
951
|
-
return iframe;
|
|
952
|
-
}
|
|
953
|
-
async onGlobalChannelEvent(e) {
|
|
954
|
-
debug("global channel event", JSON.stringify(e.data));
|
|
955
|
-
switch (e.data.type) {
|
|
956
|
-
case "cancel": {
|
|
957
|
-
this.cancelled = true;
|
|
958
|
-
break;
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
async onIframeEvent(e) {
|
|
963
|
-
var _a;
|
|
964
|
-
debug("iframe event", JSON.stringify(e.data));
|
|
965
|
-
switch (e.data.type) {
|
|
966
|
-
case "viewport": {
|
|
967
|
-
const { width, height, id } = e.data;
|
|
968
|
-
const iframe = this.iframes.get(id);
|
|
969
|
-
if (!iframe) {
|
|
970
|
-
const error = new Error(`Cannot find iframe with id ${id}`);
|
|
971
|
-
channel.postMessage({
|
|
972
|
-
type: "viewport:fail",
|
|
973
|
-
id,
|
|
974
|
-
error: error.message
|
|
975
|
-
});
|
|
976
|
-
await client.rpc.onUnhandledError(
|
|
977
|
-
{
|
|
978
|
-
name: "Teardown Error",
|
|
979
|
-
message: error.message
|
|
980
|
-
},
|
|
981
|
-
"Teardown Error"
|
|
982
|
-
);
|
|
983
|
-
return;
|
|
984
|
-
}
|
|
985
|
-
await setIframeViewport(iframe, width, height);
|
|
986
|
-
channel.postMessage({ type: "viewport:done", id });
|
|
987
|
-
break;
|
|
988
|
-
}
|
|
989
|
-
case "done": {
|
|
990
|
-
const filenames = e.data.filenames;
|
|
991
|
-
filenames.forEach((filename) => this.runningFiles.delete(filename));
|
|
992
|
-
if (!this.runningFiles.size) {
|
|
993
|
-
const ui = getUiAPI();
|
|
994
|
-
if (ui && filenames.length > 1) {
|
|
995
|
-
const id = generateFileId(filenames[filenames.length - 1]);
|
|
996
|
-
ui.setCurrentFileId(id);
|
|
997
|
-
}
|
|
998
|
-
await done();
|
|
999
|
-
} else {
|
|
1000
|
-
const iframeId = e.data.id;
|
|
1001
|
-
(_a = this.iframes.get(iframeId)) == null ? void 0 : _a.remove();
|
|
1002
|
-
this.iframes.delete(iframeId);
|
|
1003
|
-
}
|
|
1004
|
-
break;
|
|
1005
|
-
}
|
|
1006
|
-
case "error": {
|
|
1007
|
-
const iframeId = e.data.id;
|
|
1008
|
-
this.iframes.delete(iframeId);
|
|
1009
|
-
await client.rpc.onUnhandledError(e.data.error, e.data.errorType);
|
|
1010
|
-
if (iframeId === ID_ALL) {
|
|
1011
|
-
this.runningFiles.clear();
|
|
1012
|
-
} else {
|
|
1013
|
-
this.runningFiles.delete(iframeId);
|
|
1014
|
-
}
|
|
1015
|
-
if (!this.runningFiles.size) {
|
|
1016
|
-
await done();
|
|
1017
|
-
}
|
|
1018
|
-
break;
|
|
1019
|
-
}
|
|
1020
|
-
case "mock:invalidate":
|
|
1021
|
-
this.interceptor.invalidate();
|
|
1022
|
-
break;
|
|
1023
|
-
case "unmock":
|
|
1024
|
-
await this.interceptor.delete(e.data.url);
|
|
1025
|
-
break;
|
|
1026
|
-
case "mock":
|
|
1027
|
-
await this.interceptor.register(e.data.module);
|
|
1028
|
-
break;
|
|
1029
|
-
case "mock-factory:error":
|
|
1030
|
-
case "mock-factory:response":
|
|
1031
|
-
break;
|
|
1032
|
-
default: {
|
|
1033
|
-
e.data;
|
|
1034
|
-
await client.rpc.onUnhandledError(
|
|
1035
|
-
{
|
|
1036
|
-
name: "Unexpected Event",
|
|
1037
|
-
message: `Unexpected event: ${e.data.type}`
|
|
1038
|
-
},
|
|
1039
|
-
"Unexpected Event"
|
|
1040
|
-
);
|
|
1041
|
-
await done();
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
const orchestrator = new IframeOrchestrator();
|
|
1047
|
-
let promiseTesters;
|
|
1048
|
-
getBrowserState().createTesters = async (files) => {
|
|
1049
|
-
await promiseTesters;
|
|
1050
|
-
promiseTesters = orchestrator.createTesters(files).finally(() => {
|
|
1051
|
-
promiseTesters = void 0;
|
|
1052
|
-
});
|
|
1053
|
-
await promiseTesters;
|
|
1054
|
-
};
|
|
1055
|
-
async function done() {
|
|
1056
|
-
await client.rpc.finishBrowserTests(getBrowserState().contextId);
|
|
1057
|
-
}
|
|
1058
|
-
async function getContainer(config) {
|
|
1059
|
-
if (config.browser.ui) {
|
|
1060
|
-
const element = document.querySelector("#tester-ui");
|
|
1061
|
-
if (!element) {
|
|
1062
|
-
return new Promise((resolve2) => {
|
|
1063
|
-
setTimeout(() => {
|
|
1064
|
-
resolve2(getContainer(config));
|
|
1065
|
-
}, 30);
|
|
1066
|
-
});
|
|
1067
|
-
}
|
|
1068
|
-
return element;
|
|
1069
|
-
}
|
|
1070
|
-
return document.querySelector("#vitest-tester");
|
|
1071
|
-
}
|
|
1072
|
-
client.waitForConnection().then(async () => {
|
|
1073
|
-
const testFiles = getBrowserState().files;
|
|
1074
|
-
await orchestrator.init();
|
|
1075
|
-
if (testFiles.length) {
|
|
1076
|
-
await orchestrator.createTesters(testFiles);
|
|
1077
|
-
}
|
|
1078
|
-
});
|
|
1079
|
-
function generateFileId(file) {
|
|
1080
|
-
const config = getConfig();
|
|
1081
|
-
const project = config.name || "";
|
|
1082
|
-
const path = relative(config.root, file);
|
|
1083
|
-
return generateHash(`${path}${project}`);
|
|
1084
|
-
}
|
|
1085
|
-
async function setIframeViewport(iframe, width, height) {
|
|
1086
|
-
const ui = getUiAPI();
|
|
1087
|
-
if (ui) {
|
|
1088
|
-
await ui.setIframeViewport(width, height);
|
|
1089
|
-
} else {
|
|
1090
|
-
iframe.style.width = `${width}px`;
|
|
1091
|
-
iframe.style.height = `${height}px`;
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
function debug(...args) {
|
|
1095
|
-
const debug2 = getConfig().env.VITEST_BROWSER_DEBUG;
|
|
1096
|
-
if (debug2 && debug2 !== "false") {
|
|
1097
|
-
client.rpc.debug(...args.map(String));
|
|
1098
|
-
}
|
|
1099
|
-
}
|