@vitest/browser 4.1.0-beta.6 → 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.
- package/dist/client/.vite/manifest.json +6 -6
- package/dist/client/__vitest__/assets/index-C5TM4_dj.js +94 -0
- package/dist/client/__vitest__/index.html +1 -1
- package/dist/client/__vitest_browser__/{orchestrator-CXs6qrFe.js → orchestrator-DOndLT0I.js} +1 -1
- package/dist/client/__vitest_browser__/{tester-DVQLxxE-.js → tester-FJ31y3VC.js} +16 -11
- package/dist/client/__vitest_browser__/utils-Dsu9dGGg.js +3826 -0
- package/dist/client/esm-client-injector.js +3 -0
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/tester/tester.html +2 -2
- package/dist/client.js +19 -12
- package/dist/context.js +13 -4
- package/dist/expect-element.js +23 -23
- package/dist/index-5Pe7X7sp.js +7 -0
- package/dist/index.js +33 -20
- package/dist/locators.js +1 -1
- package/package.json +7 -7
- package/dist/client/__vitest__/assets/index-vKQ25zpc.js +0 -63
- package/dist/client/__vitest_browser__/utils-C2ISqq1C.js +0 -223
- package/dist/index-CDbEr3te.js +0 -7
|
@@ -0,0 +1,3826 @@
|
|
|
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
|
+
var d = {
|
|
31
|
+
reset: [0, 0],
|
|
32
|
+
bold: [1, 22, "\x1B[22m\x1B[1m"],
|
|
33
|
+
dim: [2, 22, "\x1B[22m\x1B[2m"],
|
|
34
|
+
italic: [3, 23],
|
|
35
|
+
underline: [4, 24],
|
|
36
|
+
inverse: [7, 27],
|
|
37
|
+
hidden: [8, 28],
|
|
38
|
+
strikethrough: [9, 29],
|
|
39
|
+
black: [30, 39],
|
|
40
|
+
red: [31, 39],
|
|
41
|
+
green: [32, 39],
|
|
42
|
+
yellow: [33, 39],
|
|
43
|
+
blue: [34, 39],
|
|
44
|
+
magenta: [35, 39],
|
|
45
|
+
cyan: [36, 39],
|
|
46
|
+
white: [37, 39],
|
|
47
|
+
gray: [90, 39],
|
|
48
|
+
bgBlack: [40, 49],
|
|
49
|
+
bgRed: [41, 49],
|
|
50
|
+
bgGreen: [42, 49],
|
|
51
|
+
bgYellow: [43, 49],
|
|
52
|
+
bgBlue: [44, 49],
|
|
53
|
+
bgMagenta: [45, 49],
|
|
54
|
+
bgCyan: [46, 49],
|
|
55
|
+
bgWhite: [47, 49],
|
|
56
|
+
blackBright: [90, 39],
|
|
57
|
+
redBright: [91, 39],
|
|
58
|
+
greenBright: [92, 39],
|
|
59
|
+
yellowBright: [93, 39],
|
|
60
|
+
blueBright: [94, 39],
|
|
61
|
+
magentaBright: [95, 39],
|
|
62
|
+
cyanBright: [96, 39],
|
|
63
|
+
whiteBright: [97, 39],
|
|
64
|
+
bgBlackBright: [100, 49],
|
|
65
|
+
bgRedBright: [101, 49],
|
|
66
|
+
bgGreenBright: [102, 49],
|
|
67
|
+
bgYellowBright: [103, 49],
|
|
68
|
+
bgBlueBright: [104, 49],
|
|
69
|
+
bgMagentaBright: [105, 49],
|
|
70
|
+
bgCyanBright: [106, 49],
|
|
71
|
+
bgWhiteBright: [107, 49]
|
|
72
|
+
};
|
|
73
|
+
function g(e) {
|
|
74
|
+
return String(e);
|
|
75
|
+
}
|
|
76
|
+
g.open = "";
|
|
77
|
+
g.close = "";
|
|
78
|
+
function h() {
|
|
79
|
+
let e = typeof process != "undefined" ? process : void 0, n = (e == null ? void 0 : e.env) || {}, a = n.FORCE_TTY !== "false", i = (e == null ? void 0 : e.argv) || [];
|
|
80
|
+
return !("NO_COLOR" in n || i.includes("--no-color")) && ("FORCE_COLOR" in n || i.includes("--color") || (e == null ? void 0 : e.platform) === "win32" || a && n.TERM !== "dumb" || "CI" in n) || typeof window != "undefined" && !!window.chrome;
|
|
81
|
+
}
|
|
82
|
+
function f() {
|
|
83
|
+
let e = h(), n = (r, t, u, o) => {
|
|
84
|
+
let l = "", s = 0;
|
|
85
|
+
do
|
|
86
|
+
l += r.substring(s, o) + u, s = o + t.length, o = r.indexOf(t, s);
|
|
87
|
+
while (~o);
|
|
88
|
+
return l + r.substring(s);
|
|
89
|
+
}, a = (r, t, u = r) => {
|
|
90
|
+
let o = (l) => {
|
|
91
|
+
let s = String(l), b = s.indexOf(t, r.length);
|
|
92
|
+
return ~b ? r + n(s, t, u, b) + t : r + s + t;
|
|
93
|
+
};
|
|
94
|
+
return o.open = r, o.close = t, o;
|
|
95
|
+
}, i = {
|
|
96
|
+
isColorSupported: e
|
|
97
|
+
}, c = (r) => `\x1B[${r}m`;
|
|
98
|
+
for (let r in d) {
|
|
99
|
+
let t = d[r];
|
|
100
|
+
i[r] = e ? a(
|
|
101
|
+
c(t[0]),
|
|
102
|
+
c(t[1]),
|
|
103
|
+
t[2]
|
|
104
|
+
) : g;
|
|
105
|
+
}
|
|
106
|
+
return i;
|
|
107
|
+
}
|
|
108
|
+
var C = f();
|
|
109
|
+
function _mergeNamespaces$1(n, m) {
|
|
110
|
+
m.forEach(function(e) {
|
|
111
|
+
e && typeof e !== "string" && !Array.isArray(e) && Object.keys(e).forEach(function(k) {
|
|
112
|
+
if (k !== "default" && !(k in n)) {
|
|
113
|
+
var d2 = Object.getOwnPropertyDescriptor(e, k);
|
|
114
|
+
Object.defineProperty(n, k, d2.get ? d2 : {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
get: function() {
|
|
117
|
+
return e[k];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
return Object.freeze(n);
|
|
124
|
+
}
|
|
125
|
+
function getKeysOfEnumerableProperties(object, compareKeys) {
|
|
126
|
+
const rawKeys = Object.keys(object);
|
|
127
|
+
const keys = compareKeys === null ? rawKeys : rawKeys.sort(compareKeys);
|
|
128
|
+
if (Object.getOwnPropertySymbols) {
|
|
129
|
+
for (const symbol of Object.getOwnPropertySymbols(object)) {
|
|
130
|
+
if (Object.getOwnPropertyDescriptor(object, symbol).enumerable) {
|
|
131
|
+
keys.push(symbol);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return keys;
|
|
136
|
+
}
|
|
137
|
+
function printIteratorEntries(iterator, config, indentation, depth, refs, printer2, separator = ": ") {
|
|
138
|
+
let result = "";
|
|
139
|
+
let width = 0;
|
|
140
|
+
let current = iterator.next();
|
|
141
|
+
if (!current.done) {
|
|
142
|
+
result += config.spacingOuter;
|
|
143
|
+
const indentationNext = indentation + config.indent;
|
|
144
|
+
while (!current.done) {
|
|
145
|
+
result += indentationNext;
|
|
146
|
+
if (width++ === config.maxWidth) {
|
|
147
|
+
result += "…";
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
const name = printer2(current.value[0], config, indentationNext, depth, refs);
|
|
151
|
+
const value = printer2(current.value[1], config, indentationNext, depth, refs);
|
|
152
|
+
result += name + separator + value;
|
|
153
|
+
current = iterator.next();
|
|
154
|
+
if (!current.done) {
|
|
155
|
+
result += `,${config.spacingInner}`;
|
|
156
|
+
} else if (!config.min) {
|
|
157
|
+
result += ",";
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
result += config.spacingOuter + indentation;
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
function printIteratorValues(iterator, config, indentation, depth, refs, printer2) {
|
|
165
|
+
let result = "";
|
|
166
|
+
let width = 0;
|
|
167
|
+
let current = iterator.next();
|
|
168
|
+
if (!current.done) {
|
|
169
|
+
result += config.spacingOuter;
|
|
170
|
+
const indentationNext = indentation + config.indent;
|
|
171
|
+
while (!current.done) {
|
|
172
|
+
result += indentationNext;
|
|
173
|
+
if (width++ === config.maxWidth) {
|
|
174
|
+
result += "…";
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
result += printer2(current.value, config, indentationNext, depth, refs);
|
|
178
|
+
current = iterator.next();
|
|
179
|
+
if (!current.done) {
|
|
180
|
+
result += `,${config.spacingInner}`;
|
|
181
|
+
} else if (!config.min) {
|
|
182
|
+
result += ",";
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
result += config.spacingOuter + indentation;
|
|
186
|
+
}
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
function printListItems(list, config, indentation, depth, refs, printer2) {
|
|
190
|
+
let result = "";
|
|
191
|
+
list = list instanceof ArrayBuffer ? new DataView(list) : list;
|
|
192
|
+
const isDataView = (l) => l instanceof DataView;
|
|
193
|
+
const length = isDataView(list) ? list.byteLength : list.length;
|
|
194
|
+
if (length > 0) {
|
|
195
|
+
result += config.spacingOuter;
|
|
196
|
+
const indentationNext = indentation + config.indent;
|
|
197
|
+
for (let i = 0; i < length; i++) {
|
|
198
|
+
result += indentationNext;
|
|
199
|
+
if (i === config.maxWidth) {
|
|
200
|
+
result += "…";
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
if (isDataView(list) || i in list) {
|
|
204
|
+
result += printer2(isDataView(list) ? list.getInt8(i) : list[i], config, indentationNext, depth, refs);
|
|
205
|
+
}
|
|
206
|
+
if (i < length - 1) {
|
|
207
|
+
result += `,${config.spacingInner}`;
|
|
208
|
+
} else if (!config.min) {
|
|
209
|
+
result += ",";
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
result += config.spacingOuter + indentation;
|
|
213
|
+
}
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
function printObjectProperties(val, config, indentation, depth, refs, printer2) {
|
|
217
|
+
let result = "";
|
|
218
|
+
const keys = getKeysOfEnumerableProperties(val, config.compareKeys);
|
|
219
|
+
if (keys.length > 0) {
|
|
220
|
+
result += config.spacingOuter;
|
|
221
|
+
const indentationNext = indentation + config.indent;
|
|
222
|
+
for (let i = 0; i < keys.length; i++) {
|
|
223
|
+
const key = keys[i];
|
|
224
|
+
const name = printer2(key, config, indentationNext, depth, refs);
|
|
225
|
+
const value = printer2(val[key], config, indentationNext, depth, refs);
|
|
226
|
+
result += `${indentationNext + name}: ${value}`;
|
|
227
|
+
if (i < keys.length - 1) {
|
|
228
|
+
result += `,${config.spacingInner}`;
|
|
229
|
+
} else if (!config.min) {
|
|
230
|
+
result += ",";
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
result += config.spacingOuter + indentation;
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
const asymmetricMatcher = typeof Symbol === "function" && Symbol.for ? Symbol.for("jest.asymmetricMatcher") : 1267621;
|
|
238
|
+
const SPACE$2 = " ";
|
|
239
|
+
const serialize$5 = (val, config, indentation, depth, refs, printer2) => {
|
|
240
|
+
const stringedValue = val.toString();
|
|
241
|
+
if (stringedValue === "ArrayContaining" || stringedValue === "ArrayNotContaining") {
|
|
242
|
+
if (++depth > config.maxDepth) {
|
|
243
|
+
return `[${stringedValue}]`;
|
|
244
|
+
}
|
|
245
|
+
return `${stringedValue + SPACE$2}[${printListItems(val.sample, config, indentation, depth, refs, printer2)}]`;
|
|
246
|
+
}
|
|
247
|
+
if (stringedValue === "ObjectContaining" || stringedValue === "ObjectNotContaining") {
|
|
248
|
+
if (++depth > config.maxDepth) {
|
|
249
|
+
return `[${stringedValue}]`;
|
|
250
|
+
}
|
|
251
|
+
return `${stringedValue + SPACE$2}{${printObjectProperties(val.sample, config, indentation, depth, refs, printer2)}}`;
|
|
252
|
+
}
|
|
253
|
+
if (stringedValue === "StringMatching" || stringedValue === "StringNotMatching") {
|
|
254
|
+
return stringedValue + SPACE$2 + printer2(val.sample, config, indentation, depth, refs);
|
|
255
|
+
}
|
|
256
|
+
if (stringedValue === "StringContaining" || stringedValue === "StringNotContaining") {
|
|
257
|
+
return stringedValue + SPACE$2 + printer2(val.sample, config, indentation, depth, refs);
|
|
258
|
+
}
|
|
259
|
+
if (typeof val.toAsymmetricMatcher !== "function") {
|
|
260
|
+
throw new TypeError(`Asymmetric matcher ${val.constructor.name} does not implement toAsymmetricMatcher()`);
|
|
261
|
+
}
|
|
262
|
+
return val.toAsymmetricMatcher();
|
|
263
|
+
};
|
|
264
|
+
const test$5 = (val) => val && val.$$typeof === asymmetricMatcher;
|
|
265
|
+
const plugin$5 = {
|
|
266
|
+
serialize: serialize$5,
|
|
267
|
+
test: test$5
|
|
268
|
+
};
|
|
269
|
+
const SPACE$1 = " ";
|
|
270
|
+
const OBJECT_NAMES = /* @__PURE__ */ new Set(["DOMStringMap", "NamedNodeMap"]);
|
|
271
|
+
const ARRAY_REGEXP = /^(?:HTML\w*Collection|NodeList)$/;
|
|
272
|
+
function testName(name) {
|
|
273
|
+
return OBJECT_NAMES.has(name) || ARRAY_REGEXP.test(name);
|
|
274
|
+
}
|
|
275
|
+
const test$4 = (val) => val && val.constructor && !!val.constructor.name && testName(val.constructor.name);
|
|
276
|
+
function isNamedNodeMap(collection) {
|
|
277
|
+
return collection.constructor.name === "NamedNodeMap";
|
|
278
|
+
}
|
|
279
|
+
const serialize$4 = (collection, config, indentation, depth, refs, printer2) => {
|
|
280
|
+
const name = collection.constructor.name;
|
|
281
|
+
if (++depth > config.maxDepth) {
|
|
282
|
+
return `[${name}]`;
|
|
283
|
+
}
|
|
284
|
+
return (config.min ? "" : name + SPACE$1) + (OBJECT_NAMES.has(name) ? `{${printObjectProperties(isNamedNodeMap(collection) ? [...collection].reduce((props, attribute) => {
|
|
285
|
+
props[attribute.name] = attribute.value;
|
|
286
|
+
return props;
|
|
287
|
+
}, {}) : { ...collection }, config, indentation, depth, refs, printer2)}}` : `[${printListItems([...collection], config, indentation, depth, refs, printer2)}]`);
|
|
288
|
+
};
|
|
289
|
+
const plugin$4 = {
|
|
290
|
+
serialize: serialize$4,
|
|
291
|
+
test: test$4
|
|
292
|
+
};
|
|
293
|
+
function escapeHTML(str) {
|
|
294
|
+
return str.replaceAll("<", "<").replaceAll(">", ">");
|
|
295
|
+
}
|
|
296
|
+
function printProps(keys, props, config, indentation, depth, refs, printer2) {
|
|
297
|
+
const indentationNext = indentation + config.indent;
|
|
298
|
+
const colors = config.colors;
|
|
299
|
+
return keys.map((key) => {
|
|
300
|
+
const value = props[key];
|
|
301
|
+
if (typeof value === "string" && value[0] === "_" && value.startsWith("__vitest_") && value.match(/__vitest_\d+__/)) {
|
|
302
|
+
return "";
|
|
303
|
+
}
|
|
304
|
+
let printed = printer2(value, config, indentationNext, depth, refs);
|
|
305
|
+
if (typeof value !== "string") {
|
|
306
|
+
if (printed.includes("\n")) {
|
|
307
|
+
printed = config.spacingOuter + indentationNext + printed + config.spacingOuter + indentation;
|
|
308
|
+
}
|
|
309
|
+
printed = `{${printed}}`;
|
|
310
|
+
}
|
|
311
|
+
return `${config.spacingInner + indentation + colors.prop.open + key + colors.prop.close}=${colors.value.open}${printed}${colors.value.close}`;
|
|
312
|
+
}).join("");
|
|
313
|
+
}
|
|
314
|
+
function printChildren(children, config, indentation, depth, refs, printer2) {
|
|
315
|
+
return children.map((child) => config.spacingOuter + indentation + (typeof child === "string" ? printText(child, config) : printer2(child, config, indentation, depth, refs))).join("");
|
|
316
|
+
}
|
|
317
|
+
function printShadowRoot(children, config, indentation, depth, refs, printer2) {
|
|
318
|
+
if (config.printShadowRoot === false) {
|
|
319
|
+
return "";
|
|
320
|
+
}
|
|
321
|
+
return [`${config.spacingOuter + indentation}#shadow-root`, printChildren(children, config, indentation + config.indent, depth, refs, printer2)].join("");
|
|
322
|
+
}
|
|
323
|
+
function printText(text, config) {
|
|
324
|
+
const contentColor = config.colors.content;
|
|
325
|
+
return contentColor.open + escapeHTML(text) + contentColor.close;
|
|
326
|
+
}
|
|
327
|
+
function printComment(comment, config) {
|
|
328
|
+
const commentColor = config.colors.comment;
|
|
329
|
+
return `${commentColor.open}<!--${escapeHTML(comment)}-->${commentColor.close}`;
|
|
330
|
+
}
|
|
331
|
+
function printElement(type, printedProps, printedChildren, config, indentation) {
|
|
332
|
+
const tagColor = config.colors.tag;
|
|
333
|
+
return `${tagColor.open}<${type}${printedProps && tagColor.close + printedProps + config.spacingOuter + indentation + tagColor.open}${printedChildren ? `>${tagColor.close}${printedChildren}${config.spacingOuter}${indentation}${tagColor.open}</${type}` : `${printedProps && !config.min ? "" : " "}/`}>${tagColor.close}`;
|
|
334
|
+
}
|
|
335
|
+
function printElementAsLeaf(type, config) {
|
|
336
|
+
const tagColor = config.colors.tag;
|
|
337
|
+
return `${tagColor.open}<${type}${tagColor.close} …${tagColor.open} />${tagColor.close}`;
|
|
338
|
+
}
|
|
339
|
+
const ELEMENT_NODE = 1;
|
|
340
|
+
const TEXT_NODE = 3;
|
|
341
|
+
const COMMENT_NODE = 8;
|
|
342
|
+
const FRAGMENT_NODE = 11;
|
|
343
|
+
const ELEMENT_REGEXP = /^(?:(?:HTML|SVG)\w*)?Element$/;
|
|
344
|
+
function testHasAttribute(val) {
|
|
345
|
+
try {
|
|
346
|
+
return typeof val.hasAttribute === "function" && val.hasAttribute("is");
|
|
347
|
+
} catch {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function testNode(val) {
|
|
352
|
+
const constructorName = val.constructor.name;
|
|
353
|
+
const { nodeType, tagName } = val;
|
|
354
|
+
const isCustomElement = typeof tagName === "string" && tagName.includes("-") || testHasAttribute(val);
|
|
355
|
+
return nodeType === ELEMENT_NODE && (ELEMENT_REGEXP.test(constructorName) || isCustomElement) || nodeType === TEXT_NODE && constructorName === "Text" || nodeType === COMMENT_NODE && constructorName === "Comment" || nodeType === FRAGMENT_NODE && constructorName === "DocumentFragment";
|
|
356
|
+
}
|
|
357
|
+
const test$3 = (val) => {
|
|
358
|
+
var _a;
|
|
359
|
+
return ((_a = val == null ? void 0 : val.constructor) == null ? void 0 : _a.name) && testNode(val);
|
|
360
|
+
};
|
|
361
|
+
function nodeIsText(node) {
|
|
362
|
+
return node.nodeType === TEXT_NODE;
|
|
363
|
+
}
|
|
364
|
+
function nodeIsComment(node) {
|
|
365
|
+
return node.nodeType === COMMENT_NODE;
|
|
366
|
+
}
|
|
367
|
+
function nodeIsFragment(node) {
|
|
368
|
+
return node.nodeType === FRAGMENT_NODE;
|
|
369
|
+
}
|
|
370
|
+
function filterChildren(children, filterNode) {
|
|
371
|
+
let filtered = children.filter((node) => {
|
|
372
|
+
if (node.nodeType === TEXT_NODE) {
|
|
373
|
+
const text = node.data || "";
|
|
374
|
+
return text.trim().length > 0;
|
|
375
|
+
}
|
|
376
|
+
return true;
|
|
377
|
+
});
|
|
378
|
+
if (filterNode) {
|
|
379
|
+
filtered = filtered.filter(filterNode);
|
|
380
|
+
}
|
|
381
|
+
return filtered;
|
|
382
|
+
}
|
|
383
|
+
function serializeDOM(node, config, indentation, depth, refs, printer2, filterNode) {
|
|
384
|
+
if (nodeIsText(node)) {
|
|
385
|
+
return printText(node.data, config);
|
|
386
|
+
}
|
|
387
|
+
if (nodeIsComment(node)) {
|
|
388
|
+
return printComment(node.data, config);
|
|
389
|
+
}
|
|
390
|
+
const type = nodeIsFragment(node) ? "DocumentFragment" : node.tagName.toLowerCase();
|
|
391
|
+
if (++depth > config.maxDepth) {
|
|
392
|
+
return printElementAsLeaf(type, config);
|
|
393
|
+
}
|
|
394
|
+
const children = Array.prototype.slice.call(node.childNodes || node.children);
|
|
395
|
+
const shadowChildren = nodeIsFragment(node) || !node.shadowRoot ? [] : Array.prototype.slice.call(node.shadowRoot.children);
|
|
396
|
+
const resolvedChildren = filterNode ? filterChildren(children, filterNode) : children;
|
|
397
|
+
const resolvedShadowChildren = filterNode ? filterChildren(shadowChildren, filterNode) : shadowChildren;
|
|
398
|
+
return printElement(type, printProps(nodeIsFragment(node) ? [] : Array.from(node.attributes, (attr) => attr.name).sort(), nodeIsFragment(node) ? {} : [...node.attributes].reduce((props, attribute) => {
|
|
399
|
+
props[attribute.name] = attribute.value;
|
|
400
|
+
return props;
|
|
401
|
+
}, {}), config, indentation + config.indent, depth, refs, printer2), (resolvedShadowChildren.length > 0 ? printShadowRoot(resolvedShadowChildren, config, indentation + config.indent, depth, refs, printer2) : "") + printChildren(resolvedChildren, config, indentation + config.indent, depth, refs, printer2), config, indentation);
|
|
402
|
+
}
|
|
403
|
+
const serialize$3 = (node, config, indentation, depth, refs, printer2) => serializeDOM(node, config, indentation, depth, refs, printer2);
|
|
404
|
+
function createDOMElementFilter(filterNode) {
|
|
405
|
+
return {
|
|
406
|
+
test: test$3,
|
|
407
|
+
serialize: (node, config, indentation, depth, refs, printer2) => serializeDOM(node, config, indentation, depth, refs, printer2, filterNode)
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
const plugin$3 = {
|
|
411
|
+
serialize: serialize$3,
|
|
412
|
+
test: test$3
|
|
413
|
+
};
|
|
414
|
+
const IS_ITERABLE_SENTINEL = "@@__IMMUTABLE_ITERABLE__@@";
|
|
415
|
+
const IS_LIST_SENTINEL = "@@__IMMUTABLE_LIST__@@";
|
|
416
|
+
const IS_KEYED_SENTINEL = "@@__IMMUTABLE_KEYED__@@";
|
|
417
|
+
const IS_MAP_SENTINEL = "@@__IMMUTABLE_MAP__@@";
|
|
418
|
+
const IS_ORDERED_SENTINEL = "@@__IMMUTABLE_ORDERED__@@";
|
|
419
|
+
const IS_RECORD_SENTINEL = "@@__IMMUTABLE_RECORD__@@";
|
|
420
|
+
const IS_SEQ_SENTINEL = "@@__IMMUTABLE_SEQ__@@";
|
|
421
|
+
const IS_SET_SENTINEL = "@@__IMMUTABLE_SET__@@";
|
|
422
|
+
const IS_STACK_SENTINEL = "@@__IMMUTABLE_STACK__@@";
|
|
423
|
+
const getImmutableName = (name) => `Immutable.${name}`;
|
|
424
|
+
const printAsLeaf = (name) => `[${name}]`;
|
|
425
|
+
const SPACE = " ";
|
|
426
|
+
const LAZY = "…";
|
|
427
|
+
function printImmutableEntries(val, config, indentation, depth, refs, printer2, type) {
|
|
428
|
+
return ++depth > config.maxDepth ? printAsLeaf(getImmutableName(type)) : `${getImmutableName(type) + SPACE}{${printIteratorEntries(val.entries(), config, indentation, depth, refs, printer2)}}`;
|
|
429
|
+
}
|
|
430
|
+
function getRecordEntries(val) {
|
|
431
|
+
let i = 0;
|
|
432
|
+
return { next() {
|
|
433
|
+
if (i < val._keys.length) {
|
|
434
|
+
const key = val._keys[i++];
|
|
435
|
+
return {
|
|
436
|
+
done: false,
|
|
437
|
+
value: [key, val.get(key)]
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
return {
|
|
441
|
+
done: true,
|
|
442
|
+
value: void 0
|
|
443
|
+
};
|
|
444
|
+
} };
|
|
445
|
+
}
|
|
446
|
+
function printImmutableRecord(val, config, indentation, depth, refs, printer2) {
|
|
447
|
+
const name = getImmutableName(val._name || "Record");
|
|
448
|
+
return ++depth > config.maxDepth ? printAsLeaf(name) : `${name + SPACE}{${printIteratorEntries(getRecordEntries(val), config, indentation, depth, refs, printer2)}}`;
|
|
449
|
+
}
|
|
450
|
+
function printImmutableSeq(val, config, indentation, depth, refs, printer2) {
|
|
451
|
+
const name = getImmutableName("Seq");
|
|
452
|
+
if (++depth > config.maxDepth) {
|
|
453
|
+
return printAsLeaf(name);
|
|
454
|
+
}
|
|
455
|
+
if (val[IS_KEYED_SENTINEL]) {
|
|
456
|
+
return `${name + SPACE}{${val._iter || val._object ? printIteratorEntries(val.entries(), config, indentation, depth, refs, printer2) : LAZY}}`;
|
|
457
|
+
}
|
|
458
|
+
return `${name + SPACE}[${val._iter || val._array || val._collection || val._iterable ? printIteratorValues(val.values(), config, indentation, depth, refs, printer2) : LAZY}]`;
|
|
459
|
+
}
|
|
460
|
+
function printImmutableValues(val, config, indentation, depth, refs, printer2, type) {
|
|
461
|
+
return ++depth > config.maxDepth ? printAsLeaf(getImmutableName(type)) : `${getImmutableName(type) + SPACE}[${printIteratorValues(val.values(), config, indentation, depth, refs, printer2)}]`;
|
|
462
|
+
}
|
|
463
|
+
const serialize$2 = (val, config, indentation, depth, refs, printer2) => {
|
|
464
|
+
if (val[IS_MAP_SENTINEL]) {
|
|
465
|
+
return printImmutableEntries(val, config, indentation, depth, refs, printer2, val[IS_ORDERED_SENTINEL] ? "OrderedMap" : "Map");
|
|
466
|
+
}
|
|
467
|
+
if (val[IS_LIST_SENTINEL]) {
|
|
468
|
+
return printImmutableValues(val, config, indentation, depth, refs, printer2, "List");
|
|
469
|
+
}
|
|
470
|
+
if (val[IS_SET_SENTINEL]) {
|
|
471
|
+
return printImmutableValues(val, config, indentation, depth, refs, printer2, val[IS_ORDERED_SENTINEL] ? "OrderedSet" : "Set");
|
|
472
|
+
}
|
|
473
|
+
if (val[IS_STACK_SENTINEL]) {
|
|
474
|
+
return printImmutableValues(val, config, indentation, depth, refs, printer2, "Stack");
|
|
475
|
+
}
|
|
476
|
+
if (val[IS_SEQ_SENTINEL]) {
|
|
477
|
+
return printImmutableSeq(val, config, indentation, depth, refs, printer2);
|
|
478
|
+
}
|
|
479
|
+
return printImmutableRecord(val, config, indentation, depth, refs, printer2);
|
|
480
|
+
};
|
|
481
|
+
const test$2 = (val) => val && (val[IS_ITERABLE_SENTINEL] === true || val[IS_RECORD_SENTINEL] === true);
|
|
482
|
+
const plugin$2 = {
|
|
483
|
+
serialize: serialize$2,
|
|
484
|
+
test: test$2
|
|
485
|
+
};
|
|
486
|
+
function getDefaultExportFromCjs(x) {
|
|
487
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
488
|
+
}
|
|
489
|
+
var reactIs$1 = { exports: {} };
|
|
490
|
+
var reactIs_production = {};
|
|
491
|
+
/**
|
|
492
|
+
* @license React
|
|
493
|
+
* react-is.production.js
|
|
494
|
+
*
|
|
495
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
496
|
+
*
|
|
497
|
+
* This source code is licensed under the MIT license found in the
|
|
498
|
+
* LICENSE file in the root directory of this source tree.
|
|
499
|
+
*/
|
|
500
|
+
var hasRequiredReactIs_production;
|
|
501
|
+
function requireReactIs_production() {
|
|
502
|
+
if (hasRequiredReactIs_production) return reactIs_production;
|
|
503
|
+
hasRequiredReactIs_production = 1;
|
|
504
|
+
var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"), REACT_PORTAL_TYPE = Symbol.for("react.portal"), REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"), REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"), REACT_PROFILER_TYPE = Symbol.for("react.profiler"), REACT_CONSUMER_TYPE = Symbol.for("react.consumer"), REACT_CONTEXT_TYPE = Symbol.for("react.context"), REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"), REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"), REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"), REACT_MEMO_TYPE = Symbol.for("react.memo"), REACT_LAZY_TYPE = Symbol.for("react.lazy"), REACT_VIEW_TRANSITION_TYPE = Symbol.for("react.view_transition"), REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference");
|
|
505
|
+
function typeOf(object) {
|
|
506
|
+
if ("object" === typeof object && null !== object) {
|
|
507
|
+
var $$typeof = object.$$typeof;
|
|
508
|
+
switch ($$typeof) {
|
|
509
|
+
case REACT_ELEMENT_TYPE:
|
|
510
|
+
switch (object = object.type, object) {
|
|
511
|
+
case REACT_FRAGMENT_TYPE:
|
|
512
|
+
case REACT_PROFILER_TYPE:
|
|
513
|
+
case REACT_STRICT_MODE_TYPE:
|
|
514
|
+
case REACT_SUSPENSE_TYPE:
|
|
515
|
+
case REACT_SUSPENSE_LIST_TYPE:
|
|
516
|
+
case REACT_VIEW_TRANSITION_TYPE:
|
|
517
|
+
return object;
|
|
518
|
+
default:
|
|
519
|
+
switch (object = object && object.$$typeof, object) {
|
|
520
|
+
case REACT_CONTEXT_TYPE:
|
|
521
|
+
case REACT_FORWARD_REF_TYPE:
|
|
522
|
+
case REACT_LAZY_TYPE:
|
|
523
|
+
case REACT_MEMO_TYPE:
|
|
524
|
+
return object;
|
|
525
|
+
case REACT_CONSUMER_TYPE:
|
|
526
|
+
return object;
|
|
527
|
+
default:
|
|
528
|
+
return $$typeof;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
case REACT_PORTAL_TYPE:
|
|
532
|
+
return $$typeof;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
reactIs_production.ContextConsumer = REACT_CONSUMER_TYPE;
|
|
537
|
+
reactIs_production.ContextProvider = REACT_CONTEXT_TYPE;
|
|
538
|
+
reactIs_production.Element = REACT_ELEMENT_TYPE;
|
|
539
|
+
reactIs_production.ForwardRef = REACT_FORWARD_REF_TYPE;
|
|
540
|
+
reactIs_production.Fragment = REACT_FRAGMENT_TYPE;
|
|
541
|
+
reactIs_production.Lazy = REACT_LAZY_TYPE;
|
|
542
|
+
reactIs_production.Memo = REACT_MEMO_TYPE;
|
|
543
|
+
reactIs_production.Portal = REACT_PORTAL_TYPE;
|
|
544
|
+
reactIs_production.Profiler = REACT_PROFILER_TYPE;
|
|
545
|
+
reactIs_production.StrictMode = REACT_STRICT_MODE_TYPE;
|
|
546
|
+
reactIs_production.Suspense = REACT_SUSPENSE_TYPE;
|
|
547
|
+
reactIs_production.SuspenseList = REACT_SUSPENSE_LIST_TYPE;
|
|
548
|
+
reactIs_production.isContextConsumer = function(object) {
|
|
549
|
+
return typeOf(object) === REACT_CONSUMER_TYPE;
|
|
550
|
+
};
|
|
551
|
+
reactIs_production.isContextProvider = function(object) {
|
|
552
|
+
return typeOf(object) === REACT_CONTEXT_TYPE;
|
|
553
|
+
};
|
|
554
|
+
reactIs_production.isElement = function(object) {
|
|
555
|
+
return "object" === typeof object && null !== object && object.$$typeof === REACT_ELEMENT_TYPE;
|
|
556
|
+
};
|
|
557
|
+
reactIs_production.isForwardRef = function(object) {
|
|
558
|
+
return typeOf(object) === REACT_FORWARD_REF_TYPE;
|
|
559
|
+
};
|
|
560
|
+
reactIs_production.isFragment = function(object) {
|
|
561
|
+
return typeOf(object) === REACT_FRAGMENT_TYPE;
|
|
562
|
+
};
|
|
563
|
+
reactIs_production.isLazy = function(object) {
|
|
564
|
+
return typeOf(object) === REACT_LAZY_TYPE;
|
|
565
|
+
};
|
|
566
|
+
reactIs_production.isMemo = function(object) {
|
|
567
|
+
return typeOf(object) === REACT_MEMO_TYPE;
|
|
568
|
+
};
|
|
569
|
+
reactIs_production.isPortal = function(object) {
|
|
570
|
+
return typeOf(object) === REACT_PORTAL_TYPE;
|
|
571
|
+
};
|
|
572
|
+
reactIs_production.isProfiler = function(object) {
|
|
573
|
+
return typeOf(object) === REACT_PROFILER_TYPE;
|
|
574
|
+
};
|
|
575
|
+
reactIs_production.isStrictMode = function(object) {
|
|
576
|
+
return typeOf(object) === REACT_STRICT_MODE_TYPE;
|
|
577
|
+
};
|
|
578
|
+
reactIs_production.isSuspense = function(object) {
|
|
579
|
+
return typeOf(object) === REACT_SUSPENSE_TYPE;
|
|
580
|
+
};
|
|
581
|
+
reactIs_production.isSuspenseList = function(object) {
|
|
582
|
+
return typeOf(object) === REACT_SUSPENSE_LIST_TYPE;
|
|
583
|
+
};
|
|
584
|
+
reactIs_production.isValidElementType = function(type) {
|
|
585
|
+
return "string" === typeof type || "function" === typeof type || type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || "object" === typeof type && null !== type && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_CONSUMER_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_CLIENT_REFERENCE || void 0 !== type.getModuleId) ? true : false;
|
|
586
|
+
};
|
|
587
|
+
reactIs_production.typeOf = typeOf;
|
|
588
|
+
return reactIs_production;
|
|
589
|
+
}
|
|
590
|
+
var hasRequiredReactIs$1;
|
|
591
|
+
function requireReactIs$1() {
|
|
592
|
+
if (hasRequiredReactIs$1) return reactIs$1.exports;
|
|
593
|
+
hasRequiredReactIs$1 = 1;
|
|
594
|
+
{
|
|
595
|
+
reactIs$1.exports = requireReactIs_production();
|
|
596
|
+
}
|
|
597
|
+
return reactIs$1.exports;
|
|
598
|
+
}
|
|
599
|
+
var reactIsExports$1 = requireReactIs$1();
|
|
600
|
+
var index$1 = /* @__PURE__ */ getDefaultExportFromCjs(reactIsExports$1);
|
|
601
|
+
var ReactIs19 = /* @__PURE__ */ _mergeNamespaces$1({
|
|
602
|
+
__proto__: null,
|
|
603
|
+
default: index$1
|
|
604
|
+
}, [reactIsExports$1]);
|
|
605
|
+
var reactIs = { exports: {} };
|
|
606
|
+
var reactIs_production_min = {};
|
|
607
|
+
/**
|
|
608
|
+
* @license React
|
|
609
|
+
* react-is.production.min.js
|
|
610
|
+
*
|
|
611
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
612
|
+
*
|
|
613
|
+
* This source code is licensed under the MIT license found in the
|
|
614
|
+
* LICENSE file in the root directory of this source tree.
|
|
615
|
+
*/
|
|
616
|
+
var hasRequiredReactIs_production_min;
|
|
617
|
+
function requireReactIs_production_min() {
|
|
618
|
+
if (hasRequiredReactIs_production_min) return reactIs_production_min;
|
|
619
|
+
hasRequiredReactIs_production_min = 1;
|
|
620
|
+
var b = Symbol.for("react.element"), c = Symbol.for("react.portal"), d2 = Symbol.for("react.fragment"), e = Symbol.for("react.strict_mode"), f2 = Symbol.for("react.profiler"), g2 = Symbol.for("react.provider"), h2 = Symbol.for("react.context"), k = Symbol.for("react.server_context"), l = Symbol.for("react.forward_ref"), m = Symbol.for("react.suspense"), n = Symbol.for("react.suspense_list"), p = Symbol.for("react.memo"), q = Symbol.for("react.lazy"), t = Symbol.for("react.offscreen"), u;
|
|
621
|
+
u = Symbol.for("react.module.reference");
|
|
622
|
+
function v(a) {
|
|
623
|
+
if ("object" === typeof a && null !== a) {
|
|
624
|
+
var r = a.$$typeof;
|
|
625
|
+
switch (r) {
|
|
626
|
+
case b:
|
|
627
|
+
switch (a = a.type, a) {
|
|
628
|
+
case d2:
|
|
629
|
+
case f2:
|
|
630
|
+
case e:
|
|
631
|
+
case m:
|
|
632
|
+
case n:
|
|
633
|
+
return a;
|
|
634
|
+
default:
|
|
635
|
+
switch (a = a && a.$$typeof, a) {
|
|
636
|
+
case k:
|
|
637
|
+
case h2:
|
|
638
|
+
case l:
|
|
639
|
+
case q:
|
|
640
|
+
case p:
|
|
641
|
+
case g2:
|
|
642
|
+
return a;
|
|
643
|
+
default:
|
|
644
|
+
return r;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
case c:
|
|
648
|
+
return r;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
reactIs_production_min.ContextConsumer = h2;
|
|
653
|
+
reactIs_production_min.ContextProvider = g2;
|
|
654
|
+
reactIs_production_min.Element = b;
|
|
655
|
+
reactIs_production_min.ForwardRef = l;
|
|
656
|
+
reactIs_production_min.Fragment = d2;
|
|
657
|
+
reactIs_production_min.Lazy = q;
|
|
658
|
+
reactIs_production_min.Memo = p;
|
|
659
|
+
reactIs_production_min.Portal = c;
|
|
660
|
+
reactIs_production_min.Profiler = f2;
|
|
661
|
+
reactIs_production_min.StrictMode = e;
|
|
662
|
+
reactIs_production_min.Suspense = m;
|
|
663
|
+
reactIs_production_min.SuspenseList = n;
|
|
664
|
+
reactIs_production_min.isAsyncMode = function() {
|
|
665
|
+
return false;
|
|
666
|
+
};
|
|
667
|
+
reactIs_production_min.isConcurrentMode = function() {
|
|
668
|
+
return false;
|
|
669
|
+
};
|
|
670
|
+
reactIs_production_min.isContextConsumer = function(a) {
|
|
671
|
+
return v(a) === h2;
|
|
672
|
+
};
|
|
673
|
+
reactIs_production_min.isContextProvider = function(a) {
|
|
674
|
+
return v(a) === g2;
|
|
675
|
+
};
|
|
676
|
+
reactIs_production_min.isElement = function(a) {
|
|
677
|
+
return "object" === typeof a && null !== a && a.$$typeof === b;
|
|
678
|
+
};
|
|
679
|
+
reactIs_production_min.isForwardRef = function(a) {
|
|
680
|
+
return v(a) === l;
|
|
681
|
+
};
|
|
682
|
+
reactIs_production_min.isFragment = function(a) {
|
|
683
|
+
return v(a) === d2;
|
|
684
|
+
};
|
|
685
|
+
reactIs_production_min.isLazy = function(a) {
|
|
686
|
+
return v(a) === q;
|
|
687
|
+
};
|
|
688
|
+
reactIs_production_min.isMemo = function(a) {
|
|
689
|
+
return v(a) === p;
|
|
690
|
+
};
|
|
691
|
+
reactIs_production_min.isPortal = function(a) {
|
|
692
|
+
return v(a) === c;
|
|
693
|
+
};
|
|
694
|
+
reactIs_production_min.isProfiler = function(a) {
|
|
695
|
+
return v(a) === f2;
|
|
696
|
+
};
|
|
697
|
+
reactIs_production_min.isStrictMode = function(a) {
|
|
698
|
+
return v(a) === e;
|
|
699
|
+
};
|
|
700
|
+
reactIs_production_min.isSuspense = function(a) {
|
|
701
|
+
return v(a) === m;
|
|
702
|
+
};
|
|
703
|
+
reactIs_production_min.isSuspenseList = function(a) {
|
|
704
|
+
return v(a) === n;
|
|
705
|
+
};
|
|
706
|
+
reactIs_production_min.isValidElementType = function(a) {
|
|
707
|
+
return "string" === typeof a || "function" === typeof a || a === d2 || a === f2 || a === e || a === m || a === n || a === t || "object" === typeof a && null !== a && (a.$$typeof === q || a.$$typeof === p || a.$$typeof === g2 || a.$$typeof === h2 || a.$$typeof === l || a.$$typeof === u || void 0 !== a.getModuleId) ? true : false;
|
|
708
|
+
};
|
|
709
|
+
reactIs_production_min.typeOf = v;
|
|
710
|
+
return reactIs_production_min;
|
|
711
|
+
}
|
|
712
|
+
var hasRequiredReactIs;
|
|
713
|
+
function requireReactIs() {
|
|
714
|
+
if (hasRequiredReactIs) return reactIs.exports;
|
|
715
|
+
hasRequiredReactIs = 1;
|
|
716
|
+
{
|
|
717
|
+
reactIs.exports = requireReactIs_production_min();
|
|
718
|
+
}
|
|
719
|
+
return reactIs.exports;
|
|
720
|
+
}
|
|
721
|
+
var reactIsExports = requireReactIs();
|
|
722
|
+
var index = /* @__PURE__ */ getDefaultExportFromCjs(reactIsExports);
|
|
723
|
+
var ReactIs18 = /* @__PURE__ */ _mergeNamespaces$1({
|
|
724
|
+
__proto__: null,
|
|
725
|
+
default: index
|
|
726
|
+
}, [reactIsExports]);
|
|
727
|
+
const reactIsMethods = [
|
|
728
|
+
"isAsyncMode",
|
|
729
|
+
"isConcurrentMode",
|
|
730
|
+
"isContextConsumer",
|
|
731
|
+
"isContextProvider",
|
|
732
|
+
"isElement",
|
|
733
|
+
"isForwardRef",
|
|
734
|
+
"isFragment",
|
|
735
|
+
"isLazy",
|
|
736
|
+
"isMemo",
|
|
737
|
+
"isPortal",
|
|
738
|
+
"isProfiler",
|
|
739
|
+
"isStrictMode",
|
|
740
|
+
"isSuspense",
|
|
741
|
+
"isSuspenseList",
|
|
742
|
+
"isValidElementType"
|
|
743
|
+
];
|
|
744
|
+
const ReactIs = Object.fromEntries(reactIsMethods.map((m) => [m, (v) => ReactIs18[m](v) || ReactIs19[m](v)]));
|
|
745
|
+
function getChildren(arg, children = []) {
|
|
746
|
+
if (Array.isArray(arg)) {
|
|
747
|
+
for (const item of arg) {
|
|
748
|
+
getChildren(item, children);
|
|
749
|
+
}
|
|
750
|
+
} else if (arg != null && arg !== false && arg !== "") {
|
|
751
|
+
children.push(arg);
|
|
752
|
+
}
|
|
753
|
+
return children;
|
|
754
|
+
}
|
|
755
|
+
function getType(element) {
|
|
756
|
+
const type = element.type;
|
|
757
|
+
if (typeof type === "string") {
|
|
758
|
+
return type;
|
|
759
|
+
}
|
|
760
|
+
if (typeof type === "function") {
|
|
761
|
+
return type.displayName || type.name || "Unknown";
|
|
762
|
+
}
|
|
763
|
+
if (ReactIs.isFragment(element)) {
|
|
764
|
+
return "React.Fragment";
|
|
765
|
+
}
|
|
766
|
+
if (ReactIs.isSuspense(element)) {
|
|
767
|
+
return "React.Suspense";
|
|
768
|
+
}
|
|
769
|
+
if (typeof type === "object" && type !== null) {
|
|
770
|
+
if (ReactIs.isContextProvider(element)) {
|
|
771
|
+
return "Context.Provider";
|
|
772
|
+
}
|
|
773
|
+
if (ReactIs.isContextConsumer(element)) {
|
|
774
|
+
return "Context.Consumer";
|
|
775
|
+
}
|
|
776
|
+
if (ReactIs.isForwardRef(element)) {
|
|
777
|
+
if (type.displayName) {
|
|
778
|
+
return type.displayName;
|
|
779
|
+
}
|
|
780
|
+
const functionName = type.render.displayName || type.render.name || "";
|
|
781
|
+
return functionName === "" ? "ForwardRef" : `ForwardRef(${functionName})`;
|
|
782
|
+
}
|
|
783
|
+
if (ReactIs.isMemo(element)) {
|
|
784
|
+
const functionName = type.displayName || type.type.displayName || type.type.name || "";
|
|
785
|
+
return functionName === "" ? "Memo" : `Memo(${functionName})`;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
return "UNDEFINED";
|
|
789
|
+
}
|
|
790
|
+
function getPropKeys$1(element) {
|
|
791
|
+
const { props } = element;
|
|
792
|
+
return Object.keys(props).filter((key) => key !== "children" && props[key] !== void 0).sort();
|
|
793
|
+
}
|
|
794
|
+
const serialize$1 = (element, config, indentation, depth, refs, printer2) => ++depth > config.maxDepth ? printElementAsLeaf(getType(element), config) : printElement(getType(element), printProps(getPropKeys$1(element), element.props, config, indentation + config.indent, depth, refs, printer2), printChildren(getChildren(element.props.children), config, indentation + config.indent, depth, refs, printer2), config, indentation);
|
|
795
|
+
const test$1 = (val) => val != null && ReactIs.isElement(val);
|
|
796
|
+
const plugin$1 = {
|
|
797
|
+
serialize: serialize$1,
|
|
798
|
+
test: test$1
|
|
799
|
+
};
|
|
800
|
+
const testSymbol = typeof Symbol === "function" && Symbol.for ? Symbol.for("react.test.json") : 245830487;
|
|
801
|
+
function getPropKeys(object) {
|
|
802
|
+
const { props } = object;
|
|
803
|
+
return props ? Object.keys(props).filter((key) => props[key] !== void 0).sort() : [];
|
|
804
|
+
}
|
|
805
|
+
const serialize = (object, config, indentation, depth, refs, printer2) => ++depth > config.maxDepth ? printElementAsLeaf(object.type, config) : printElement(object.type, object.props ? printProps(getPropKeys(object), object.props, config, indentation + config.indent, depth, refs, printer2) : "", object.children ? printChildren(object.children, config, indentation + config.indent, depth, refs, printer2) : "", config, indentation);
|
|
806
|
+
const test = (val) => val && val.$$typeof === testSymbol;
|
|
807
|
+
const plugin = {
|
|
808
|
+
serialize,
|
|
809
|
+
test
|
|
810
|
+
};
|
|
811
|
+
const toString$1 = Object.prototype.toString;
|
|
812
|
+
const toISOString = Date.prototype.toISOString;
|
|
813
|
+
const errorToString = Error.prototype.toString;
|
|
814
|
+
const regExpToString = RegExp.prototype.toString;
|
|
815
|
+
function getConstructorName(val) {
|
|
816
|
+
return typeof val.constructor === "function" && val.constructor.name || "Object";
|
|
817
|
+
}
|
|
818
|
+
function isWindow(val) {
|
|
819
|
+
return typeof window !== "undefined" && val === window;
|
|
820
|
+
}
|
|
821
|
+
const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/;
|
|
822
|
+
const NEWLINE_REGEXP = /\n/g;
|
|
823
|
+
class PrettyFormatPluginError extends Error {
|
|
824
|
+
constructor(message, stack) {
|
|
825
|
+
super(message);
|
|
826
|
+
this.stack = stack;
|
|
827
|
+
this.name = this.constructor.name;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
function isToStringedArrayType(toStringed) {
|
|
831
|
+
return toStringed === "[object Array]" || toStringed === "[object ArrayBuffer]" || toStringed === "[object DataView]" || toStringed === "[object Float32Array]" || toStringed === "[object Float64Array]" || toStringed === "[object Int8Array]" || toStringed === "[object Int16Array]" || toStringed === "[object Int32Array]" || toStringed === "[object Uint8Array]" || toStringed === "[object Uint8ClampedArray]" || toStringed === "[object Uint16Array]" || toStringed === "[object Uint32Array]";
|
|
832
|
+
}
|
|
833
|
+
function printNumber(val) {
|
|
834
|
+
return Object.is(val, -0) ? "-0" : String(val);
|
|
835
|
+
}
|
|
836
|
+
function printBigInt(val) {
|
|
837
|
+
return String(`${val}n`);
|
|
838
|
+
}
|
|
839
|
+
function printFunction(val, printFunctionName) {
|
|
840
|
+
if (!printFunctionName) {
|
|
841
|
+
return "[Function]";
|
|
842
|
+
}
|
|
843
|
+
return `[Function ${val.name || "anonymous"}]`;
|
|
844
|
+
}
|
|
845
|
+
function printSymbol(val) {
|
|
846
|
+
return String(val).replace(SYMBOL_REGEXP, "Symbol($1)");
|
|
847
|
+
}
|
|
848
|
+
function printError(val) {
|
|
849
|
+
return `[${errorToString.call(val)}]`;
|
|
850
|
+
}
|
|
851
|
+
function printBasicValue(val, printFunctionName, escapeRegex, escapeString) {
|
|
852
|
+
if (val === true || val === false) {
|
|
853
|
+
return `${val}`;
|
|
854
|
+
}
|
|
855
|
+
if (val === void 0) {
|
|
856
|
+
return "undefined";
|
|
857
|
+
}
|
|
858
|
+
if (val === null) {
|
|
859
|
+
return "null";
|
|
860
|
+
}
|
|
861
|
+
const typeOf = typeof val;
|
|
862
|
+
if (typeOf === "number") {
|
|
863
|
+
return printNumber(val);
|
|
864
|
+
}
|
|
865
|
+
if (typeOf === "bigint") {
|
|
866
|
+
return printBigInt(val);
|
|
867
|
+
}
|
|
868
|
+
if (typeOf === "string") {
|
|
869
|
+
if (escapeString) {
|
|
870
|
+
return `"${val.replaceAll(/"|\\/g, "\\$&")}"`;
|
|
871
|
+
}
|
|
872
|
+
return `"${val}"`;
|
|
873
|
+
}
|
|
874
|
+
if (typeOf === "function") {
|
|
875
|
+
return printFunction(val, printFunctionName);
|
|
876
|
+
}
|
|
877
|
+
if (typeOf === "symbol") {
|
|
878
|
+
return printSymbol(val);
|
|
879
|
+
}
|
|
880
|
+
const toStringed = toString$1.call(val);
|
|
881
|
+
if (toStringed === "[object WeakMap]") {
|
|
882
|
+
return "WeakMap {}";
|
|
883
|
+
}
|
|
884
|
+
if (toStringed === "[object WeakSet]") {
|
|
885
|
+
return "WeakSet {}";
|
|
886
|
+
}
|
|
887
|
+
if (toStringed === "[object Function]" || toStringed === "[object GeneratorFunction]") {
|
|
888
|
+
return printFunction(val, printFunctionName);
|
|
889
|
+
}
|
|
890
|
+
if (toStringed === "[object Symbol]") {
|
|
891
|
+
return printSymbol(val);
|
|
892
|
+
}
|
|
893
|
+
if (toStringed === "[object Date]") {
|
|
894
|
+
return Number.isNaN(+val) ? "Date { NaN }" : toISOString.call(val);
|
|
895
|
+
}
|
|
896
|
+
if (toStringed === "[object Error]") {
|
|
897
|
+
return printError(val);
|
|
898
|
+
}
|
|
899
|
+
if (toStringed === "[object RegExp]") {
|
|
900
|
+
if (escapeRegex) {
|
|
901
|
+
return regExpToString.call(val).replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");
|
|
902
|
+
}
|
|
903
|
+
return regExpToString.call(val);
|
|
904
|
+
}
|
|
905
|
+
if (val instanceof Error) {
|
|
906
|
+
return printError(val);
|
|
907
|
+
}
|
|
908
|
+
return null;
|
|
909
|
+
}
|
|
910
|
+
function printComplexValue(val, config, indentation, depth, refs, hasCalledToJSON) {
|
|
911
|
+
if (refs.includes(val)) {
|
|
912
|
+
return "[Circular]";
|
|
913
|
+
}
|
|
914
|
+
refs = [...refs];
|
|
915
|
+
refs.push(val);
|
|
916
|
+
const hitMaxDepth = ++depth > config.maxDepth;
|
|
917
|
+
const min = config.min;
|
|
918
|
+
if (config.callToJSON && !hitMaxDepth && val.toJSON && typeof val.toJSON === "function" && !hasCalledToJSON) {
|
|
919
|
+
return printer(val.toJSON(), config, indentation, depth, refs, true);
|
|
920
|
+
}
|
|
921
|
+
const toStringed = toString$1.call(val);
|
|
922
|
+
if (toStringed === "[object Arguments]") {
|
|
923
|
+
return hitMaxDepth ? "[Arguments]" : `${min ? "" : "Arguments "}[${printListItems(val, config, indentation, depth, refs, printer)}]`;
|
|
924
|
+
}
|
|
925
|
+
if (isToStringedArrayType(toStringed)) {
|
|
926
|
+
return hitMaxDepth ? `[${val.constructor.name}]` : `${min ? "" : !config.printBasicPrototype && val.constructor.name === "Array" ? "" : `${val.constructor.name} `}[${printListItems(val, config, indentation, depth, refs, printer)}]`;
|
|
927
|
+
}
|
|
928
|
+
if (toStringed === "[object Map]") {
|
|
929
|
+
return hitMaxDepth ? "[Map]" : `Map {${printIteratorEntries(val.entries(), config, indentation, depth, refs, printer, " => ")}}`;
|
|
930
|
+
}
|
|
931
|
+
if (toStringed === "[object Set]") {
|
|
932
|
+
return hitMaxDepth ? "[Set]" : `Set {${printIteratorValues(val.values(), config, indentation, depth, refs, printer)}}`;
|
|
933
|
+
}
|
|
934
|
+
return hitMaxDepth || isWindow(val) ? `[${getConstructorName(val)}]` : `${min ? "" : !config.printBasicPrototype && getConstructorName(val) === "Object" ? "" : `${getConstructorName(val)} `}{${printObjectProperties(val, config, indentation, depth, refs, printer)}}`;
|
|
935
|
+
}
|
|
936
|
+
function isNewPlugin(plugin2) {
|
|
937
|
+
return plugin2.serialize != null;
|
|
938
|
+
}
|
|
939
|
+
function printPlugin(plugin2, val, config, indentation, depth, refs) {
|
|
940
|
+
let printed;
|
|
941
|
+
try {
|
|
942
|
+
printed = isNewPlugin(plugin2) ? plugin2.serialize(val, config, indentation, depth, refs, printer) : plugin2.print(val, (valChild) => printer(valChild, config, indentation, depth, refs), (str) => {
|
|
943
|
+
const indentationNext = indentation + config.indent;
|
|
944
|
+
return indentationNext + str.replaceAll(NEWLINE_REGEXP, `
|
|
945
|
+
${indentationNext}`);
|
|
946
|
+
}, {
|
|
947
|
+
edgeSpacing: config.spacingOuter,
|
|
948
|
+
min: config.min,
|
|
949
|
+
spacing: config.spacingInner
|
|
950
|
+
}, config.colors);
|
|
951
|
+
} catch (error) {
|
|
952
|
+
throw new PrettyFormatPluginError(error.message, error.stack);
|
|
953
|
+
}
|
|
954
|
+
if (typeof printed !== "string") {
|
|
955
|
+
throw new TypeError(`pretty-format: Plugin must return type "string" but instead returned "${typeof printed}".`);
|
|
956
|
+
}
|
|
957
|
+
return printed;
|
|
958
|
+
}
|
|
959
|
+
function findPlugin(plugins2, val) {
|
|
960
|
+
for (const plugin2 of plugins2) {
|
|
961
|
+
try {
|
|
962
|
+
if (plugin2.test(val)) {
|
|
963
|
+
return plugin2;
|
|
964
|
+
}
|
|
965
|
+
} catch (error) {
|
|
966
|
+
throw new PrettyFormatPluginError(error.message, error.stack);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
return null;
|
|
970
|
+
}
|
|
971
|
+
function printer(val, config, indentation, depth, refs, hasCalledToJSON) {
|
|
972
|
+
let result;
|
|
973
|
+
const plugin2 = findPlugin(config.plugins, val);
|
|
974
|
+
if (plugin2 !== null) {
|
|
975
|
+
result = printPlugin(plugin2, val, config, indentation, depth, refs);
|
|
976
|
+
} else {
|
|
977
|
+
const basicResult = printBasicValue(val, config.printFunctionName, config.escapeRegex, config.escapeString);
|
|
978
|
+
if (basicResult !== null) {
|
|
979
|
+
result = basicResult;
|
|
980
|
+
} else {
|
|
981
|
+
result = printComplexValue(val, config, indentation, depth, refs, hasCalledToJSON);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
config.outputLength += result.length;
|
|
985
|
+
if (config.outputLength > config.maxOutputLength) {
|
|
986
|
+
config.maxDepth = 0;
|
|
987
|
+
}
|
|
988
|
+
return result;
|
|
989
|
+
}
|
|
990
|
+
const DEFAULT_THEME = {
|
|
991
|
+
comment: "gray",
|
|
992
|
+
content: "reset",
|
|
993
|
+
prop: "yellow",
|
|
994
|
+
tag: "cyan",
|
|
995
|
+
value: "green"
|
|
996
|
+
};
|
|
997
|
+
const DEFAULT_THEME_KEYS = Object.keys(DEFAULT_THEME);
|
|
998
|
+
const DEFAULT_OPTIONS = {
|
|
999
|
+
callToJSON: true,
|
|
1000
|
+
compareKeys: void 0,
|
|
1001
|
+
escapeRegex: false,
|
|
1002
|
+
escapeString: true,
|
|
1003
|
+
highlight: false,
|
|
1004
|
+
indent: 2,
|
|
1005
|
+
maxDepth: Number.POSITIVE_INFINITY,
|
|
1006
|
+
maxOutputLength: 1e6,
|
|
1007
|
+
maxWidth: Number.POSITIVE_INFINITY,
|
|
1008
|
+
min: false,
|
|
1009
|
+
plugins: [],
|
|
1010
|
+
printBasicPrototype: true,
|
|
1011
|
+
printFunctionName: true,
|
|
1012
|
+
printShadowRoot: true,
|
|
1013
|
+
theme: DEFAULT_THEME
|
|
1014
|
+
};
|
|
1015
|
+
function validateOptions(options) {
|
|
1016
|
+
for (const key of Object.keys(options)) {
|
|
1017
|
+
if (!Object.hasOwn(DEFAULT_OPTIONS, key)) {
|
|
1018
|
+
throw new Error(`pretty-format: Unknown option "${key}".`);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
if (options.min && options.indent !== void 0 && options.indent !== 0) {
|
|
1022
|
+
throw new Error('pretty-format: Options "min" and "indent" cannot be used together.');
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
function getColorsHighlight() {
|
|
1026
|
+
return DEFAULT_THEME_KEYS.reduce((colors, key) => {
|
|
1027
|
+
const value = DEFAULT_THEME[key];
|
|
1028
|
+
const color = value && C[value];
|
|
1029
|
+
if (color && typeof color.close === "string" && typeof color.open === "string") {
|
|
1030
|
+
colors[key] = color;
|
|
1031
|
+
} else {
|
|
1032
|
+
throw new Error(`pretty-format: Option "theme" has a key "${key}" whose value "${value}" is undefined in ansi-styles.`);
|
|
1033
|
+
}
|
|
1034
|
+
return colors;
|
|
1035
|
+
}, /* @__PURE__ */ Object.create(null));
|
|
1036
|
+
}
|
|
1037
|
+
function getColorsEmpty() {
|
|
1038
|
+
return DEFAULT_THEME_KEYS.reduce((colors, key) => {
|
|
1039
|
+
colors[key] = {
|
|
1040
|
+
close: "",
|
|
1041
|
+
open: ""
|
|
1042
|
+
};
|
|
1043
|
+
return colors;
|
|
1044
|
+
}, /* @__PURE__ */ Object.create(null));
|
|
1045
|
+
}
|
|
1046
|
+
function getPrintFunctionName(options) {
|
|
1047
|
+
return (options == null ? void 0 : options.printFunctionName) ?? DEFAULT_OPTIONS.printFunctionName;
|
|
1048
|
+
}
|
|
1049
|
+
function getEscapeRegex(options) {
|
|
1050
|
+
return (options == null ? void 0 : options.escapeRegex) ?? DEFAULT_OPTIONS.escapeRegex;
|
|
1051
|
+
}
|
|
1052
|
+
function getEscapeString(options) {
|
|
1053
|
+
return (options == null ? void 0 : options.escapeString) ?? DEFAULT_OPTIONS.escapeString;
|
|
1054
|
+
}
|
|
1055
|
+
function getConfig$1(options) {
|
|
1056
|
+
return {
|
|
1057
|
+
callToJSON: (options == null ? void 0 : options.callToJSON) ?? DEFAULT_OPTIONS.callToJSON,
|
|
1058
|
+
colors: (options == null ? void 0 : options.highlight) ? getColorsHighlight() : getColorsEmpty(),
|
|
1059
|
+
compareKeys: typeof (options == null ? void 0 : options.compareKeys) === "function" || (options == null ? void 0 : options.compareKeys) === null ? options.compareKeys : DEFAULT_OPTIONS.compareKeys,
|
|
1060
|
+
escapeRegex: getEscapeRegex(options),
|
|
1061
|
+
escapeString: getEscapeString(options),
|
|
1062
|
+
indent: (options == null ? void 0 : options.min) ? "" : createIndent((options == null ? void 0 : options.indent) ?? DEFAULT_OPTIONS.indent),
|
|
1063
|
+
maxDepth: (options == null ? void 0 : options.maxDepth) ?? DEFAULT_OPTIONS.maxDepth,
|
|
1064
|
+
maxWidth: (options == null ? void 0 : options.maxWidth) ?? DEFAULT_OPTIONS.maxWidth,
|
|
1065
|
+
min: (options == null ? void 0 : options.min) ?? DEFAULT_OPTIONS.min,
|
|
1066
|
+
plugins: (options == null ? void 0 : options.plugins) ?? DEFAULT_OPTIONS.plugins,
|
|
1067
|
+
printBasicPrototype: (options == null ? void 0 : options.printBasicPrototype) ?? true,
|
|
1068
|
+
printFunctionName: getPrintFunctionName(options),
|
|
1069
|
+
printShadowRoot: (options == null ? void 0 : options.printShadowRoot) ?? true,
|
|
1070
|
+
spacingInner: (options == null ? void 0 : options.min) ? " " : "\n",
|
|
1071
|
+
spacingOuter: (options == null ? void 0 : options.min) ? "" : "\n",
|
|
1072
|
+
maxOutputLength: (options == null ? void 0 : options.maxOutputLength) ?? DEFAULT_OPTIONS.maxOutputLength,
|
|
1073
|
+
outputLength: 0
|
|
1074
|
+
};
|
|
1075
|
+
}
|
|
1076
|
+
function createIndent(indent) {
|
|
1077
|
+
return Array.from({ length: indent + 1 }).join(" ");
|
|
1078
|
+
}
|
|
1079
|
+
function format$1(val, options) {
|
|
1080
|
+
if (options) {
|
|
1081
|
+
validateOptions(options);
|
|
1082
|
+
if (options.plugins) {
|
|
1083
|
+
const plugin2 = findPlugin(options.plugins, val);
|
|
1084
|
+
if (plugin2 !== null) {
|
|
1085
|
+
return printPlugin(plugin2, val, getConfig$1(options), "", 0, []);
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
const basicResult = printBasicValue(val, getPrintFunctionName(options), getEscapeRegex(options), getEscapeString(options));
|
|
1090
|
+
if (basicResult !== null) {
|
|
1091
|
+
return basicResult;
|
|
1092
|
+
}
|
|
1093
|
+
return printComplexValue(val, getConfig$1(options), "", 0, []);
|
|
1094
|
+
}
|
|
1095
|
+
const plugins = {
|
|
1096
|
+
AsymmetricMatcher: plugin$5,
|
|
1097
|
+
DOMCollection: plugin$4,
|
|
1098
|
+
DOMElement: plugin$3,
|
|
1099
|
+
Immutable: plugin$2,
|
|
1100
|
+
ReactElement: plugin$1,
|
|
1101
|
+
ReactTestComponent: plugin
|
|
1102
|
+
};
|
|
1103
|
+
const ansiColors = {
|
|
1104
|
+
bold: ["1", "22"],
|
|
1105
|
+
dim: ["2", "22"],
|
|
1106
|
+
italic: ["3", "23"],
|
|
1107
|
+
underline: ["4", "24"],
|
|
1108
|
+
// 5 & 6 are blinking
|
|
1109
|
+
inverse: ["7", "27"],
|
|
1110
|
+
hidden: ["8", "28"],
|
|
1111
|
+
strike: ["9", "29"],
|
|
1112
|
+
// 10-20 are fonts
|
|
1113
|
+
// 21-29 are resets for 1-9
|
|
1114
|
+
black: ["30", "39"],
|
|
1115
|
+
red: ["31", "39"],
|
|
1116
|
+
green: ["32", "39"],
|
|
1117
|
+
yellow: ["33", "39"],
|
|
1118
|
+
blue: ["34", "39"],
|
|
1119
|
+
magenta: ["35", "39"],
|
|
1120
|
+
cyan: ["36", "39"],
|
|
1121
|
+
white: ["37", "39"],
|
|
1122
|
+
brightblack: ["30;1", "39"],
|
|
1123
|
+
brightred: ["31;1", "39"],
|
|
1124
|
+
brightgreen: ["32;1", "39"],
|
|
1125
|
+
brightyellow: ["33;1", "39"],
|
|
1126
|
+
brightblue: ["34;1", "39"],
|
|
1127
|
+
brightmagenta: ["35;1", "39"],
|
|
1128
|
+
brightcyan: ["36;1", "39"],
|
|
1129
|
+
brightwhite: ["37;1", "39"],
|
|
1130
|
+
grey: ["90", "39"]
|
|
1131
|
+
};
|
|
1132
|
+
const styles = {
|
|
1133
|
+
special: "cyan",
|
|
1134
|
+
number: "yellow",
|
|
1135
|
+
bigint: "yellow",
|
|
1136
|
+
boolean: "yellow",
|
|
1137
|
+
undefined: "grey",
|
|
1138
|
+
null: "bold",
|
|
1139
|
+
string: "green",
|
|
1140
|
+
symbol: "green",
|
|
1141
|
+
date: "magenta",
|
|
1142
|
+
regexp: "red"
|
|
1143
|
+
};
|
|
1144
|
+
const truncator = "…";
|
|
1145
|
+
function colorise(value, styleType) {
|
|
1146
|
+
const color = ansiColors[styles[styleType]] || ansiColors[styleType] || "";
|
|
1147
|
+
if (!color) {
|
|
1148
|
+
return String(value);
|
|
1149
|
+
}
|
|
1150
|
+
return `\x1B[${color[0]}m${String(value)}\x1B[${color[1]}m`;
|
|
1151
|
+
}
|
|
1152
|
+
function normaliseOptions({
|
|
1153
|
+
showHidden = false,
|
|
1154
|
+
depth = 2,
|
|
1155
|
+
colors = false,
|
|
1156
|
+
customInspect = true,
|
|
1157
|
+
showProxy = false,
|
|
1158
|
+
maxArrayLength = Infinity,
|
|
1159
|
+
breakLength = Infinity,
|
|
1160
|
+
seen = [],
|
|
1161
|
+
// eslint-disable-next-line no-shadow
|
|
1162
|
+
truncate: truncate2 = Infinity,
|
|
1163
|
+
stylize = String
|
|
1164
|
+
} = {}, inspect2) {
|
|
1165
|
+
const options = {
|
|
1166
|
+
showHidden: Boolean(showHidden),
|
|
1167
|
+
depth: Number(depth),
|
|
1168
|
+
colors: Boolean(colors),
|
|
1169
|
+
customInspect: Boolean(customInspect),
|
|
1170
|
+
showProxy: Boolean(showProxy),
|
|
1171
|
+
maxArrayLength: Number(maxArrayLength),
|
|
1172
|
+
breakLength: Number(breakLength),
|
|
1173
|
+
truncate: Number(truncate2),
|
|
1174
|
+
seen,
|
|
1175
|
+
inspect: inspect2,
|
|
1176
|
+
stylize
|
|
1177
|
+
};
|
|
1178
|
+
if (options.colors) {
|
|
1179
|
+
options.stylize = colorise;
|
|
1180
|
+
}
|
|
1181
|
+
return options;
|
|
1182
|
+
}
|
|
1183
|
+
function isHighSurrogate(char) {
|
|
1184
|
+
return char >= "\uD800" && char <= "\uDBFF";
|
|
1185
|
+
}
|
|
1186
|
+
function truncate(string, length, tail = truncator) {
|
|
1187
|
+
string = String(string);
|
|
1188
|
+
const tailLength = tail.length;
|
|
1189
|
+
const stringLength = string.length;
|
|
1190
|
+
if (tailLength > length && stringLength > tailLength) {
|
|
1191
|
+
return tail;
|
|
1192
|
+
}
|
|
1193
|
+
if (stringLength > length && stringLength > tailLength) {
|
|
1194
|
+
let end = length - tailLength;
|
|
1195
|
+
if (end > 0 && isHighSurrogate(string[end - 1])) {
|
|
1196
|
+
end = end - 1;
|
|
1197
|
+
}
|
|
1198
|
+
return `${string.slice(0, end)}${tail}`;
|
|
1199
|
+
}
|
|
1200
|
+
return string;
|
|
1201
|
+
}
|
|
1202
|
+
function inspectList(list, options, inspectItem, separator = ", ") {
|
|
1203
|
+
inspectItem = inspectItem || options.inspect;
|
|
1204
|
+
const size = list.length;
|
|
1205
|
+
if (size === 0)
|
|
1206
|
+
return "";
|
|
1207
|
+
const originalLength = options.truncate;
|
|
1208
|
+
let output = "";
|
|
1209
|
+
let peek = "";
|
|
1210
|
+
let truncated = "";
|
|
1211
|
+
for (let i = 0; i < size; i += 1) {
|
|
1212
|
+
const last = i + 1 === list.length;
|
|
1213
|
+
const secondToLast = i + 2 === list.length;
|
|
1214
|
+
truncated = `${truncator}(${list.length - i})`;
|
|
1215
|
+
const value = list[i];
|
|
1216
|
+
options.truncate = originalLength - output.length - (last ? 0 : separator.length);
|
|
1217
|
+
const string = peek || inspectItem(value, options) + (last ? "" : separator);
|
|
1218
|
+
const nextLength = output.length + string.length;
|
|
1219
|
+
const truncatedLength = nextLength + truncated.length;
|
|
1220
|
+
if (last && nextLength > originalLength && output.length + truncated.length <= originalLength) {
|
|
1221
|
+
break;
|
|
1222
|
+
}
|
|
1223
|
+
if (!last && !secondToLast && truncatedLength > originalLength) {
|
|
1224
|
+
break;
|
|
1225
|
+
}
|
|
1226
|
+
peek = last ? "" : inspectItem(list[i + 1], options) + (secondToLast ? "" : separator);
|
|
1227
|
+
if (!last && secondToLast && truncatedLength > originalLength && nextLength + peek.length > originalLength) {
|
|
1228
|
+
break;
|
|
1229
|
+
}
|
|
1230
|
+
output += string;
|
|
1231
|
+
if (!last && !secondToLast && nextLength + peek.length >= originalLength) {
|
|
1232
|
+
truncated = `${truncator}(${list.length - i - 1})`;
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
1235
|
+
truncated = "";
|
|
1236
|
+
}
|
|
1237
|
+
return `${output}${truncated}`;
|
|
1238
|
+
}
|
|
1239
|
+
function quoteComplexKey(key) {
|
|
1240
|
+
if (key.match(/^[a-zA-Z_][a-zA-Z_0-9]*$/)) {
|
|
1241
|
+
return key;
|
|
1242
|
+
}
|
|
1243
|
+
return JSON.stringify(key).replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
|
|
1244
|
+
}
|
|
1245
|
+
function inspectProperty([key, value], options) {
|
|
1246
|
+
options.truncate -= 2;
|
|
1247
|
+
if (typeof key === "string") {
|
|
1248
|
+
key = quoteComplexKey(key);
|
|
1249
|
+
} else if (typeof key !== "number") {
|
|
1250
|
+
key = `[${options.inspect(key, options)}]`;
|
|
1251
|
+
}
|
|
1252
|
+
options.truncate -= key.length;
|
|
1253
|
+
value = options.inspect(value, options);
|
|
1254
|
+
return `${key}: ${value}`;
|
|
1255
|
+
}
|
|
1256
|
+
function inspectArray(array, options) {
|
|
1257
|
+
const nonIndexProperties = Object.keys(array).slice(array.length);
|
|
1258
|
+
if (!array.length && !nonIndexProperties.length)
|
|
1259
|
+
return "[]";
|
|
1260
|
+
options.truncate -= 4;
|
|
1261
|
+
const listContents = inspectList(array, options);
|
|
1262
|
+
options.truncate -= listContents.length;
|
|
1263
|
+
let propertyContents = "";
|
|
1264
|
+
if (nonIndexProperties.length) {
|
|
1265
|
+
propertyContents = inspectList(nonIndexProperties.map((key) => [key, array[key]]), options, inspectProperty);
|
|
1266
|
+
}
|
|
1267
|
+
return `[ ${listContents}${propertyContents ? `, ${propertyContents}` : ""} ]`;
|
|
1268
|
+
}
|
|
1269
|
+
const getArrayName = (array) => {
|
|
1270
|
+
if (typeof Buffer === "function" && array instanceof Buffer) {
|
|
1271
|
+
return "Buffer";
|
|
1272
|
+
}
|
|
1273
|
+
if (array[Symbol.toStringTag]) {
|
|
1274
|
+
return array[Symbol.toStringTag];
|
|
1275
|
+
}
|
|
1276
|
+
return array.constructor.name;
|
|
1277
|
+
};
|
|
1278
|
+
function inspectTypedArray(array, options) {
|
|
1279
|
+
const name = getArrayName(array);
|
|
1280
|
+
options.truncate -= name.length + 4;
|
|
1281
|
+
const nonIndexProperties = Object.keys(array).slice(array.length);
|
|
1282
|
+
if (!array.length && !nonIndexProperties.length)
|
|
1283
|
+
return `${name}[]`;
|
|
1284
|
+
let output = "";
|
|
1285
|
+
for (let i = 0; i < array.length; i++) {
|
|
1286
|
+
const string = `${options.stylize(truncate(array[i], options.truncate), "number")}${i === array.length - 1 ? "" : ", "}`;
|
|
1287
|
+
options.truncate -= string.length;
|
|
1288
|
+
if (array[i] !== array.length && options.truncate <= 3) {
|
|
1289
|
+
output += `${truncator}(${array.length - array[i] + 1})`;
|
|
1290
|
+
break;
|
|
1291
|
+
}
|
|
1292
|
+
output += string;
|
|
1293
|
+
}
|
|
1294
|
+
let propertyContents = "";
|
|
1295
|
+
if (nonIndexProperties.length) {
|
|
1296
|
+
propertyContents = inspectList(nonIndexProperties.map((key) => [key, array[key]]), options, inspectProperty);
|
|
1297
|
+
}
|
|
1298
|
+
return `${name}[ ${output}${propertyContents ? `, ${propertyContents}` : ""} ]`;
|
|
1299
|
+
}
|
|
1300
|
+
function inspectDate(dateObject, options) {
|
|
1301
|
+
const stringRepresentation = dateObject.toJSON();
|
|
1302
|
+
if (stringRepresentation === null) {
|
|
1303
|
+
return "Invalid Date";
|
|
1304
|
+
}
|
|
1305
|
+
const split = stringRepresentation.split("T");
|
|
1306
|
+
const date = split[0];
|
|
1307
|
+
return options.stylize(`${date}T${truncate(split[1], options.truncate - date.length - 1)}`, "date");
|
|
1308
|
+
}
|
|
1309
|
+
function inspectFunction(func, options) {
|
|
1310
|
+
const functionType = func[Symbol.toStringTag] || "Function";
|
|
1311
|
+
const name = func.name;
|
|
1312
|
+
if (!name) {
|
|
1313
|
+
return options.stylize(`[${functionType}]`, "special");
|
|
1314
|
+
}
|
|
1315
|
+
return options.stylize(`[${functionType} ${truncate(name, options.truncate - 11)}]`, "special");
|
|
1316
|
+
}
|
|
1317
|
+
function inspectMapEntry([key, value], options) {
|
|
1318
|
+
options.truncate -= 4;
|
|
1319
|
+
key = options.inspect(key, options);
|
|
1320
|
+
options.truncate -= key.length;
|
|
1321
|
+
value = options.inspect(value, options);
|
|
1322
|
+
return `${key} => ${value}`;
|
|
1323
|
+
}
|
|
1324
|
+
function mapToEntries(map) {
|
|
1325
|
+
const entries = [];
|
|
1326
|
+
map.forEach((value, key) => {
|
|
1327
|
+
entries.push([key, value]);
|
|
1328
|
+
});
|
|
1329
|
+
return entries;
|
|
1330
|
+
}
|
|
1331
|
+
function inspectMap(map, options) {
|
|
1332
|
+
if (map.size === 0)
|
|
1333
|
+
return "Map{}";
|
|
1334
|
+
options.truncate -= 7;
|
|
1335
|
+
return `Map{ ${inspectList(mapToEntries(map), options, inspectMapEntry)} }`;
|
|
1336
|
+
}
|
|
1337
|
+
const isNaN = Number.isNaN || ((i) => i !== i);
|
|
1338
|
+
function inspectNumber(number, options) {
|
|
1339
|
+
if (isNaN(number)) {
|
|
1340
|
+
return options.stylize("NaN", "number");
|
|
1341
|
+
}
|
|
1342
|
+
if (number === Infinity) {
|
|
1343
|
+
return options.stylize("Infinity", "number");
|
|
1344
|
+
}
|
|
1345
|
+
if (number === -Infinity) {
|
|
1346
|
+
return options.stylize("-Infinity", "number");
|
|
1347
|
+
}
|
|
1348
|
+
if (number === 0) {
|
|
1349
|
+
return options.stylize(1 / number === Infinity ? "+0" : "-0", "number");
|
|
1350
|
+
}
|
|
1351
|
+
return options.stylize(truncate(String(number), options.truncate), "number");
|
|
1352
|
+
}
|
|
1353
|
+
function inspectBigInt(number, options) {
|
|
1354
|
+
let nums = truncate(number.toString(), options.truncate - 1);
|
|
1355
|
+
if (nums !== truncator)
|
|
1356
|
+
nums += "n";
|
|
1357
|
+
return options.stylize(nums, "bigint");
|
|
1358
|
+
}
|
|
1359
|
+
function inspectRegExp(value, options) {
|
|
1360
|
+
const flags = value.toString().split("/")[2];
|
|
1361
|
+
const sourceLength = options.truncate - (2 + flags.length);
|
|
1362
|
+
const source = value.source;
|
|
1363
|
+
return options.stylize(`/${truncate(source, sourceLength)}/${flags}`, "regexp");
|
|
1364
|
+
}
|
|
1365
|
+
function arrayFromSet(set) {
|
|
1366
|
+
const values = [];
|
|
1367
|
+
set.forEach((value) => {
|
|
1368
|
+
values.push(value);
|
|
1369
|
+
});
|
|
1370
|
+
return values;
|
|
1371
|
+
}
|
|
1372
|
+
function inspectSet(set, options) {
|
|
1373
|
+
if (set.size === 0)
|
|
1374
|
+
return "Set{}";
|
|
1375
|
+
options.truncate -= 7;
|
|
1376
|
+
return `Set{ ${inspectList(arrayFromSet(set), options)} }`;
|
|
1377
|
+
}
|
|
1378
|
+
const stringEscapeChars = new RegExp("['\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]", "g");
|
|
1379
|
+
const escapeCharacters = {
|
|
1380
|
+
"\b": "\\b",
|
|
1381
|
+
" ": "\\t",
|
|
1382
|
+
"\n": "\\n",
|
|
1383
|
+
"\f": "\\f",
|
|
1384
|
+
"\r": "\\r",
|
|
1385
|
+
"'": "\\'",
|
|
1386
|
+
"\\": "\\\\"
|
|
1387
|
+
};
|
|
1388
|
+
const hex = 16;
|
|
1389
|
+
function escape(char) {
|
|
1390
|
+
return escapeCharacters[char] || `\\u${`0000${char.charCodeAt(0).toString(hex)}`.slice(-4)}`;
|
|
1391
|
+
}
|
|
1392
|
+
function inspectString(string, options) {
|
|
1393
|
+
if (stringEscapeChars.test(string)) {
|
|
1394
|
+
string = string.replace(stringEscapeChars, escape);
|
|
1395
|
+
}
|
|
1396
|
+
return options.stylize(`'${truncate(string, options.truncate - 2)}'`, "string");
|
|
1397
|
+
}
|
|
1398
|
+
function inspectSymbol(value) {
|
|
1399
|
+
if ("description" in Symbol.prototype) {
|
|
1400
|
+
return value.description ? `Symbol(${value.description})` : "Symbol()";
|
|
1401
|
+
}
|
|
1402
|
+
return value.toString();
|
|
1403
|
+
}
|
|
1404
|
+
const getPromiseValue = () => "Promise{…}";
|
|
1405
|
+
function inspectObject$1(object, options) {
|
|
1406
|
+
const properties = Object.getOwnPropertyNames(object);
|
|
1407
|
+
const symbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : [];
|
|
1408
|
+
if (properties.length === 0 && symbols.length === 0) {
|
|
1409
|
+
return "{}";
|
|
1410
|
+
}
|
|
1411
|
+
options.truncate -= 4;
|
|
1412
|
+
options.seen = options.seen || [];
|
|
1413
|
+
if (options.seen.includes(object)) {
|
|
1414
|
+
return "[Circular]";
|
|
1415
|
+
}
|
|
1416
|
+
options.seen.push(object);
|
|
1417
|
+
const propertyContents = inspectList(properties.map((key) => [key, object[key]]), options, inspectProperty);
|
|
1418
|
+
const symbolContents = inspectList(symbols.map((key) => [key, object[key]]), options, inspectProperty);
|
|
1419
|
+
options.seen.pop();
|
|
1420
|
+
let sep = "";
|
|
1421
|
+
if (propertyContents && symbolContents) {
|
|
1422
|
+
sep = ", ";
|
|
1423
|
+
}
|
|
1424
|
+
return `{ ${propertyContents}${sep}${symbolContents} }`;
|
|
1425
|
+
}
|
|
1426
|
+
const toStringTag = typeof Symbol !== "undefined" && Symbol.toStringTag ? Symbol.toStringTag : false;
|
|
1427
|
+
function inspectClass(value, options) {
|
|
1428
|
+
let name = "";
|
|
1429
|
+
if (toStringTag && toStringTag in value) {
|
|
1430
|
+
name = value[toStringTag];
|
|
1431
|
+
}
|
|
1432
|
+
name = name || value.constructor.name;
|
|
1433
|
+
if (!name || name === "_class") {
|
|
1434
|
+
name = "<Anonymous Class>";
|
|
1435
|
+
}
|
|
1436
|
+
options.truncate -= name.length;
|
|
1437
|
+
return `${name}${inspectObject$1(value, options)}`;
|
|
1438
|
+
}
|
|
1439
|
+
function inspectArguments(args, options) {
|
|
1440
|
+
if (args.length === 0)
|
|
1441
|
+
return "Arguments[]";
|
|
1442
|
+
options.truncate -= 13;
|
|
1443
|
+
return `Arguments[ ${inspectList(args, options)} ]`;
|
|
1444
|
+
}
|
|
1445
|
+
const errorKeys = [
|
|
1446
|
+
"stack",
|
|
1447
|
+
"line",
|
|
1448
|
+
"column",
|
|
1449
|
+
"name",
|
|
1450
|
+
"message",
|
|
1451
|
+
"fileName",
|
|
1452
|
+
"lineNumber",
|
|
1453
|
+
"columnNumber",
|
|
1454
|
+
"number",
|
|
1455
|
+
"description",
|
|
1456
|
+
"cause"
|
|
1457
|
+
];
|
|
1458
|
+
function inspectObject(error, options) {
|
|
1459
|
+
const properties = Object.getOwnPropertyNames(error).filter((key) => errorKeys.indexOf(key) === -1);
|
|
1460
|
+
const name = error.name;
|
|
1461
|
+
options.truncate -= name.length;
|
|
1462
|
+
let message = "";
|
|
1463
|
+
if (typeof error.message === "string") {
|
|
1464
|
+
message = truncate(error.message, options.truncate);
|
|
1465
|
+
} else {
|
|
1466
|
+
properties.unshift("message");
|
|
1467
|
+
}
|
|
1468
|
+
message = message ? `: ${message}` : "";
|
|
1469
|
+
options.truncate -= message.length + 5;
|
|
1470
|
+
options.seen = options.seen || [];
|
|
1471
|
+
if (options.seen.includes(error)) {
|
|
1472
|
+
return "[Circular]";
|
|
1473
|
+
}
|
|
1474
|
+
options.seen.push(error);
|
|
1475
|
+
const propertyContents = inspectList(properties.map((key) => [key, error[key]]), options, inspectProperty);
|
|
1476
|
+
return `${name}${message}${propertyContents ? ` { ${propertyContents} }` : ""}`;
|
|
1477
|
+
}
|
|
1478
|
+
function inspectAttribute([key, value], options) {
|
|
1479
|
+
options.truncate -= 3;
|
|
1480
|
+
if (!value) {
|
|
1481
|
+
return `${options.stylize(String(key), "yellow")}`;
|
|
1482
|
+
}
|
|
1483
|
+
return `${options.stylize(String(key), "yellow")}=${options.stylize(`"${value}"`, "string")}`;
|
|
1484
|
+
}
|
|
1485
|
+
function inspectNodeCollection(collection, options) {
|
|
1486
|
+
return inspectList(collection, options, inspectNode, "\n");
|
|
1487
|
+
}
|
|
1488
|
+
function inspectNode(node, options) {
|
|
1489
|
+
switch (node.nodeType) {
|
|
1490
|
+
case 1:
|
|
1491
|
+
return inspectHTML(node, options);
|
|
1492
|
+
case 3:
|
|
1493
|
+
return options.inspect(node.data, options);
|
|
1494
|
+
default:
|
|
1495
|
+
return options.inspect(node, options);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
function inspectHTML(element, options) {
|
|
1499
|
+
const properties = element.getAttributeNames();
|
|
1500
|
+
const name = element.tagName.toLowerCase();
|
|
1501
|
+
const head = options.stylize(`<${name}`, "special");
|
|
1502
|
+
const headClose = options.stylize(`>`, "special");
|
|
1503
|
+
const tail = options.stylize(`</${name}>`, "special");
|
|
1504
|
+
options.truncate -= name.length * 2 + 5;
|
|
1505
|
+
let propertyContents = "";
|
|
1506
|
+
if (properties.length > 0) {
|
|
1507
|
+
propertyContents += " ";
|
|
1508
|
+
propertyContents += inspectList(properties.map((key) => [key, element.getAttribute(key)]), options, inspectAttribute, " ");
|
|
1509
|
+
}
|
|
1510
|
+
options.truncate -= propertyContents.length;
|
|
1511
|
+
const truncate2 = options.truncate;
|
|
1512
|
+
let children = inspectNodeCollection(element.children, options);
|
|
1513
|
+
if (children && children.length > truncate2) {
|
|
1514
|
+
children = `${truncator}(${element.children.length})`;
|
|
1515
|
+
}
|
|
1516
|
+
return `${head}${propertyContents}${headClose}${children}${tail}`;
|
|
1517
|
+
}
|
|
1518
|
+
const symbolsSupported = typeof Symbol === "function" && typeof Symbol.for === "function";
|
|
1519
|
+
const chaiInspect = symbolsSupported ? Symbol.for("chai/inspect") : "@@chai/inspect";
|
|
1520
|
+
const nodeInspect = Symbol.for("nodejs.util.inspect.custom");
|
|
1521
|
+
const constructorMap = /* @__PURE__ */ new WeakMap();
|
|
1522
|
+
const stringTagMap = {};
|
|
1523
|
+
const baseTypesMap = {
|
|
1524
|
+
undefined: (value, options) => options.stylize("undefined", "undefined"),
|
|
1525
|
+
null: (value, options) => options.stylize("null", "null"),
|
|
1526
|
+
boolean: (value, options) => options.stylize(String(value), "boolean"),
|
|
1527
|
+
Boolean: (value, options) => options.stylize(String(value), "boolean"),
|
|
1528
|
+
number: inspectNumber,
|
|
1529
|
+
Number: inspectNumber,
|
|
1530
|
+
bigint: inspectBigInt,
|
|
1531
|
+
BigInt: inspectBigInt,
|
|
1532
|
+
string: inspectString,
|
|
1533
|
+
String: inspectString,
|
|
1534
|
+
function: inspectFunction,
|
|
1535
|
+
Function: inspectFunction,
|
|
1536
|
+
symbol: inspectSymbol,
|
|
1537
|
+
// A Symbol polyfill will return `Symbol` not `symbol` from typedetect
|
|
1538
|
+
Symbol: inspectSymbol,
|
|
1539
|
+
Array: inspectArray,
|
|
1540
|
+
Date: inspectDate,
|
|
1541
|
+
Map: inspectMap,
|
|
1542
|
+
Set: inspectSet,
|
|
1543
|
+
RegExp: inspectRegExp,
|
|
1544
|
+
Promise: getPromiseValue,
|
|
1545
|
+
// WeakSet, WeakMap are totally opaque to us
|
|
1546
|
+
WeakSet: (value, options) => options.stylize("WeakSet{…}", "special"),
|
|
1547
|
+
WeakMap: (value, options) => options.stylize("WeakMap{…}", "special"),
|
|
1548
|
+
Arguments: inspectArguments,
|
|
1549
|
+
Int8Array: inspectTypedArray,
|
|
1550
|
+
Uint8Array: inspectTypedArray,
|
|
1551
|
+
Uint8ClampedArray: inspectTypedArray,
|
|
1552
|
+
Int16Array: inspectTypedArray,
|
|
1553
|
+
Uint16Array: inspectTypedArray,
|
|
1554
|
+
Int32Array: inspectTypedArray,
|
|
1555
|
+
Uint32Array: inspectTypedArray,
|
|
1556
|
+
Float32Array: inspectTypedArray,
|
|
1557
|
+
Float64Array: inspectTypedArray,
|
|
1558
|
+
Generator: () => "",
|
|
1559
|
+
DataView: () => "",
|
|
1560
|
+
ArrayBuffer: () => "",
|
|
1561
|
+
Error: inspectObject,
|
|
1562
|
+
HTMLCollection: inspectNodeCollection,
|
|
1563
|
+
NodeList: inspectNodeCollection
|
|
1564
|
+
};
|
|
1565
|
+
const inspectCustom = (value, options, type, inspectFn) => {
|
|
1566
|
+
if (chaiInspect in value && typeof value[chaiInspect] === "function") {
|
|
1567
|
+
return value[chaiInspect](options);
|
|
1568
|
+
}
|
|
1569
|
+
if (nodeInspect in value && typeof value[nodeInspect] === "function") {
|
|
1570
|
+
return value[nodeInspect](options.depth, options, inspectFn);
|
|
1571
|
+
}
|
|
1572
|
+
if ("inspect" in value && typeof value.inspect === "function") {
|
|
1573
|
+
return value.inspect(options.depth, options);
|
|
1574
|
+
}
|
|
1575
|
+
if ("constructor" in value && constructorMap.has(value.constructor)) {
|
|
1576
|
+
return constructorMap.get(value.constructor)(value, options);
|
|
1577
|
+
}
|
|
1578
|
+
if (stringTagMap[type]) {
|
|
1579
|
+
return stringTagMap[type](value, options);
|
|
1580
|
+
}
|
|
1581
|
+
return "";
|
|
1582
|
+
};
|
|
1583
|
+
const toString = Object.prototype.toString;
|
|
1584
|
+
function inspect$1(value, opts = {}) {
|
|
1585
|
+
const options = normaliseOptions(opts, inspect$1);
|
|
1586
|
+
const { customInspect } = options;
|
|
1587
|
+
let type = value === null ? "null" : typeof value;
|
|
1588
|
+
if (type === "object") {
|
|
1589
|
+
type = toString.call(value).slice(8, -1);
|
|
1590
|
+
}
|
|
1591
|
+
if (type in baseTypesMap) {
|
|
1592
|
+
return baseTypesMap[type](value, options);
|
|
1593
|
+
}
|
|
1594
|
+
if (customInspect && value) {
|
|
1595
|
+
const output = inspectCustom(value, options, type, inspect$1);
|
|
1596
|
+
if (output) {
|
|
1597
|
+
if (typeof output === "string")
|
|
1598
|
+
return output;
|
|
1599
|
+
return inspect$1(output, options);
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
const proto = value ? Object.getPrototypeOf(value) : false;
|
|
1603
|
+
if (proto === Object.prototype || proto === null) {
|
|
1604
|
+
return inspectObject$1(value, options);
|
|
1605
|
+
}
|
|
1606
|
+
if (value && typeof HTMLElement === "function" && value instanceof HTMLElement) {
|
|
1607
|
+
return inspectHTML(value, options);
|
|
1608
|
+
}
|
|
1609
|
+
if ("constructor" in value) {
|
|
1610
|
+
if (value.constructor !== Object) {
|
|
1611
|
+
return inspectClass(value, options);
|
|
1612
|
+
}
|
|
1613
|
+
return inspectObject$1(value, options);
|
|
1614
|
+
}
|
|
1615
|
+
if (value === Object(value)) {
|
|
1616
|
+
return inspectObject$1(value, options);
|
|
1617
|
+
}
|
|
1618
|
+
return options.stylize(String(value), type);
|
|
1619
|
+
}
|
|
1620
|
+
const { AsymmetricMatcher, DOMCollection, DOMElement, Immutable, ReactElement, ReactTestComponent } = plugins;
|
|
1621
|
+
const PLUGINS = [
|
|
1622
|
+
ReactTestComponent,
|
|
1623
|
+
ReactElement,
|
|
1624
|
+
DOMElement,
|
|
1625
|
+
DOMCollection,
|
|
1626
|
+
Immutable,
|
|
1627
|
+
AsymmetricMatcher
|
|
1628
|
+
];
|
|
1629
|
+
function stringify(object, maxDepth = 10, { maxLength, filterNode, ...options } = {}) {
|
|
1630
|
+
const MAX_LENGTH = maxLength ?? 1e4;
|
|
1631
|
+
let result;
|
|
1632
|
+
const filterFn = typeof filterNode === "string" ? createNodeFilterFromSelector(filterNode) : filterNode;
|
|
1633
|
+
const plugins2 = filterFn ? [
|
|
1634
|
+
ReactTestComponent,
|
|
1635
|
+
ReactElement,
|
|
1636
|
+
createDOMElementFilter(filterFn),
|
|
1637
|
+
DOMCollection,
|
|
1638
|
+
Immutable,
|
|
1639
|
+
AsymmetricMatcher
|
|
1640
|
+
] : PLUGINS;
|
|
1641
|
+
try {
|
|
1642
|
+
result = format$1(object, {
|
|
1643
|
+
maxDepth,
|
|
1644
|
+
escapeString: false,
|
|
1645
|
+
plugins: plugins2,
|
|
1646
|
+
...options
|
|
1647
|
+
});
|
|
1648
|
+
} catch {
|
|
1649
|
+
result = format$1(object, {
|
|
1650
|
+
callToJSON: false,
|
|
1651
|
+
maxDepth,
|
|
1652
|
+
escapeString: false,
|
|
1653
|
+
plugins: plugins2,
|
|
1654
|
+
...options
|
|
1655
|
+
});
|
|
1656
|
+
}
|
|
1657
|
+
return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(Math.min(maxDepth, Number.MAX_SAFE_INTEGER) / 2), {
|
|
1658
|
+
maxLength,
|
|
1659
|
+
filterNode,
|
|
1660
|
+
...options
|
|
1661
|
+
}) : result;
|
|
1662
|
+
}
|
|
1663
|
+
function createNodeFilterFromSelector(selector) {
|
|
1664
|
+
const ELEMENT_NODE2 = 1;
|
|
1665
|
+
const COMMENT_NODE2 = 8;
|
|
1666
|
+
return (node) => {
|
|
1667
|
+
if (node.nodeType === COMMENT_NODE2) {
|
|
1668
|
+
return false;
|
|
1669
|
+
}
|
|
1670
|
+
if (node.nodeType === ELEMENT_NODE2 && node.matches) {
|
|
1671
|
+
try {
|
|
1672
|
+
return !node.matches(selector);
|
|
1673
|
+
} catch {
|
|
1674
|
+
return true;
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
return true;
|
|
1678
|
+
};
|
|
1679
|
+
}
|
|
1680
|
+
const formatRegExp = /%[sdjifoOc%]/g;
|
|
1681
|
+
function baseFormat(args, options = {}) {
|
|
1682
|
+
const formatArg = (item, inspecOptions) => {
|
|
1683
|
+
if (options.prettifyObject) {
|
|
1684
|
+
return stringify(item, void 0, {
|
|
1685
|
+
printBasicPrototype: false,
|
|
1686
|
+
escapeString: false
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
return inspect(item, inspecOptions);
|
|
1690
|
+
};
|
|
1691
|
+
if (typeof args[0] !== "string") {
|
|
1692
|
+
const objects = [];
|
|
1693
|
+
for (let i2 = 0; i2 < args.length; i2++) {
|
|
1694
|
+
objects.push(formatArg(args[i2], {
|
|
1695
|
+
depth: 0,
|
|
1696
|
+
colors: false
|
|
1697
|
+
}));
|
|
1698
|
+
}
|
|
1699
|
+
return objects.join(" ");
|
|
1700
|
+
}
|
|
1701
|
+
const len = args.length;
|
|
1702
|
+
let i = 1;
|
|
1703
|
+
const template = args[0];
|
|
1704
|
+
let str = String(template).replace(formatRegExp, (x) => {
|
|
1705
|
+
if (x === "%%") {
|
|
1706
|
+
return "%";
|
|
1707
|
+
}
|
|
1708
|
+
if (i >= len) {
|
|
1709
|
+
return x;
|
|
1710
|
+
}
|
|
1711
|
+
switch (x) {
|
|
1712
|
+
case "%s": {
|
|
1713
|
+
const value = args[i++];
|
|
1714
|
+
if (typeof value === "bigint") {
|
|
1715
|
+
return `${value.toString()}n`;
|
|
1716
|
+
}
|
|
1717
|
+
if (typeof value === "number" && value === 0 && 1 / value < 0) {
|
|
1718
|
+
return "-0";
|
|
1719
|
+
}
|
|
1720
|
+
if (typeof value === "object" && value !== null) {
|
|
1721
|
+
if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) {
|
|
1722
|
+
return value.toString();
|
|
1723
|
+
}
|
|
1724
|
+
return formatArg(value, {
|
|
1725
|
+
depth: 0,
|
|
1726
|
+
colors: false
|
|
1727
|
+
});
|
|
1728
|
+
}
|
|
1729
|
+
return String(value);
|
|
1730
|
+
}
|
|
1731
|
+
case "%d": {
|
|
1732
|
+
const value = args[i++];
|
|
1733
|
+
if (typeof value === "bigint") {
|
|
1734
|
+
return `${value.toString()}n`;
|
|
1735
|
+
}
|
|
1736
|
+
if (typeof value === "symbol") {
|
|
1737
|
+
return "NaN";
|
|
1738
|
+
}
|
|
1739
|
+
return Number(value).toString();
|
|
1740
|
+
}
|
|
1741
|
+
case "%i": {
|
|
1742
|
+
const value = args[i++];
|
|
1743
|
+
if (typeof value === "bigint") {
|
|
1744
|
+
return `${value.toString()}n`;
|
|
1745
|
+
}
|
|
1746
|
+
return Number.parseInt(String(value)).toString();
|
|
1747
|
+
}
|
|
1748
|
+
case "%f":
|
|
1749
|
+
return Number.parseFloat(String(args[i++])).toString();
|
|
1750
|
+
case "%o":
|
|
1751
|
+
return formatArg(args[i++], {
|
|
1752
|
+
showHidden: true,
|
|
1753
|
+
showProxy: true
|
|
1754
|
+
});
|
|
1755
|
+
case "%O":
|
|
1756
|
+
return formatArg(args[i++]);
|
|
1757
|
+
case "%c": {
|
|
1758
|
+
i++;
|
|
1759
|
+
return "";
|
|
1760
|
+
}
|
|
1761
|
+
case "%j":
|
|
1762
|
+
try {
|
|
1763
|
+
return JSON.stringify(args[i++]);
|
|
1764
|
+
} catch (err) {
|
|
1765
|
+
const m = err.message;
|
|
1766
|
+
if (m.includes("circular structure") || m.includes("cyclic structures") || m.includes("cyclic object")) {
|
|
1767
|
+
return "[Circular]";
|
|
1768
|
+
}
|
|
1769
|
+
throw err;
|
|
1770
|
+
}
|
|
1771
|
+
default:
|
|
1772
|
+
return x;
|
|
1773
|
+
}
|
|
1774
|
+
});
|
|
1775
|
+
for (let x = args[i]; i < len; x = args[++i]) {
|
|
1776
|
+
if (x === null || typeof x !== "object") {
|
|
1777
|
+
str += ` ${typeof x === "symbol" ? x.toString() : x}`;
|
|
1778
|
+
} else {
|
|
1779
|
+
str += ` ${formatArg(x)}`;
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
return str;
|
|
1783
|
+
}
|
|
1784
|
+
function format(...args) {
|
|
1785
|
+
return baseFormat(args);
|
|
1786
|
+
}
|
|
1787
|
+
function inspect(obj, options = {}) {
|
|
1788
|
+
if (options.truncate === 0) {
|
|
1789
|
+
options.truncate = Number.POSITIVE_INFINITY;
|
|
1790
|
+
}
|
|
1791
|
+
return inspect$1(obj, options);
|
|
1792
|
+
}
|
|
1793
|
+
function objDisplay(obj, options = {}) {
|
|
1794
|
+
if (typeof options.truncate === "undefined") {
|
|
1795
|
+
options.truncate = 40;
|
|
1796
|
+
}
|
|
1797
|
+
const str = inspect(obj, options);
|
|
1798
|
+
const type = Object.prototype.toString.call(obj);
|
|
1799
|
+
if (options.truncate && str.length >= options.truncate) {
|
|
1800
|
+
if (type === "[object Function]") {
|
|
1801
|
+
const fn = obj;
|
|
1802
|
+
return !fn.name ? "[Function]" : `[Function: ${fn.name}]`;
|
|
1803
|
+
} else if (type === "[object Array]") {
|
|
1804
|
+
return `[ Array(${obj.length}) ]`;
|
|
1805
|
+
} else if (type === "[object Object]") {
|
|
1806
|
+
const keys = Object.keys(obj);
|
|
1807
|
+
const kstr = keys.length > 2 ? `${keys.splice(0, 2).join(", ")}, ...` : keys.join(", ");
|
|
1808
|
+
return `{ Object (${kstr}) }`;
|
|
1809
|
+
} else {
|
|
1810
|
+
return str;
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
return str;
|
|
1814
|
+
}
|
|
1815
|
+
function assertTypes(value, name, types) {
|
|
1816
|
+
const receivedType = typeof value;
|
|
1817
|
+
const pass = types.includes(receivedType);
|
|
1818
|
+
if (!pass) {
|
|
1819
|
+
throw new TypeError(`${name} value must be ${types.join(" or ")}, received "${receivedType}"`);
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
function filterOutComments(s) {
|
|
1823
|
+
const result = [];
|
|
1824
|
+
let commentState = "none";
|
|
1825
|
+
for (let i = 0; i < s.length; ++i) {
|
|
1826
|
+
if (commentState === "singleline") {
|
|
1827
|
+
if (s[i] === "\n") {
|
|
1828
|
+
commentState = "none";
|
|
1829
|
+
}
|
|
1830
|
+
} else if (commentState === "multiline") {
|
|
1831
|
+
if (s[i - 1] === "*" && s[i] === "/") {
|
|
1832
|
+
commentState = "none";
|
|
1833
|
+
}
|
|
1834
|
+
} else if (commentState === "none") {
|
|
1835
|
+
if (s[i] === "/" && s[i + 1] === "/") {
|
|
1836
|
+
commentState = "singleline";
|
|
1837
|
+
} else if (s[i] === "/" && s[i + 1] === "*") {
|
|
1838
|
+
commentState = "multiline";
|
|
1839
|
+
i += 2;
|
|
1840
|
+
} else {
|
|
1841
|
+
result.push(s[i]);
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
return result.join("");
|
|
1846
|
+
}
|
|
1847
|
+
function toArray(array) {
|
|
1848
|
+
if (array === null || array === void 0) {
|
|
1849
|
+
array = [];
|
|
1850
|
+
}
|
|
1851
|
+
if (Array.isArray(array)) {
|
|
1852
|
+
return array;
|
|
1853
|
+
}
|
|
1854
|
+
return [array];
|
|
1855
|
+
}
|
|
1856
|
+
function isObject(item) {
|
|
1857
|
+
return item != null && typeof item === "object" && !Array.isArray(item);
|
|
1858
|
+
}
|
|
1859
|
+
function objectAttr(source, path, defaultValue = void 0) {
|
|
1860
|
+
const paths = path.replace(/\[(\d+)\]/g, ".$1").split(".");
|
|
1861
|
+
let result = source;
|
|
1862
|
+
for (const p of paths) {
|
|
1863
|
+
result = new Object(result)[p];
|
|
1864
|
+
if (result === void 0) {
|
|
1865
|
+
return defaultValue;
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
return result;
|
|
1869
|
+
}
|
|
1870
|
+
function createDefer() {
|
|
1871
|
+
let resolve2 = null;
|
|
1872
|
+
let reject = null;
|
|
1873
|
+
const p = new Promise((_resolve, _reject) => {
|
|
1874
|
+
resolve2 = _resolve;
|
|
1875
|
+
reject = _reject;
|
|
1876
|
+
});
|
|
1877
|
+
p.resolve = resolve2;
|
|
1878
|
+
p.reject = reject;
|
|
1879
|
+
return p;
|
|
1880
|
+
}
|
|
1881
|
+
function isNegativeNaN(val) {
|
|
1882
|
+
if (!Number.isNaN(val)) {
|
|
1883
|
+
return false;
|
|
1884
|
+
}
|
|
1885
|
+
const f64 = new Float64Array(1);
|
|
1886
|
+
f64[0] = val;
|
|
1887
|
+
const u32 = new Uint32Array(f64.buffer);
|
|
1888
|
+
const isNegative = u32[1] >>> 31 === 1;
|
|
1889
|
+
return isNegative;
|
|
1890
|
+
}
|
|
1891
|
+
function ordinal(i) {
|
|
1892
|
+
const j = i % 10;
|
|
1893
|
+
const k = i % 100;
|
|
1894
|
+
if (j === 1 && k !== 11) {
|
|
1895
|
+
return `${i}st`;
|
|
1896
|
+
}
|
|
1897
|
+
if (j === 2 && k !== 12) {
|
|
1898
|
+
return `${i}nd`;
|
|
1899
|
+
}
|
|
1900
|
+
if (j === 3 && k !== 13) {
|
|
1901
|
+
return `${i}rd`;
|
|
1902
|
+
}
|
|
1903
|
+
return `${i}th`;
|
|
1904
|
+
}
|
|
1905
|
+
function unique(array) {
|
|
1906
|
+
return Array.from(new Set(array));
|
|
1907
|
+
}
|
|
1908
|
+
const SAFE_TIMERS_SYMBOL = Symbol("vitest:SAFE_TIMERS");
|
|
1909
|
+
function getSafeTimers() {
|
|
1910
|
+
const { setTimeout: safeSetTimeout, setInterval: safeSetInterval, clearInterval: safeClearInterval, clearTimeout: safeClearTimeout, setImmediate: safeSetImmediate, clearImmediate: safeClearImmediate, queueMicrotask: safeQueueMicrotask } = globalThis[SAFE_TIMERS_SYMBOL] || globalThis;
|
|
1911
|
+
const { nextTick: safeNextTick } = globalThis[SAFE_TIMERS_SYMBOL] || globalThis.process || {};
|
|
1912
|
+
return {
|
|
1913
|
+
nextTick: safeNextTick,
|
|
1914
|
+
setTimeout: safeSetTimeout,
|
|
1915
|
+
setInterval: safeSetInterval,
|
|
1916
|
+
clearInterval: safeClearInterval,
|
|
1917
|
+
clearTimeout: safeClearTimeout,
|
|
1918
|
+
setImmediate: safeSetImmediate,
|
|
1919
|
+
clearImmediate: safeClearImmediate,
|
|
1920
|
+
queueMicrotask: safeQueueMicrotask
|
|
1921
|
+
};
|
|
1922
|
+
}
|
|
1923
|
+
const _DRIVE_LETTER_START_RE$1 = /^[A-Za-z]:\//;
|
|
1924
|
+
function normalizeWindowsPath$1(input = "") {
|
|
1925
|
+
if (!input) {
|
|
1926
|
+
return input;
|
|
1927
|
+
}
|
|
1928
|
+
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE$1, (r) => r.toUpperCase());
|
|
1929
|
+
}
|
|
1930
|
+
const _IS_ABSOLUTE_RE$1 = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
1931
|
+
function cwd$1() {
|
|
1932
|
+
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
1933
|
+
return process.cwd().replace(/\\/g, "/");
|
|
1934
|
+
}
|
|
1935
|
+
return "/";
|
|
1936
|
+
}
|
|
1937
|
+
const resolve$1 = function(...arguments_) {
|
|
1938
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath$1(argument));
|
|
1939
|
+
let resolvedPath = "";
|
|
1940
|
+
let resolvedAbsolute = false;
|
|
1941
|
+
for (let index2 = arguments_.length - 1; index2 >= -1 && !resolvedAbsolute; index2--) {
|
|
1942
|
+
const path = index2 >= 0 ? arguments_[index2] : cwd$1();
|
|
1943
|
+
if (!path || path.length === 0) {
|
|
1944
|
+
continue;
|
|
1945
|
+
}
|
|
1946
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
1947
|
+
resolvedAbsolute = isAbsolute$1(path);
|
|
1948
|
+
}
|
|
1949
|
+
resolvedPath = normalizeString$1(resolvedPath, !resolvedAbsolute);
|
|
1950
|
+
if (resolvedAbsolute && !isAbsolute$1(resolvedPath)) {
|
|
1951
|
+
return `/${resolvedPath}`;
|
|
1952
|
+
}
|
|
1953
|
+
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
1954
|
+
};
|
|
1955
|
+
function normalizeString$1(path, allowAboveRoot) {
|
|
1956
|
+
let res = "";
|
|
1957
|
+
let lastSegmentLength = 0;
|
|
1958
|
+
let lastSlash = -1;
|
|
1959
|
+
let dots = 0;
|
|
1960
|
+
let char = null;
|
|
1961
|
+
for (let index2 = 0; index2 <= path.length; ++index2) {
|
|
1962
|
+
if (index2 < path.length) {
|
|
1963
|
+
char = path[index2];
|
|
1964
|
+
} else if (char === "/") {
|
|
1965
|
+
break;
|
|
1966
|
+
} else {
|
|
1967
|
+
char = "/";
|
|
1968
|
+
}
|
|
1969
|
+
if (char === "/") {
|
|
1970
|
+
if (lastSlash === index2 - 1 || dots === 1) ;
|
|
1971
|
+
else if (dots === 2) {
|
|
1972
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
1973
|
+
if (res.length > 2) {
|
|
1974
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
1975
|
+
if (lastSlashIndex === -1) {
|
|
1976
|
+
res = "";
|
|
1977
|
+
lastSegmentLength = 0;
|
|
1978
|
+
} else {
|
|
1979
|
+
res = res.slice(0, lastSlashIndex);
|
|
1980
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
1981
|
+
}
|
|
1982
|
+
lastSlash = index2;
|
|
1983
|
+
dots = 0;
|
|
1984
|
+
continue;
|
|
1985
|
+
} else if (res.length > 0) {
|
|
1986
|
+
res = "";
|
|
1987
|
+
lastSegmentLength = 0;
|
|
1988
|
+
lastSlash = index2;
|
|
1989
|
+
dots = 0;
|
|
1990
|
+
continue;
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
if (allowAboveRoot) {
|
|
1994
|
+
res += res.length > 0 ? "/.." : "..";
|
|
1995
|
+
lastSegmentLength = 2;
|
|
1996
|
+
}
|
|
1997
|
+
} else {
|
|
1998
|
+
if (res.length > 0) {
|
|
1999
|
+
res += `/${path.slice(lastSlash + 1, index2)}`;
|
|
2000
|
+
} else {
|
|
2001
|
+
res = path.slice(lastSlash + 1, index2);
|
|
2002
|
+
}
|
|
2003
|
+
lastSegmentLength = index2 - lastSlash - 1;
|
|
2004
|
+
}
|
|
2005
|
+
lastSlash = index2;
|
|
2006
|
+
dots = 0;
|
|
2007
|
+
} else if (char === "." && dots !== -1) {
|
|
2008
|
+
++dots;
|
|
2009
|
+
} else {
|
|
2010
|
+
dots = -1;
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
return res;
|
|
2014
|
+
}
|
|
2015
|
+
const isAbsolute$1 = function(p) {
|
|
2016
|
+
return _IS_ABSOLUTE_RE$1.test(p);
|
|
2017
|
+
};
|
|
2018
|
+
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
2019
|
+
var intToChar = new Uint8Array(64);
|
|
2020
|
+
var charToInt = new Uint8Array(128);
|
|
2021
|
+
for (let i = 0; i < chars.length; i++) {
|
|
2022
|
+
const c = chars.charCodeAt(i);
|
|
2023
|
+
intToChar[i] = c;
|
|
2024
|
+
charToInt[c] = i;
|
|
2025
|
+
}
|
|
2026
|
+
const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
|
|
2027
|
+
const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
|
|
2028
|
+
const NOW_LENGTH = Date.now().toString().length;
|
|
2029
|
+
const REGEXP_VITEST = new RegExp(`vitest=\\d{${NOW_LENGTH}}`);
|
|
2030
|
+
function extractLocation(urlLike) {
|
|
2031
|
+
if (!urlLike.includes(":")) {
|
|
2032
|
+
return [urlLike];
|
|
2033
|
+
}
|
|
2034
|
+
const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
|
|
2035
|
+
const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, ""));
|
|
2036
|
+
if (!parts) {
|
|
2037
|
+
return [urlLike];
|
|
2038
|
+
}
|
|
2039
|
+
let url = parts[1];
|
|
2040
|
+
if (url.startsWith("async ")) {
|
|
2041
|
+
url = url.slice(6);
|
|
2042
|
+
}
|
|
2043
|
+
if (url.startsWith("http:") || url.startsWith("https:")) {
|
|
2044
|
+
const urlObj = new URL(url);
|
|
2045
|
+
urlObj.searchParams.delete("import");
|
|
2046
|
+
urlObj.searchParams.delete("browserv");
|
|
2047
|
+
url = urlObj.pathname + urlObj.hash + urlObj.search;
|
|
2048
|
+
}
|
|
2049
|
+
if (url.startsWith("/@fs/")) {
|
|
2050
|
+
const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
|
|
2051
|
+
url = url.slice(isWindows ? 5 : 4);
|
|
2052
|
+
}
|
|
2053
|
+
if (url.includes("vitest=")) {
|
|
2054
|
+
url = url.replace(REGEXP_VITEST, "").replace(/[?&]$/, "");
|
|
2055
|
+
}
|
|
2056
|
+
return [
|
|
2057
|
+
url,
|
|
2058
|
+
parts[2] || void 0,
|
|
2059
|
+
parts[3] || void 0
|
|
2060
|
+
];
|
|
2061
|
+
}
|
|
2062
|
+
function parseSingleFFOrSafariStack(raw) {
|
|
2063
|
+
let line = raw.trim();
|
|
2064
|
+
if (SAFARI_NATIVE_CODE_REGEXP.test(line)) {
|
|
2065
|
+
return null;
|
|
2066
|
+
}
|
|
2067
|
+
if (line.includes(" > eval")) {
|
|
2068
|
+
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1");
|
|
2069
|
+
}
|
|
2070
|
+
if (!line.includes("@")) {
|
|
2071
|
+
return null;
|
|
2072
|
+
}
|
|
2073
|
+
let atIndex = -1;
|
|
2074
|
+
let locationPart = "";
|
|
2075
|
+
let functionName;
|
|
2076
|
+
for (let i = 0; i < line.length; i++) {
|
|
2077
|
+
if (line[i] === "@") {
|
|
2078
|
+
const candidateLocation = line.slice(i + 1);
|
|
2079
|
+
if (candidateLocation.includes(":") && candidateLocation.length >= 3) {
|
|
2080
|
+
atIndex = i;
|
|
2081
|
+
locationPart = candidateLocation;
|
|
2082
|
+
functionName = i > 0 ? line.slice(0, i) : void 0;
|
|
2083
|
+
break;
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
if (atIndex === -1 || !locationPart.includes(":") || locationPart.length < 3) {
|
|
2088
|
+
return null;
|
|
2089
|
+
}
|
|
2090
|
+
const [url, lineNumber, columnNumber] = extractLocation(locationPart);
|
|
2091
|
+
if (!url || !lineNumber || !columnNumber) {
|
|
2092
|
+
return null;
|
|
2093
|
+
}
|
|
2094
|
+
return {
|
|
2095
|
+
file: url,
|
|
2096
|
+
method: functionName || "",
|
|
2097
|
+
line: Number.parseInt(lineNumber),
|
|
2098
|
+
column: Number.parseInt(columnNumber)
|
|
2099
|
+
};
|
|
2100
|
+
}
|
|
2101
|
+
function parseSingleStack(raw) {
|
|
2102
|
+
const line = raw.trim();
|
|
2103
|
+
if (!CHROME_IE_STACK_REGEXP.test(line)) {
|
|
2104
|
+
return parseSingleFFOrSafariStack(line);
|
|
2105
|
+
}
|
|
2106
|
+
return parseSingleV8Stack(line);
|
|
2107
|
+
}
|
|
2108
|
+
function parseSingleV8Stack(raw) {
|
|
2109
|
+
let line = raw.trim();
|
|
2110
|
+
if (!CHROME_IE_STACK_REGEXP.test(line)) {
|
|
2111
|
+
return null;
|
|
2112
|
+
}
|
|
2113
|
+
if (line.includes("(eval ")) {
|
|
2114
|
+
line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
|
|
2115
|
+
}
|
|
2116
|
+
let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
|
|
2117
|
+
const location = sanitizedLine.match(/ (\(.+\)$)/);
|
|
2118
|
+
sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
|
|
2119
|
+
const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
|
|
2120
|
+
let method = location && sanitizedLine || "";
|
|
2121
|
+
let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
|
|
2122
|
+
if (!file || !lineNumber || !columnNumber) {
|
|
2123
|
+
return null;
|
|
2124
|
+
}
|
|
2125
|
+
if (method.startsWith("async ")) {
|
|
2126
|
+
method = method.slice(6);
|
|
2127
|
+
}
|
|
2128
|
+
if (file.startsWith("file://")) {
|
|
2129
|
+
file = file.slice(7);
|
|
2130
|
+
}
|
|
2131
|
+
file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve$1(file);
|
|
2132
|
+
if (method) {
|
|
2133
|
+
method = method.replace(/\(0\s?,\s?__vite_ssr_import_\d+__.(\w+)\)/g, "$1").replace(/__(vite_ssr_import|vi_import)_\d+__\./g, "").replace(/(Object\.)?__vite_ssr_export_default__\s?/g, "");
|
|
2134
|
+
}
|
|
2135
|
+
return {
|
|
2136
|
+
method,
|
|
2137
|
+
file,
|
|
2138
|
+
line: Number.parseInt(lineNumber),
|
|
2139
|
+
column: Number.parseInt(columnNumber)
|
|
2140
|
+
};
|
|
2141
|
+
}
|
|
2142
|
+
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
2143
|
+
function normalizeWindowsPath(input = "") {
|
|
2144
|
+
if (!input) {
|
|
2145
|
+
return input;
|
|
2146
|
+
}
|
|
2147
|
+
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
2148
|
+
}
|
|
2149
|
+
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
2150
|
+
const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
|
|
2151
|
+
function cwd() {
|
|
2152
|
+
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
2153
|
+
return process.cwd().replace(/\\/g, "/");
|
|
2154
|
+
}
|
|
2155
|
+
return "/";
|
|
2156
|
+
}
|
|
2157
|
+
const resolve = function(...arguments_) {
|
|
2158
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
2159
|
+
let resolvedPath = "";
|
|
2160
|
+
let resolvedAbsolute = false;
|
|
2161
|
+
for (let index2 = arguments_.length - 1; index2 >= -1 && !resolvedAbsolute; index2--) {
|
|
2162
|
+
const path = index2 >= 0 ? arguments_[index2] : cwd();
|
|
2163
|
+
if (!path || path.length === 0) {
|
|
2164
|
+
continue;
|
|
2165
|
+
}
|
|
2166
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
2167
|
+
resolvedAbsolute = isAbsolute(path);
|
|
2168
|
+
}
|
|
2169
|
+
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
2170
|
+
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
2171
|
+
return `/${resolvedPath}`;
|
|
2172
|
+
}
|
|
2173
|
+
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
2174
|
+
};
|
|
2175
|
+
function normalizeString(path, allowAboveRoot) {
|
|
2176
|
+
let res = "";
|
|
2177
|
+
let lastSegmentLength = 0;
|
|
2178
|
+
let lastSlash = -1;
|
|
2179
|
+
let dots = 0;
|
|
2180
|
+
let char = null;
|
|
2181
|
+
for (let index2 = 0; index2 <= path.length; ++index2) {
|
|
2182
|
+
if (index2 < path.length) {
|
|
2183
|
+
char = path[index2];
|
|
2184
|
+
} else if (char === "/") {
|
|
2185
|
+
break;
|
|
2186
|
+
} else {
|
|
2187
|
+
char = "/";
|
|
2188
|
+
}
|
|
2189
|
+
if (char === "/") {
|
|
2190
|
+
if (lastSlash === index2 - 1 || dots === 1) ;
|
|
2191
|
+
else if (dots === 2) {
|
|
2192
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
2193
|
+
if (res.length > 2) {
|
|
2194
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
2195
|
+
if (lastSlashIndex === -1) {
|
|
2196
|
+
res = "";
|
|
2197
|
+
lastSegmentLength = 0;
|
|
2198
|
+
} else {
|
|
2199
|
+
res = res.slice(0, lastSlashIndex);
|
|
2200
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
2201
|
+
}
|
|
2202
|
+
lastSlash = index2;
|
|
2203
|
+
dots = 0;
|
|
2204
|
+
continue;
|
|
2205
|
+
} else if (res.length > 0) {
|
|
2206
|
+
res = "";
|
|
2207
|
+
lastSegmentLength = 0;
|
|
2208
|
+
lastSlash = index2;
|
|
2209
|
+
dots = 0;
|
|
2210
|
+
continue;
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
if (allowAboveRoot) {
|
|
2214
|
+
res += res.length > 0 ? "/.." : "..";
|
|
2215
|
+
lastSegmentLength = 2;
|
|
2216
|
+
}
|
|
2217
|
+
} else {
|
|
2218
|
+
if (res.length > 0) {
|
|
2219
|
+
res += `/${path.slice(lastSlash + 1, index2)}`;
|
|
2220
|
+
} else {
|
|
2221
|
+
res = path.slice(lastSlash + 1, index2);
|
|
2222
|
+
}
|
|
2223
|
+
lastSegmentLength = index2 - lastSlash - 1;
|
|
2224
|
+
}
|
|
2225
|
+
lastSlash = index2;
|
|
2226
|
+
dots = 0;
|
|
2227
|
+
} else if (char === "." && dots !== -1) {
|
|
2228
|
+
++dots;
|
|
2229
|
+
} else {
|
|
2230
|
+
dots = -1;
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
return res;
|
|
2234
|
+
}
|
|
2235
|
+
const isAbsolute = function(p) {
|
|
2236
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
2237
|
+
};
|
|
2238
|
+
const relative = function(from, to) {
|
|
2239
|
+
const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
2240
|
+
const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
2241
|
+
if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
|
|
2242
|
+
return _to.join("/");
|
|
2243
|
+
}
|
|
2244
|
+
const _fromCopy = [..._from];
|
|
2245
|
+
for (const segment of _fromCopy) {
|
|
2246
|
+
if (_to[0] !== segment) {
|
|
2247
|
+
break;
|
|
2248
|
+
}
|
|
2249
|
+
_from.shift();
|
|
2250
|
+
_to.shift();
|
|
2251
|
+
}
|
|
2252
|
+
return [..._from.map(() => ".."), ..._to].join("/");
|
|
2253
|
+
};
|
|
2254
|
+
class PendingError extends Error {
|
|
2255
|
+
code = "VITEST_PENDING";
|
|
2256
|
+
taskId;
|
|
2257
|
+
constructor(message, task, note) {
|
|
2258
|
+
super(message);
|
|
2259
|
+
this.message = message;
|
|
2260
|
+
this.note = note;
|
|
2261
|
+
this.taskId = task.id;
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
class FixtureDependencyError extends Error {
|
|
2265
|
+
name = "FixtureDependencyError";
|
|
2266
|
+
}
|
|
2267
|
+
class FixtureAccessError extends Error {
|
|
2268
|
+
name = "FixtureAccessError";
|
|
2269
|
+
}
|
|
2270
|
+
class FixtureParseError extends Error {
|
|
2271
|
+
name = "FixtureParseError";
|
|
2272
|
+
}
|
|
2273
|
+
const fnMap = /* @__PURE__ */ new WeakMap();
|
|
2274
|
+
const testFixtureMap = /* @__PURE__ */ new WeakMap();
|
|
2275
|
+
const hooksMap = /* @__PURE__ */ new WeakMap();
|
|
2276
|
+
function setFn(key, fn) {
|
|
2277
|
+
fnMap.set(key, fn);
|
|
2278
|
+
}
|
|
2279
|
+
function setTestFixture(key, fixture) {
|
|
2280
|
+
testFixtureMap.set(key, fixture);
|
|
2281
|
+
}
|
|
2282
|
+
function getTestFixtures(key) {
|
|
2283
|
+
return testFixtureMap.get(key);
|
|
2284
|
+
}
|
|
2285
|
+
function setHooks(key, hooks) {
|
|
2286
|
+
hooksMap.set(key, hooks);
|
|
2287
|
+
}
|
|
2288
|
+
function getHooks(key) {
|
|
2289
|
+
return hooksMap.get(key);
|
|
2290
|
+
}
|
|
2291
|
+
const FIXTURE_STACK_TRACE_KEY = Symbol.for("VITEST_FIXTURE_STACK_TRACE");
|
|
2292
|
+
class TestFixtures {
|
|
2293
|
+
_suiteContexts;
|
|
2294
|
+
_overrides = /* @__PURE__ */ new WeakMap();
|
|
2295
|
+
_registrations;
|
|
2296
|
+
static _definitions = [];
|
|
2297
|
+
static _builtinFixtures = [
|
|
2298
|
+
"task",
|
|
2299
|
+
"signal",
|
|
2300
|
+
"onTestFailed",
|
|
2301
|
+
"onTestFinished",
|
|
2302
|
+
"skip",
|
|
2303
|
+
"annotate"
|
|
2304
|
+
];
|
|
2305
|
+
static _fixtureOptionKeys = [
|
|
2306
|
+
"auto",
|
|
2307
|
+
"injected",
|
|
2308
|
+
"scope"
|
|
2309
|
+
];
|
|
2310
|
+
static _fixtureScopes = [
|
|
2311
|
+
"test",
|
|
2312
|
+
"file",
|
|
2313
|
+
"worker"
|
|
2314
|
+
];
|
|
2315
|
+
static _workerContextSuite = { type: "worker" };
|
|
2316
|
+
static clearDefinitions() {
|
|
2317
|
+
TestFixtures._definitions.length = 0;
|
|
2318
|
+
}
|
|
2319
|
+
static getWorkerContexts() {
|
|
2320
|
+
return TestFixtures._definitions.map((f2) => f2.getWorkerContext());
|
|
2321
|
+
}
|
|
2322
|
+
static getFileContexts(file) {
|
|
2323
|
+
return TestFixtures._definitions.map((f2) => f2.getFileContext(file));
|
|
2324
|
+
}
|
|
2325
|
+
static isFixtureOptions(obj) {
|
|
2326
|
+
return isObject(obj) && Object.keys(obj).some((key) => TestFixtures._fixtureOptionKeys.includes(key));
|
|
2327
|
+
}
|
|
2328
|
+
constructor(registrations) {
|
|
2329
|
+
this._registrations = registrations ?? /* @__PURE__ */ new Map();
|
|
2330
|
+
this._suiteContexts = /* @__PURE__ */ new WeakMap();
|
|
2331
|
+
TestFixtures._definitions.push(this);
|
|
2332
|
+
}
|
|
2333
|
+
extend(runner2, userFixtures) {
|
|
2334
|
+
const { suite: suite2 } = getCurrentSuite();
|
|
2335
|
+
const isTopLevel = !suite2 || suite2.file === suite2;
|
|
2336
|
+
const registrations = this.parseUserFixtures(runner2, userFixtures, isTopLevel);
|
|
2337
|
+
return new TestFixtures(registrations);
|
|
2338
|
+
}
|
|
2339
|
+
get(suite2) {
|
|
2340
|
+
let currentSuite = suite2;
|
|
2341
|
+
while (currentSuite) {
|
|
2342
|
+
const overrides = this._overrides.get(currentSuite);
|
|
2343
|
+
if (overrides) {
|
|
2344
|
+
return overrides;
|
|
2345
|
+
}
|
|
2346
|
+
if (currentSuite === currentSuite.file) {
|
|
2347
|
+
break;
|
|
2348
|
+
}
|
|
2349
|
+
currentSuite = currentSuite.suite || currentSuite.file;
|
|
2350
|
+
}
|
|
2351
|
+
return this._registrations;
|
|
2352
|
+
}
|
|
2353
|
+
override(runner2, userFixtures) {
|
|
2354
|
+
const { suite: currentSuite, file } = getCurrentSuite();
|
|
2355
|
+
const suite2 = currentSuite || file;
|
|
2356
|
+
const isTopLevel = !currentSuite || currentSuite.file === currentSuite;
|
|
2357
|
+
const suiteRegistrations = new Map(this.get(suite2));
|
|
2358
|
+
const registrations = this.parseUserFixtures(runner2, userFixtures, isTopLevel, suiteRegistrations);
|
|
2359
|
+
if (isTopLevel) {
|
|
2360
|
+
this._registrations = registrations;
|
|
2361
|
+
} else {
|
|
2362
|
+
this._overrides.set(suite2, registrations);
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
getFileContext(file) {
|
|
2366
|
+
if (!this._suiteContexts.has(file)) {
|
|
2367
|
+
this._suiteContexts.set(file, /* @__PURE__ */ Object.create(null));
|
|
2368
|
+
}
|
|
2369
|
+
return this._suiteContexts.get(file);
|
|
2370
|
+
}
|
|
2371
|
+
getWorkerContext() {
|
|
2372
|
+
if (!this._suiteContexts.has(TestFixtures._workerContextSuite)) {
|
|
2373
|
+
this._suiteContexts.set(TestFixtures._workerContextSuite, /* @__PURE__ */ Object.create(null));
|
|
2374
|
+
}
|
|
2375
|
+
return this._suiteContexts.get(TestFixtures._workerContextSuite);
|
|
2376
|
+
}
|
|
2377
|
+
parseUserFixtures(runner2, userFixtures, supportNonTest, registrations = new Map(this._registrations)) {
|
|
2378
|
+
const errors = [];
|
|
2379
|
+
Object.entries(userFixtures).forEach(([name, fn]) => {
|
|
2380
|
+
var _a;
|
|
2381
|
+
let options;
|
|
2382
|
+
let value;
|
|
2383
|
+
let _options;
|
|
2384
|
+
if (Array.isArray(fn) && fn.length >= 2 && TestFixtures.isFixtureOptions(fn[1])) {
|
|
2385
|
+
_options = fn[1];
|
|
2386
|
+
options = {
|
|
2387
|
+
auto: _options.auto ?? false,
|
|
2388
|
+
scope: _options.scope ?? "test",
|
|
2389
|
+
injected: _options.injected ?? false
|
|
2390
|
+
};
|
|
2391
|
+
value = options.injected ? ((_a = runner2.injectValue) == null ? void 0 : _a.call(runner2, name)) ?? fn[0] : fn[0];
|
|
2392
|
+
} else {
|
|
2393
|
+
value = fn;
|
|
2394
|
+
}
|
|
2395
|
+
const parent = registrations.get(name);
|
|
2396
|
+
if (parent && options) {
|
|
2397
|
+
if (parent.scope !== options.scope) {
|
|
2398
|
+
errors.push(new FixtureDependencyError(`The "${name}" fixture was already registered with a "${options.scope}" scope.`));
|
|
2399
|
+
}
|
|
2400
|
+
if (parent.auto !== options.auto) {
|
|
2401
|
+
errors.push(new FixtureDependencyError(`The "${name}" fixture was already registered as { auto: ${options.auto} }.`));
|
|
2402
|
+
}
|
|
2403
|
+
} else if (parent) {
|
|
2404
|
+
options = {
|
|
2405
|
+
auto: parent.auto,
|
|
2406
|
+
scope: parent.scope,
|
|
2407
|
+
injected: parent.injected
|
|
2408
|
+
};
|
|
2409
|
+
} else if (!options) {
|
|
2410
|
+
options = {
|
|
2411
|
+
auto: false,
|
|
2412
|
+
injected: false,
|
|
2413
|
+
scope: "test"
|
|
2414
|
+
};
|
|
2415
|
+
}
|
|
2416
|
+
if (options.scope && !TestFixtures._fixtureScopes.includes(options.scope)) {
|
|
2417
|
+
errors.push(new FixtureDependencyError(`The "${name}" fixture has unknown scope "${options.scope}".`));
|
|
2418
|
+
}
|
|
2419
|
+
if (!supportNonTest && options.scope !== "test") {
|
|
2420
|
+
errors.push(new FixtureDependencyError(`The "${name}" fixture cannot be defined with a ${options.scope} scope${!(_options == null ? void 0 : _options.scope) && (parent == null ? void 0 : parent.scope) ? " (inherited from the base fixture)" : ""} inside the describe block. Define it at the top level of the file instead.`));
|
|
2421
|
+
}
|
|
2422
|
+
const deps = isFixtureFunction(value) ? getUsedProps(value) : /* @__PURE__ */ new Set();
|
|
2423
|
+
const item = {
|
|
2424
|
+
name,
|
|
2425
|
+
value,
|
|
2426
|
+
auto: options.auto ?? false,
|
|
2427
|
+
injected: options.injected ?? false,
|
|
2428
|
+
scope: options.scope ?? "test",
|
|
2429
|
+
deps,
|
|
2430
|
+
parent
|
|
2431
|
+
};
|
|
2432
|
+
if (isFixtureFunction(value)) {
|
|
2433
|
+
Object.assign(value, { [FIXTURE_STACK_TRACE_KEY]: new Error("STACK_TRACE_ERROR") });
|
|
2434
|
+
}
|
|
2435
|
+
registrations.set(name, item);
|
|
2436
|
+
if (item.scope === "worker" && (runner2.pool === "vmThreads" || runner2.pool === "vmForks")) {
|
|
2437
|
+
item.scope = "file";
|
|
2438
|
+
}
|
|
2439
|
+
});
|
|
2440
|
+
for (const fixture of registrations.values()) {
|
|
2441
|
+
for (const depName of fixture.deps) {
|
|
2442
|
+
if (TestFixtures._builtinFixtures.includes(depName)) {
|
|
2443
|
+
continue;
|
|
2444
|
+
}
|
|
2445
|
+
const dep = registrations.get(depName);
|
|
2446
|
+
if (!dep) {
|
|
2447
|
+
errors.push(new FixtureDependencyError(`The "${fixture.name}" fixture depends on unknown fixture "${depName}".`));
|
|
2448
|
+
continue;
|
|
2449
|
+
}
|
|
2450
|
+
if (depName === fixture.name && !fixture.parent) {
|
|
2451
|
+
errors.push(new FixtureDependencyError(`The "${fixture.name}" fixture depends on itself, but does not have a base implementation.`));
|
|
2452
|
+
continue;
|
|
2453
|
+
}
|
|
2454
|
+
if (TestFixtures._fixtureScopes.indexOf(fixture.scope) > TestFixtures._fixtureScopes.indexOf(dep.scope)) {
|
|
2455
|
+
errors.push(new FixtureDependencyError(`The ${fixture.scope} "${fixture.name}" fixture cannot depend on a ${dep.scope} fixture "${dep.name}".`));
|
|
2456
|
+
continue;
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
if (errors.length === 1) {
|
|
2461
|
+
throw errors[0];
|
|
2462
|
+
} else if (errors.length > 1) {
|
|
2463
|
+
throw new AggregateError(errors, "Cannot resolve user fixtures. See errors for more information.");
|
|
2464
|
+
}
|
|
2465
|
+
return registrations;
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
const cleanupFnArrayMap = /* @__PURE__ */ new WeakMap();
|
|
2469
|
+
const contextHasFixturesCache = /* @__PURE__ */ new WeakMap();
|
|
2470
|
+
function withFixtures(fn, options) {
|
|
2471
|
+
const collector = getCurrentSuite();
|
|
2472
|
+
const suite2 = (options == null ? void 0 : options.suite) || collector.suite || collector.file;
|
|
2473
|
+
return async (hookContext) => {
|
|
2474
|
+
var _a;
|
|
2475
|
+
const context = hookContext || (options == null ? void 0 : options.context);
|
|
2476
|
+
if (!context) {
|
|
2477
|
+
if (options == null ? void 0 : options.suiteHook) {
|
|
2478
|
+
validateSuiteHook(fn, options.suiteHook, options.stackTraceError);
|
|
2479
|
+
}
|
|
2480
|
+
return fn({});
|
|
2481
|
+
}
|
|
2482
|
+
const fixtures = (options == null ? void 0 : options.fixtures) || getTestFixtures(context);
|
|
2483
|
+
if (!fixtures) {
|
|
2484
|
+
return fn(context);
|
|
2485
|
+
}
|
|
2486
|
+
const registrations = fixtures.get(suite2);
|
|
2487
|
+
if (!registrations.size) {
|
|
2488
|
+
return fn(context);
|
|
2489
|
+
}
|
|
2490
|
+
const usedFixtures = [];
|
|
2491
|
+
const usedProps = getUsedProps(fn);
|
|
2492
|
+
for (const fixture of registrations.values()) {
|
|
2493
|
+
if (fixture.auto || usedProps.has(fixture.name)) {
|
|
2494
|
+
usedFixtures.push(fixture);
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
if (!usedFixtures.length) {
|
|
2498
|
+
return fn(context);
|
|
2499
|
+
}
|
|
2500
|
+
if (!cleanupFnArrayMap.has(context)) {
|
|
2501
|
+
cleanupFnArrayMap.set(context, []);
|
|
2502
|
+
}
|
|
2503
|
+
const cleanupFnArray = cleanupFnArrayMap.get(context);
|
|
2504
|
+
const pendingFixtures = resolveDeps(usedFixtures, registrations);
|
|
2505
|
+
if (!pendingFixtures.length) {
|
|
2506
|
+
return fn(context);
|
|
2507
|
+
}
|
|
2508
|
+
if (options == null ? void 0 : options.suiteHook) {
|
|
2509
|
+
const testScopedFixtures = pendingFixtures.filter((f2) => f2.scope === "test");
|
|
2510
|
+
if (testScopedFixtures.length > 0) {
|
|
2511
|
+
const fixtureNames = testScopedFixtures.map((f2) => `"${f2.name}"`).join(", ");
|
|
2512
|
+
const alternativeHook = {
|
|
2513
|
+
aroundAll: "aroundEach",
|
|
2514
|
+
beforeAll: "beforeEach",
|
|
2515
|
+
afterAll: "afterEach"
|
|
2516
|
+
};
|
|
2517
|
+
const error = new FixtureDependencyError(`Test-scoped fixtures cannot be used inside ${options.suiteHook} hook. The following fixtures are test-scoped: ${fixtureNames}. Use { scope: 'file' } or { scope: 'worker' } fixtures instead, or move the logic to ${alternativeHook[options.suiteHook]} hook.`);
|
|
2518
|
+
if ((_a = options.stackTraceError) == null ? void 0 : _a.stack) {
|
|
2519
|
+
error.stack = error.message + options.stackTraceError.stack.replace(options.stackTraceError.message, "");
|
|
2520
|
+
}
|
|
2521
|
+
throw error;
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
if (!contextHasFixturesCache.has(context)) {
|
|
2525
|
+
contextHasFixturesCache.set(context, /* @__PURE__ */ new WeakSet());
|
|
2526
|
+
}
|
|
2527
|
+
const cachedFixtures = contextHasFixturesCache.get(context);
|
|
2528
|
+
for (const fixture of pendingFixtures) {
|
|
2529
|
+
if (fixture.scope === "test") {
|
|
2530
|
+
if (cachedFixtures.has(fixture)) {
|
|
2531
|
+
continue;
|
|
2532
|
+
}
|
|
2533
|
+
cachedFixtures.add(fixture);
|
|
2534
|
+
const resolvedValue = await resolveTestFixtureValue(fixture, context, cleanupFnArray);
|
|
2535
|
+
context[fixture.name] = resolvedValue;
|
|
2536
|
+
cleanupFnArray.push(() => {
|
|
2537
|
+
cachedFixtures.delete(fixture);
|
|
2538
|
+
});
|
|
2539
|
+
} else {
|
|
2540
|
+
const resolvedValue = await resolveScopeFixtureValue(fixtures, suite2, fixture);
|
|
2541
|
+
context[fixture.name] = resolvedValue;
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
return fn(context);
|
|
2545
|
+
};
|
|
2546
|
+
}
|
|
2547
|
+
function isFixtureFunction(value) {
|
|
2548
|
+
return typeof value === "function";
|
|
2549
|
+
}
|
|
2550
|
+
function resolveTestFixtureValue(fixture, context, cleanupFnArray) {
|
|
2551
|
+
if (!isFixtureFunction(fixture.value)) {
|
|
2552
|
+
return fixture.value;
|
|
2553
|
+
}
|
|
2554
|
+
return resolveFixtureFunction(fixture.value, fixture.name, context, cleanupFnArray);
|
|
2555
|
+
}
|
|
2556
|
+
const scopedFixturePromiseCache = /* @__PURE__ */ new WeakMap();
|
|
2557
|
+
async function resolveScopeFixtureValue(fixtures, suite2, fixture) {
|
|
2558
|
+
const workerContext = fixtures.getWorkerContext();
|
|
2559
|
+
const fileContext = fixtures.getFileContext(suite2.file);
|
|
2560
|
+
const fixtureContext = fixture.scope === "worker" ? workerContext : fileContext;
|
|
2561
|
+
if (!isFixtureFunction(fixture.value)) {
|
|
2562
|
+
fixtureContext[fixture.name] = fixture.value;
|
|
2563
|
+
return fixture.value;
|
|
2564
|
+
}
|
|
2565
|
+
if (fixture.name in fixtureContext) {
|
|
2566
|
+
return fixtureContext[fixture.name];
|
|
2567
|
+
}
|
|
2568
|
+
if (scopedFixturePromiseCache.has(fixture)) {
|
|
2569
|
+
return scopedFixturePromiseCache.get(fixture);
|
|
2570
|
+
}
|
|
2571
|
+
if (!cleanupFnArrayMap.has(fixtureContext)) {
|
|
2572
|
+
cleanupFnArrayMap.set(fixtureContext, []);
|
|
2573
|
+
}
|
|
2574
|
+
const cleanupFnFileArray = cleanupFnArrayMap.get(fixtureContext);
|
|
2575
|
+
const promise = resolveFixtureFunction(fixture.value, fixture.name, fixture.scope === "file" ? {
|
|
2576
|
+
...workerContext,
|
|
2577
|
+
...fileContext
|
|
2578
|
+
} : fixtureContext, cleanupFnFileArray).then((value) => {
|
|
2579
|
+
fixtureContext[fixture.name] = value;
|
|
2580
|
+
scopedFixturePromiseCache.delete(fixture);
|
|
2581
|
+
return value;
|
|
2582
|
+
});
|
|
2583
|
+
scopedFixturePromiseCache.set(fixture, promise);
|
|
2584
|
+
return promise;
|
|
2585
|
+
}
|
|
2586
|
+
async function resolveFixtureFunction(fixtureFn, fixtureName, context, cleanupFnArray) {
|
|
2587
|
+
const useFnArgPromise = createDefer();
|
|
2588
|
+
const stackTraceError = FIXTURE_STACK_TRACE_KEY in fixtureFn && fixtureFn[FIXTURE_STACK_TRACE_KEY] instanceof Error ? fixtureFn[FIXTURE_STACK_TRACE_KEY] : void 0;
|
|
2589
|
+
let isUseFnArgResolved = false;
|
|
2590
|
+
const fixtureReturn = fixtureFn(context, async (useFnArg) => {
|
|
2591
|
+
isUseFnArgResolved = true;
|
|
2592
|
+
useFnArgPromise.resolve(useFnArg);
|
|
2593
|
+
const useReturnPromise = createDefer();
|
|
2594
|
+
cleanupFnArray.push(async () => {
|
|
2595
|
+
useReturnPromise.resolve();
|
|
2596
|
+
await fixtureReturn;
|
|
2597
|
+
});
|
|
2598
|
+
await useReturnPromise;
|
|
2599
|
+
}).then(() => {
|
|
2600
|
+
if (!isUseFnArgResolved) {
|
|
2601
|
+
const error = new Error(`Fixture "${fixtureName}" returned without calling "use". Make sure to call "use" in every code path of the fixture function.`);
|
|
2602
|
+
if (stackTraceError == null ? void 0 : stackTraceError.stack) {
|
|
2603
|
+
error.stack = error.message + stackTraceError.stack.replace(stackTraceError.message, "");
|
|
2604
|
+
}
|
|
2605
|
+
useFnArgPromise.reject(error);
|
|
2606
|
+
}
|
|
2607
|
+
}).catch((e) => {
|
|
2608
|
+
if (!isUseFnArgResolved) {
|
|
2609
|
+
useFnArgPromise.reject(e);
|
|
2610
|
+
return;
|
|
2611
|
+
}
|
|
2612
|
+
throw e;
|
|
2613
|
+
});
|
|
2614
|
+
return useFnArgPromise;
|
|
2615
|
+
}
|
|
2616
|
+
function resolveDeps(usedFixtures, registrations, depSet = /* @__PURE__ */ new Set(), pendingFixtures = []) {
|
|
2617
|
+
usedFixtures.forEach((fixture) => {
|
|
2618
|
+
if (pendingFixtures.includes(fixture)) {
|
|
2619
|
+
return;
|
|
2620
|
+
}
|
|
2621
|
+
if (!isFixtureFunction(fixture.value) || !fixture.deps) {
|
|
2622
|
+
pendingFixtures.push(fixture);
|
|
2623
|
+
return;
|
|
2624
|
+
}
|
|
2625
|
+
if (depSet.has(fixture)) {
|
|
2626
|
+
if (fixture.parent) {
|
|
2627
|
+
fixture = fixture.parent;
|
|
2628
|
+
} else {
|
|
2629
|
+
throw new Error(`Circular fixture dependency detected: ${fixture.name} <- ${[...depSet].reverse().map((d2) => d2.name).join(" <- ")}`);
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
depSet.add(fixture);
|
|
2633
|
+
resolveDeps([...fixture.deps].map((n) => n === fixture.name ? fixture.parent : registrations.get(n)).filter((n) => !!n), registrations, depSet, pendingFixtures);
|
|
2634
|
+
pendingFixtures.push(fixture);
|
|
2635
|
+
depSet.clear();
|
|
2636
|
+
});
|
|
2637
|
+
return pendingFixtures;
|
|
2638
|
+
}
|
|
2639
|
+
function validateSuiteHook(fn, hook, suiteError) {
|
|
2640
|
+
var _a;
|
|
2641
|
+
const usedProps = getUsedProps(fn, {
|
|
2642
|
+
sourceError: suiteError,
|
|
2643
|
+
suiteHook: hook
|
|
2644
|
+
});
|
|
2645
|
+
if (usedProps.size) {
|
|
2646
|
+
const error = new FixtureAccessError(`The ${hook} hook uses fixtures "${[...usedProps].join('", "')}", but has no access to context. Did you forget to call it as "test.${hook}()" instead of "${hook}()"?
|
|
2647
|
+
If you used internal "suite" task as the first argument previously, access it in the second argument instead. See https://vitest.dev/guide/test-context#suite-level-hooks`);
|
|
2648
|
+
if (suiteError) {
|
|
2649
|
+
error.stack = (_a = suiteError.stack) == null ? void 0 : _a.replace(suiteError.message, error.message);
|
|
2650
|
+
}
|
|
2651
|
+
throw error;
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
const kPropsSymbol = Symbol("$vitest:fixture-props");
|
|
2655
|
+
const kPropNamesSymbol = Symbol("$vitest:fixture-prop-names");
|
|
2656
|
+
function configureProps(fn, options) {
|
|
2657
|
+
Object.defineProperty(fn, kPropsSymbol, {
|
|
2658
|
+
value: options,
|
|
2659
|
+
enumerable: false
|
|
2660
|
+
});
|
|
2661
|
+
}
|
|
2662
|
+
function memoProps(fn, props) {
|
|
2663
|
+
fn[kPropNamesSymbol] = props;
|
|
2664
|
+
return props;
|
|
2665
|
+
}
|
|
2666
|
+
function getUsedProps(fn, { sourceError, suiteHook } = {}) {
|
|
2667
|
+
var _a, _b;
|
|
2668
|
+
if (kPropNamesSymbol in fn) {
|
|
2669
|
+
return fn[kPropNamesSymbol];
|
|
2670
|
+
}
|
|
2671
|
+
const { index: fixturesIndex = 0, original: implementation = fn } = kPropsSymbol in fn ? fn[kPropsSymbol] : {};
|
|
2672
|
+
let fnString = filterOutComments(implementation.toString());
|
|
2673
|
+
if (/__async\((?:this|null), (?:null|arguments|\[[_0-9, ]*\]), function\*/.test(fnString)) {
|
|
2674
|
+
fnString = fnString.split(/__async\((?:this|null),/)[1];
|
|
2675
|
+
}
|
|
2676
|
+
const match = fnString.match(/[^(]*\(([^)]*)/);
|
|
2677
|
+
if (!match) {
|
|
2678
|
+
return memoProps(fn, /* @__PURE__ */ new Set());
|
|
2679
|
+
}
|
|
2680
|
+
const args = splitByComma(match[1]);
|
|
2681
|
+
if (!args.length) {
|
|
2682
|
+
return memoProps(fn, /* @__PURE__ */ new Set());
|
|
2683
|
+
}
|
|
2684
|
+
const fixturesArgument = args[fixturesIndex];
|
|
2685
|
+
if (!fixturesArgument) {
|
|
2686
|
+
return memoProps(fn, /* @__PURE__ */ new Set());
|
|
2687
|
+
}
|
|
2688
|
+
if (!(fixturesArgument[0] === "{" && fixturesArgument.endsWith("}"))) {
|
|
2689
|
+
const ordinalArgument = ordinal(fixturesIndex + 1);
|
|
2690
|
+
const error = new FixtureParseError(`The ${ordinalArgument} argument inside a fixture must use object destructuring pattern, e.g. ({ task } => {}). Instead, received "${fixturesArgument}".${suiteHook ? ` If you used internal "suite" task as the ${ordinalArgument} argument previously, access it in the ${ordinal(fixturesIndex + 2)} argument instead.` : ""}`);
|
|
2691
|
+
if (sourceError) {
|
|
2692
|
+
error.stack = (_a = sourceError.stack) == null ? void 0 : _a.replace(sourceError.message, error.message);
|
|
2693
|
+
}
|
|
2694
|
+
throw error;
|
|
2695
|
+
}
|
|
2696
|
+
const _first = fixturesArgument.slice(1, -1).replace(/\s/g, "");
|
|
2697
|
+
const props = splitByComma(_first).map((prop) => {
|
|
2698
|
+
return prop.replace(/:.*|=.*/g, "");
|
|
2699
|
+
});
|
|
2700
|
+
const last = props.at(-1);
|
|
2701
|
+
if (last && last.startsWith("...")) {
|
|
2702
|
+
const error = new FixtureParseError(`Rest parameters are not supported in fixtures, received "${last}".`);
|
|
2703
|
+
if (sourceError) {
|
|
2704
|
+
error.stack = (_b = sourceError.stack) == null ? void 0 : _b.replace(sourceError.message, error.message);
|
|
2705
|
+
}
|
|
2706
|
+
throw error;
|
|
2707
|
+
}
|
|
2708
|
+
return memoProps(fn, new Set(props));
|
|
2709
|
+
}
|
|
2710
|
+
function splitByComma(s) {
|
|
2711
|
+
const result = [];
|
|
2712
|
+
const stack = [];
|
|
2713
|
+
let start = 0;
|
|
2714
|
+
for (let i = 0; i < s.length; i++) {
|
|
2715
|
+
if (s[i] === "{" || s[i] === "[") {
|
|
2716
|
+
stack.push(s[i] === "{" ? "}" : "]");
|
|
2717
|
+
} else if (s[i] === stack.at(-1)) {
|
|
2718
|
+
stack.pop();
|
|
2719
|
+
} else if (!stack.length && s[i] === ",") {
|
|
2720
|
+
const token = s.substring(start, i).trim();
|
|
2721
|
+
if (token) {
|
|
2722
|
+
result.push(token);
|
|
2723
|
+
}
|
|
2724
|
+
start = i + 1;
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
const lastToken = s.substring(start).trim();
|
|
2728
|
+
if (lastToken) {
|
|
2729
|
+
result.push(lastToken);
|
|
2730
|
+
}
|
|
2731
|
+
return result;
|
|
2732
|
+
}
|
|
2733
|
+
const kChainableContext = Symbol("kChainableContext");
|
|
2734
|
+
function getChainableContext(chainable) {
|
|
2735
|
+
return chainable == null ? void 0 : chainable[kChainableContext];
|
|
2736
|
+
}
|
|
2737
|
+
function createChainable(keys, fn, context) {
|
|
2738
|
+
function create(context2) {
|
|
2739
|
+
const chain2 = function(...args) {
|
|
2740
|
+
return fn.apply(context2, args);
|
|
2741
|
+
};
|
|
2742
|
+
Object.assign(chain2, fn);
|
|
2743
|
+
Object.defineProperty(chain2, kChainableContext, {
|
|
2744
|
+
value: {
|
|
2745
|
+
withContext: () => chain2.bind(context2),
|
|
2746
|
+
getFixtures: () => context2.fixtures,
|
|
2747
|
+
setContext: (key, value) => {
|
|
2748
|
+
context2[key] = value;
|
|
2749
|
+
},
|
|
2750
|
+
mergeContext: (ctx) => {
|
|
2751
|
+
Object.assign(context2, ctx);
|
|
2752
|
+
}
|
|
2753
|
+
},
|
|
2754
|
+
enumerable: false
|
|
2755
|
+
});
|
|
2756
|
+
for (const key of keys) {
|
|
2757
|
+
Object.defineProperty(chain2, key, { get() {
|
|
2758
|
+
return create({
|
|
2759
|
+
...context2,
|
|
2760
|
+
[key]: true
|
|
2761
|
+
});
|
|
2762
|
+
} });
|
|
2763
|
+
}
|
|
2764
|
+
return chain2;
|
|
2765
|
+
}
|
|
2766
|
+
const chain = create(context ?? {});
|
|
2767
|
+
Object.defineProperty(chain, "fn", {
|
|
2768
|
+
value: fn,
|
|
2769
|
+
enumerable: false
|
|
2770
|
+
});
|
|
2771
|
+
return chain;
|
|
2772
|
+
}
|
|
2773
|
+
function getDefaultHookTimeout() {
|
|
2774
|
+
return getRunner().config.hookTimeout;
|
|
2775
|
+
}
|
|
2776
|
+
const CLEANUP_TIMEOUT_KEY = Symbol.for("VITEST_CLEANUP_TIMEOUT");
|
|
2777
|
+
const CLEANUP_STACK_TRACE_KEY = Symbol.for("VITEST_CLEANUP_STACK_TRACE");
|
|
2778
|
+
const AROUND_TIMEOUT_KEY = Symbol.for("VITEST_AROUND_TIMEOUT");
|
|
2779
|
+
const AROUND_STACK_TRACE_KEY = Symbol.for("VITEST_AROUND_STACK_TRACE");
|
|
2780
|
+
function beforeAll(fn, timeout = getDefaultHookTimeout()) {
|
|
2781
|
+
assertTypes(fn, '"beforeAll" callback', ["function"]);
|
|
2782
|
+
const stackTraceError = new Error("STACK_TRACE_ERROR");
|
|
2783
|
+
const context = getChainableContext(this);
|
|
2784
|
+
return getCurrentSuite().on("beforeAll", Object.assign(withTimeout(withSuiteFixtures("beforeAll", fn, context, stackTraceError), timeout, true, stackTraceError), {
|
|
2785
|
+
[CLEANUP_TIMEOUT_KEY]: timeout,
|
|
2786
|
+
[CLEANUP_STACK_TRACE_KEY]: stackTraceError
|
|
2787
|
+
}));
|
|
2788
|
+
}
|
|
2789
|
+
function afterAll(fn, timeout) {
|
|
2790
|
+
assertTypes(fn, '"afterAll" callback', ["function"]);
|
|
2791
|
+
const context = getChainableContext(this);
|
|
2792
|
+
const stackTraceError = new Error("STACK_TRACE_ERROR");
|
|
2793
|
+
return getCurrentSuite().on("afterAll", withTimeout(withSuiteFixtures("afterAll", fn, context, stackTraceError), timeout ?? getDefaultHookTimeout(), true, stackTraceError));
|
|
2794
|
+
}
|
|
2795
|
+
function beforeEach(fn, timeout = getDefaultHookTimeout()) {
|
|
2796
|
+
assertTypes(fn, '"beforeEach" callback', ["function"]);
|
|
2797
|
+
const stackTraceError = new Error("STACK_TRACE_ERROR");
|
|
2798
|
+
const wrapper = (context, suite2) => {
|
|
2799
|
+
const fixtureResolver = withFixtures(fn, { suite: suite2 });
|
|
2800
|
+
return fixtureResolver(context);
|
|
2801
|
+
};
|
|
2802
|
+
return getCurrentSuite().on("beforeEach", Object.assign(withTimeout(wrapper, timeout ?? getDefaultHookTimeout(), true, stackTraceError, abortIfTimeout), {
|
|
2803
|
+
[CLEANUP_TIMEOUT_KEY]: timeout,
|
|
2804
|
+
[CLEANUP_STACK_TRACE_KEY]: stackTraceError
|
|
2805
|
+
}));
|
|
2806
|
+
}
|
|
2807
|
+
function afterEach(fn, timeout) {
|
|
2808
|
+
assertTypes(fn, '"afterEach" callback', ["function"]);
|
|
2809
|
+
const wrapper = (context, suite2) => {
|
|
2810
|
+
const fixtureResolver = withFixtures(fn, { suite: suite2 });
|
|
2811
|
+
return fixtureResolver(context);
|
|
2812
|
+
};
|
|
2813
|
+
return getCurrentSuite().on("afterEach", withTimeout(wrapper, timeout ?? getDefaultHookTimeout(), true, new Error("STACK_TRACE_ERROR"), abortIfTimeout));
|
|
2814
|
+
}
|
|
2815
|
+
function aroundAll(fn, timeout) {
|
|
2816
|
+
assertTypes(fn, '"aroundAll" callback', ["function"]);
|
|
2817
|
+
const stackTraceError = new Error("STACK_TRACE_ERROR");
|
|
2818
|
+
const resolvedTimeout = timeout ?? getDefaultHookTimeout();
|
|
2819
|
+
const context = getChainableContext(this);
|
|
2820
|
+
return getCurrentSuite().on("aroundAll", Object.assign(withSuiteFixtures("aroundAll", fn, context, stackTraceError, 1), {
|
|
2821
|
+
[AROUND_TIMEOUT_KEY]: resolvedTimeout,
|
|
2822
|
+
[AROUND_STACK_TRACE_KEY]: stackTraceError
|
|
2823
|
+
}));
|
|
2824
|
+
}
|
|
2825
|
+
function aroundEach(fn, timeout) {
|
|
2826
|
+
assertTypes(fn, '"aroundEach" callback', ["function"]);
|
|
2827
|
+
const stackTraceError = new Error("STACK_TRACE_ERROR");
|
|
2828
|
+
const resolvedTimeout = timeout ?? getDefaultHookTimeout();
|
|
2829
|
+
const wrapper = (runTest, context, suite2) => {
|
|
2830
|
+
const innerFn = (ctx) => fn(runTest, ctx, suite2);
|
|
2831
|
+
configureProps(innerFn, {
|
|
2832
|
+
index: 1,
|
|
2833
|
+
original: fn
|
|
2834
|
+
});
|
|
2835
|
+
const fixtureResolver = withFixtures(innerFn, { suite: suite2 });
|
|
2836
|
+
return fixtureResolver(context);
|
|
2837
|
+
};
|
|
2838
|
+
return getCurrentSuite().on("aroundEach", Object.assign(wrapper, {
|
|
2839
|
+
[AROUND_TIMEOUT_KEY]: resolvedTimeout,
|
|
2840
|
+
[AROUND_STACK_TRACE_KEY]: stackTraceError
|
|
2841
|
+
}));
|
|
2842
|
+
}
|
|
2843
|
+
function withSuiteFixtures(suiteHook, fn, context, stackTraceError, contextIndex = 0) {
|
|
2844
|
+
return (...args) => {
|
|
2845
|
+
const suite2 = args.at(-1);
|
|
2846
|
+
const prefix = args.slice(0, -1);
|
|
2847
|
+
const wrapper = (ctx) => fn(...prefix, ctx, suite2);
|
|
2848
|
+
configureProps(wrapper, {
|
|
2849
|
+
index: contextIndex,
|
|
2850
|
+
original: fn
|
|
2851
|
+
});
|
|
2852
|
+
const fixtures = context == null ? void 0 : context.getFixtures();
|
|
2853
|
+
const fileContext = fixtures == null ? void 0 : fixtures.getFileContext(suite2.file);
|
|
2854
|
+
const fixtured = withFixtures(wrapper, {
|
|
2855
|
+
suiteHook,
|
|
2856
|
+
fixtures,
|
|
2857
|
+
context: fileContext,
|
|
2858
|
+
stackTraceError
|
|
2859
|
+
});
|
|
2860
|
+
return fixtured();
|
|
2861
|
+
};
|
|
2862
|
+
}
|
|
2863
|
+
// @__NO_SIDE_EFFECTS__
|
|
2864
|
+
function generateHash(str) {
|
|
2865
|
+
let hash = 0;
|
|
2866
|
+
if (str.length === 0) {
|
|
2867
|
+
return `${hash}`;
|
|
2868
|
+
}
|
|
2869
|
+
for (let i = 0; i < str.length; i++) {
|
|
2870
|
+
const char = str.charCodeAt(i);
|
|
2871
|
+
hash = (hash << 5) - hash + char;
|
|
2872
|
+
hash = hash & hash;
|
|
2873
|
+
}
|
|
2874
|
+
return `${hash}`;
|
|
2875
|
+
}
|
|
2876
|
+
// @__NO_SIDE_EFFECTS__
|
|
2877
|
+
function generateFileHash(file, projectName) {
|
|
2878
|
+
return /* @__PURE__ */ generateHash(`${file}${projectName || ""}`);
|
|
2879
|
+
}
|
|
2880
|
+
function findTestFileStackTrace(testFilePath, error) {
|
|
2881
|
+
const lines = error.split("\n").slice(1);
|
|
2882
|
+
for (const line of lines) {
|
|
2883
|
+
const stack = parseSingleStack(line);
|
|
2884
|
+
if (stack && stack.file === testFilePath) {
|
|
2885
|
+
return stack;
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
function validateTags(config, tags) {
|
|
2890
|
+
if (!config.strictTags) {
|
|
2891
|
+
return;
|
|
2892
|
+
}
|
|
2893
|
+
const availableTags = new Set(config.tags.map((tag) => tag.name));
|
|
2894
|
+
for (const tag of tags) {
|
|
2895
|
+
if (!availableTags.has(tag)) {
|
|
2896
|
+
throw createNoTagsError(config.tags, tag);
|
|
2897
|
+
}
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
function createNoTagsError(availableTags, tag, prefix = "tag") {
|
|
2901
|
+
if (!availableTags.length) {
|
|
2902
|
+
throw new Error(`The Vitest config does't define any "tags", cannot apply "${tag}" ${prefix} for this test. See: https://vitest.dev/guide/test-tags`);
|
|
2903
|
+
}
|
|
2904
|
+
throw new Error(`The ${prefix} "${tag}" is not defined in the configuration. Available tags are:
|
|
2905
|
+
${availableTags.map((t) => `- ${t.name}${t.description ? `: ${t.description}` : ""}`).join("\n")}`);
|
|
2906
|
+
}
|
|
2907
|
+
function getNames(task) {
|
|
2908
|
+
const names = [task.name];
|
|
2909
|
+
let current = task;
|
|
2910
|
+
while (current == null ? void 0 : current.suite) {
|
|
2911
|
+
current = current.suite;
|
|
2912
|
+
if (current == null ? void 0 : current.name) {
|
|
2913
|
+
names.unshift(current.name);
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
if (current !== task.file) {
|
|
2917
|
+
names.unshift(task.file.name);
|
|
2918
|
+
}
|
|
2919
|
+
return names;
|
|
2920
|
+
}
|
|
2921
|
+
function getTestName(task, separator = " > ") {
|
|
2922
|
+
return getNames(task).slice(1).join(separator);
|
|
2923
|
+
}
|
|
2924
|
+
function createTaskName(names, separator = " > ") {
|
|
2925
|
+
return names.filter((name) => name !== void 0).join(separator);
|
|
2926
|
+
}
|
|
2927
|
+
const suite = createSuite();
|
|
2928
|
+
createTest(function(name, optionsOrFn, optionsOrTest) {
|
|
2929
|
+
getCurrentSuite().test.fn.call(this, formatName(name), optionsOrFn, optionsOrTest);
|
|
2930
|
+
});
|
|
2931
|
+
let runner;
|
|
2932
|
+
let defaultSuite;
|
|
2933
|
+
let currentTestFilepath;
|
|
2934
|
+
function assert(condition, message) {
|
|
2935
|
+
if (!condition) {
|
|
2936
|
+
throw new Error(`Vitest failed to find ${message}. One of the following is possible:
|
|
2937
|
+
- "vitest" is imported directly without running "vitest" command
|
|
2938
|
+
- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)
|
|
2939
|
+
- "vitest" is imported inside Vite / Vitest config file
|
|
2940
|
+
- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues
|
|
2941
|
+
`);
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
function getRunner() {
|
|
2945
|
+
assert(runner, "the runner");
|
|
2946
|
+
return runner;
|
|
2947
|
+
}
|
|
2948
|
+
function getCurrentSuite() {
|
|
2949
|
+
const currentSuite = collectorContext.currentSuite || defaultSuite;
|
|
2950
|
+
assert(currentSuite, "the current suite");
|
|
2951
|
+
return currentSuite;
|
|
2952
|
+
}
|
|
2953
|
+
function createSuiteHooks() {
|
|
2954
|
+
return {
|
|
2955
|
+
beforeAll: [],
|
|
2956
|
+
afterAll: [],
|
|
2957
|
+
beforeEach: [],
|
|
2958
|
+
afterEach: [],
|
|
2959
|
+
aroundEach: [],
|
|
2960
|
+
aroundAll: []
|
|
2961
|
+
};
|
|
2962
|
+
}
|
|
2963
|
+
const POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
|
|
2964
|
+
function parseArguments(optionsOrFn, timeoutOrTest) {
|
|
2965
|
+
if (timeoutOrTest != null && typeof timeoutOrTest === "object") {
|
|
2966
|
+
throw new TypeError(`Signature "test(name, fn, { ... })" was deprecated in Vitest 3 and removed in Vitest 4. Please, provide options as a second argument instead.`);
|
|
2967
|
+
}
|
|
2968
|
+
let options = {};
|
|
2969
|
+
let fn;
|
|
2970
|
+
if (typeof timeoutOrTest === "number") {
|
|
2971
|
+
options = { timeout: timeoutOrTest };
|
|
2972
|
+
} else if (typeof optionsOrFn === "object") {
|
|
2973
|
+
options = optionsOrFn;
|
|
2974
|
+
}
|
|
2975
|
+
if (typeof optionsOrFn === "function") {
|
|
2976
|
+
if (typeof timeoutOrTest === "function") {
|
|
2977
|
+
throw new TypeError("Cannot use two functions as arguments. Please use the second argument for options.");
|
|
2978
|
+
}
|
|
2979
|
+
fn = optionsOrFn;
|
|
2980
|
+
} else if (typeof timeoutOrTest === "function") {
|
|
2981
|
+
fn = timeoutOrTest;
|
|
2982
|
+
}
|
|
2983
|
+
return {
|
|
2984
|
+
options,
|
|
2985
|
+
handler: fn
|
|
2986
|
+
};
|
|
2987
|
+
}
|
|
2988
|
+
function createSuiteCollector(name, factory = () => {
|
|
2989
|
+
}, mode, each, suiteOptions) {
|
|
2990
|
+
const tasks = [];
|
|
2991
|
+
let suite2;
|
|
2992
|
+
initSuite();
|
|
2993
|
+
const task = function(name2 = "", options = {}) {
|
|
2994
|
+
var _a, _b, _c, _d, _e;
|
|
2995
|
+
const currentSuite = (_a = collectorContext.currentSuite) == null ? void 0 : _a.suite;
|
|
2996
|
+
const parentTask = currentSuite ?? ((_b = collectorContext.currentSuite) == null ? void 0 : _b.file);
|
|
2997
|
+
const parentTags = (parentTask == null ? void 0 : parentTask.tags) || [];
|
|
2998
|
+
const testTags = unique([...parentTags, ...toArray(options.tags)]);
|
|
2999
|
+
const tagsOptions = testTags.map((tag) => {
|
|
3000
|
+
var _a2;
|
|
3001
|
+
const tagDefinition = (_a2 = runner.config.tags) == null ? void 0 : _a2.find((t) => t.name === tag);
|
|
3002
|
+
if (!tagDefinition && runner.config.strictTags) {
|
|
3003
|
+
throw createNoTagsError(runner.config.tags, tag);
|
|
3004
|
+
}
|
|
3005
|
+
return tagDefinition;
|
|
3006
|
+
}).filter((r) => r != null).sort((tag1, tag2) => (tag2.priority ?? POSITIVE_INFINITY) - (tag1.priority ?? POSITIVE_INFINITY)).reduce((acc, tag) => {
|
|
3007
|
+
const { name: name3, description, priority, meta, ...options2 } = tag;
|
|
3008
|
+
Object.assign(acc, options2);
|
|
3009
|
+
if (meta) {
|
|
3010
|
+
acc.meta = Object.assign(acc.meta ?? /* @__PURE__ */ Object.create(null), meta);
|
|
3011
|
+
}
|
|
3012
|
+
return acc;
|
|
3013
|
+
}, {});
|
|
3014
|
+
const testOwnMeta = options.meta;
|
|
3015
|
+
options = {
|
|
3016
|
+
...tagsOptions,
|
|
3017
|
+
...options
|
|
3018
|
+
};
|
|
3019
|
+
const timeout = options.timeout ?? runner.config.testTimeout;
|
|
3020
|
+
const parentMeta = currentSuite == null ? void 0 : currentSuite.meta;
|
|
3021
|
+
const tagMeta = tagsOptions.meta;
|
|
3022
|
+
const testMeta = /* @__PURE__ */ Object.create(null);
|
|
3023
|
+
if (tagMeta) {
|
|
3024
|
+
Object.assign(testMeta, tagMeta);
|
|
3025
|
+
}
|
|
3026
|
+
if (parentMeta) {
|
|
3027
|
+
Object.assign(testMeta, parentMeta);
|
|
3028
|
+
}
|
|
3029
|
+
if (testOwnMeta) {
|
|
3030
|
+
Object.assign(testMeta, testOwnMeta);
|
|
3031
|
+
}
|
|
3032
|
+
const task2 = {
|
|
3033
|
+
id: "",
|
|
3034
|
+
name: name2,
|
|
3035
|
+
fullName: createTaskName([(currentSuite == null ? void 0 : currentSuite.fullName) ?? ((_d = (_c = collectorContext.currentSuite) == null ? void 0 : _c.file) == null ? void 0 : _d.fullName), name2]),
|
|
3036
|
+
fullTestName: createTaskName([currentSuite == null ? void 0 : currentSuite.fullTestName, name2]),
|
|
3037
|
+
suite: currentSuite,
|
|
3038
|
+
each: options.each,
|
|
3039
|
+
fails: options.fails,
|
|
3040
|
+
context: void 0,
|
|
3041
|
+
type: "test",
|
|
3042
|
+
file: (currentSuite == null ? void 0 : currentSuite.file) ?? ((_e = collectorContext.currentSuite) == null ? void 0 : _e.file),
|
|
3043
|
+
timeout,
|
|
3044
|
+
retry: options.retry ?? runner.config.retry,
|
|
3045
|
+
repeats: options.repeats,
|
|
3046
|
+
mode: options.only ? "only" : options.skip ? "skip" : options.todo ? "todo" : "run",
|
|
3047
|
+
meta: testMeta,
|
|
3048
|
+
annotations: [],
|
|
3049
|
+
artifacts: [],
|
|
3050
|
+
tags: testTags
|
|
3051
|
+
};
|
|
3052
|
+
const handler = options.handler;
|
|
3053
|
+
if (task2.mode === "run" && !handler) {
|
|
3054
|
+
task2.mode = "todo";
|
|
3055
|
+
}
|
|
3056
|
+
if (options.concurrent || !options.sequential && runner.config.sequence.concurrent) {
|
|
3057
|
+
task2.concurrent = true;
|
|
3058
|
+
}
|
|
3059
|
+
task2.shuffle = suiteOptions == null ? void 0 : suiteOptions.shuffle;
|
|
3060
|
+
const context = createTestContext(task2, runner);
|
|
3061
|
+
Object.defineProperty(task2, "context", {
|
|
3062
|
+
value: context,
|
|
3063
|
+
enumerable: false
|
|
3064
|
+
});
|
|
3065
|
+
setTestFixture(context, options.fixtures ?? new TestFixtures());
|
|
3066
|
+
const limit = Error.stackTraceLimit;
|
|
3067
|
+
Error.stackTraceLimit = 10;
|
|
3068
|
+
const stackTraceError = new Error("STACK_TRACE_ERROR");
|
|
3069
|
+
Error.stackTraceLimit = limit;
|
|
3070
|
+
if (handler) {
|
|
3071
|
+
setFn(task2, withTimeout(withCancel(withAwaitAsyncAssertions(withFixtures(handler, { context }), task2), task2.context.signal), timeout, false, stackTraceError, (_, error) => abortIfTimeout([context], error)));
|
|
3072
|
+
}
|
|
3073
|
+
if (runner.config.includeTaskLocation) {
|
|
3074
|
+
const error = stackTraceError.stack;
|
|
3075
|
+
const stack = findTestFileStackTrace(currentTestFilepath, error);
|
|
3076
|
+
if (stack) {
|
|
3077
|
+
task2.location = {
|
|
3078
|
+
line: stack.line,
|
|
3079
|
+
column: stack.column
|
|
3080
|
+
};
|
|
3081
|
+
}
|
|
3082
|
+
}
|
|
3083
|
+
tasks.push(task2);
|
|
3084
|
+
return task2;
|
|
3085
|
+
};
|
|
3086
|
+
const test2 = createTest(function(name2, optionsOrFn, timeoutOrTest) {
|
|
3087
|
+
let { options, handler } = parseArguments(optionsOrFn, timeoutOrTest);
|
|
3088
|
+
if (typeof suiteOptions === "object") {
|
|
3089
|
+
options = Object.assign({}, suiteOptions, options);
|
|
3090
|
+
}
|
|
3091
|
+
const concurrent = this.concurrent ?? (!this.sequential && (options == null ? void 0 : options.concurrent));
|
|
3092
|
+
if (options.concurrent != null && concurrent != null) {
|
|
3093
|
+
options.concurrent = concurrent;
|
|
3094
|
+
}
|
|
3095
|
+
const sequential = this.sequential ?? (!this.concurrent && (options == null ? void 0 : options.sequential));
|
|
3096
|
+
if (options.sequential != null && sequential != null) {
|
|
3097
|
+
options.sequential = sequential;
|
|
3098
|
+
}
|
|
3099
|
+
const test3 = task(formatName(name2), {
|
|
3100
|
+
...this,
|
|
3101
|
+
...options,
|
|
3102
|
+
handler
|
|
3103
|
+
});
|
|
3104
|
+
test3.type = "test";
|
|
3105
|
+
});
|
|
3106
|
+
const collector = {
|
|
3107
|
+
type: "collector",
|
|
3108
|
+
name,
|
|
3109
|
+
mode,
|
|
3110
|
+
suite: suite2,
|
|
3111
|
+
options: suiteOptions,
|
|
3112
|
+
test: test2,
|
|
3113
|
+
file: suite2.file,
|
|
3114
|
+
tasks,
|
|
3115
|
+
collect,
|
|
3116
|
+
task,
|
|
3117
|
+
clear,
|
|
3118
|
+
on: addHook
|
|
3119
|
+
};
|
|
3120
|
+
function addHook(name2, ...fn) {
|
|
3121
|
+
getHooks(suite2)[name2].push(...fn);
|
|
3122
|
+
}
|
|
3123
|
+
function initSuite(includeLocation) {
|
|
3124
|
+
var _a, _b, _c, _d, _e;
|
|
3125
|
+
if (typeof suiteOptions === "number") {
|
|
3126
|
+
suiteOptions = { timeout: suiteOptions };
|
|
3127
|
+
}
|
|
3128
|
+
const currentSuite = (_a = collectorContext.currentSuite) == null ? void 0 : _a.suite;
|
|
3129
|
+
const parentTask = currentSuite ?? ((_b = collectorContext.currentSuite) == null ? void 0 : _b.file);
|
|
3130
|
+
const suiteTags = toArray(suiteOptions == null ? void 0 : suiteOptions.tags);
|
|
3131
|
+
validateTags(runner.config, suiteTags);
|
|
3132
|
+
suite2 = {
|
|
3133
|
+
id: "",
|
|
3134
|
+
type: "suite",
|
|
3135
|
+
name,
|
|
3136
|
+
fullName: createTaskName([(currentSuite == null ? void 0 : currentSuite.fullName) ?? ((_d = (_c = collectorContext.currentSuite) == null ? void 0 : _c.file) == null ? void 0 : _d.fullName), name]),
|
|
3137
|
+
fullTestName: createTaskName([currentSuite == null ? void 0 : currentSuite.fullTestName, name]),
|
|
3138
|
+
suite: currentSuite,
|
|
3139
|
+
mode,
|
|
3140
|
+
each,
|
|
3141
|
+
file: (currentSuite == null ? void 0 : currentSuite.file) ?? ((_e = collectorContext.currentSuite) == null ? void 0 : _e.file),
|
|
3142
|
+
shuffle: suiteOptions == null ? void 0 : suiteOptions.shuffle,
|
|
3143
|
+
tasks: [],
|
|
3144
|
+
meta: (suiteOptions == null ? void 0 : suiteOptions.meta) ?? /* @__PURE__ */ Object.create(null),
|
|
3145
|
+
concurrent: suiteOptions == null ? void 0 : suiteOptions.concurrent,
|
|
3146
|
+
tags: unique([...(parentTask == null ? void 0 : parentTask.tags) || [], ...suiteTags])
|
|
3147
|
+
};
|
|
3148
|
+
setHooks(suite2, createSuiteHooks());
|
|
3149
|
+
}
|
|
3150
|
+
function clear() {
|
|
3151
|
+
tasks.length = 0;
|
|
3152
|
+
initSuite();
|
|
3153
|
+
}
|
|
3154
|
+
async function collect(file) {
|
|
3155
|
+
if (!file) {
|
|
3156
|
+
throw new TypeError("File is required to collect tasks.");
|
|
3157
|
+
}
|
|
3158
|
+
if (factory) {
|
|
3159
|
+
await runWithSuite(collector, () => factory(test2));
|
|
3160
|
+
}
|
|
3161
|
+
const allChildren = [];
|
|
3162
|
+
for (const i of tasks) {
|
|
3163
|
+
allChildren.push(i.type === "collector" ? await i.collect(file) : i);
|
|
3164
|
+
}
|
|
3165
|
+
suite2.tasks = allChildren;
|
|
3166
|
+
return suite2;
|
|
3167
|
+
}
|
|
3168
|
+
collectTask(collector);
|
|
3169
|
+
return collector;
|
|
3170
|
+
}
|
|
3171
|
+
function withAwaitAsyncAssertions(fn, task) {
|
|
3172
|
+
return (async (...args) => {
|
|
3173
|
+
const fnResult = await fn(...args);
|
|
3174
|
+
if (task.promises) {
|
|
3175
|
+
const result = await Promise.allSettled(task.promises);
|
|
3176
|
+
const errors = result.map((r) => r.status === "rejected" ? r.reason : void 0).filter(Boolean);
|
|
3177
|
+
if (errors.length) {
|
|
3178
|
+
throw errors;
|
|
3179
|
+
}
|
|
3180
|
+
}
|
|
3181
|
+
return fnResult;
|
|
3182
|
+
});
|
|
3183
|
+
}
|
|
3184
|
+
function createSuite() {
|
|
3185
|
+
function suiteFn(name, factoryOrOptions, optionsOrFactory) {
|
|
3186
|
+
var _a;
|
|
3187
|
+
const currentSuite = collectorContext.currentSuite || defaultSuite;
|
|
3188
|
+
let { options, handler: factory } = parseArguments(factoryOrOptions, optionsOrFactory);
|
|
3189
|
+
const isConcurrentSpecified = options.concurrent || this.concurrent || options.sequential === false;
|
|
3190
|
+
const isSequentialSpecified = options.sequential || this.sequential || options.concurrent === false;
|
|
3191
|
+
const { meta: parentMeta, ...parentOptions } = (currentSuite == null ? void 0 : currentSuite.options) || {};
|
|
3192
|
+
options = {
|
|
3193
|
+
...parentOptions,
|
|
3194
|
+
...options
|
|
3195
|
+
};
|
|
3196
|
+
const shuffle = this.shuffle ?? options.shuffle ?? ((_a = currentSuite == null ? void 0 : currentSuite.options) == null ? void 0 : _a.shuffle) ?? (runner == null ? void 0 : runner.config.sequence.shuffle);
|
|
3197
|
+
if (shuffle != null) {
|
|
3198
|
+
options.shuffle = shuffle;
|
|
3199
|
+
}
|
|
3200
|
+
let mode = this.only ?? options.only ? "only" : this.skip ?? options.skip ? "skip" : this.todo ?? options.todo ? "todo" : "run";
|
|
3201
|
+
if (mode === "run" && !factory) {
|
|
3202
|
+
mode = "todo";
|
|
3203
|
+
}
|
|
3204
|
+
const isConcurrent = isConcurrentSpecified || options.concurrent && !isSequentialSpecified;
|
|
3205
|
+
const isSequential = isSequentialSpecified || options.sequential && !isConcurrentSpecified;
|
|
3206
|
+
if (isConcurrent != null) {
|
|
3207
|
+
options.concurrent = isConcurrent && !isSequential;
|
|
3208
|
+
}
|
|
3209
|
+
if (isSequential != null) {
|
|
3210
|
+
options.sequential = isSequential && !isConcurrent;
|
|
3211
|
+
}
|
|
3212
|
+
if (parentMeta) {
|
|
3213
|
+
options.meta = Object.assign(/* @__PURE__ */ Object.create(null), parentMeta, options.meta);
|
|
3214
|
+
}
|
|
3215
|
+
return createSuiteCollector(formatName(name), factory, mode, this.each, options);
|
|
3216
|
+
}
|
|
3217
|
+
suiteFn.each = function(cases, ...args) {
|
|
3218
|
+
const context = getChainableContext(this);
|
|
3219
|
+
const suite2 = context.withContext();
|
|
3220
|
+
context.setContext("each", true);
|
|
3221
|
+
if (Array.isArray(cases) && args.length) {
|
|
3222
|
+
cases = formatTemplateString(cases, args);
|
|
3223
|
+
}
|
|
3224
|
+
return (name, optionsOrFn, fnOrOptions) => {
|
|
3225
|
+
const _name = formatName(name);
|
|
3226
|
+
const arrayOnlyCases = cases.every(Array.isArray);
|
|
3227
|
+
const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
|
|
3228
|
+
const fnFirst = typeof optionsOrFn === "function";
|
|
3229
|
+
cases.forEach((i, idx) => {
|
|
3230
|
+
const items = Array.isArray(i) ? i : [i];
|
|
3231
|
+
if (fnFirst) {
|
|
3232
|
+
if (arrayOnlyCases) {
|
|
3233
|
+
suite2(formatTitle(_name, items, idx), handler ? () => handler(...items) : void 0, options.timeout);
|
|
3234
|
+
} else {
|
|
3235
|
+
suite2(formatTitle(_name, items, idx), handler ? () => handler(i) : void 0, options.timeout);
|
|
3236
|
+
}
|
|
3237
|
+
} else {
|
|
3238
|
+
if (arrayOnlyCases) {
|
|
3239
|
+
suite2(formatTitle(_name, items, idx), options, handler ? () => handler(...items) : void 0);
|
|
3240
|
+
} else {
|
|
3241
|
+
suite2(formatTitle(_name, items, idx), options, handler ? () => handler(i) : void 0);
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3244
|
+
});
|
|
3245
|
+
context.setContext("each", void 0);
|
|
3246
|
+
};
|
|
3247
|
+
};
|
|
3248
|
+
suiteFn.for = function(cases, ...args) {
|
|
3249
|
+
if (Array.isArray(cases) && args.length) {
|
|
3250
|
+
cases = formatTemplateString(cases, args);
|
|
3251
|
+
}
|
|
3252
|
+
return (name, optionsOrFn, fnOrOptions) => {
|
|
3253
|
+
const name_ = formatName(name);
|
|
3254
|
+
const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
|
|
3255
|
+
cases.forEach((item, idx) => {
|
|
3256
|
+
suite(formatTitle(name_, toArray(item), idx), options, handler ? () => handler(item) : void 0);
|
|
3257
|
+
});
|
|
3258
|
+
};
|
|
3259
|
+
};
|
|
3260
|
+
suiteFn.skipIf = (condition) => condition ? suite.skip : suite;
|
|
3261
|
+
suiteFn.runIf = (condition) => condition ? suite : suite.skip;
|
|
3262
|
+
return createChainable([
|
|
3263
|
+
"concurrent",
|
|
3264
|
+
"sequential",
|
|
3265
|
+
"shuffle",
|
|
3266
|
+
"skip",
|
|
3267
|
+
"only",
|
|
3268
|
+
"todo"
|
|
3269
|
+
], suiteFn);
|
|
3270
|
+
}
|
|
3271
|
+
function createTaskCollector(fn) {
|
|
3272
|
+
const taskFn = fn;
|
|
3273
|
+
taskFn.each = function(cases, ...args) {
|
|
3274
|
+
const context = getChainableContext(this);
|
|
3275
|
+
const test2 = context.withContext();
|
|
3276
|
+
context.setContext("each", true);
|
|
3277
|
+
if (Array.isArray(cases) && args.length) {
|
|
3278
|
+
cases = formatTemplateString(cases, args);
|
|
3279
|
+
}
|
|
3280
|
+
return (name, optionsOrFn, fnOrOptions) => {
|
|
3281
|
+
const _name = formatName(name);
|
|
3282
|
+
const arrayOnlyCases = cases.every(Array.isArray);
|
|
3283
|
+
const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
|
|
3284
|
+
const fnFirst = typeof optionsOrFn === "function";
|
|
3285
|
+
cases.forEach((i, idx) => {
|
|
3286
|
+
const items = Array.isArray(i) ? i : [i];
|
|
3287
|
+
if (fnFirst) {
|
|
3288
|
+
if (arrayOnlyCases) {
|
|
3289
|
+
test2(formatTitle(_name, items, idx), handler ? () => handler(...items) : void 0, options.timeout);
|
|
3290
|
+
} else {
|
|
3291
|
+
test2(formatTitle(_name, items, idx), handler ? () => handler(i) : void 0, options.timeout);
|
|
3292
|
+
}
|
|
3293
|
+
} else {
|
|
3294
|
+
if (arrayOnlyCases) {
|
|
3295
|
+
test2(formatTitle(_name, items, idx), options, handler ? () => handler(...items) : void 0);
|
|
3296
|
+
} else {
|
|
3297
|
+
test2(formatTitle(_name, items, idx), options, handler ? () => handler(i) : void 0);
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
});
|
|
3301
|
+
context.setContext("each", void 0);
|
|
3302
|
+
};
|
|
3303
|
+
};
|
|
3304
|
+
taskFn.for = function(cases, ...args) {
|
|
3305
|
+
const context = getChainableContext(this);
|
|
3306
|
+
const test2 = context.withContext();
|
|
3307
|
+
if (Array.isArray(cases) && args.length) {
|
|
3308
|
+
cases = formatTemplateString(cases, args);
|
|
3309
|
+
}
|
|
3310
|
+
return (name, optionsOrFn, fnOrOptions) => {
|
|
3311
|
+
const _name = formatName(name);
|
|
3312
|
+
const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
|
|
3313
|
+
cases.forEach((item, idx) => {
|
|
3314
|
+
const handlerWrapper = handler ? (ctx) => handler(item, ctx) : void 0;
|
|
3315
|
+
if (handlerWrapper) {
|
|
3316
|
+
configureProps(handlerWrapper, {
|
|
3317
|
+
index: 1,
|
|
3318
|
+
original: handler
|
|
3319
|
+
});
|
|
3320
|
+
}
|
|
3321
|
+
test2(formatTitle(_name, toArray(item), idx), options, handlerWrapper);
|
|
3322
|
+
});
|
|
3323
|
+
};
|
|
3324
|
+
};
|
|
3325
|
+
taskFn.skipIf = function(condition) {
|
|
3326
|
+
return condition ? this.skip : this;
|
|
3327
|
+
};
|
|
3328
|
+
taskFn.runIf = function(condition) {
|
|
3329
|
+
return condition ? this : this.skip;
|
|
3330
|
+
};
|
|
3331
|
+
function parseBuilderFixtures(fixturesOrName, optionsOrFn, maybeFn) {
|
|
3332
|
+
if (typeof fixturesOrName !== "string") {
|
|
3333
|
+
return fixturesOrName;
|
|
3334
|
+
}
|
|
3335
|
+
const fixtureName = fixturesOrName;
|
|
3336
|
+
let fixtureOptions;
|
|
3337
|
+
let fixtureValue;
|
|
3338
|
+
if (maybeFn !== void 0) {
|
|
3339
|
+
fixtureOptions = optionsOrFn;
|
|
3340
|
+
fixtureValue = maybeFn;
|
|
3341
|
+
} else {
|
|
3342
|
+
if (optionsOrFn !== null && typeof optionsOrFn === "object" && !Array.isArray(optionsOrFn) && TestFixtures.isFixtureOptions(optionsOrFn)) {
|
|
3343
|
+
fixtureOptions = optionsOrFn;
|
|
3344
|
+
fixtureValue = {};
|
|
3345
|
+
} else {
|
|
3346
|
+
fixtureOptions = void 0;
|
|
3347
|
+
fixtureValue = optionsOrFn;
|
|
3348
|
+
}
|
|
3349
|
+
}
|
|
3350
|
+
if (typeof fixtureValue === "function") {
|
|
3351
|
+
const builderFn = fixtureValue;
|
|
3352
|
+
const fixture = async (ctx, use) => {
|
|
3353
|
+
let cleanup;
|
|
3354
|
+
const onCleanup = (fn2) => {
|
|
3355
|
+
if (cleanup !== void 0) {
|
|
3356
|
+
throw new Error(`onCleanup can only be called once per fixture. Define separate fixtures if you need multiple cleanup functions.`);
|
|
3357
|
+
}
|
|
3358
|
+
cleanup = fn2;
|
|
3359
|
+
};
|
|
3360
|
+
const value = await builderFn(ctx, { onCleanup });
|
|
3361
|
+
await use(value);
|
|
3362
|
+
if (cleanup) {
|
|
3363
|
+
await cleanup();
|
|
3364
|
+
}
|
|
3365
|
+
};
|
|
3366
|
+
configureProps(fixture, { original: builderFn });
|
|
3367
|
+
if (fixtureOptions) {
|
|
3368
|
+
return { [fixtureName]: [fixture, fixtureOptions] };
|
|
3369
|
+
}
|
|
3370
|
+
return { [fixtureName]: fixture };
|
|
3371
|
+
}
|
|
3372
|
+
if (fixtureOptions) {
|
|
3373
|
+
return { [fixtureName]: [fixtureValue, fixtureOptions] };
|
|
3374
|
+
}
|
|
3375
|
+
return { [fixtureName]: fixtureValue };
|
|
3376
|
+
}
|
|
3377
|
+
taskFn.override = function(fixturesOrName, optionsOrFn, maybeFn) {
|
|
3378
|
+
const userFixtures = parseBuilderFixtures(fixturesOrName, optionsOrFn, maybeFn);
|
|
3379
|
+
getChainableContext(this).getFixtures().override(runner, userFixtures);
|
|
3380
|
+
return this;
|
|
3381
|
+
};
|
|
3382
|
+
taskFn.scoped = function(fixtures) {
|
|
3383
|
+
console.warn(`test.scoped() is deprecated and will be removed in future versions. Please use test.override() instead.`);
|
|
3384
|
+
return this.override(fixtures);
|
|
3385
|
+
};
|
|
3386
|
+
taskFn.extend = function(fixturesOrName, optionsOrFn, maybeFn) {
|
|
3387
|
+
const userFixtures = parseBuilderFixtures(fixturesOrName, optionsOrFn, maybeFn);
|
|
3388
|
+
const fixtures = getChainableContext(this).getFixtures().extend(runner, userFixtures);
|
|
3389
|
+
const _test2 = createTest(function(name, optionsOrFn2, optionsOrTest) {
|
|
3390
|
+
fn.call(this, formatName(name), optionsOrFn2, optionsOrTest);
|
|
3391
|
+
});
|
|
3392
|
+
getChainableContext(_test2).mergeContext({ fixtures });
|
|
3393
|
+
return _test2;
|
|
3394
|
+
};
|
|
3395
|
+
taskFn.describe = suite;
|
|
3396
|
+
taskFn.suite = suite;
|
|
3397
|
+
taskFn.beforeEach = beforeEach;
|
|
3398
|
+
taskFn.afterEach = afterEach;
|
|
3399
|
+
taskFn.beforeAll = beforeAll;
|
|
3400
|
+
taskFn.afterAll = afterAll;
|
|
3401
|
+
taskFn.aroundEach = aroundEach;
|
|
3402
|
+
taskFn.aroundAll = aroundAll;
|
|
3403
|
+
const _test = createChainable([
|
|
3404
|
+
"concurrent",
|
|
3405
|
+
"sequential",
|
|
3406
|
+
"skip",
|
|
3407
|
+
"only",
|
|
3408
|
+
"todo",
|
|
3409
|
+
"fails"
|
|
3410
|
+
], taskFn, { fixtures: new TestFixtures() });
|
|
3411
|
+
return _test;
|
|
3412
|
+
}
|
|
3413
|
+
function createTest(fn) {
|
|
3414
|
+
return createTaskCollector(fn);
|
|
3415
|
+
}
|
|
3416
|
+
function formatName(name) {
|
|
3417
|
+
return typeof name === "string" ? name : typeof name === "function" ? name.name || "<anonymous>" : String(name);
|
|
3418
|
+
}
|
|
3419
|
+
function formatTitle(template, items, idx) {
|
|
3420
|
+
if (template.includes("%#") || template.includes("%$")) {
|
|
3421
|
+
template = template.replace(/%%/g, "__vitest_escaped_%__").replace(/%#/g, `${idx}`).replace(/%\$/g, `${idx + 1}`).replace(/__vitest_escaped_%__/g, "%%");
|
|
3422
|
+
}
|
|
3423
|
+
const count = template.split("%").length - 1;
|
|
3424
|
+
if (template.includes("%f")) {
|
|
3425
|
+
const placeholders = template.match(/%f/g) || [];
|
|
3426
|
+
placeholders.forEach((_, i2) => {
|
|
3427
|
+
if (isNegativeNaN(items[i2]) || Object.is(items[i2], -0)) {
|
|
3428
|
+
let occurrence = 0;
|
|
3429
|
+
template = template.replace(/%f/g, (match) => {
|
|
3430
|
+
occurrence++;
|
|
3431
|
+
return occurrence === i2 + 1 ? "-%f" : match;
|
|
3432
|
+
});
|
|
3433
|
+
}
|
|
3434
|
+
});
|
|
3435
|
+
}
|
|
3436
|
+
const isObjectItem = isObject(items[0]);
|
|
3437
|
+
function formatAttribute(s) {
|
|
3438
|
+
return s.replace(/\$([$\w.]+)/g, (_, key) => {
|
|
3439
|
+
var _a, _b;
|
|
3440
|
+
const isArrayKey = /^\d+$/.test(key);
|
|
3441
|
+
if (!isObjectItem && !isArrayKey) {
|
|
3442
|
+
return `$${key}`;
|
|
3443
|
+
}
|
|
3444
|
+
const arrayElement = isArrayKey ? objectAttr(items, key) : void 0;
|
|
3445
|
+
const value = isObjectItem ? objectAttr(items[0], key, arrayElement) : arrayElement;
|
|
3446
|
+
return objDisplay(value, { truncate: (_b = (_a = runner == null ? void 0 : runner.config) == null ? void 0 : _a.chaiConfig) == null ? void 0 : _b.truncateThreshold });
|
|
3447
|
+
});
|
|
3448
|
+
}
|
|
3449
|
+
let output = "";
|
|
3450
|
+
let i = 0;
|
|
3451
|
+
handleRegexMatch(
|
|
3452
|
+
template,
|
|
3453
|
+
formatRegExp,
|
|
3454
|
+
// format "%"
|
|
3455
|
+
(match) => {
|
|
3456
|
+
if (i < count) {
|
|
3457
|
+
output += format(match[0], items[i++]);
|
|
3458
|
+
} else {
|
|
3459
|
+
output += match[0];
|
|
3460
|
+
}
|
|
3461
|
+
},
|
|
3462
|
+
// format "$"
|
|
3463
|
+
(nonMatch) => {
|
|
3464
|
+
output += formatAttribute(nonMatch);
|
|
3465
|
+
}
|
|
3466
|
+
);
|
|
3467
|
+
return output;
|
|
3468
|
+
}
|
|
3469
|
+
function handleRegexMatch(input, regex, onMatch, onNonMatch) {
|
|
3470
|
+
let lastIndex = 0;
|
|
3471
|
+
for (const m of input.matchAll(regex)) {
|
|
3472
|
+
if (lastIndex < m.index) {
|
|
3473
|
+
onNonMatch(input.slice(lastIndex, m.index));
|
|
3474
|
+
}
|
|
3475
|
+
onMatch(m);
|
|
3476
|
+
lastIndex = m.index + m[0].length;
|
|
3477
|
+
}
|
|
3478
|
+
if (lastIndex < input.length) {
|
|
3479
|
+
onNonMatch(input.slice(lastIndex));
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3482
|
+
function formatTemplateString(cases, args) {
|
|
3483
|
+
const header = cases.join("").trim().replace(/ /g, "").split("\n").map((i) => i.split("|"))[0];
|
|
3484
|
+
const res = [];
|
|
3485
|
+
for (let i = 0; i < Math.floor(args.length / header.length); i++) {
|
|
3486
|
+
const oneCase = {};
|
|
3487
|
+
for (let j = 0; j < header.length; j++) {
|
|
3488
|
+
oneCase[header[j]] = args[i * header.length + j];
|
|
3489
|
+
}
|
|
3490
|
+
res.push(oneCase);
|
|
3491
|
+
}
|
|
3492
|
+
return res;
|
|
3493
|
+
}
|
|
3494
|
+
const now$2 = globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
|
|
3495
|
+
const collectorContext = {
|
|
3496
|
+
currentSuite: null
|
|
3497
|
+
};
|
|
3498
|
+
function collectTask(task) {
|
|
3499
|
+
var _a;
|
|
3500
|
+
(_a = collectorContext.currentSuite) == null ? void 0 : _a.tasks.push(task);
|
|
3501
|
+
}
|
|
3502
|
+
async function runWithSuite(suite2, fn) {
|
|
3503
|
+
const prev = collectorContext.currentSuite;
|
|
3504
|
+
collectorContext.currentSuite = suite2;
|
|
3505
|
+
await fn();
|
|
3506
|
+
collectorContext.currentSuite = prev;
|
|
3507
|
+
}
|
|
3508
|
+
function withTimeout(fn, timeout, isHook = false, stackTraceError, onTimeout) {
|
|
3509
|
+
if (timeout <= 0 || timeout === Number.POSITIVE_INFINITY) {
|
|
3510
|
+
return fn;
|
|
3511
|
+
}
|
|
3512
|
+
const { setTimeout, clearTimeout } = getSafeTimers();
|
|
3513
|
+
return (function runWithTimeout(...args) {
|
|
3514
|
+
const startTime = now$2();
|
|
3515
|
+
const runner2 = getRunner();
|
|
3516
|
+
runner2._currentTaskStartTime = startTime;
|
|
3517
|
+
runner2._currentTaskTimeout = timeout;
|
|
3518
|
+
return new Promise((resolve_, reject_) => {
|
|
3519
|
+
var _a;
|
|
3520
|
+
const timer = setTimeout(() => {
|
|
3521
|
+
clearTimeout(timer);
|
|
3522
|
+
rejectTimeoutError();
|
|
3523
|
+
}, timeout);
|
|
3524
|
+
(_a = timer.unref) == null ? void 0 : _a.call(timer);
|
|
3525
|
+
function rejectTimeoutError() {
|
|
3526
|
+
const error = makeTimeoutError(isHook, timeout, stackTraceError);
|
|
3527
|
+
onTimeout == null ? void 0 : onTimeout(args, error);
|
|
3528
|
+
reject_(error);
|
|
3529
|
+
}
|
|
3530
|
+
function resolve2(result) {
|
|
3531
|
+
runner2._currentTaskStartTime = void 0;
|
|
3532
|
+
runner2._currentTaskTimeout = void 0;
|
|
3533
|
+
clearTimeout(timer);
|
|
3534
|
+
if (now$2() - startTime >= timeout) {
|
|
3535
|
+
rejectTimeoutError();
|
|
3536
|
+
return;
|
|
3537
|
+
}
|
|
3538
|
+
resolve_(result);
|
|
3539
|
+
}
|
|
3540
|
+
function reject(error) {
|
|
3541
|
+
runner2._currentTaskStartTime = void 0;
|
|
3542
|
+
runner2._currentTaskTimeout = void 0;
|
|
3543
|
+
clearTimeout(timer);
|
|
3544
|
+
reject_(error);
|
|
3545
|
+
}
|
|
3546
|
+
try {
|
|
3547
|
+
const result = fn(...args);
|
|
3548
|
+
if (typeof result === "object" && result != null && typeof result.then === "function") {
|
|
3549
|
+
result.then(resolve2, reject);
|
|
3550
|
+
} else {
|
|
3551
|
+
resolve2(result);
|
|
3552
|
+
}
|
|
3553
|
+
} catch (error) {
|
|
3554
|
+
reject(error);
|
|
3555
|
+
}
|
|
3556
|
+
});
|
|
3557
|
+
});
|
|
3558
|
+
}
|
|
3559
|
+
function withCancel(fn, signal) {
|
|
3560
|
+
return (function runWithCancel(...args) {
|
|
3561
|
+
return new Promise((resolve2, reject) => {
|
|
3562
|
+
signal.addEventListener("abort", () => reject(signal.reason));
|
|
3563
|
+
try {
|
|
3564
|
+
const result = fn(...args);
|
|
3565
|
+
if (typeof result === "object" && result != null && typeof result.then === "function") {
|
|
3566
|
+
result.then(resolve2, reject);
|
|
3567
|
+
} else {
|
|
3568
|
+
resolve2(result);
|
|
3569
|
+
}
|
|
3570
|
+
} catch (error) {
|
|
3571
|
+
reject(error);
|
|
3572
|
+
}
|
|
3573
|
+
});
|
|
3574
|
+
});
|
|
3575
|
+
}
|
|
3576
|
+
const abortControllers = /* @__PURE__ */ new WeakMap();
|
|
3577
|
+
function abortIfTimeout([context], error) {
|
|
3578
|
+
if (context) {
|
|
3579
|
+
abortContextSignal(context, error);
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
function abortContextSignal(context, error) {
|
|
3583
|
+
const abortController = abortControllers.get(context);
|
|
3584
|
+
abortController == null ? void 0 : abortController.abort(error);
|
|
3585
|
+
}
|
|
3586
|
+
function createTestContext(test2, runner2) {
|
|
3587
|
+
var _a;
|
|
3588
|
+
const context = function() {
|
|
3589
|
+
throw new Error("done() callback is deprecated, use promise instead");
|
|
3590
|
+
};
|
|
3591
|
+
let abortController = abortControllers.get(context);
|
|
3592
|
+
if (!abortController) {
|
|
3593
|
+
abortController = new AbortController();
|
|
3594
|
+
abortControllers.set(context, abortController);
|
|
3595
|
+
}
|
|
3596
|
+
context.signal = abortController.signal;
|
|
3597
|
+
context.task = test2;
|
|
3598
|
+
context.skip = (condition, note) => {
|
|
3599
|
+
if (condition === false) {
|
|
3600
|
+
return void 0;
|
|
3601
|
+
}
|
|
3602
|
+
test2.result ?? (test2.result = { state: "skip" });
|
|
3603
|
+
test2.result.pending = true;
|
|
3604
|
+
throw new PendingError("test is skipped; abort execution", test2, typeof condition === "string" ? condition : note);
|
|
3605
|
+
};
|
|
3606
|
+
context.annotate = ((message, type, attachment) => {
|
|
3607
|
+
if (test2.result && test2.result.state !== "run") {
|
|
3608
|
+
throw new Error(`Cannot annotate tests outside of the test run. The test "${test2.name}" finished running with the "${test2.result.state}" state already.`);
|
|
3609
|
+
}
|
|
3610
|
+
const annotation = {
|
|
3611
|
+
message,
|
|
3612
|
+
type: typeof type === "object" || type === void 0 ? "notice" : type
|
|
3613
|
+
};
|
|
3614
|
+
const annotationAttachment = typeof type === "object" ? type : attachment;
|
|
3615
|
+
if (annotationAttachment) {
|
|
3616
|
+
annotation.attachment = annotationAttachment;
|
|
3617
|
+
manageArtifactAttachment(annotation.attachment);
|
|
3618
|
+
}
|
|
3619
|
+
return recordAsyncOperation(test2, recordArtifact(test2, {
|
|
3620
|
+
type: "internal:annotation",
|
|
3621
|
+
annotation
|
|
3622
|
+
}).then(async ({ annotation: annotation2 }) => {
|
|
3623
|
+
if (!runner2.onTestAnnotate) {
|
|
3624
|
+
throw new Error(`Test runner doesn't support test annotations.`);
|
|
3625
|
+
}
|
|
3626
|
+
await finishSendTasksUpdate(runner2);
|
|
3627
|
+
const resolvedAnnotation = await runner2.onTestAnnotate(test2, annotation2);
|
|
3628
|
+
test2.annotations.push(resolvedAnnotation);
|
|
3629
|
+
return resolvedAnnotation;
|
|
3630
|
+
}));
|
|
3631
|
+
});
|
|
3632
|
+
context.onTestFailed = (handler, timeout) => {
|
|
3633
|
+
test2.onFailed || (test2.onFailed = []);
|
|
3634
|
+
test2.onFailed.push(withTimeout(handler, timeout ?? runner2.config.hookTimeout, true, new Error("STACK_TRACE_ERROR"), (_, error) => abortController.abort(error)));
|
|
3635
|
+
};
|
|
3636
|
+
context.onTestFinished = (handler, timeout) => {
|
|
3637
|
+
test2.onFinished || (test2.onFinished = []);
|
|
3638
|
+
test2.onFinished.push(withTimeout(handler, timeout ?? runner2.config.hookTimeout, true, new Error("STACK_TRACE_ERROR"), (_, error) => abortController.abort(error)));
|
|
3639
|
+
};
|
|
3640
|
+
return ((_a = runner2.extendTaskContext) == null ? void 0 : _a.call(runner2, context)) || context;
|
|
3641
|
+
}
|
|
3642
|
+
function makeTimeoutError(isHook, timeout, stackTraceError) {
|
|
3643
|
+
const message = `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.
|
|
3644
|
+
If this is a long-running ${isHook ? "hook" : "test"}, pass a timeout value as the last argument or configure it globally with "${isHook ? "hookTimeout" : "testTimeout"}".`;
|
|
3645
|
+
const error = new Error(message);
|
|
3646
|
+
if (stackTraceError == null ? void 0 : stackTraceError.stack) {
|
|
3647
|
+
error.stack = stackTraceError.stack.replace(error.message, stackTraceError.message);
|
|
3648
|
+
}
|
|
3649
|
+
return error;
|
|
3650
|
+
}
|
|
3651
|
+
globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
|
|
3652
|
+
globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
|
|
3653
|
+
getSafeTimers();
|
|
3654
|
+
const packs = /* @__PURE__ */ new Map();
|
|
3655
|
+
const eventsPacks = [];
|
|
3656
|
+
const pendingTasksUpdates = [];
|
|
3657
|
+
function sendTasksUpdate(runner2) {
|
|
3658
|
+
var _a;
|
|
3659
|
+
if (packs.size) {
|
|
3660
|
+
const taskPacks = Array.from(packs).map(([id, task]) => {
|
|
3661
|
+
return [
|
|
3662
|
+
id,
|
|
3663
|
+
task[0],
|
|
3664
|
+
task[1]
|
|
3665
|
+
];
|
|
3666
|
+
});
|
|
3667
|
+
const p = (_a = runner2.onTaskUpdate) == null ? void 0 : _a.call(runner2, taskPacks, eventsPacks);
|
|
3668
|
+
if (p) {
|
|
3669
|
+
pendingTasksUpdates.push(p);
|
|
3670
|
+
p.then(() => pendingTasksUpdates.splice(pendingTasksUpdates.indexOf(p), 1), () => {
|
|
3671
|
+
});
|
|
3672
|
+
}
|
|
3673
|
+
eventsPacks.length = 0;
|
|
3674
|
+
packs.clear();
|
|
3675
|
+
}
|
|
3676
|
+
}
|
|
3677
|
+
async function finishSendTasksUpdate(runner2) {
|
|
3678
|
+
sendTasksUpdate(runner2);
|
|
3679
|
+
await Promise.all(pendingTasksUpdates);
|
|
3680
|
+
}
|
|
3681
|
+
async function recordArtifact(task, artifact) {
|
|
3682
|
+
const runner2 = getRunner();
|
|
3683
|
+
const stack = findTestFileStackTrace(task.file.filepath, new Error("STACK_TRACE").stack);
|
|
3684
|
+
if (stack) {
|
|
3685
|
+
artifact.location = {
|
|
3686
|
+
file: stack.file,
|
|
3687
|
+
line: stack.line,
|
|
3688
|
+
column: stack.column
|
|
3689
|
+
};
|
|
3690
|
+
if (artifact.type === "internal:annotation") {
|
|
3691
|
+
artifact.annotation.location = artifact.location;
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3694
|
+
if (Array.isArray(artifact.attachments)) {
|
|
3695
|
+
for (const attachment of artifact.attachments) {
|
|
3696
|
+
manageArtifactAttachment(attachment);
|
|
3697
|
+
}
|
|
3698
|
+
}
|
|
3699
|
+
if (artifact.type === "internal:annotation") {
|
|
3700
|
+
return artifact;
|
|
3701
|
+
}
|
|
3702
|
+
if (!runner2.onTestArtifactRecord) {
|
|
3703
|
+
throw new Error(`Test runner doesn't support test artifacts.`);
|
|
3704
|
+
}
|
|
3705
|
+
await finishSendTasksUpdate(runner2);
|
|
3706
|
+
const resolvedArtifact = await runner2.onTestArtifactRecord(task, artifact);
|
|
3707
|
+
task.artifacts.push(resolvedArtifact);
|
|
3708
|
+
return resolvedArtifact;
|
|
3709
|
+
}
|
|
3710
|
+
const table = [];
|
|
3711
|
+
for (let i = 65; i < 91; i++) {
|
|
3712
|
+
table.push(String.fromCharCode(i));
|
|
3713
|
+
}
|
|
3714
|
+
for (let i = 97; i < 123; i++) {
|
|
3715
|
+
table.push(String.fromCharCode(i));
|
|
3716
|
+
}
|
|
3717
|
+
for (let i = 0; i < 10; i++) {
|
|
3718
|
+
table.push(i.toString(10));
|
|
3719
|
+
}
|
|
3720
|
+
table.push("+", "/");
|
|
3721
|
+
function encodeUint8Array(bytes) {
|
|
3722
|
+
let base64 = "";
|
|
3723
|
+
const len = bytes.byteLength;
|
|
3724
|
+
for (let i = 0; i < len; i += 3) {
|
|
3725
|
+
if (len === i + 1) {
|
|
3726
|
+
const a = (bytes[i] & 252) >> 2;
|
|
3727
|
+
const b = (bytes[i] & 3) << 4;
|
|
3728
|
+
base64 += table[a];
|
|
3729
|
+
base64 += table[b];
|
|
3730
|
+
base64 += "==";
|
|
3731
|
+
} else if (len === i + 2) {
|
|
3732
|
+
const a = (bytes[i] & 252) >> 2;
|
|
3733
|
+
const b = (bytes[i] & 3) << 4 | (bytes[i + 1] & 240) >> 4;
|
|
3734
|
+
const c = (bytes[i + 1] & 15) << 2;
|
|
3735
|
+
base64 += table[a];
|
|
3736
|
+
base64 += table[b];
|
|
3737
|
+
base64 += table[c];
|
|
3738
|
+
base64 += "=";
|
|
3739
|
+
} else {
|
|
3740
|
+
const a = (bytes[i] & 252) >> 2;
|
|
3741
|
+
const b = (bytes[i] & 3) << 4 | (bytes[i + 1] & 240) >> 4;
|
|
3742
|
+
const c = (bytes[i + 1] & 15) << 2 | (bytes[i + 2] & 192) >> 6;
|
|
3743
|
+
const d2 = bytes[i + 2] & 63;
|
|
3744
|
+
base64 += table[a];
|
|
3745
|
+
base64 += table[b];
|
|
3746
|
+
base64 += table[c];
|
|
3747
|
+
base64 += table[d2];
|
|
3748
|
+
}
|
|
3749
|
+
}
|
|
3750
|
+
return base64;
|
|
3751
|
+
}
|
|
3752
|
+
function recordAsyncOperation(test2, promise) {
|
|
3753
|
+
promise = promise.finally(() => {
|
|
3754
|
+
if (!test2.promises) {
|
|
3755
|
+
return;
|
|
3756
|
+
}
|
|
3757
|
+
const index2 = test2.promises.indexOf(promise);
|
|
3758
|
+
if (index2 !== -1) {
|
|
3759
|
+
test2.promises.splice(index2, 1);
|
|
3760
|
+
}
|
|
3761
|
+
});
|
|
3762
|
+
if (!test2.promises) {
|
|
3763
|
+
test2.promises = [];
|
|
3764
|
+
}
|
|
3765
|
+
test2.promises.push(promise);
|
|
3766
|
+
return promise;
|
|
3767
|
+
}
|
|
3768
|
+
function manageArtifactAttachment(attachment) {
|
|
3769
|
+
if (attachment.body == null && !attachment.path) {
|
|
3770
|
+
throw new TypeError(`Test attachment requires "body" or "path" to be set. Both are missing.`);
|
|
3771
|
+
}
|
|
3772
|
+
if (attachment.body && attachment.path) {
|
|
3773
|
+
throw new TypeError(`Test attachment requires only one of "body" or "path" to be set. Both are specified.`);
|
|
3774
|
+
}
|
|
3775
|
+
if (attachment.body instanceof Uint8Array) {
|
|
3776
|
+
attachment.body = encodeUint8Array(attachment.body);
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
async function importId(id) {
|
|
3780
|
+
const name = `/@id/${id}`.replace(/\\/g, "/");
|
|
3781
|
+
return (/* @__PURE__ */ getBrowserState()).wrapModule(() => import(
|
|
3782
|
+
/* @vite-ignore */
|
|
3783
|
+
name
|
|
3784
|
+
));
|
|
3785
|
+
}
|
|
3786
|
+
async function importFs(id) {
|
|
3787
|
+
const name = `/@fs/${id}`.replace(/\\/g, "/");
|
|
3788
|
+
return (/* @__PURE__ */ getBrowserState()).wrapModule(() => import(
|
|
3789
|
+
/* @vite-ignore */
|
|
3790
|
+
name
|
|
3791
|
+
));
|
|
3792
|
+
}
|
|
3793
|
+
const moduleRunner = {
|
|
3794
|
+
isBrowser: true,
|
|
3795
|
+
import: (id) => {
|
|
3796
|
+
if (id[0] === "/" || id[1] === ":") {
|
|
3797
|
+
return importFs(id);
|
|
3798
|
+
}
|
|
3799
|
+
return importId(id);
|
|
3800
|
+
}
|
|
3801
|
+
};
|
|
3802
|
+
function getConfig() {
|
|
3803
|
+
return (/* @__PURE__ */ getBrowserState()).config;
|
|
3804
|
+
}
|
|
3805
|
+
// @__NO_SIDE_EFFECTS__
|
|
3806
|
+
function getBrowserState() {
|
|
3807
|
+
return window.__vitest_browser_runner__;
|
|
3808
|
+
}
|
|
3809
|
+
// @__NO_SIDE_EFFECTS__
|
|
3810
|
+
function getWorkerState() {
|
|
3811
|
+
const state = window.__vitest_worker__;
|
|
3812
|
+
if (!state) {
|
|
3813
|
+
throw new Error("Worker state is not found. This is an issue with Vitest. Please, open an issue.");
|
|
3814
|
+
}
|
|
3815
|
+
return state;
|
|
3816
|
+
}
|
|
3817
|
+
export {
|
|
3818
|
+
getConfig as a,
|
|
3819
|
+
generateFileHash as b,
|
|
3820
|
+
resolve as c,
|
|
3821
|
+
getWorkerState as d,
|
|
3822
|
+
getTestName as e,
|
|
3823
|
+
getBrowserState as g,
|
|
3824
|
+
moduleRunner as m,
|
|
3825
|
+
relative as r
|
|
3826
|
+
};
|