@vitest/browser 2.1.0 → 2.1.2

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.
@@ -0,0 +1,1096 @@
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: "/__vitest_msw__"
838
+ },
839
+ quiet: true
840
+ }
841
+ });
842
+ }
843
+ function getFactoryExports(id) {
844
+ const eventId = nanoid();
845
+ channel.postMessage({
846
+ type: "mock-factory:request",
847
+ eventId,
848
+ id
849
+ });
850
+ return new Promise((resolve2, reject) => {
851
+ channel.addEventListener(
852
+ "message",
853
+ function onMessage(e) {
854
+ if (e.data.type === "mock-factory:response" && e.data.eventId === eventId) {
855
+ resolve2(e.data.exports);
856
+ channel.removeEventListener("message", onMessage);
857
+ }
858
+ if (e.data.type === "mock-factory:error" && e.data.eventId === eventId) {
859
+ reject(e.data.error);
860
+ channel.removeEventListener("message", onMessage);
861
+ }
862
+ }
863
+ );
864
+ });
865
+ }
866
+ const url = new URL(location.href);
867
+ const ID_ALL = "__vitest_all__";
868
+ class IframeOrchestrator {
869
+ constructor() {
870
+ __publicField(this, "cancelled", false);
871
+ __publicField(this, "runningFiles", /* @__PURE__ */ new Set());
872
+ __publicField(this, "interceptor", createModuleMockerInterceptor());
873
+ __publicField(this, "iframes", /* @__PURE__ */ new Map());
874
+ }
875
+ async init() {
876
+ const testFiles = getBrowserState().files;
877
+ debug("test files", testFiles.join(", "));
878
+ this.runningFiles.clear();
879
+ testFiles.forEach((file) => this.runningFiles.add(file));
880
+ channel.addEventListener(
881
+ "message",
882
+ (e) => this.onIframeEvent(e)
883
+ );
884
+ globalChannel.addEventListener(
885
+ "message",
886
+ (e) => this.onGlobalChannelEvent(e)
887
+ );
888
+ }
889
+ async createTesters(testFiles) {
890
+ this.cancelled = false;
891
+ this.runningFiles.clear();
892
+ testFiles.forEach((file) => this.runningFiles.add(file));
893
+ const config = getConfig();
894
+ const container = await getContainer(config);
895
+ if (config.browser.ui) {
896
+ container.className = "absolute origin-top mt-[8px]";
897
+ container.parentElement.setAttribute("data-ready", "true");
898
+ container.textContent = "";
899
+ }
900
+ const { width, height } = config.browser.viewport;
901
+ this.iframes.forEach((iframe) => iframe.remove());
902
+ this.iframes.clear();
903
+ if (config.isolate === false) {
904
+ const iframe = this.createIframe(container, ID_ALL);
905
+ await setIframeViewport(iframe, width, height);
906
+ return;
907
+ }
908
+ for (const file of testFiles) {
909
+ if (this.cancelled) {
910
+ done();
911
+ return;
912
+ }
913
+ const iframe = this.createIframe(container, file);
914
+ await setIframeViewport(iframe, width, height);
915
+ await new Promise((resolve2) => {
916
+ channel.addEventListener(
917
+ "message",
918
+ function handler(e) {
919
+ if (e.data.type === "done" || e.data.type === "error") {
920
+ channel.removeEventListener("message", handler);
921
+ resolve2();
922
+ }
923
+ }
924
+ );
925
+ });
926
+ }
927
+ }
928
+ createIframe(container, file) {
929
+ if (this.iframes.has(file)) {
930
+ this.iframes.get(file).remove();
931
+ this.iframes.delete(file);
932
+ }
933
+ const iframe = document.createElement("iframe");
934
+ iframe.setAttribute("loading", "eager");
935
+ iframe.setAttribute(
936
+ "src",
937
+ `${url.pathname}__vitest_test__/__test__/${getBrowserState().contextId}/${encodeURIComponent(file)}`
938
+ );
939
+ iframe.setAttribute("data-vitest", "true");
940
+ iframe.style.border = "none";
941
+ iframe.style.width = "100%";
942
+ iframe.style.height = "100%";
943
+ iframe.setAttribute("allowfullscreen", "true");
944
+ iframe.setAttribute("allow", "clipboard-write;");
945
+ iframe.setAttribute("name", "vitest-iframe");
946
+ this.iframes.set(file, iframe);
947
+ container.appendChild(iframe);
948
+ return iframe;
949
+ }
950
+ async onGlobalChannelEvent(e) {
951
+ debug("global channel event", JSON.stringify(e.data));
952
+ switch (e.data.type) {
953
+ case "cancel": {
954
+ this.cancelled = true;
955
+ break;
956
+ }
957
+ }
958
+ }
959
+ async onIframeEvent(e) {
960
+ var _a;
961
+ debug("iframe event", JSON.stringify(e.data));
962
+ switch (e.data.type) {
963
+ case "viewport": {
964
+ const { width, height, id } = e.data;
965
+ const iframe = this.iframes.get(id);
966
+ if (!iframe) {
967
+ const error = new Error(`Cannot find iframe with id ${id}`);
968
+ channel.postMessage({
969
+ type: "viewport:fail",
970
+ id,
971
+ error: error.message
972
+ });
973
+ await client.rpc.onUnhandledError(
974
+ {
975
+ name: "Teardown Error",
976
+ message: error.message
977
+ },
978
+ "Teardown Error"
979
+ );
980
+ return;
981
+ }
982
+ await setIframeViewport(iframe, width, height);
983
+ channel.postMessage({ type: "viewport:done", id });
984
+ break;
985
+ }
986
+ case "done": {
987
+ const filenames = e.data.filenames;
988
+ filenames.forEach((filename) => this.runningFiles.delete(filename));
989
+ if (!this.runningFiles.size) {
990
+ const ui = getUiAPI();
991
+ if (ui && filenames.length > 1) {
992
+ const id = generateFileId(filenames[filenames.length - 1]);
993
+ ui.setCurrentFileId(id);
994
+ }
995
+ await done();
996
+ } else {
997
+ const iframeId = e.data.id;
998
+ (_a = this.iframes.get(iframeId)) == null ? void 0 : _a.remove();
999
+ this.iframes.delete(iframeId);
1000
+ }
1001
+ break;
1002
+ }
1003
+ case "error": {
1004
+ const iframeId = e.data.id;
1005
+ this.iframes.delete(iframeId);
1006
+ await client.rpc.onUnhandledError(e.data.error, e.data.errorType);
1007
+ if (iframeId === ID_ALL) {
1008
+ this.runningFiles.clear();
1009
+ } else {
1010
+ this.runningFiles.delete(iframeId);
1011
+ }
1012
+ if (!this.runningFiles.size) {
1013
+ await done();
1014
+ }
1015
+ break;
1016
+ }
1017
+ case "mock:invalidate":
1018
+ this.interceptor.invalidate();
1019
+ break;
1020
+ case "unmock":
1021
+ await this.interceptor.delete(e.data.url);
1022
+ break;
1023
+ case "mock":
1024
+ await this.interceptor.register(e.data.module);
1025
+ break;
1026
+ case "mock-factory:error":
1027
+ case "mock-factory:response":
1028
+ break;
1029
+ default: {
1030
+ e.data;
1031
+ await client.rpc.onUnhandledError(
1032
+ {
1033
+ name: "Unexpected Event",
1034
+ message: `Unexpected event: ${e.data.type}`
1035
+ },
1036
+ "Unexpected Event"
1037
+ );
1038
+ await done();
1039
+ }
1040
+ }
1041
+ }
1042
+ }
1043
+ const orchestrator = new IframeOrchestrator();
1044
+ let promiseTesters;
1045
+ getBrowserState().createTesters = async (files) => {
1046
+ await promiseTesters;
1047
+ promiseTesters = orchestrator.createTesters(files).finally(() => {
1048
+ promiseTesters = void 0;
1049
+ });
1050
+ await promiseTesters;
1051
+ };
1052
+ async function done() {
1053
+ await client.rpc.finishBrowserTests(getBrowserState().contextId);
1054
+ }
1055
+ async function getContainer(config) {
1056
+ if (config.browser.ui) {
1057
+ const element = document.querySelector("#tester-ui");
1058
+ if (!element) {
1059
+ return new Promise((resolve2) => {
1060
+ setTimeout(() => {
1061
+ resolve2(getContainer(config));
1062
+ }, 30);
1063
+ });
1064
+ }
1065
+ return element;
1066
+ }
1067
+ return document.querySelector("#vitest-tester");
1068
+ }
1069
+ client.waitForConnection().then(async () => {
1070
+ const testFiles = getBrowserState().files;
1071
+ await orchestrator.init();
1072
+ if (testFiles.length) {
1073
+ await orchestrator.createTesters(testFiles);
1074
+ }
1075
+ });
1076
+ function generateFileId(file) {
1077
+ const config = getConfig();
1078
+ const project = config.name || "";
1079
+ const path = relative(config.root, file);
1080
+ return generateHash(`${path}${project}`);
1081
+ }
1082
+ async function setIframeViewport(iframe, width, height) {
1083
+ const ui = getUiAPI();
1084
+ if (ui) {
1085
+ await ui.setIframeViewport(width, height);
1086
+ } else {
1087
+ iframe.style.width = `${width}px`;
1088
+ iframe.style.height = `${height}px`;
1089
+ }
1090
+ }
1091
+ function debug(...args) {
1092
+ const debug2 = getConfig().env.VITEST_BROWSER_DEBUG;
1093
+ if (debug2 && debug2 !== "false") {
1094
+ client.rpc.debug(...args.map(String));
1095
+ }
1096
+ }