@rstest/core 0.9.4 → 0.9.6
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/LICENSE.md +54 -202
- package/dist/0~8843.js +32 -14
- package/dist/{0~lib.js → 0~@babel/code-frame.js} +2 -2
- package/dist/0~@clack/prompts.js +1044 -0
- package/dist/0~browserLoader.js +1 -1
- package/dist/0~browser~1.js +19 -19
- package/dist/0~checkThresholds.js +2 -2
- package/dist/0~chokidar.js +43 -42
- package/dist/0~console.js +1 -1
- package/dist/0~fake-timers.js +1586 -0
- package/dist/0~generate.js +5 -5
- package/dist/0~happyDom.js +1 -1
- package/dist/0~jsdom.js +1 -1
- package/dist/0~listTests.js +3 -3
- package/dist/0~loadModule.js +1 -1
- package/dist/0~magic-string.es.js +1 -181
- package/dist/0~restart.js +1 -1
- package/dist/0~runTests.js +11 -4
- package/dist/0~snapshot.js +2140 -0
- package/dist/0~snapshot.js.LICENSE.txt +7 -0
- package/dist/0~utils.js +1 -1
- package/dist/1255.js +11 -11
- package/dist/1949.js +2919 -9808
- package/dist/1949.js.LICENSE.txt +1 -49
- package/dist/3145.js +415 -40
- package/dist/4411.js +245 -60
- package/dist/6830.js +62 -10
- package/dist/6887.js +15 -0
- package/dist/7552.js +22 -4918
- package/dist/9743.js +1982 -0
- package/dist/9784.js +1343 -0
- package/dist/{7552.js.LICENSE.txt → 9784.js.LICENSE.txt} +19 -8
- package/dist/browser-runtime/2~fake-timers.js +1760 -0
- package/dist/browser-runtime/2~magic-string.es.js +3 -189
- package/dist/browser-runtime/2~snapshot.js +2138 -0
- package/dist/browser-runtime/2~snapshot.js.LICENSE.txt +7 -0
- package/dist/browser-runtime/723.js +1818 -10300
- package/dist/browser-runtime/723.js.LICENSE.txt +0 -17
- package/dist/browser-runtime/index.d.ts +205 -16
- package/dist/browser.d.ts +55 -10
- package/dist/browser.js +2 -2
- package/dist/globalSetupWorker.js +2 -2
- package/dist/index.d.ts +78 -16
- package/dist/index.js +1 -1
- package/dist/mockRuntimeCode.js +2 -0
- package/dist/worker.d.ts +47 -10
- package/dist/worker.js +12 -10
- package/package.json +27 -28
- package/dist/0~dist.js +0 -1014
- package/dist/4899.js +0 -11
- package/dist/browser-runtime/rslib-runtime.js +0 -56
- /package/dist/{rslib-runtime.js → 0~rslib-runtime.js} +0 -0
|
@@ -0,0 +1,2138 @@
|
|
|
1
|
+
/*! LICENSE: 2~snapshot.js.LICENSE.txt */
|
|
2
|
+
import { __webpack_require__ } from "./723.js";
|
|
3
|
+
import { dist_format, dist_plugins, getTaskNameWithPrefix, subsetEquality, pathe_M_eThtNZ_resolve, dist_equals, iterableEquality } from "./723.js";
|
|
4
|
+
var snapshot_namespaceObject = {};
|
|
5
|
+
__webpack_require__.r(snapshot_namespaceObject);
|
|
6
|
+
__webpack_require__.d(snapshot_namespaceObject, {
|
|
7
|
+
SnapshotPlugin: ()=>SnapshotPlugin
|
|
8
|
+
});
|
|
9
|
+
var process = __webpack_require__("../../node_modules/.pnpm/process@0.11.10/node_modules/process/browser.js");
|
|
10
|
+
const comma = ','.charCodeAt(0);
|
|
11
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
12
|
+
const intToChar = new Uint8Array(64);
|
|
13
|
+
const charToInt = new Uint8Array(128);
|
|
14
|
+
for(let i = 0; i < chars.length; i++){
|
|
15
|
+
const c = chars.charCodeAt(i);
|
|
16
|
+
intToChar[i] = c;
|
|
17
|
+
charToInt[c] = i;
|
|
18
|
+
}
|
|
19
|
+
function decodeInteger(reader, relative) {
|
|
20
|
+
let value = 0;
|
|
21
|
+
let shift = 0;
|
|
22
|
+
let integer = 0;
|
|
23
|
+
do {
|
|
24
|
+
const c = reader.next();
|
|
25
|
+
integer = charToInt[c];
|
|
26
|
+
value |= (31 & integer) << shift;
|
|
27
|
+
shift += 5;
|
|
28
|
+
}while (32 & integer)
|
|
29
|
+
const shouldNegate = 1 & value;
|
|
30
|
+
value >>>= 1;
|
|
31
|
+
if (shouldNegate) value = -2147483648 | -value;
|
|
32
|
+
return relative + value;
|
|
33
|
+
}
|
|
34
|
+
function hasMoreVlq(reader, max) {
|
|
35
|
+
if (reader.pos >= max) return false;
|
|
36
|
+
return reader.peek() !== comma;
|
|
37
|
+
}
|
|
38
|
+
class StringReader {
|
|
39
|
+
constructor(buffer){
|
|
40
|
+
this.pos = 0;
|
|
41
|
+
this.buffer = buffer;
|
|
42
|
+
}
|
|
43
|
+
next() {
|
|
44
|
+
return this.buffer.charCodeAt(this.pos++);
|
|
45
|
+
}
|
|
46
|
+
peek() {
|
|
47
|
+
return this.buffer.charCodeAt(this.pos);
|
|
48
|
+
}
|
|
49
|
+
indexOf(char) {
|
|
50
|
+
const { buffer, pos } = this;
|
|
51
|
+
const idx = buffer.indexOf(char, pos);
|
|
52
|
+
return -1 === idx ? buffer.length : idx;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function decode(mappings) {
|
|
56
|
+
const { length } = mappings;
|
|
57
|
+
const reader = new StringReader(mappings);
|
|
58
|
+
const decoded = [];
|
|
59
|
+
let genColumn = 0;
|
|
60
|
+
let sourcesIndex = 0;
|
|
61
|
+
let sourceLine = 0;
|
|
62
|
+
let sourceColumn = 0;
|
|
63
|
+
let namesIndex = 0;
|
|
64
|
+
do {
|
|
65
|
+
const semi = reader.indexOf(';');
|
|
66
|
+
const line = [];
|
|
67
|
+
let sorted = true;
|
|
68
|
+
let lastCol = 0;
|
|
69
|
+
genColumn = 0;
|
|
70
|
+
while(reader.pos < semi){
|
|
71
|
+
let seg;
|
|
72
|
+
genColumn = decodeInteger(reader, genColumn);
|
|
73
|
+
if (genColumn < lastCol) sorted = false;
|
|
74
|
+
lastCol = genColumn;
|
|
75
|
+
if (hasMoreVlq(reader, semi)) {
|
|
76
|
+
sourcesIndex = decodeInteger(reader, sourcesIndex);
|
|
77
|
+
sourceLine = decodeInteger(reader, sourceLine);
|
|
78
|
+
sourceColumn = decodeInteger(reader, sourceColumn);
|
|
79
|
+
if (hasMoreVlq(reader, semi)) {
|
|
80
|
+
namesIndex = decodeInteger(reader, namesIndex);
|
|
81
|
+
seg = [
|
|
82
|
+
genColumn,
|
|
83
|
+
sourcesIndex,
|
|
84
|
+
sourceLine,
|
|
85
|
+
sourceColumn,
|
|
86
|
+
namesIndex
|
|
87
|
+
];
|
|
88
|
+
} else seg = [
|
|
89
|
+
genColumn,
|
|
90
|
+
sourcesIndex,
|
|
91
|
+
sourceLine,
|
|
92
|
+
sourceColumn
|
|
93
|
+
];
|
|
94
|
+
} else seg = [
|
|
95
|
+
genColumn
|
|
96
|
+
];
|
|
97
|
+
line.push(seg);
|
|
98
|
+
reader.pos++;
|
|
99
|
+
}
|
|
100
|
+
if (!sorted) sort(line);
|
|
101
|
+
decoded.push(line);
|
|
102
|
+
reader.pos = semi + 1;
|
|
103
|
+
}while (reader.pos <= length)
|
|
104
|
+
return decoded;
|
|
105
|
+
}
|
|
106
|
+
function sort(line) {
|
|
107
|
+
line.sort(sortComparator$1);
|
|
108
|
+
}
|
|
109
|
+
function sortComparator$1(a, b) {
|
|
110
|
+
return a[0] - b[0];
|
|
111
|
+
}
|
|
112
|
+
const schemeRegex = /^[\w+.-]+:\/\//;
|
|
113
|
+
const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
|
|
114
|
+
const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
|
|
115
|
+
var dist_UrlType;
|
|
116
|
+
(function(UrlType) {
|
|
117
|
+
UrlType[UrlType["Empty"] = 1] = "Empty";
|
|
118
|
+
UrlType[UrlType["Hash"] = 2] = "Hash";
|
|
119
|
+
UrlType[UrlType["Query"] = 3] = "Query";
|
|
120
|
+
UrlType[UrlType["RelativePath"] = 4] = "RelativePath";
|
|
121
|
+
UrlType[UrlType["AbsolutePath"] = 5] = "AbsolutePath";
|
|
122
|
+
UrlType[UrlType["SchemeRelative"] = 6] = "SchemeRelative";
|
|
123
|
+
UrlType[UrlType["Absolute"] = 7] = "Absolute";
|
|
124
|
+
})(dist_UrlType || (dist_UrlType = {}));
|
|
125
|
+
function isAbsoluteUrl(input) {
|
|
126
|
+
return schemeRegex.test(input);
|
|
127
|
+
}
|
|
128
|
+
function isSchemeRelativeUrl(input) {
|
|
129
|
+
return input.startsWith('//');
|
|
130
|
+
}
|
|
131
|
+
function isAbsolutePath(input) {
|
|
132
|
+
return input.startsWith('/');
|
|
133
|
+
}
|
|
134
|
+
function isFileUrl(input) {
|
|
135
|
+
return input.startsWith('file:');
|
|
136
|
+
}
|
|
137
|
+
function isRelative(input) {
|
|
138
|
+
return /^[.?#]/.test(input);
|
|
139
|
+
}
|
|
140
|
+
function parseAbsoluteUrl(input) {
|
|
141
|
+
const match = urlRegex.exec(input);
|
|
142
|
+
return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/', match[6] || '', match[7] || '');
|
|
143
|
+
}
|
|
144
|
+
function parseFileUrl(input) {
|
|
145
|
+
const match = fileRegex.exec(input);
|
|
146
|
+
const path = match[2];
|
|
147
|
+
return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path, match[3] || '', match[4] || '');
|
|
148
|
+
}
|
|
149
|
+
function makeUrl(scheme, user, host, port, path, query, hash) {
|
|
150
|
+
return {
|
|
151
|
+
scheme,
|
|
152
|
+
user,
|
|
153
|
+
host,
|
|
154
|
+
port,
|
|
155
|
+
path,
|
|
156
|
+
query,
|
|
157
|
+
hash,
|
|
158
|
+
type: dist_UrlType.Absolute
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function parseUrl(input) {
|
|
162
|
+
if (isSchemeRelativeUrl(input)) {
|
|
163
|
+
const url = parseAbsoluteUrl('http:' + input);
|
|
164
|
+
url.scheme = '';
|
|
165
|
+
url.type = dist_UrlType.SchemeRelative;
|
|
166
|
+
return url;
|
|
167
|
+
}
|
|
168
|
+
if (isAbsolutePath(input)) {
|
|
169
|
+
const url = parseAbsoluteUrl('http://foo.com' + input);
|
|
170
|
+
url.scheme = '';
|
|
171
|
+
url.host = '';
|
|
172
|
+
url.type = dist_UrlType.AbsolutePath;
|
|
173
|
+
return url;
|
|
174
|
+
}
|
|
175
|
+
if (isFileUrl(input)) return parseFileUrl(input);
|
|
176
|
+
if (isAbsoluteUrl(input)) return parseAbsoluteUrl(input);
|
|
177
|
+
const url = parseAbsoluteUrl('http://foo.com/' + input);
|
|
178
|
+
url.scheme = '';
|
|
179
|
+
url.host = '';
|
|
180
|
+
url.type = input ? input.startsWith('?') ? dist_UrlType.Query : input.startsWith('#') ? dist_UrlType.Hash : dist_UrlType.RelativePath : dist_UrlType.Empty;
|
|
181
|
+
return url;
|
|
182
|
+
}
|
|
183
|
+
function stripPathFilename(path) {
|
|
184
|
+
if (path.endsWith('/..')) return path;
|
|
185
|
+
const index = path.lastIndexOf('/');
|
|
186
|
+
return path.slice(0, index + 1);
|
|
187
|
+
}
|
|
188
|
+
function mergePaths(url, base) {
|
|
189
|
+
normalizePath(base, base.type);
|
|
190
|
+
if ('/' === url.path) url.path = base.path;
|
|
191
|
+
else url.path = stripPathFilename(base.path) + url.path;
|
|
192
|
+
}
|
|
193
|
+
function normalizePath(url, type) {
|
|
194
|
+
const rel = type <= dist_UrlType.RelativePath;
|
|
195
|
+
const pieces = url.path.split('/');
|
|
196
|
+
let pointer = 1;
|
|
197
|
+
let positive = 0;
|
|
198
|
+
let addTrailingSlash = false;
|
|
199
|
+
for(let i = 1; i < pieces.length; i++){
|
|
200
|
+
const piece = pieces[i];
|
|
201
|
+
if (!piece) {
|
|
202
|
+
addTrailingSlash = true;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
addTrailingSlash = false;
|
|
206
|
+
if ('.' !== piece) {
|
|
207
|
+
if ('..' === piece) {
|
|
208
|
+
if (positive) {
|
|
209
|
+
addTrailingSlash = true;
|
|
210
|
+
positive--;
|
|
211
|
+
pointer--;
|
|
212
|
+
} else if (rel) pieces[pointer++] = piece;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
pieces[pointer++] = piece;
|
|
216
|
+
positive++;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
let path = '';
|
|
220
|
+
for(let i = 1; i < pointer; i++)path += '/' + pieces[i];
|
|
221
|
+
if (!path || addTrailingSlash && !path.endsWith('/..')) path += '/';
|
|
222
|
+
url.path = path;
|
|
223
|
+
}
|
|
224
|
+
function resolve$1(input, base) {
|
|
225
|
+
if (!input && !base) return '';
|
|
226
|
+
const url = parseUrl(input);
|
|
227
|
+
let inputType = url.type;
|
|
228
|
+
if (base && inputType !== dist_UrlType.Absolute) {
|
|
229
|
+
const baseUrl = parseUrl(base);
|
|
230
|
+
const baseType = baseUrl.type;
|
|
231
|
+
switch(inputType){
|
|
232
|
+
case dist_UrlType.Empty:
|
|
233
|
+
url.hash = baseUrl.hash;
|
|
234
|
+
case dist_UrlType.Hash:
|
|
235
|
+
url.query = baseUrl.query;
|
|
236
|
+
case dist_UrlType.Query:
|
|
237
|
+
case dist_UrlType.RelativePath:
|
|
238
|
+
mergePaths(url, baseUrl);
|
|
239
|
+
case dist_UrlType.AbsolutePath:
|
|
240
|
+
url.user = baseUrl.user;
|
|
241
|
+
url.host = baseUrl.host;
|
|
242
|
+
url.port = baseUrl.port;
|
|
243
|
+
case dist_UrlType.SchemeRelative:
|
|
244
|
+
url.scheme = baseUrl.scheme;
|
|
245
|
+
}
|
|
246
|
+
if (baseType > inputType) inputType = baseType;
|
|
247
|
+
}
|
|
248
|
+
normalizePath(url, inputType);
|
|
249
|
+
const queryHash = url.query + url.hash;
|
|
250
|
+
switch(inputType){
|
|
251
|
+
case dist_UrlType.Hash:
|
|
252
|
+
case dist_UrlType.Query:
|
|
253
|
+
return queryHash;
|
|
254
|
+
case dist_UrlType.RelativePath:
|
|
255
|
+
{
|
|
256
|
+
const path = url.path.slice(1);
|
|
257
|
+
if (!path) return queryHash || '.';
|
|
258
|
+
if (isRelative(base || input) && !isRelative(path)) return './' + path + queryHash;
|
|
259
|
+
return path + queryHash;
|
|
260
|
+
}
|
|
261
|
+
case dist_UrlType.AbsolutePath:
|
|
262
|
+
return url.path + queryHash;
|
|
263
|
+
default:
|
|
264
|
+
return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function resolve(input, base) {
|
|
268
|
+
if (base && !base.endsWith('/')) base += '/';
|
|
269
|
+
return resolve$1(input, base);
|
|
270
|
+
}
|
|
271
|
+
function stripFilename(path) {
|
|
272
|
+
if (!path) return '';
|
|
273
|
+
const index = path.lastIndexOf('/');
|
|
274
|
+
return path.slice(0, index + 1);
|
|
275
|
+
}
|
|
276
|
+
const COLUMN = 0;
|
|
277
|
+
const SOURCES_INDEX = 1;
|
|
278
|
+
const SOURCE_LINE = 2;
|
|
279
|
+
const SOURCE_COLUMN = 3;
|
|
280
|
+
const NAMES_INDEX = 4;
|
|
281
|
+
function maybeSort(mappings, owned) {
|
|
282
|
+
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
|
|
283
|
+
if (unsortedIndex === mappings.length) return mappings;
|
|
284
|
+
if (!owned) mappings = mappings.slice();
|
|
285
|
+
for(let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1))mappings[i] = sortSegments(mappings[i], owned);
|
|
286
|
+
return mappings;
|
|
287
|
+
}
|
|
288
|
+
function nextUnsortedSegmentLine(mappings, start) {
|
|
289
|
+
for(let i = start; i < mappings.length; i++)if (!isSorted(mappings[i])) return i;
|
|
290
|
+
return mappings.length;
|
|
291
|
+
}
|
|
292
|
+
function isSorted(line) {
|
|
293
|
+
for(let j = 1; j < line.length; j++)if (line[j][COLUMN] < line[j - 1][COLUMN]) return false;
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
function sortSegments(line, owned) {
|
|
297
|
+
if (!owned) line = line.slice();
|
|
298
|
+
return line.sort(sortComparator);
|
|
299
|
+
}
|
|
300
|
+
function sortComparator(a, b) {
|
|
301
|
+
return a[COLUMN] - b[COLUMN];
|
|
302
|
+
}
|
|
303
|
+
let found = false;
|
|
304
|
+
function binarySearch(haystack, needle, low, high) {
|
|
305
|
+
while(low <= high){
|
|
306
|
+
const mid = low + (high - low >> 1);
|
|
307
|
+
const cmp = haystack[mid][COLUMN] - needle;
|
|
308
|
+
if (0 === cmp) {
|
|
309
|
+
found = true;
|
|
310
|
+
return mid;
|
|
311
|
+
}
|
|
312
|
+
if (cmp < 0) low = mid + 1;
|
|
313
|
+
else high = mid - 1;
|
|
314
|
+
}
|
|
315
|
+
found = false;
|
|
316
|
+
return low - 1;
|
|
317
|
+
}
|
|
318
|
+
function upperBound(haystack, needle, index) {
|
|
319
|
+
for(let i = index + 1; i < haystack.length && haystack[i][COLUMN] === needle; index = i++);
|
|
320
|
+
return index;
|
|
321
|
+
}
|
|
322
|
+
function lowerBound(haystack, needle, index) {
|
|
323
|
+
for(let i = index - 1; i >= 0 && haystack[i][COLUMN] === needle; index = i--);
|
|
324
|
+
return index;
|
|
325
|
+
}
|
|
326
|
+
function memoizedState() {
|
|
327
|
+
return {
|
|
328
|
+
lastKey: -1,
|
|
329
|
+
lastNeedle: -1,
|
|
330
|
+
lastIndex: -1
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function memoizedBinarySearch(haystack, needle, state, key) {
|
|
334
|
+
const { lastKey, lastNeedle, lastIndex } = state;
|
|
335
|
+
let low = 0;
|
|
336
|
+
let high = haystack.length - 1;
|
|
337
|
+
if (key === lastKey) {
|
|
338
|
+
if (needle === lastNeedle) {
|
|
339
|
+
found = -1 !== lastIndex && haystack[lastIndex][COLUMN] === needle;
|
|
340
|
+
return lastIndex;
|
|
341
|
+
}
|
|
342
|
+
if (needle >= lastNeedle) low = -1 === lastIndex ? 0 : lastIndex;
|
|
343
|
+
else high = lastIndex;
|
|
344
|
+
}
|
|
345
|
+
state.lastKey = key;
|
|
346
|
+
state.lastNeedle = needle;
|
|
347
|
+
return state.lastIndex = binarySearch(haystack, needle, low, high);
|
|
348
|
+
}
|
|
349
|
+
const LINE_GTR_ZERO = '`line` must be greater than 0 (lines start at line 1)';
|
|
350
|
+
const COL_GTR_EQ_ZERO = '`column` must be greater than or equal to 0 (columns start at column 0)';
|
|
351
|
+
const LEAST_UPPER_BOUND = -1;
|
|
352
|
+
const GREATEST_LOWER_BOUND = 1;
|
|
353
|
+
class TraceMap {
|
|
354
|
+
constructor(map, mapUrl){
|
|
355
|
+
const isString = 'string' == typeof map;
|
|
356
|
+
if (!isString && map._decodedMemo) return map;
|
|
357
|
+
const parsed = isString ? JSON.parse(map) : map;
|
|
358
|
+
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|
359
|
+
this.version = version;
|
|
360
|
+
this.file = file;
|
|
361
|
+
this.names = names || [];
|
|
362
|
+
this.sourceRoot = sourceRoot;
|
|
363
|
+
this.sources = sources;
|
|
364
|
+
this.sourcesContent = sourcesContent;
|
|
365
|
+
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
|
366
|
+
const from = resolve(sourceRoot || '', stripFilename(mapUrl));
|
|
367
|
+
this.resolvedSources = sources.map((s)=>resolve(s || '', from));
|
|
368
|
+
const { mappings } = parsed;
|
|
369
|
+
if ('string' == typeof mappings) {
|
|
370
|
+
this._encoded = mappings;
|
|
371
|
+
this._decoded = void 0;
|
|
372
|
+
} else {
|
|
373
|
+
this._encoded = void 0;
|
|
374
|
+
this._decoded = maybeSort(mappings, isString);
|
|
375
|
+
}
|
|
376
|
+
this._decodedMemo = memoizedState();
|
|
377
|
+
this._bySources = void 0;
|
|
378
|
+
this._bySourceMemos = void 0;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
function cast(map) {
|
|
382
|
+
return map;
|
|
383
|
+
}
|
|
384
|
+
function decodedMappings(map) {
|
|
385
|
+
var _a;
|
|
386
|
+
return (_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded));
|
|
387
|
+
}
|
|
388
|
+
function originalPositionFor(map, needle) {
|
|
389
|
+
let { line, column, bias } = needle;
|
|
390
|
+
line--;
|
|
391
|
+
if (line < 0) throw new Error(LINE_GTR_ZERO);
|
|
392
|
+
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
|
393
|
+
const decoded = decodedMappings(map);
|
|
394
|
+
if (line >= decoded.length) return OMapping(null, null, null, null);
|
|
395
|
+
const segments = decoded[line];
|
|
396
|
+
const index = traceSegmentInternal(segments, cast(map)._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
|
|
397
|
+
if (-1 === index) return OMapping(null, null, null, null);
|
|
398
|
+
const segment = segments[index];
|
|
399
|
+
if (1 === segment.length) return OMapping(null, null, null, null);
|
|
400
|
+
const { names, resolvedSources } = map;
|
|
401
|
+
return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], 5 === segment.length ? names[segment[NAMES_INDEX]] : null);
|
|
402
|
+
}
|
|
403
|
+
function OMapping(source, line, column, name) {
|
|
404
|
+
return {
|
|
405
|
+
source,
|
|
406
|
+
line,
|
|
407
|
+
column,
|
|
408
|
+
name
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
412
|
+
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
413
|
+
if (found) index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
|
|
414
|
+
else if (bias === LEAST_UPPER_BOUND) index++;
|
|
415
|
+
if (-1 === index || index === segments.length) return -1;
|
|
416
|
+
return index;
|
|
417
|
+
}
|
|
418
|
+
function notNullish(v) {
|
|
419
|
+
return null != v;
|
|
420
|
+
}
|
|
421
|
+
function isPrimitive(value) {
|
|
422
|
+
return null === value || "function" != typeof value && "object" != typeof value;
|
|
423
|
+
}
|
|
424
|
+
function isObject(item) {
|
|
425
|
+
return null != item && "object" == typeof item && !Array.isArray(item);
|
|
426
|
+
}
|
|
427
|
+
function getCallLastIndex(code) {
|
|
428
|
+
let charIndex = -1;
|
|
429
|
+
let inString = null;
|
|
430
|
+
let startedBracers = 0;
|
|
431
|
+
let endedBracers = 0;
|
|
432
|
+
let beforeChar = null;
|
|
433
|
+
while(charIndex <= code.length){
|
|
434
|
+
beforeChar = code[charIndex];
|
|
435
|
+
charIndex++;
|
|
436
|
+
const char = code[charIndex];
|
|
437
|
+
const isCharString = "\"" === char || "'" === char || "`" === char;
|
|
438
|
+
if (isCharString && "\\" !== beforeChar) {
|
|
439
|
+
if (inString === char) inString = null;
|
|
440
|
+
else if (!inString) inString = char;
|
|
441
|
+
}
|
|
442
|
+
if (!inString) {
|
|
443
|
+
if ("(" === char) startedBracers++;
|
|
444
|
+
if (")" === char) endedBracers++;
|
|
445
|
+
}
|
|
446
|
+
if (startedBracers && endedBracers && startedBracers === endedBracers) return charIndex;
|
|
447
|
+
}
|
|
448
|
+
return null;
|
|
449
|
+
}
|
|
450
|
+
const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
|
|
451
|
+
const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
|
|
452
|
+
const stackIgnorePatterns = [
|
|
453
|
+
"node:internal",
|
|
454
|
+
/\/packages\/\w+\/dist\//,
|
|
455
|
+
/\/@vitest\/\w+\/dist\//,
|
|
456
|
+
"/vitest/dist/",
|
|
457
|
+
"/vitest/src/",
|
|
458
|
+
"/vite-node/dist/",
|
|
459
|
+
"/vite-node/src/",
|
|
460
|
+
"/node_modules/chai/",
|
|
461
|
+
"/node_modules/tinypool/",
|
|
462
|
+
"/node_modules/tinyspy/",
|
|
463
|
+
"/deps/chunk-",
|
|
464
|
+
"/deps/@vitest",
|
|
465
|
+
"/deps/loupe",
|
|
466
|
+
"/deps/chai",
|
|
467
|
+
/node:\w+/,
|
|
468
|
+
/__vitest_test__/,
|
|
469
|
+
/__vitest_browser__/,
|
|
470
|
+
/\/deps\/vitest_/
|
|
471
|
+
];
|
|
472
|
+
function extractLocation(urlLike) {
|
|
473
|
+
if (!urlLike.includes(":")) return [
|
|
474
|
+
urlLike
|
|
475
|
+
];
|
|
476
|
+
const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
|
|
477
|
+
const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, ""));
|
|
478
|
+
if (!parts) return [
|
|
479
|
+
urlLike
|
|
480
|
+
];
|
|
481
|
+
let url = parts[1];
|
|
482
|
+
if (url.startsWith("async ")) url = url.slice(6);
|
|
483
|
+
if (url.startsWith("http:") || url.startsWith("https:")) {
|
|
484
|
+
const urlObj = new URL(url);
|
|
485
|
+
urlObj.searchParams.delete("import");
|
|
486
|
+
urlObj.searchParams.delete("browserv");
|
|
487
|
+
url = urlObj.pathname + urlObj.hash + urlObj.search;
|
|
488
|
+
}
|
|
489
|
+
if (url.startsWith("/@fs/")) {
|
|
490
|
+
const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
|
|
491
|
+
url = url.slice(isWindows ? 5 : 4);
|
|
492
|
+
}
|
|
493
|
+
return [
|
|
494
|
+
url,
|
|
495
|
+
parts[2] || void 0,
|
|
496
|
+
parts[3] || void 0
|
|
497
|
+
];
|
|
498
|
+
}
|
|
499
|
+
function parseSingleFFOrSafariStack(raw) {
|
|
500
|
+
let line = raw.trim();
|
|
501
|
+
if (SAFARI_NATIVE_CODE_REGEXP.test(line)) return null;
|
|
502
|
+
if (line.includes(" > eval")) line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1");
|
|
503
|
+
if (!line.includes("@") && !line.includes(":")) return null;
|
|
504
|
+
const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(@)/;
|
|
505
|
+
const matches = line.match(functionNameRegex);
|
|
506
|
+
const functionName = matches && matches[1] ? matches[1] : void 0;
|
|
507
|
+
const [url, lineNumber, columnNumber] = extractLocation(line.replace(functionNameRegex, ""));
|
|
508
|
+
if (!url || !lineNumber || !columnNumber) return null;
|
|
509
|
+
return {
|
|
510
|
+
file: url,
|
|
511
|
+
method: functionName || "",
|
|
512
|
+
line: Number.parseInt(lineNumber),
|
|
513
|
+
column: Number.parseInt(columnNumber)
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
function parseSingleV8Stack(raw) {
|
|
517
|
+
let line = raw.trim();
|
|
518
|
+
if (!CHROME_IE_STACK_REGEXP.test(line)) return null;
|
|
519
|
+
if (line.includes("(eval ")) line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
|
|
520
|
+
let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
|
|
521
|
+
const location = sanitizedLine.match(/ (\(.+\)$)/);
|
|
522
|
+
sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
|
|
523
|
+
const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
|
|
524
|
+
let method = location && sanitizedLine || "";
|
|
525
|
+
let file = url && [
|
|
526
|
+
"eval",
|
|
527
|
+
"<anonymous>"
|
|
528
|
+
].includes(url) ? void 0 : url;
|
|
529
|
+
if (!file || !lineNumber || !columnNumber) return null;
|
|
530
|
+
if (method.startsWith("async ")) method = method.slice(6);
|
|
531
|
+
if (file.startsWith("file://")) file = file.slice(7);
|
|
532
|
+
file = file.startsWith("node:") || file.startsWith("internal:") ? file : pathe_M_eThtNZ_resolve(file);
|
|
533
|
+
if (method) method = method.replace(/__vite_ssr_import_\d+__\./g, "");
|
|
534
|
+
return {
|
|
535
|
+
method,
|
|
536
|
+
file,
|
|
537
|
+
line: Number.parseInt(lineNumber),
|
|
538
|
+
column: Number.parseInt(columnNumber)
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function parseStacktrace(stack, options = {}) {
|
|
542
|
+
const { ignoreStackEntries = stackIgnorePatterns } = options;
|
|
543
|
+
const stacks = CHROME_IE_STACK_REGEXP.test(stack) ? parseV8Stacktrace(stack) : parseFFOrSafariStackTrace(stack);
|
|
544
|
+
return stacks.map((stack)=>{
|
|
545
|
+
var _options$getSourceMap;
|
|
546
|
+
if (options.getUrlId) stack.file = options.getUrlId(stack.file);
|
|
547
|
+
const map = null == (_options$getSourceMap = options.getSourceMap) ? void 0 : _options$getSourceMap.call(options, stack.file);
|
|
548
|
+
if (!map || "object" != typeof map || !map.version) return shouldFilter(ignoreStackEntries, stack.file) ? null : stack;
|
|
549
|
+
const traceMap = new TraceMap(map);
|
|
550
|
+
const { line, column, source, name } = originalPositionFor(traceMap, stack);
|
|
551
|
+
let file = stack.file;
|
|
552
|
+
if (source) {
|
|
553
|
+
const fileUrl = stack.file.startsWith("file://") ? stack.file : `file://${stack.file}`;
|
|
554
|
+
const sourceRootUrl = map.sourceRoot ? new URL(map.sourceRoot, fileUrl) : fileUrl;
|
|
555
|
+
file = new URL(source, sourceRootUrl).pathname;
|
|
556
|
+
if (file.match(/\/\w:\//)) file = file.slice(1);
|
|
557
|
+
}
|
|
558
|
+
if (shouldFilter(ignoreStackEntries, file)) return null;
|
|
559
|
+
if (null != line && null != column) return {
|
|
560
|
+
line,
|
|
561
|
+
column,
|
|
562
|
+
file,
|
|
563
|
+
method: name || stack.method
|
|
564
|
+
};
|
|
565
|
+
return stack;
|
|
566
|
+
}).filter((s)=>null != s);
|
|
567
|
+
}
|
|
568
|
+
function shouldFilter(ignoreStackEntries, file) {
|
|
569
|
+
return ignoreStackEntries.some((p)=>file.match(p));
|
|
570
|
+
}
|
|
571
|
+
function parseFFOrSafariStackTrace(stack) {
|
|
572
|
+
return stack.split("\n").map((line)=>parseSingleFFOrSafariStack(line)).filter(notNullish);
|
|
573
|
+
}
|
|
574
|
+
function parseV8Stacktrace(stack) {
|
|
575
|
+
return stack.split("\n").map((line)=>parseSingleV8Stack(line)).filter(notNullish);
|
|
576
|
+
}
|
|
577
|
+
function parseErrorStacktrace(e, options = {}) {
|
|
578
|
+
if (!e || isPrimitive(e)) return [];
|
|
579
|
+
if (e.stacks) return e.stacks;
|
|
580
|
+
const stackStr = e.stack || "";
|
|
581
|
+
let stackFrames = "string" == typeof stackStr ? parseStacktrace(stackStr, options) : [];
|
|
582
|
+
if (!stackFrames.length) {
|
|
583
|
+
const e_ = e;
|
|
584
|
+
if (null != e_.fileName && null != e_.lineNumber && null != e_.columnNumber) stackFrames = parseStacktrace(`${e_.fileName}:${e_.lineNumber}:${e_.columnNumber}`, options);
|
|
585
|
+
if (null != e_.sourceURL && null != e_.line && null != e_._column) stackFrames = parseStacktrace(`${e_.sourceURL}:${e_.line}:${e_.column}`, options);
|
|
586
|
+
}
|
|
587
|
+
if (options.frameFilter) stackFrames = stackFrames.filter((f)=>false !== options.frameFilter(e, f));
|
|
588
|
+
e.stacks = stackFrames;
|
|
589
|
+
return stackFrames;
|
|
590
|
+
}
|
|
591
|
+
try {
|
|
592
|
+
const { getPromiseDetails, kPending, kRejected } = process.binding('util');
|
|
593
|
+
Array.isArray(getPromiseDetails(Promise.resolve()));
|
|
594
|
+
} catch (notNode) {}
|
|
595
|
+
const { AsymmetricMatcher: AsymmetricMatcher$1, DOMCollection: DOMCollection$1, DOMElement: DOMElement$1, Immutable: Immutable$1, ReactElement: ReactElement$1, ReactTestComponent: ReactTestComponent$1 } = dist_plugins;
|
|
596
|
+
function getDefaultExportFromCjs(x) {
|
|
597
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
598
|
+
}
|
|
599
|
+
var jsTokens_1;
|
|
600
|
+
var hasRequiredJsTokens;
|
|
601
|
+
function requireJsTokens() {
|
|
602
|
+
if (hasRequiredJsTokens) return jsTokens_1;
|
|
603
|
+
hasRequiredJsTokens = 1;
|
|
604
|
+
var Identifier, JSXIdentifier, JSXPunctuator, JSXString, JSXText, KeywordsWithExpressionAfter, KeywordsWithNoLineTerminatorAfter, LineTerminatorSequence, MultiLineComment, Newline, NumericLiteral, Punctuator, RegularExpressionLiteral, SingleLineComment, StringLiteral, Template, TokensNotPrecedingObjectLiteral, TokensPrecedingExpression, WhiteSpace;
|
|
605
|
+
RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\\]).|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/yu;
|
|
606
|
+
Punctuator = /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/y;
|
|
607
|
+
Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/yu;
|
|
608
|
+
StringLiteral = /(['"])(?:(?!\1)[^\\\n\r]|\\(?:\r\n|[^]))*(\1)?/y;
|
|
609
|
+
NumericLiteral = /(?:0[xX][\da-fA-F](?:_?[\da-fA-F])*|0[oO][0-7](?:_?[0-7])*|0[bB][01](?:_?[01])*)n?|0n|[1-9](?:_?\d)*n|(?:(?:0(?!\d)|0\d*[89]\d*|[1-9](?:_?\d)*)(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:[eE][+-]?\d(?:_?\d)*)?|0[0-7]+/y;
|
|
610
|
+
Template = /[`}](?:[^`\\$]|\\[^]|\$(?!\{))*(`|\$\{)?/y;
|
|
611
|
+
WhiteSpace = /[\t\v\f\ufeff\p{Zs}]+/yu;
|
|
612
|
+
LineTerminatorSequence = /\r?\n|[\r\u2028\u2029]/y;
|
|
613
|
+
MultiLineComment = /\/\*(?:[^*]|\*(?!\/))*(\*\/)?/y;
|
|
614
|
+
SingleLineComment = /\/\/.*/y;
|
|
615
|
+
JSXPunctuator = /[<>.:={}]|\/(?![\/*])/y;
|
|
616
|
+
JSXIdentifier = /[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}-]*/yu;
|
|
617
|
+
JSXString = /(['"])(?:(?!\1)[^])*(\1)?/y;
|
|
618
|
+
JSXText = /[^<>{}]+/y;
|
|
619
|
+
TokensPrecedingExpression = /^(?:[\/+-]|\.{3}|\?(?:InterpolationIn(?:JSX|Template)|NoLineTerminatorHere|NonExpressionParenEnd|UnaryIncDec))?$|[{}([,;<>=*%&|^!~?:]$/;
|
|
620
|
+
TokensNotPrecedingObjectLiteral = /^(?:=>|[;\]){}]|else|\?(?:NoLineTerminatorHere|NonExpressionParenEnd))?$/;
|
|
621
|
+
KeywordsWithExpressionAfter = /^(?:await|case|default|delete|do|else|instanceof|new|return|throw|typeof|void|yield)$/;
|
|
622
|
+
KeywordsWithNoLineTerminatorAfter = /^(?:return|throw|yield)$/;
|
|
623
|
+
Newline = RegExp(LineTerminatorSequence.source);
|
|
624
|
+
jsTokens_1 = function*(input, { jsx = false } = {}) {
|
|
625
|
+
var braces, firstCodePoint, isExpression, lastIndex, lastSignificantToken, length, match, mode, nextLastIndex, nextLastSignificantToken, parenNesting, postfixIncDec, punctuator, stack;
|
|
626
|
+
({ length } = input);
|
|
627
|
+
lastIndex = 0;
|
|
628
|
+
lastSignificantToken = "";
|
|
629
|
+
stack = [
|
|
630
|
+
{
|
|
631
|
+
tag: "JS"
|
|
632
|
+
}
|
|
633
|
+
];
|
|
634
|
+
braces = [];
|
|
635
|
+
parenNesting = 0;
|
|
636
|
+
postfixIncDec = false;
|
|
637
|
+
while(lastIndex < length){
|
|
638
|
+
mode = stack[stack.length - 1];
|
|
639
|
+
switch(mode.tag){
|
|
640
|
+
case "JS":
|
|
641
|
+
case "JSNonExpressionParen":
|
|
642
|
+
case "InterpolationInTemplate":
|
|
643
|
+
case "InterpolationInJSX":
|
|
644
|
+
if ("/" === input[lastIndex] && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
|
|
645
|
+
RegularExpressionLiteral.lastIndex = lastIndex;
|
|
646
|
+
if (match = RegularExpressionLiteral.exec(input)) {
|
|
647
|
+
lastIndex = RegularExpressionLiteral.lastIndex;
|
|
648
|
+
lastSignificantToken = match[0];
|
|
649
|
+
postfixIncDec = true;
|
|
650
|
+
yield {
|
|
651
|
+
type: "RegularExpressionLiteral",
|
|
652
|
+
value: match[0],
|
|
653
|
+
closed: void 0 !== match[1] && "\\" !== match[1]
|
|
654
|
+
};
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
Punctuator.lastIndex = lastIndex;
|
|
659
|
+
if (match = Punctuator.exec(input)) {
|
|
660
|
+
punctuator = match[0];
|
|
661
|
+
nextLastIndex = Punctuator.lastIndex;
|
|
662
|
+
nextLastSignificantToken = punctuator;
|
|
663
|
+
switch(punctuator){
|
|
664
|
+
case "(":
|
|
665
|
+
if ("?NonExpressionParenKeyword" === lastSignificantToken) stack.push({
|
|
666
|
+
tag: "JSNonExpressionParen",
|
|
667
|
+
nesting: parenNesting
|
|
668
|
+
});
|
|
669
|
+
parenNesting++;
|
|
670
|
+
postfixIncDec = false;
|
|
671
|
+
break;
|
|
672
|
+
case ")":
|
|
673
|
+
parenNesting--;
|
|
674
|
+
postfixIncDec = true;
|
|
675
|
+
if ("JSNonExpressionParen" === mode.tag && parenNesting === mode.nesting) {
|
|
676
|
+
stack.pop();
|
|
677
|
+
nextLastSignificantToken = "?NonExpressionParenEnd";
|
|
678
|
+
postfixIncDec = false;
|
|
679
|
+
}
|
|
680
|
+
break;
|
|
681
|
+
case "{":
|
|
682
|
+
Punctuator.lastIndex = 0;
|
|
683
|
+
isExpression = !TokensNotPrecedingObjectLiteral.test(lastSignificantToken) && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken));
|
|
684
|
+
braces.push(isExpression);
|
|
685
|
+
postfixIncDec = false;
|
|
686
|
+
break;
|
|
687
|
+
case "}":
|
|
688
|
+
switch(mode.tag){
|
|
689
|
+
case "InterpolationInTemplate":
|
|
690
|
+
if (braces.length === mode.nesting) {
|
|
691
|
+
Template.lastIndex = lastIndex;
|
|
692
|
+
match = Template.exec(input);
|
|
693
|
+
lastIndex = Template.lastIndex;
|
|
694
|
+
lastSignificantToken = match[0];
|
|
695
|
+
if ("${" === match[1]) {
|
|
696
|
+
lastSignificantToken = "?InterpolationInTemplate";
|
|
697
|
+
postfixIncDec = false;
|
|
698
|
+
yield {
|
|
699
|
+
type: "TemplateMiddle",
|
|
700
|
+
value: match[0]
|
|
701
|
+
};
|
|
702
|
+
} else {
|
|
703
|
+
stack.pop();
|
|
704
|
+
postfixIncDec = true;
|
|
705
|
+
yield {
|
|
706
|
+
type: "TemplateTail",
|
|
707
|
+
value: match[0],
|
|
708
|
+
closed: "`" === match[1]
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
break;
|
|
714
|
+
case "InterpolationInJSX":
|
|
715
|
+
if (braces.length === mode.nesting) {
|
|
716
|
+
stack.pop();
|
|
717
|
+
lastIndex += 1;
|
|
718
|
+
lastSignificantToken = "}";
|
|
719
|
+
yield {
|
|
720
|
+
type: "JSXPunctuator",
|
|
721
|
+
value: "}"
|
|
722
|
+
};
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
postfixIncDec = braces.pop();
|
|
727
|
+
nextLastSignificantToken = postfixIncDec ? "?ExpressionBraceEnd" : "}";
|
|
728
|
+
break;
|
|
729
|
+
case "]":
|
|
730
|
+
postfixIncDec = true;
|
|
731
|
+
break;
|
|
732
|
+
case "++":
|
|
733
|
+
case "--":
|
|
734
|
+
nextLastSignificantToken = postfixIncDec ? "?PostfixIncDec" : "?UnaryIncDec";
|
|
735
|
+
break;
|
|
736
|
+
case "<":
|
|
737
|
+
if (jsx && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
|
|
738
|
+
stack.push({
|
|
739
|
+
tag: "JSXTag"
|
|
740
|
+
});
|
|
741
|
+
lastIndex += 1;
|
|
742
|
+
lastSignificantToken = "<";
|
|
743
|
+
yield {
|
|
744
|
+
type: "JSXPunctuator",
|
|
745
|
+
value: punctuator
|
|
746
|
+
};
|
|
747
|
+
continue;
|
|
748
|
+
}
|
|
749
|
+
postfixIncDec = false;
|
|
750
|
+
break;
|
|
751
|
+
default:
|
|
752
|
+
postfixIncDec = false;
|
|
753
|
+
}
|
|
754
|
+
lastIndex = nextLastIndex;
|
|
755
|
+
lastSignificantToken = nextLastSignificantToken;
|
|
756
|
+
yield {
|
|
757
|
+
type: "Punctuator",
|
|
758
|
+
value: punctuator
|
|
759
|
+
};
|
|
760
|
+
continue;
|
|
761
|
+
}
|
|
762
|
+
Identifier.lastIndex = lastIndex;
|
|
763
|
+
if (match = Identifier.exec(input)) {
|
|
764
|
+
lastIndex = Identifier.lastIndex;
|
|
765
|
+
nextLastSignificantToken = match[0];
|
|
766
|
+
switch(match[0]){
|
|
767
|
+
case "for":
|
|
768
|
+
case "if":
|
|
769
|
+
case "while":
|
|
770
|
+
case "with":
|
|
771
|
+
if ("." !== lastSignificantToken && "?." !== lastSignificantToken) nextLastSignificantToken = "?NonExpressionParenKeyword";
|
|
772
|
+
}
|
|
773
|
+
lastSignificantToken = nextLastSignificantToken;
|
|
774
|
+
postfixIncDec = !KeywordsWithExpressionAfter.test(match[0]);
|
|
775
|
+
yield {
|
|
776
|
+
type: "#" === match[1] ? "PrivateIdentifier" : "IdentifierName",
|
|
777
|
+
value: match[0]
|
|
778
|
+
};
|
|
779
|
+
continue;
|
|
780
|
+
}
|
|
781
|
+
StringLiteral.lastIndex = lastIndex;
|
|
782
|
+
if (match = StringLiteral.exec(input)) {
|
|
783
|
+
lastIndex = StringLiteral.lastIndex;
|
|
784
|
+
lastSignificantToken = match[0];
|
|
785
|
+
postfixIncDec = true;
|
|
786
|
+
yield {
|
|
787
|
+
type: "StringLiteral",
|
|
788
|
+
value: match[0],
|
|
789
|
+
closed: void 0 !== match[2]
|
|
790
|
+
};
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
NumericLiteral.lastIndex = lastIndex;
|
|
794
|
+
if (match = NumericLiteral.exec(input)) {
|
|
795
|
+
lastIndex = NumericLiteral.lastIndex;
|
|
796
|
+
lastSignificantToken = match[0];
|
|
797
|
+
postfixIncDec = true;
|
|
798
|
+
yield {
|
|
799
|
+
type: "NumericLiteral",
|
|
800
|
+
value: match[0]
|
|
801
|
+
};
|
|
802
|
+
continue;
|
|
803
|
+
}
|
|
804
|
+
Template.lastIndex = lastIndex;
|
|
805
|
+
if (match = Template.exec(input)) {
|
|
806
|
+
lastIndex = Template.lastIndex;
|
|
807
|
+
lastSignificantToken = match[0];
|
|
808
|
+
if ("${" === match[1]) {
|
|
809
|
+
lastSignificantToken = "?InterpolationInTemplate";
|
|
810
|
+
stack.push({
|
|
811
|
+
tag: "InterpolationInTemplate",
|
|
812
|
+
nesting: braces.length
|
|
813
|
+
});
|
|
814
|
+
postfixIncDec = false;
|
|
815
|
+
yield {
|
|
816
|
+
type: "TemplateHead",
|
|
817
|
+
value: match[0]
|
|
818
|
+
};
|
|
819
|
+
} else {
|
|
820
|
+
postfixIncDec = true;
|
|
821
|
+
yield {
|
|
822
|
+
type: "NoSubstitutionTemplate",
|
|
823
|
+
value: match[0],
|
|
824
|
+
closed: "`" === match[1]
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
continue;
|
|
828
|
+
}
|
|
829
|
+
break;
|
|
830
|
+
case "JSXTag":
|
|
831
|
+
case "JSXTagEnd":
|
|
832
|
+
JSXPunctuator.lastIndex = lastIndex;
|
|
833
|
+
if (match = JSXPunctuator.exec(input)) {
|
|
834
|
+
lastIndex = JSXPunctuator.lastIndex;
|
|
835
|
+
nextLastSignificantToken = match[0];
|
|
836
|
+
switch(match[0]){
|
|
837
|
+
case "<":
|
|
838
|
+
stack.push({
|
|
839
|
+
tag: "JSXTag"
|
|
840
|
+
});
|
|
841
|
+
break;
|
|
842
|
+
case ">":
|
|
843
|
+
stack.pop();
|
|
844
|
+
if ("/" === lastSignificantToken || "JSXTagEnd" === mode.tag) {
|
|
845
|
+
nextLastSignificantToken = "?JSX";
|
|
846
|
+
postfixIncDec = true;
|
|
847
|
+
} else stack.push({
|
|
848
|
+
tag: "JSXChildren"
|
|
849
|
+
});
|
|
850
|
+
break;
|
|
851
|
+
case "{":
|
|
852
|
+
stack.push({
|
|
853
|
+
tag: "InterpolationInJSX",
|
|
854
|
+
nesting: braces.length
|
|
855
|
+
});
|
|
856
|
+
nextLastSignificantToken = "?InterpolationInJSX";
|
|
857
|
+
postfixIncDec = false;
|
|
858
|
+
break;
|
|
859
|
+
case "/":
|
|
860
|
+
if ("<" === lastSignificantToken) {
|
|
861
|
+
stack.pop();
|
|
862
|
+
if ("JSXChildren" === stack[stack.length - 1].tag) stack.pop();
|
|
863
|
+
stack.push({
|
|
864
|
+
tag: "JSXTagEnd"
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
lastSignificantToken = nextLastSignificantToken;
|
|
869
|
+
yield {
|
|
870
|
+
type: "JSXPunctuator",
|
|
871
|
+
value: match[0]
|
|
872
|
+
};
|
|
873
|
+
continue;
|
|
874
|
+
}
|
|
875
|
+
JSXIdentifier.lastIndex = lastIndex;
|
|
876
|
+
if (match = JSXIdentifier.exec(input)) {
|
|
877
|
+
lastIndex = JSXIdentifier.lastIndex;
|
|
878
|
+
lastSignificantToken = match[0];
|
|
879
|
+
yield {
|
|
880
|
+
type: "JSXIdentifier",
|
|
881
|
+
value: match[0]
|
|
882
|
+
};
|
|
883
|
+
continue;
|
|
884
|
+
}
|
|
885
|
+
JSXString.lastIndex = lastIndex;
|
|
886
|
+
if (match = JSXString.exec(input)) {
|
|
887
|
+
lastIndex = JSXString.lastIndex;
|
|
888
|
+
lastSignificantToken = match[0];
|
|
889
|
+
yield {
|
|
890
|
+
type: "JSXString",
|
|
891
|
+
value: match[0],
|
|
892
|
+
closed: void 0 !== match[2]
|
|
893
|
+
};
|
|
894
|
+
continue;
|
|
895
|
+
}
|
|
896
|
+
break;
|
|
897
|
+
case "JSXChildren":
|
|
898
|
+
JSXText.lastIndex = lastIndex;
|
|
899
|
+
if (match = JSXText.exec(input)) {
|
|
900
|
+
lastIndex = JSXText.lastIndex;
|
|
901
|
+
lastSignificantToken = match[0];
|
|
902
|
+
yield {
|
|
903
|
+
type: "JSXText",
|
|
904
|
+
value: match[0]
|
|
905
|
+
};
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
switch(input[lastIndex]){
|
|
909
|
+
case "<":
|
|
910
|
+
stack.push({
|
|
911
|
+
tag: "JSXTag"
|
|
912
|
+
});
|
|
913
|
+
lastIndex++;
|
|
914
|
+
lastSignificantToken = "<";
|
|
915
|
+
yield {
|
|
916
|
+
type: "JSXPunctuator",
|
|
917
|
+
value: "<"
|
|
918
|
+
};
|
|
919
|
+
continue;
|
|
920
|
+
case "{":
|
|
921
|
+
stack.push({
|
|
922
|
+
tag: "InterpolationInJSX",
|
|
923
|
+
nesting: braces.length
|
|
924
|
+
});
|
|
925
|
+
lastIndex++;
|
|
926
|
+
lastSignificantToken = "?InterpolationInJSX";
|
|
927
|
+
postfixIncDec = false;
|
|
928
|
+
yield {
|
|
929
|
+
type: "JSXPunctuator",
|
|
930
|
+
value: "{"
|
|
931
|
+
};
|
|
932
|
+
continue;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
WhiteSpace.lastIndex = lastIndex;
|
|
936
|
+
if (match = WhiteSpace.exec(input)) {
|
|
937
|
+
lastIndex = WhiteSpace.lastIndex;
|
|
938
|
+
yield {
|
|
939
|
+
type: "WhiteSpace",
|
|
940
|
+
value: match[0]
|
|
941
|
+
};
|
|
942
|
+
continue;
|
|
943
|
+
}
|
|
944
|
+
LineTerminatorSequence.lastIndex = lastIndex;
|
|
945
|
+
if (match = LineTerminatorSequence.exec(input)) {
|
|
946
|
+
lastIndex = LineTerminatorSequence.lastIndex;
|
|
947
|
+
postfixIncDec = false;
|
|
948
|
+
if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) lastSignificantToken = "?NoLineTerminatorHere";
|
|
949
|
+
yield {
|
|
950
|
+
type: "LineTerminatorSequence",
|
|
951
|
+
value: match[0]
|
|
952
|
+
};
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
955
|
+
MultiLineComment.lastIndex = lastIndex;
|
|
956
|
+
if (match = MultiLineComment.exec(input)) {
|
|
957
|
+
lastIndex = MultiLineComment.lastIndex;
|
|
958
|
+
if (Newline.test(match[0])) {
|
|
959
|
+
postfixIncDec = false;
|
|
960
|
+
if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) lastSignificantToken = "?NoLineTerminatorHere";
|
|
961
|
+
}
|
|
962
|
+
yield {
|
|
963
|
+
type: "MultiLineComment",
|
|
964
|
+
value: match[0],
|
|
965
|
+
closed: void 0 !== match[1]
|
|
966
|
+
};
|
|
967
|
+
continue;
|
|
968
|
+
}
|
|
969
|
+
SingleLineComment.lastIndex = lastIndex;
|
|
970
|
+
if (match = SingleLineComment.exec(input)) {
|
|
971
|
+
lastIndex = SingleLineComment.lastIndex;
|
|
972
|
+
postfixIncDec = false;
|
|
973
|
+
yield {
|
|
974
|
+
type: "SingleLineComment",
|
|
975
|
+
value: match[0]
|
|
976
|
+
};
|
|
977
|
+
continue;
|
|
978
|
+
}
|
|
979
|
+
firstCodePoint = String.fromCodePoint(input.codePointAt(lastIndex));
|
|
980
|
+
lastIndex += firstCodePoint.length;
|
|
981
|
+
lastSignificantToken = firstCodePoint;
|
|
982
|
+
postfixIncDec = false;
|
|
983
|
+
yield {
|
|
984
|
+
type: mode.tag.startsWith("JSX") ? "JSXInvalid" : "Invalid",
|
|
985
|
+
value: firstCodePoint
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
};
|
|
989
|
+
return jsTokens_1;
|
|
990
|
+
}
|
|
991
|
+
requireJsTokens();
|
|
992
|
+
var reservedWords = {
|
|
993
|
+
keyword: [
|
|
994
|
+
"break",
|
|
995
|
+
"case",
|
|
996
|
+
"catch",
|
|
997
|
+
"continue",
|
|
998
|
+
"debugger",
|
|
999
|
+
"default",
|
|
1000
|
+
"do",
|
|
1001
|
+
"else",
|
|
1002
|
+
"finally",
|
|
1003
|
+
"for",
|
|
1004
|
+
"function",
|
|
1005
|
+
"if",
|
|
1006
|
+
"return",
|
|
1007
|
+
"switch",
|
|
1008
|
+
"throw",
|
|
1009
|
+
"try",
|
|
1010
|
+
"var",
|
|
1011
|
+
"const",
|
|
1012
|
+
"while",
|
|
1013
|
+
"with",
|
|
1014
|
+
"new",
|
|
1015
|
+
"this",
|
|
1016
|
+
"super",
|
|
1017
|
+
"class",
|
|
1018
|
+
"extends",
|
|
1019
|
+
"export",
|
|
1020
|
+
"import",
|
|
1021
|
+
"null",
|
|
1022
|
+
"true",
|
|
1023
|
+
"false",
|
|
1024
|
+
"in",
|
|
1025
|
+
"instanceof",
|
|
1026
|
+
"typeof",
|
|
1027
|
+
"void",
|
|
1028
|
+
"delete"
|
|
1029
|
+
],
|
|
1030
|
+
strict: [
|
|
1031
|
+
"implements",
|
|
1032
|
+
"interface",
|
|
1033
|
+
"let",
|
|
1034
|
+
"package",
|
|
1035
|
+
"private",
|
|
1036
|
+
"protected",
|
|
1037
|
+
"public",
|
|
1038
|
+
"static",
|
|
1039
|
+
"yield"
|
|
1040
|
+
]
|
|
1041
|
+
};
|
|
1042
|
+
new Set(reservedWords.keyword);
|
|
1043
|
+
new Set(reservedWords.strict);
|
|
1044
|
+
var dist_f = {
|
|
1045
|
+
reset: [
|
|
1046
|
+
0,
|
|
1047
|
+
0
|
|
1048
|
+
],
|
|
1049
|
+
bold: [
|
|
1050
|
+
1,
|
|
1051
|
+
22,
|
|
1052
|
+
"\x1B[22m\x1B[1m"
|
|
1053
|
+
],
|
|
1054
|
+
dim: [
|
|
1055
|
+
2,
|
|
1056
|
+
22,
|
|
1057
|
+
"\x1B[22m\x1B[2m"
|
|
1058
|
+
],
|
|
1059
|
+
italic: [
|
|
1060
|
+
3,
|
|
1061
|
+
23
|
|
1062
|
+
],
|
|
1063
|
+
underline: [
|
|
1064
|
+
4,
|
|
1065
|
+
24
|
|
1066
|
+
],
|
|
1067
|
+
inverse: [
|
|
1068
|
+
7,
|
|
1069
|
+
27
|
|
1070
|
+
],
|
|
1071
|
+
hidden: [
|
|
1072
|
+
8,
|
|
1073
|
+
28
|
|
1074
|
+
],
|
|
1075
|
+
strikethrough: [
|
|
1076
|
+
9,
|
|
1077
|
+
29
|
|
1078
|
+
],
|
|
1079
|
+
black: [
|
|
1080
|
+
30,
|
|
1081
|
+
39
|
|
1082
|
+
],
|
|
1083
|
+
red: [
|
|
1084
|
+
31,
|
|
1085
|
+
39
|
|
1086
|
+
],
|
|
1087
|
+
green: [
|
|
1088
|
+
32,
|
|
1089
|
+
39
|
|
1090
|
+
],
|
|
1091
|
+
yellow: [
|
|
1092
|
+
33,
|
|
1093
|
+
39
|
|
1094
|
+
],
|
|
1095
|
+
blue: [
|
|
1096
|
+
34,
|
|
1097
|
+
39
|
|
1098
|
+
],
|
|
1099
|
+
magenta: [
|
|
1100
|
+
35,
|
|
1101
|
+
39
|
|
1102
|
+
],
|
|
1103
|
+
cyan: [
|
|
1104
|
+
36,
|
|
1105
|
+
39
|
|
1106
|
+
],
|
|
1107
|
+
white: [
|
|
1108
|
+
37,
|
|
1109
|
+
39
|
|
1110
|
+
],
|
|
1111
|
+
gray: [
|
|
1112
|
+
90,
|
|
1113
|
+
39
|
|
1114
|
+
],
|
|
1115
|
+
bgBlack: [
|
|
1116
|
+
40,
|
|
1117
|
+
49
|
|
1118
|
+
],
|
|
1119
|
+
bgRed: [
|
|
1120
|
+
41,
|
|
1121
|
+
49
|
|
1122
|
+
],
|
|
1123
|
+
bgGreen: [
|
|
1124
|
+
42,
|
|
1125
|
+
49
|
|
1126
|
+
],
|
|
1127
|
+
bgYellow: [
|
|
1128
|
+
43,
|
|
1129
|
+
49
|
|
1130
|
+
],
|
|
1131
|
+
bgBlue: [
|
|
1132
|
+
44,
|
|
1133
|
+
49
|
|
1134
|
+
],
|
|
1135
|
+
bgMagenta: [
|
|
1136
|
+
45,
|
|
1137
|
+
49
|
|
1138
|
+
],
|
|
1139
|
+
bgCyan: [
|
|
1140
|
+
46,
|
|
1141
|
+
49
|
|
1142
|
+
],
|
|
1143
|
+
bgWhite: [
|
|
1144
|
+
47,
|
|
1145
|
+
49
|
|
1146
|
+
],
|
|
1147
|
+
blackBright: [
|
|
1148
|
+
90,
|
|
1149
|
+
39
|
|
1150
|
+
],
|
|
1151
|
+
redBright: [
|
|
1152
|
+
91,
|
|
1153
|
+
39
|
|
1154
|
+
],
|
|
1155
|
+
greenBright: [
|
|
1156
|
+
92,
|
|
1157
|
+
39
|
|
1158
|
+
],
|
|
1159
|
+
yellowBright: [
|
|
1160
|
+
93,
|
|
1161
|
+
39
|
|
1162
|
+
],
|
|
1163
|
+
blueBright: [
|
|
1164
|
+
94,
|
|
1165
|
+
39
|
|
1166
|
+
],
|
|
1167
|
+
magentaBright: [
|
|
1168
|
+
95,
|
|
1169
|
+
39
|
|
1170
|
+
],
|
|
1171
|
+
cyanBright: [
|
|
1172
|
+
96,
|
|
1173
|
+
39
|
|
1174
|
+
],
|
|
1175
|
+
whiteBright: [
|
|
1176
|
+
97,
|
|
1177
|
+
39
|
|
1178
|
+
],
|
|
1179
|
+
bgBlackBright: [
|
|
1180
|
+
100,
|
|
1181
|
+
49
|
|
1182
|
+
],
|
|
1183
|
+
bgRedBright: [
|
|
1184
|
+
101,
|
|
1185
|
+
49
|
|
1186
|
+
],
|
|
1187
|
+
bgGreenBright: [
|
|
1188
|
+
102,
|
|
1189
|
+
49
|
|
1190
|
+
],
|
|
1191
|
+
bgYellowBright: [
|
|
1192
|
+
103,
|
|
1193
|
+
49
|
|
1194
|
+
],
|
|
1195
|
+
bgBlueBright: [
|
|
1196
|
+
104,
|
|
1197
|
+
49
|
|
1198
|
+
],
|
|
1199
|
+
bgMagentaBright: [
|
|
1200
|
+
105,
|
|
1201
|
+
49
|
|
1202
|
+
],
|
|
1203
|
+
bgCyanBright: [
|
|
1204
|
+
106,
|
|
1205
|
+
49
|
|
1206
|
+
],
|
|
1207
|
+
bgWhiteBright: [
|
|
1208
|
+
107,
|
|
1209
|
+
49
|
|
1210
|
+
]
|
|
1211
|
+
}, h = Object.entries(dist_f);
|
|
1212
|
+
function dist_a(n) {
|
|
1213
|
+
return String(n);
|
|
1214
|
+
}
|
|
1215
|
+
dist_a.open = "";
|
|
1216
|
+
dist_a.close = "";
|
|
1217
|
+
function C(n = false) {
|
|
1218
|
+
let e = void 0 !== process ? process : void 0, i = (null == e ? void 0 : e.env) || {}, g = (null == e ? void 0 : e.argv) || [];
|
|
1219
|
+
return !("NO_COLOR" in i || g.includes("--no-color")) && ("FORCE_COLOR" in i || g.includes("--color") || (null == e ? void 0 : e.platform) === "win32" || n && "dumb" !== i.TERM || "CI" in i) || "u" > typeof window && !!window.chrome;
|
|
1220
|
+
}
|
|
1221
|
+
function dist_p(n = false) {
|
|
1222
|
+
let e = C(n), i = (r, t, c, o)=>{
|
|
1223
|
+
let l = "", s = 0;
|
|
1224
|
+
do l += r.substring(s, o) + c, s = o + t.length, o = r.indexOf(t, s);
|
|
1225
|
+
while (~o)
|
|
1226
|
+
return l + r.substring(s);
|
|
1227
|
+
}, g = (r, t, c = r)=>{
|
|
1228
|
+
let o = (l)=>{
|
|
1229
|
+
let s = String(l), b = s.indexOf(t, r.length);
|
|
1230
|
+
return ~b ? r + i(s, t, c, b) + t : r + s + t;
|
|
1231
|
+
};
|
|
1232
|
+
return o.open = r, o.close = t, o;
|
|
1233
|
+
}, u = {
|
|
1234
|
+
isColorSupported: e
|
|
1235
|
+
}, d = (r)=>`\x1B[${r}m`;
|
|
1236
|
+
for (let [r, t] of h)u[r] = e ? g(d(t[0]), d(t[1]), t[2]) : dist_a;
|
|
1237
|
+
return u;
|
|
1238
|
+
}
|
|
1239
|
+
dist_p();
|
|
1240
|
+
const lineSplitRE = /\r?\n/;
|
|
1241
|
+
function positionToOffset(source, lineNumber, columnNumber) {
|
|
1242
|
+
const lines = source.split(lineSplitRE);
|
|
1243
|
+
const nl = /\r\n/.test(source) ? 2 : 1;
|
|
1244
|
+
let start = 0;
|
|
1245
|
+
if (lineNumber > lines.length) return source.length;
|
|
1246
|
+
for(let i = 0; i < lineNumber - 1; i++)start += lines[i].length + nl;
|
|
1247
|
+
return start + columnNumber;
|
|
1248
|
+
}
|
|
1249
|
+
function offsetToLineNumber(source, offset) {
|
|
1250
|
+
if (offset > source.length) throw new Error(`offset is longer than source length! offset ${offset} > length ${source.length}`);
|
|
1251
|
+
const lines = source.split(lineSplitRE);
|
|
1252
|
+
const nl = /\r\n/.test(source) ? 2 : 1;
|
|
1253
|
+
let counted = 0;
|
|
1254
|
+
let line = 0;
|
|
1255
|
+
for(; line < lines.length; line++){
|
|
1256
|
+
const lineLength = lines[line].length + nl;
|
|
1257
|
+
if (counted + lineLength >= offset) break;
|
|
1258
|
+
counted += lineLength;
|
|
1259
|
+
}
|
|
1260
|
+
return line + 1;
|
|
1261
|
+
}
|
|
1262
|
+
async function saveInlineSnapshots(environment, snapshots) {
|
|
1263
|
+
const MagicString = (await import("./2~magic-string.es.js")).default;
|
|
1264
|
+
const files = new Set(snapshots.map((i)=>i.file));
|
|
1265
|
+
await Promise.all(Array.from(files).map(async (file)=>{
|
|
1266
|
+
const snaps = snapshots.filter((i)=>i.file === file);
|
|
1267
|
+
const code = await environment.readSnapshotFile(file);
|
|
1268
|
+
const s = new MagicString(code);
|
|
1269
|
+
for (const snap of snaps){
|
|
1270
|
+
const index = positionToOffset(code, snap.line, snap.column);
|
|
1271
|
+
replaceInlineSnap(code, s, index, snap.snapshot);
|
|
1272
|
+
}
|
|
1273
|
+
const transformed = s.toString();
|
|
1274
|
+
if (transformed !== code) await environment.saveSnapshotFile(file, transformed);
|
|
1275
|
+
}));
|
|
1276
|
+
}
|
|
1277
|
+
const startObjectRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*\{/;
|
|
1278
|
+
function replaceObjectSnap(code, s, index, newSnap) {
|
|
1279
|
+
let _code = code.slice(index);
|
|
1280
|
+
const startMatch = startObjectRegex.exec(_code);
|
|
1281
|
+
if (!startMatch) return false;
|
|
1282
|
+
_code = _code.slice(startMatch.index);
|
|
1283
|
+
let callEnd = getCallLastIndex(_code);
|
|
1284
|
+
if (null === callEnd) return false;
|
|
1285
|
+
callEnd += index + startMatch.index;
|
|
1286
|
+
const shapeStart = index + startMatch.index + startMatch[0].length;
|
|
1287
|
+
const shapeEnd = getObjectShapeEndIndex(code, shapeStart);
|
|
1288
|
+
const snap = `, ${prepareSnapString(newSnap, code, index)}`;
|
|
1289
|
+
if (shapeEnd === callEnd) s.appendLeft(callEnd, snap);
|
|
1290
|
+
else s.overwrite(shapeEnd, callEnd, snap);
|
|
1291
|
+
return true;
|
|
1292
|
+
}
|
|
1293
|
+
function getObjectShapeEndIndex(code, index) {
|
|
1294
|
+
let startBraces = 1;
|
|
1295
|
+
let endBraces = 0;
|
|
1296
|
+
while(startBraces !== endBraces && index < code.length){
|
|
1297
|
+
const s = code[index++];
|
|
1298
|
+
if ("{" === s) startBraces++;
|
|
1299
|
+
else if ("}" === s) endBraces++;
|
|
1300
|
+
}
|
|
1301
|
+
return index;
|
|
1302
|
+
}
|
|
1303
|
+
function prepareSnapString(snap, source, index) {
|
|
1304
|
+
const lineNumber = offsetToLineNumber(source, index);
|
|
1305
|
+
const line = source.split(lineSplitRE)[lineNumber - 1];
|
|
1306
|
+
const indent = line.match(/^\s*/)[0] || "";
|
|
1307
|
+
const indentNext = indent.includes(" ") ? `${indent}\t` : `${indent} `;
|
|
1308
|
+
const lines = snap.trim().replace(/\\/g, "\\\\").split(/\n/g);
|
|
1309
|
+
const isOneline = lines.length <= 1;
|
|
1310
|
+
const quote = "`";
|
|
1311
|
+
if (isOneline) return `${quote}${lines.join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}${quote}`;
|
|
1312
|
+
return `${quote}\n${lines.map((i)=>i ? indentNext + i : "").join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}\n${indent}${quote}`;
|
|
1313
|
+
}
|
|
1314
|
+
const toMatchInlineName = "toMatchInlineSnapshot";
|
|
1315
|
+
const toThrowErrorMatchingInlineName = "toThrowErrorMatchingInlineSnapshot";
|
|
1316
|
+
function getCodeStartingAtIndex(code, index) {
|
|
1317
|
+
const indexInline = index - toMatchInlineName.length;
|
|
1318
|
+
if (code.slice(indexInline, index) === toMatchInlineName) return {
|
|
1319
|
+
code: code.slice(indexInline),
|
|
1320
|
+
index: indexInline
|
|
1321
|
+
};
|
|
1322
|
+
const indexThrowInline = index - toThrowErrorMatchingInlineName.length;
|
|
1323
|
+
if (code.slice(index - indexThrowInline, index) === toThrowErrorMatchingInlineName) return {
|
|
1324
|
+
code: code.slice(index - indexThrowInline),
|
|
1325
|
+
index: index - indexThrowInline
|
|
1326
|
+
};
|
|
1327
|
+
return {
|
|
1328
|
+
code: code.slice(index),
|
|
1329
|
+
index
|
|
1330
|
+
};
|
|
1331
|
+
}
|
|
1332
|
+
const startRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*[\w$]*(['"`)])/;
|
|
1333
|
+
function replaceInlineSnap(code, s, currentIndex, newSnap) {
|
|
1334
|
+
const { code: codeStartingAtIndex, index } = getCodeStartingAtIndex(code, currentIndex);
|
|
1335
|
+
const startMatch = startRegex.exec(codeStartingAtIndex);
|
|
1336
|
+
const firstKeywordMatch = /toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot/.exec(codeStartingAtIndex);
|
|
1337
|
+
if (!startMatch || startMatch.index !== (null == firstKeywordMatch ? void 0 : firstKeywordMatch.index)) return replaceObjectSnap(code, s, index, newSnap);
|
|
1338
|
+
const quote = startMatch[1];
|
|
1339
|
+
const startIndex = index + startMatch.index + startMatch[0].length;
|
|
1340
|
+
const snapString = prepareSnapString(newSnap, code, index);
|
|
1341
|
+
if (")" === quote) {
|
|
1342
|
+
s.appendRight(startIndex - 1, snapString);
|
|
1343
|
+
return true;
|
|
1344
|
+
}
|
|
1345
|
+
const quoteEndRE = new RegExp(`(?:^|[^\\\\])${quote}`);
|
|
1346
|
+
const endMatch = quoteEndRE.exec(code.slice(startIndex));
|
|
1347
|
+
if (!endMatch) return false;
|
|
1348
|
+
const endIndex = startIndex + endMatch.index + endMatch[0].length;
|
|
1349
|
+
s.overwrite(startIndex - 1, endIndex, snapString);
|
|
1350
|
+
return true;
|
|
1351
|
+
}
|
|
1352
|
+
const INDENTATION_REGEX = /^([^\S\n]*)\S/m;
|
|
1353
|
+
function stripSnapshotIndentation(inlineSnapshot) {
|
|
1354
|
+
const match = inlineSnapshot.match(INDENTATION_REGEX);
|
|
1355
|
+
if (!match || !match[1]) return inlineSnapshot;
|
|
1356
|
+
const indentation = match[1];
|
|
1357
|
+
const lines = inlineSnapshot.split(/\n/g);
|
|
1358
|
+
if (lines.length <= 2) return inlineSnapshot;
|
|
1359
|
+
if ("" !== lines[0].trim() || "" !== lines[lines.length - 1].trim()) return inlineSnapshot;
|
|
1360
|
+
for(let i = 1; i < lines.length - 1; i++)if ("" !== lines[i]) {
|
|
1361
|
+
if (0 !== lines[i].indexOf(indentation)) return inlineSnapshot;
|
|
1362
|
+
lines[i] = lines[i].substring(indentation.length);
|
|
1363
|
+
}
|
|
1364
|
+
lines[lines.length - 1] = "";
|
|
1365
|
+
inlineSnapshot = lines.join("\n");
|
|
1366
|
+
return inlineSnapshot;
|
|
1367
|
+
}
|
|
1368
|
+
async function saveRawSnapshots(environment, snapshots) {
|
|
1369
|
+
await Promise.all(snapshots.map(async (snap)=>{
|
|
1370
|
+
if (!snap.readonly) await environment.saveSnapshotFile(snap.file, snap.snapshot);
|
|
1371
|
+
}));
|
|
1372
|
+
}
|
|
1373
|
+
var naturalCompare$1 = {
|
|
1374
|
+
exports: {}
|
|
1375
|
+
};
|
|
1376
|
+
var hasRequiredNaturalCompare;
|
|
1377
|
+
function requireNaturalCompare() {
|
|
1378
|
+
if (hasRequiredNaturalCompare) return naturalCompare$1.exports;
|
|
1379
|
+
hasRequiredNaturalCompare = 1;
|
|
1380
|
+
/*
|
|
1381
|
+
* @version 1.4.0
|
|
1382
|
+
* @date 2015-10-26
|
|
1383
|
+
* @stability 3 - Stable
|
|
1384
|
+
* @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
|
|
1385
|
+
* @license MIT License
|
|
1386
|
+
*/ var naturalCompare = function(a, b) {
|
|
1387
|
+
var i, codeA, codeB = 1, posA = 0, posB = 0, alphabet = String.alphabet;
|
|
1388
|
+
function getCode(str, pos, code) {
|
|
1389
|
+
if (code) {
|
|
1390
|
+
for(i = pos; code = getCode(str, i), code < 76 && code > 65;)++i;
|
|
1391
|
+
return +str.slice(pos - 1, i);
|
|
1392
|
+
}
|
|
1393
|
+
code = alphabet && alphabet.indexOf(str.charAt(pos));
|
|
1394
|
+
return code > -1 ? code + 76 : (code = str.charCodeAt(pos) || 0, code < 45 || code > 127) ? code : code < 46 ? 65 : code < 48 ? code - 1 : code < 58 ? code + 18 : code < 65 ? code - 11 : code < 91 ? code + 11 : code < 97 ? code - 37 : code < 123 ? code + 5 : code - 63;
|
|
1395
|
+
}
|
|
1396
|
+
if ((a += "") != (b += "")) for(; codeB;){
|
|
1397
|
+
codeA = getCode(a, posA++);
|
|
1398
|
+
codeB = getCode(b, posB++);
|
|
1399
|
+
if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
|
|
1400
|
+
codeA = getCode(a, posA, posA);
|
|
1401
|
+
codeB = getCode(b, posB, posA = i);
|
|
1402
|
+
posB = i;
|
|
1403
|
+
}
|
|
1404
|
+
if (codeA != codeB) return codeA < codeB ? -1 : 1;
|
|
1405
|
+
}
|
|
1406
|
+
return 0;
|
|
1407
|
+
};
|
|
1408
|
+
try {
|
|
1409
|
+
naturalCompare$1.exports = naturalCompare;
|
|
1410
|
+
} catch (e) {
|
|
1411
|
+
String.naturalCompare = naturalCompare;
|
|
1412
|
+
}
|
|
1413
|
+
return naturalCompare$1.exports;
|
|
1414
|
+
}
|
|
1415
|
+
var naturalCompareExports = requireNaturalCompare();
|
|
1416
|
+
var dist_naturalCompare = /*@__PURE__*/ getDefaultExportFromCjs(naturalCompareExports);
|
|
1417
|
+
const serialize$1 = (val, config, indentation, depth, refs, printer)=>{
|
|
1418
|
+
const name = val.getMockName();
|
|
1419
|
+
const nameString = "vi.fn()" === name ? "" : ` ${name}`;
|
|
1420
|
+
let callsString = "";
|
|
1421
|
+
if (0 !== val.mock.calls.length) {
|
|
1422
|
+
const indentationNext = indentation + config.indent;
|
|
1423
|
+
callsString = ` {${config.spacingOuter}${indentationNext}"calls": ${printer(val.mock.calls, config, indentationNext, depth, refs)}${config.min ? ", " : ","}${config.spacingOuter}${indentationNext}"results": ${printer(val.mock.results, config, indentationNext, depth, refs)}${config.min ? "" : ","}${config.spacingOuter}${indentation}}`;
|
|
1424
|
+
}
|
|
1425
|
+
return `[MockFunction${nameString}]${callsString}`;
|
|
1426
|
+
};
|
|
1427
|
+
const dist_test = (val)=>val && !!val._isMockFunction;
|
|
1428
|
+
const dist_plugin = {
|
|
1429
|
+
serialize: serialize$1,
|
|
1430
|
+
test: dist_test
|
|
1431
|
+
};
|
|
1432
|
+
const { DOMCollection: DOMCollection, DOMElement: DOMElement, Immutable: Immutable, ReactElement: ReactElement, ReactTestComponent: ReactTestComponent, AsymmetricMatcher: AsymmetricMatcher } = dist_plugins;
|
|
1433
|
+
let PLUGINS = [
|
|
1434
|
+
ReactTestComponent,
|
|
1435
|
+
ReactElement,
|
|
1436
|
+
DOMElement,
|
|
1437
|
+
DOMCollection,
|
|
1438
|
+
Immutable,
|
|
1439
|
+
AsymmetricMatcher,
|
|
1440
|
+
dist_plugin
|
|
1441
|
+
];
|
|
1442
|
+
function addSerializer(plugin) {
|
|
1443
|
+
PLUGINS = [
|
|
1444
|
+
plugin
|
|
1445
|
+
].concat(PLUGINS);
|
|
1446
|
+
}
|
|
1447
|
+
function getSerializers() {
|
|
1448
|
+
return PLUGINS;
|
|
1449
|
+
}
|
|
1450
|
+
function testNameToKey(testName, count) {
|
|
1451
|
+
return `${testName} ${count}`;
|
|
1452
|
+
}
|
|
1453
|
+
function keyToTestName(key) {
|
|
1454
|
+
if (!/ \d+$/.test(key)) throw new Error("Snapshot keys must end with a number.");
|
|
1455
|
+
return key.replace(/ \d+$/, "");
|
|
1456
|
+
}
|
|
1457
|
+
function getSnapshotData(content, options) {
|
|
1458
|
+
const update = options.updateSnapshot;
|
|
1459
|
+
const data = Object.create(null);
|
|
1460
|
+
let snapshotContents = "";
|
|
1461
|
+
let dirty = false;
|
|
1462
|
+
if (null != content) try {
|
|
1463
|
+
snapshotContents = content;
|
|
1464
|
+
const populate = new Function("exports", snapshotContents);
|
|
1465
|
+
populate(data);
|
|
1466
|
+
} catch {}
|
|
1467
|
+
const isInvalid = snapshotContents;
|
|
1468
|
+
if (("all" === update || "new" === update) && isInvalid) dirty = true;
|
|
1469
|
+
return {
|
|
1470
|
+
data,
|
|
1471
|
+
dirty
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1474
|
+
function addExtraLineBreaks(string) {
|
|
1475
|
+
return string.includes("\n") ? `\n${string}\n` : string;
|
|
1476
|
+
}
|
|
1477
|
+
function removeExtraLineBreaks(string) {
|
|
1478
|
+
return string.length > 2 && string.startsWith("\n") && string.endsWith("\n") ? string.slice(1, -1) : string;
|
|
1479
|
+
}
|
|
1480
|
+
const escapeRegex = true;
|
|
1481
|
+
const printFunctionName = false;
|
|
1482
|
+
function serialize(val, indent = 2, formatOverrides = {}) {
|
|
1483
|
+
return normalizeNewlines(dist_format(val, {
|
|
1484
|
+
escapeRegex: escapeRegex,
|
|
1485
|
+
indent,
|
|
1486
|
+
plugins: getSerializers(),
|
|
1487
|
+
printFunctionName: printFunctionName,
|
|
1488
|
+
...formatOverrides
|
|
1489
|
+
}));
|
|
1490
|
+
}
|
|
1491
|
+
function escapeBacktickString(str) {
|
|
1492
|
+
return str.replace(/`|\\|\$\{/g, "\\$&");
|
|
1493
|
+
}
|
|
1494
|
+
function printBacktickString(str) {
|
|
1495
|
+
return `\`${escapeBacktickString(str)}\``;
|
|
1496
|
+
}
|
|
1497
|
+
function normalizeNewlines(string) {
|
|
1498
|
+
return string.replace(/\r\n|\r/g, "\n");
|
|
1499
|
+
}
|
|
1500
|
+
async function saveSnapshotFile(environment, snapshotData, snapshotPath) {
|
|
1501
|
+
const snapshots = Object.keys(snapshotData).sort(dist_naturalCompare).map((key)=>`exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`);
|
|
1502
|
+
const content = `${environment.getHeader()}\n\n${snapshots.join("\n\n")}\n`;
|
|
1503
|
+
const oldContent = await environment.readSnapshotFile(snapshotPath);
|
|
1504
|
+
const skipWriting = null != oldContent && oldContent === content;
|
|
1505
|
+
if (skipWriting) return;
|
|
1506
|
+
await environment.saveSnapshotFile(snapshotPath, content);
|
|
1507
|
+
}
|
|
1508
|
+
function deepMergeArray(target = [], source = []) {
|
|
1509
|
+
const mergedOutput = Array.from(target);
|
|
1510
|
+
source.forEach((sourceElement, index)=>{
|
|
1511
|
+
const targetElement = mergedOutput[index];
|
|
1512
|
+
if (Array.isArray(target[index])) mergedOutput[index] = deepMergeArray(target[index], sourceElement);
|
|
1513
|
+
else if (isObject(targetElement)) mergedOutput[index] = deepMergeSnapshot(target[index], sourceElement);
|
|
1514
|
+
else mergedOutput[index] = sourceElement;
|
|
1515
|
+
});
|
|
1516
|
+
return mergedOutput;
|
|
1517
|
+
}
|
|
1518
|
+
function deepMergeSnapshot(target, source) {
|
|
1519
|
+
if (isObject(target) && isObject(source)) {
|
|
1520
|
+
const mergedOutput = {
|
|
1521
|
+
...target
|
|
1522
|
+
};
|
|
1523
|
+
Object.keys(source).forEach((key)=>{
|
|
1524
|
+
if (isObject(source[key]) && !source[key].$$typeof) if (key in target) mergedOutput[key] = deepMergeSnapshot(target[key], source[key]);
|
|
1525
|
+
else Object.assign(mergedOutput, {
|
|
1526
|
+
[key]: source[key]
|
|
1527
|
+
});
|
|
1528
|
+
else if (Array.isArray(source[key])) mergedOutput[key] = deepMergeArray(target[key], source[key]);
|
|
1529
|
+
else Object.assign(mergedOutput, {
|
|
1530
|
+
[key]: source[key]
|
|
1531
|
+
});
|
|
1532
|
+
});
|
|
1533
|
+
return mergedOutput;
|
|
1534
|
+
}
|
|
1535
|
+
if (Array.isArray(target) && Array.isArray(source)) return deepMergeArray(target, source);
|
|
1536
|
+
return target;
|
|
1537
|
+
}
|
|
1538
|
+
class DefaultMap extends Map {
|
|
1539
|
+
constructor(defaultFn, entries){
|
|
1540
|
+
super(entries);
|
|
1541
|
+
this.defaultFn = defaultFn;
|
|
1542
|
+
}
|
|
1543
|
+
get(key) {
|
|
1544
|
+
if (!this.has(key)) this.set(key, this.defaultFn(key));
|
|
1545
|
+
return super.get(key);
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
class CounterMap extends DefaultMap {
|
|
1549
|
+
constructor(){
|
|
1550
|
+
super(()=>0);
|
|
1551
|
+
}
|
|
1552
|
+
_total;
|
|
1553
|
+
valueOf() {
|
|
1554
|
+
return this._total = this.total();
|
|
1555
|
+
}
|
|
1556
|
+
increment(key) {
|
|
1557
|
+
if (void 0 !== this._total) this._total++;
|
|
1558
|
+
this.set(key, this.get(key) + 1);
|
|
1559
|
+
}
|
|
1560
|
+
total() {
|
|
1561
|
+
if (void 0 !== this._total) return this._total;
|
|
1562
|
+
let total = 0;
|
|
1563
|
+
for (const x of this.values())total += x;
|
|
1564
|
+
return total;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
function isSameStackPosition(x, y) {
|
|
1568
|
+
return x.file === y.file && x.column === y.column && x.line === y.line;
|
|
1569
|
+
}
|
|
1570
|
+
class SnapshotState {
|
|
1571
|
+
_counters = new CounterMap();
|
|
1572
|
+
_dirty;
|
|
1573
|
+
_updateSnapshot;
|
|
1574
|
+
_snapshotData;
|
|
1575
|
+
_initialData;
|
|
1576
|
+
_inlineSnapshots;
|
|
1577
|
+
_inlineSnapshotStacks;
|
|
1578
|
+
_testIdToKeys = new DefaultMap(()=>[]);
|
|
1579
|
+
_rawSnapshots;
|
|
1580
|
+
_uncheckedKeys;
|
|
1581
|
+
_snapshotFormat;
|
|
1582
|
+
_environment;
|
|
1583
|
+
_fileExists;
|
|
1584
|
+
expand;
|
|
1585
|
+
_added = new CounterMap();
|
|
1586
|
+
_matched = new CounterMap();
|
|
1587
|
+
_unmatched = new CounterMap();
|
|
1588
|
+
_updated = new CounterMap();
|
|
1589
|
+
get added() {
|
|
1590
|
+
return this._added;
|
|
1591
|
+
}
|
|
1592
|
+
set added(value) {
|
|
1593
|
+
this._added._total = value;
|
|
1594
|
+
}
|
|
1595
|
+
get matched() {
|
|
1596
|
+
return this._matched;
|
|
1597
|
+
}
|
|
1598
|
+
set matched(value) {
|
|
1599
|
+
this._matched._total = value;
|
|
1600
|
+
}
|
|
1601
|
+
get unmatched() {
|
|
1602
|
+
return this._unmatched;
|
|
1603
|
+
}
|
|
1604
|
+
set unmatched(value) {
|
|
1605
|
+
this._unmatched._total = value;
|
|
1606
|
+
}
|
|
1607
|
+
get updated() {
|
|
1608
|
+
return this._updated;
|
|
1609
|
+
}
|
|
1610
|
+
set updated(value) {
|
|
1611
|
+
this._updated._total = value;
|
|
1612
|
+
}
|
|
1613
|
+
constructor(testFilePath, snapshotPath, snapshotContent, options){
|
|
1614
|
+
this.testFilePath = testFilePath;
|
|
1615
|
+
this.snapshotPath = snapshotPath;
|
|
1616
|
+
const { data, dirty } = getSnapshotData(snapshotContent, options);
|
|
1617
|
+
this._fileExists = null != snapshotContent;
|
|
1618
|
+
this._initialData = {
|
|
1619
|
+
...data
|
|
1620
|
+
};
|
|
1621
|
+
this._snapshotData = {
|
|
1622
|
+
...data
|
|
1623
|
+
};
|
|
1624
|
+
this._dirty = dirty;
|
|
1625
|
+
this._inlineSnapshots = [];
|
|
1626
|
+
this._inlineSnapshotStacks = [];
|
|
1627
|
+
this._rawSnapshots = [];
|
|
1628
|
+
this._uncheckedKeys = new Set(Object.keys(this._snapshotData));
|
|
1629
|
+
this.expand = options.expand || false;
|
|
1630
|
+
this._updateSnapshot = options.updateSnapshot;
|
|
1631
|
+
this._snapshotFormat = {
|
|
1632
|
+
printBasicPrototype: false,
|
|
1633
|
+
escapeString: false,
|
|
1634
|
+
...options.snapshotFormat
|
|
1635
|
+
};
|
|
1636
|
+
this._environment = options.snapshotEnvironment;
|
|
1637
|
+
}
|
|
1638
|
+
static async create(testFilePath, options) {
|
|
1639
|
+
const snapshotPath = await options.snapshotEnvironment.resolvePath(testFilePath);
|
|
1640
|
+
const content = await options.snapshotEnvironment.readSnapshotFile(snapshotPath);
|
|
1641
|
+
return new SnapshotState(testFilePath, snapshotPath, content, options);
|
|
1642
|
+
}
|
|
1643
|
+
get environment() {
|
|
1644
|
+
return this._environment;
|
|
1645
|
+
}
|
|
1646
|
+
markSnapshotsAsCheckedForTest(testName) {
|
|
1647
|
+
this._uncheckedKeys.forEach((uncheckedKey)=>{
|
|
1648
|
+
if (/ \d+$| > /.test(uncheckedKey.slice(testName.length))) this._uncheckedKeys.delete(uncheckedKey);
|
|
1649
|
+
});
|
|
1650
|
+
}
|
|
1651
|
+
clearTest(testId) {
|
|
1652
|
+
this._inlineSnapshots = this._inlineSnapshots.filter((s)=>s.testId !== testId);
|
|
1653
|
+
this._inlineSnapshotStacks = this._inlineSnapshotStacks.filter((s)=>s.testId !== testId);
|
|
1654
|
+
for (const key of this._testIdToKeys.get(testId)){
|
|
1655
|
+
const name = keyToTestName(key);
|
|
1656
|
+
const count = this._counters.get(name);
|
|
1657
|
+
if (count > 0) {
|
|
1658
|
+
if (key in this._snapshotData || key in this._initialData) this._snapshotData[key] = this._initialData[key];
|
|
1659
|
+
this._counters.set(name, count - 1);
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
this._testIdToKeys.delete(testId);
|
|
1663
|
+
this.added.delete(testId);
|
|
1664
|
+
this.updated.delete(testId);
|
|
1665
|
+
this.matched.delete(testId);
|
|
1666
|
+
this.unmatched.delete(testId);
|
|
1667
|
+
}
|
|
1668
|
+
_inferInlineSnapshotStack(stacks) {
|
|
1669
|
+
const promiseIndex = stacks.findIndex((i)=>i.method.match(/__VITEST_(RESOLVES|REJECTS)__/));
|
|
1670
|
+
if (-1 !== promiseIndex) return stacks[promiseIndex + 3];
|
|
1671
|
+
const stackIndex = stacks.findIndex((i)=>i.method.includes("__INLINE_SNAPSHOT__"));
|
|
1672
|
+
return -1 !== stackIndex ? stacks[stackIndex + 2] : null;
|
|
1673
|
+
}
|
|
1674
|
+
_addSnapshot(key, receivedSerialized, options) {
|
|
1675
|
+
this._dirty = true;
|
|
1676
|
+
if (options.stack) this._inlineSnapshots.push({
|
|
1677
|
+
snapshot: receivedSerialized,
|
|
1678
|
+
testId: options.testId,
|
|
1679
|
+
...options.stack
|
|
1680
|
+
});
|
|
1681
|
+
else if (options.rawSnapshot) this._rawSnapshots.push({
|
|
1682
|
+
...options.rawSnapshot,
|
|
1683
|
+
snapshot: receivedSerialized
|
|
1684
|
+
});
|
|
1685
|
+
else this._snapshotData[key] = receivedSerialized;
|
|
1686
|
+
}
|
|
1687
|
+
async save() {
|
|
1688
|
+
const hasExternalSnapshots = Object.keys(this._snapshotData).length;
|
|
1689
|
+
const hasInlineSnapshots = this._inlineSnapshots.length;
|
|
1690
|
+
const hasRawSnapshots = this._rawSnapshots.length;
|
|
1691
|
+
const isEmpty = !hasExternalSnapshots && !hasInlineSnapshots && !hasRawSnapshots;
|
|
1692
|
+
const status = {
|
|
1693
|
+
deleted: false,
|
|
1694
|
+
saved: false
|
|
1695
|
+
};
|
|
1696
|
+
if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) {
|
|
1697
|
+
if (hasExternalSnapshots) {
|
|
1698
|
+
await saveSnapshotFile(this._environment, this._snapshotData, this.snapshotPath);
|
|
1699
|
+
this._fileExists = true;
|
|
1700
|
+
}
|
|
1701
|
+
if (hasInlineSnapshots) await saveInlineSnapshots(this._environment, this._inlineSnapshots);
|
|
1702
|
+
if (hasRawSnapshots) await saveRawSnapshots(this._environment, this._rawSnapshots);
|
|
1703
|
+
status.saved = true;
|
|
1704
|
+
} else if (!hasExternalSnapshots && this._fileExists) {
|
|
1705
|
+
if ("all" === this._updateSnapshot) {
|
|
1706
|
+
await this._environment.removeSnapshotFile(this.snapshotPath);
|
|
1707
|
+
this._fileExists = false;
|
|
1708
|
+
}
|
|
1709
|
+
status.deleted = true;
|
|
1710
|
+
}
|
|
1711
|
+
return status;
|
|
1712
|
+
}
|
|
1713
|
+
getUncheckedCount() {
|
|
1714
|
+
return this._uncheckedKeys.size || 0;
|
|
1715
|
+
}
|
|
1716
|
+
getUncheckedKeys() {
|
|
1717
|
+
return Array.from(this._uncheckedKeys);
|
|
1718
|
+
}
|
|
1719
|
+
removeUncheckedKeys() {
|
|
1720
|
+
if ("all" === this._updateSnapshot && this._uncheckedKeys.size) {
|
|
1721
|
+
this._dirty = true;
|
|
1722
|
+
this._uncheckedKeys.forEach((key)=>delete this._snapshotData[key]);
|
|
1723
|
+
this._uncheckedKeys.clear();
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
match({ testId, testName, received, key, inlineSnapshot, isInline, error, rawSnapshot }) {
|
|
1727
|
+
this._counters.increment(testName);
|
|
1728
|
+
const count = this._counters.get(testName);
|
|
1729
|
+
if (!key) key = testNameToKey(testName, count);
|
|
1730
|
+
this._testIdToKeys.get(testId).push(key);
|
|
1731
|
+
if (!(isInline && void 0 !== this._snapshotData[key])) this._uncheckedKeys.delete(key);
|
|
1732
|
+
let receivedSerialized = rawSnapshot && "string" == typeof received ? received : serialize(received, void 0, this._snapshotFormat);
|
|
1733
|
+
if (!rawSnapshot) receivedSerialized = addExtraLineBreaks(receivedSerialized);
|
|
1734
|
+
if (rawSnapshot) {
|
|
1735
|
+
if (rawSnapshot.content && rawSnapshot.content.match(/\r\n/) && !receivedSerialized.match(/\r\n/)) rawSnapshot.content = normalizeNewlines(rawSnapshot.content);
|
|
1736
|
+
}
|
|
1737
|
+
const expected = isInline ? inlineSnapshot : rawSnapshot ? rawSnapshot.content : this._snapshotData[key];
|
|
1738
|
+
const expectedTrimmed = rawSnapshot ? expected : null == expected ? void 0 : expected.trim();
|
|
1739
|
+
const pass = expectedTrimmed === (rawSnapshot ? receivedSerialized : receivedSerialized.trim());
|
|
1740
|
+
const hasSnapshot = void 0 !== expected;
|
|
1741
|
+
const snapshotIsPersisted = isInline || this._fileExists || rawSnapshot && null != rawSnapshot.content;
|
|
1742
|
+
if (pass && !isInline && !rawSnapshot) this._snapshotData[key] = receivedSerialized;
|
|
1743
|
+
let stack;
|
|
1744
|
+
if (isInline) {
|
|
1745
|
+
var _this$environment$pro, _this$environment;
|
|
1746
|
+
const stacks = parseErrorStacktrace(error || new Error("snapshot"), {
|
|
1747
|
+
ignoreStackEntries: []
|
|
1748
|
+
});
|
|
1749
|
+
const _stack = this._inferInlineSnapshotStack(stacks);
|
|
1750
|
+
if (!_stack) throw new Error(`@vitest/snapshot: Couldn't infer stack frame for inline snapshot.\n${JSON.stringify(stacks)}`);
|
|
1751
|
+
stack = (null == (_this$environment$pro = (_this$environment = this.environment).processStackTrace) ? void 0 : _this$environment$pro.call(_this$environment, _stack)) || _stack;
|
|
1752
|
+
stack.column--;
|
|
1753
|
+
const snapshotsWithSameStack = this._inlineSnapshotStacks.filter((s)=>isSameStackPosition(s, stack));
|
|
1754
|
+
if (snapshotsWithSameStack.length > 0) {
|
|
1755
|
+
this._inlineSnapshots = this._inlineSnapshots.filter((s)=>!isSameStackPosition(s, stack));
|
|
1756
|
+
const differentSnapshot = snapshotsWithSameStack.find((s)=>s.snapshot !== receivedSerialized);
|
|
1757
|
+
if (differentSnapshot) throw Object.assign(new Error("toMatchInlineSnapshot with different snapshots cannot be called at the same location"), {
|
|
1758
|
+
actual: receivedSerialized,
|
|
1759
|
+
expected: differentSnapshot.snapshot
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
this._inlineSnapshotStacks.push({
|
|
1763
|
+
...stack,
|
|
1764
|
+
testId,
|
|
1765
|
+
snapshot: receivedSerialized
|
|
1766
|
+
});
|
|
1767
|
+
}
|
|
1768
|
+
if ((!hasSnapshot || "all" !== this._updateSnapshot) && (hasSnapshot && snapshotIsPersisted || "new" !== this._updateSnapshot && "all" !== this._updateSnapshot)) if (pass) {
|
|
1769
|
+
this.matched.increment(testId);
|
|
1770
|
+
return {
|
|
1771
|
+
actual: "",
|
|
1772
|
+
count,
|
|
1773
|
+
expected: "",
|
|
1774
|
+
key,
|
|
1775
|
+
pass: true
|
|
1776
|
+
};
|
|
1777
|
+
} else {
|
|
1778
|
+
this.unmatched.increment(testId);
|
|
1779
|
+
return {
|
|
1780
|
+
actual: rawSnapshot ? receivedSerialized : removeExtraLineBreaks(receivedSerialized),
|
|
1781
|
+
count,
|
|
1782
|
+
expected: void 0 !== expectedTrimmed ? rawSnapshot ? expectedTrimmed : removeExtraLineBreaks(expectedTrimmed) : void 0,
|
|
1783
|
+
key,
|
|
1784
|
+
pass: false
|
|
1785
|
+
};
|
|
1786
|
+
}
|
|
1787
|
+
if ("all" === this._updateSnapshot) if (pass) this.matched.increment(testId);
|
|
1788
|
+
else {
|
|
1789
|
+
if (hasSnapshot) this.updated.increment(testId);
|
|
1790
|
+
else this.added.increment(testId);
|
|
1791
|
+
this._addSnapshot(key, receivedSerialized, {
|
|
1792
|
+
stack,
|
|
1793
|
+
testId,
|
|
1794
|
+
rawSnapshot
|
|
1795
|
+
});
|
|
1796
|
+
}
|
|
1797
|
+
else {
|
|
1798
|
+
this._addSnapshot(key, receivedSerialized, {
|
|
1799
|
+
stack,
|
|
1800
|
+
testId,
|
|
1801
|
+
rawSnapshot
|
|
1802
|
+
});
|
|
1803
|
+
this.added.increment(testId);
|
|
1804
|
+
}
|
|
1805
|
+
return {
|
|
1806
|
+
actual: "",
|
|
1807
|
+
count,
|
|
1808
|
+
expected: "",
|
|
1809
|
+
key,
|
|
1810
|
+
pass: true
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
async pack() {
|
|
1814
|
+
const snapshot = {
|
|
1815
|
+
filepath: this.testFilePath,
|
|
1816
|
+
added: 0,
|
|
1817
|
+
fileDeleted: false,
|
|
1818
|
+
matched: 0,
|
|
1819
|
+
unchecked: 0,
|
|
1820
|
+
uncheckedKeys: [],
|
|
1821
|
+
unmatched: 0,
|
|
1822
|
+
updated: 0
|
|
1823
|
+
};
|
|
1824
|
+
const uncheckedCount = this.getUncheckedCount();
|
|
1825
|
+
const uncheckedKeys = this.getUncheckedKeys();
|
|
1826
|
+
if (uncheckedCount) this.removeUncheckedKeys();
|
|
1827
|
+
const status = await this.save();
|
|
1828
|
+
snapshot.fileDeleted = status.deleted;
|
|
1829
|
+
snapshot.added = this.added.total();
|
|
1830
|
+
snapshot.matched = this.matched.total();
|
|
1831
|
+
snapshot.unmatched = this.unmatched.total();
|
|
1832
|
+
snapshot.updated = this.updated.total();
|
|
1833
|
+
snapshot.unchecked = status.deleted ? 0 : uncheckedCount;
|
|
1834
|
+
snapshot.uncheckedKeys = Array.from(uncheckedKeys);
|
|
1835
|
+
return snapshot;
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
function createMismatchError(message, expand, actual, expected) {
|
|
1839
|
+
const error = new Error(message);
|
|
1840
|
+
Object.defineProperty(error, "actual", {
|
|
1841
|
+
value: actual,
|
|
1842
|
+
enumerable: true,
|
|
1843
|
+
configurable: true,
|
|
1844
|
+
writable: true
|
|
1845
|
+
});
|
|
1846
|
+
Object.defineProperty(error, "expected", {
|
|
1847
|
+
value: expected,
|
|
1848
|
+
enumerable: true,
|
|
1849
|
+
configurable: true,
|
|
1850
|
+
writable: true
|
|
1851
|
+
});
|
|
1852
|
+
Object.defineProperty(error, "diffOptions", {
|
|
1853
|
+
value: {
|
|
1854
|
+
expand
|
|
1855
|
+
}
|
|
1856
|
+
});
|
|
1857
|
+
return error;
|
|
1858
|
+
}
|
|
1859
|
+
class SnapshotClient {
|
|
1860
|
+
snapshotStateMap = new Map();
|
|
1861
|
+
constructor(options = {}){
|
|
1862
|
+
this.options = options;
|
|
1863
|
+
}
|
|
1864
|
+
async setup(filepath, options) {
|
|
1865
|
+
if (this.snapshotStateMap.has(filepath)) return;
|
|
1866
|
+
this.snapshotStateMap.set(filepath, await SnapshotState.create(filepath, options));
|
|
1867
|
+
}
|
|
1868
|
+
async finish(filepath) {
|
|
1869
|
+
const state = this.getSnapshotState(filepath);
|
|
1870
|
+
const result = await state.pack();
|
|
1871
|
+
this.snapshotStateMap.delete(filepath);
|
|
1872
|
+
return result;
|
|
1873
|
+
}
|
|
1874
|
+
skipTest(filepath, testName) {
|
|
1875
|
+
const state = this.getSnapshotState(filepath);
|
|
1876
|
+
state.markSnapshotsAsCheckedForTest(testName);
|
|
1877
|
+
}
|
|
1878
|
+
clearTest(filepath, testId) {
|
|
1879
|
+
const state = this.getSnapshotState(filepath);
|
|
1880
|
+
state.clearTest(testId);
|
|
1881
|
+
}
|
|
1882
|
+
getSnapshotState(filepath) {
|
|
1883
|
+
const state = this.snapshotStateMap.get(filepath);
|
|
1884
|
+
if (!state) throw new Error(`The snapshot state for '${filepath}' is not found. Did you call 'SnapshotClient.setup()'?`);
|
|
1885
|
+
return state;
|
|
1886
|
+
}
|
|
1887
|
+
assert(options) {
|
|
1888
|
+
const { filepath, name, testId = name, message, isInline = false, properties, inlineSnapshot, error, errorMessage, rawSnapshot } = options;
|
|
1889
|
+
let { received } = options;
|
|
1890
|
+
if (!filepath) throw new Error("Snapshot cannot be used outside of test");
|
|
1891
|
+
const snapshotState = this.getSnapshotState(filepath);
|
|
1892
|
+
if ("object" == typeof properties) {
|
|
1893
|
+
if ("object" != typeof received || !received) throw new Error("Received value must be an object when the matcher has properties");
|
|
1894
|
+
try {
|
|
1895
|
+
var _this$options$isEqual, _this$options;
|
|
1896
|
+
const pass = (null == (_this$options$isEqual = (_this$options = this.options).isEqual) ? void 0 : _this$options$isEqual.call(_this$options, received, properties)) ?? false;
|
|
1897
|
+
if (pass) received = deepMergeSnapshot(received, properties);
|
|
1898
|
+
else throw createMismatchError("Snapshot properties mismatched", snapshotState.expand, received, properties);
|
|
1899
|
+
} catch (err) {
|
|
1900
|
+
err.message = errorMessage || "Snapshot mismatched";
|
|
1901
|
+
throw err;
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
const testName = [
|
|
1905
|
+
name,
|
|
1906
|
+
...message ? [
|
|
1907
|
+
message
|
|
1908
|
+
] : []
|
|
1909
|
+
].join(" > ");
|
|
1910
|
+
const { actual, expected, key, pass } = snapshotState.match({
|
|
1911
|
+
testId,
|
|
1912
|
+
testName,
|
|
1913
|
+
received,
|
|
1914
|
+
isInline,
|
|
1915
|
+
error,
|
|
1916
|
+
inlineSnapshot,
|
|
1917
|
+
rawSnapshot
|
|
1918
|
+
});
|
|
1919
|
+
if (!pass) throw createMismatchError(`Snapshot \`${key || "unknown"}\` mismatched`, snapshotState.expand, rawSnapshot ? actual : null == actual ? void 0 : actual.trim(), rawSnapshot ? expected : null == expected ? void 0 : expected.trim());
|
|
1920
|
+
}
|
|
1921
|
+
async assertRaw(options) {
|
|
1922
|
+
if (!options.rawSnapshot) throw new Error("Raw snapshot is required");
|
|
1923
|
+
const { filepath, rawSnapshot } = options;
|
|
1924
|
+
if (null == rawSnapshot.content) {
|
|
1925
|
+
if (!filepath) throw new Error("Snapshot cannot be used outside of test");
|
|
1926
|
+
const snapshotState = this.getSnapshotState(filepath);
|
|
1927
|
+
options.filepath || (options.filepath = filepath);
|
|
1928
|
+
rawSnapshot.file = await snapshotState.environment.resolveRawPath(filepath, rawSnapshot.file);
|
|
1929
|
+
rawSnapshot.content = await snapshotState.environment.readSnapshotFile(rawSnapshot.file) ?? void 0;
|
|
1930
|
+
}
|
|
1931
|
+
return this.assert(options);
|
|
1932
|
+
}
|
|
1933
|
+
clear() {
|
|
1934
|
+
this.snapshotStateMap.clear();
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
function recordAsyncExpect(_test, promise, assertion, error) {
|
|
1938
|
+
const test = _test;
|
|
1939
|
+
if (test && promise instanceof Promise) {
|
|
1940
|
+
promise = promise.finally(()=>{
|
|
1941
|
+
if (!test.promises) return;
|
|
1942
|
+
const index = test.promises.indexOf(promise);
|
|
1943
|
+
if (-1 !== index) test.promises.splice(index, 1);
|
|
1944
|
+
});
|
|
1945
|
+
if (!test.promises) test.promises = [];
|
|
1946
|
+
test.promises.push(promise);
|
|
1947
|
+
let resolved = false;
|
|
1948
|
+
test.onFinished ??= [];
|
|
1949
|
+
test.onFinished.push(()=>{
|
|
1950
|
+
if (!resolved) {
|
|
1951
|
+
const processor = globalThis.__vitest_worker__?.onFilterStackTrace || ((s)=>s || '');
|
|
1952
|
+
const stack = processor(error.stack);
|
|
1953
|
+
console.warn([
|
|
1954
|
+
`Promise returned by \`${assertion}\` was not awaited. `,
|
|
1955
|
+
'Rstest currently auto-awaits hanging assertions at the end of the test.',
|
|
1956
|
+
'Please remember to await the assertion.\n',
|
|
1957
|
+
stack
|
|
1958
|
+
].join(''));
|
|
1959
|
+
}
|
|
1960
|
+
});
|
|
1961
|
+
return {
|
|
1962
|
+
then (onFulfilled, onRejected) {
|
|
1963
|
+
resolved = true;
|
|
1964
|
+
return promise.then(onFulfilled, onRejected);
|
|
1965
|
+
},
|
|
1966
|
+
catch (onRejected) {
|
|
1967
|
+
return promise.catch(onRejected);
|
|
1968
|
+
},
|
|
1969
|
+
finally (onFinally) {
|
|
1970
|
+
return promise.finally(onFinally);
|
|
1971
|
+
},
|
|
1972
|
+
[Symbol.toStringTag]: 'Promise'
|
|
1973
|
+
};
|
|
1974
|
+
}
|
|
1975
|
+
return promise;
|
|
1976
|
+
}
|
|
1977
|
+
function createAssertionMessage(util, assertion, hasArgs) {
|
|
1978
|
+
const not = util.flag(assertion, 'negate') ? 'not.' : '';
|
|
1979
|
+
const name = `${util.flag(assertion, '_name')}(${hasArgs ? 'expected' : ''})`;
|
|
1980
|
+
const promiseName = util.flag(assertion, 'promise');
|
|
1981
|
+
const promise = promiseName ? `.${promiseName}` : '';
|
|
1982
|
+
return `expect(actual)${promise}.${not}${name}`;
|
|
1983
|
+
}
|
|
1984
|
+
function getError(expected, promise) {
|
|
1985
|
+
if ('function' != typeof expected) {
|
|
1986
|
+
if (!promise) throw new Error(`expected must be a function, received ${typeof expected}`);
|
|
1987
|
+
return expected;
|
|
1988
|
+
}
|
|
1989
|
+
try {
|
|
1990
|
+
expected();
|
|
1991
|
+
} catch (e) {
|
|
1992
|
+
return e;
|
|
1993
|
+
}
|
|
1994
|
+
throw new Error("snapshot function didn't throw");
|
|
1995
|
+
}
|
|
1996
|
+
function getTestMeta(test) {
|
|
1997
|
+
return {
|
|
1998
|
+
filepath: test.testPath,
|
|
1999
|
+
name: getTaskNameWithPrefix(test),
|
|
2000
|
+
testId: test.testId
|
|
2001
|
+
};
|
|
2002
|
+
}
|
|
2003
|
+
const SnapshotPlugin = (workerState)=>{
|
|
2004
|
+
let _client;
|
|
2005
|
+
if (!workerState.snapshotClient) workerState.snapshotClient = new SnapshotClient({
|
|
2006
|
+
isEqual: (received, expected)=>dist_equals(received, expected, [
|
|
2007
|
+
iterableEquality,
|
|
2008
|
+
subsetEquality
|
|
2009
|
+
])
|
|
2010
|
+
});
|
|
2011
|
+
_client = workerState.snapshotClient;
|
|
2012
|
+
function getSnapshotClient() {
|
|
2013
|
+
return _client;
|
|
2014
|
+
}
|
|
2015
|
+
return (chai, utils)=>{
|
|
2016
|
+
function getTest(obj) {
|
|
2017
|
+
const test = utils.flag(obj, 'vitest-test');
|
|
2018
|
+
return test;
|
|
2019
|
+
}
|
|
2020
|
+
function getTestOrThrow(assertionName, obj) {
|
|
2021
|
+
const test = getTest(obj);
|
|
2022
|
+
if (!test) throw new Error(`'${assertionName}' cannot be used without test context`);
|
|
2023
|
+
return test;
|
|
2024
|
+
}
|
|
2025
|
+
for (const key of [
|
|
2026
|
+
'matchSnapshot',
|
|
2027
|
+
'toMatchSnapshot'
|
|
2028
|
+
])utils.addMethod(chai.Assertion.prototype, key, function(properties, message) {
|
|
2029
|
+
utils.flag(this, '_name', key);
|
|
2030
|
+
const isNot = utils.flag(this, 'negate');
|
|
2031
|
+
if (isNot) throw new Error(`${key} cannot be used with "not"`);
|
|
2032
|
+
const expected = utils.flag(this, 'object');
|
|
2033
|
+
const test = getTestOrThrow(key, this);
|
|
2034
|
+
if ('string' == typeof properties && void 0 === message) {
|
|
2035
|
+
message = properties;
|
|
2036
|
+
properties = void 0;
|
|
2037
|
+
}
|
|
2038
|
+
const errorMessage = utils.flag(this, 'message');
|
|
2039
|
+
getSnapshotClient().assert({
|
|
2040
|
+
received: expected,
|
|
2041
|
+
message,
|
|
2042
|
+
isInline: false,
|
|
2043
|
+
properties,
|
|
2044
|
+
errorMessage,
|
|
2045
|
+
...getTestMeta(test)
|
|
2046
|
+
});
|
|
2047
|
+
});
|
|
2048
|
+
utils.addMethod(chai.Assertion.prototype, 'toMatchFileSnapshot', function(file, message) {
|
|
2049
|
+
utils.flag(this, '_name', 'toMatchFileSnapshot');
|
|
2050
|
+
const isNot = utils.flag(this, 'negate');
|
|
2051
|
+
if (isNot) throw new Error('toMatchFileSnapshot cannot be used with "not"');
|
|
2052
|
+
const error = new Error('resolves');
|
|
2053
|
+
const expected = utils.flag(this, 'object');
|
|
2054
|
+
const test = getTestOrThrow('toMatchFileSnapshot', this);
|
|
2055
|
+
const errorMessage = utils.flag(this, 'message');
|
|
2056
|
+
const promise = getSnapshotClient().assertRaw({
|
|
2057
|
+
received: expected,
|
|
2058
|
+
message,
|
|
2059
|
+
isInline: false,
|
|
2060
|
+
rawSnapshot: {
|
|
2061
|
+
file
|
|
2062
|
+
},
|
|
2063
|
+
errorMessage,
|
|
2064
|
+
...getTestMeta(test)
|
|
2065
|
+
});
|
|
2066
|
+
return recordAsyncExpect(test, promise, createAssertionMessage(utils, this, true), error);
|
|
2067
|
+
});
|
|
2068
|
+
utils.addMethod(chai.Assertion.prototype, 'toMatchInlineSnapshot', function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
|
|
2069
|
+
utils.flag(this, '_name', 'toMatchInlineSnapshot');
|
|
2070
|
+
const isNot = utils.flag(this, 'negate');
|
|
2071
|
+
if (isNot) throw new Error('toMatchInlineSnapshot cannot be used with "not"');
|
|
2072
|
+
const test = getTest(this);
|
|
2073
|
+
const expected = utils.flag(this, 'object');
|
|
2074
|
+
const error = utils.flag(this, 'error');
|
|
2075
|
+
if ('string' == typeof properties) {
|
|
2076
|
+
message = inlineSnapshot;
|
|
2077
|
+
inlineSnapshot = properties;
|
|
2078
|
+
properties = void 0;
|
|
2079
|
+
}
|
|
2080
|
+
if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
|
|
2081
|
+
const errorMessage = utils.flag(this, 'message');
|
|
2082
|
+
getSnapshotClient().assert({
|
|
2083
|
+
received: expected,
|
|
2084
|
+
message,
|
|
2085
|
+
isInline: true,
|
|
2086
|
+
properties,
|
|
2087
|
+
inlineSnapshot,
|
|
2088
|
+
error,
|
|
2089
|
+
errorMessage,
|
|
2090
|
+
...test ? getTestMeta(test) : {
|
|
2091
|
+
filepath: workerState.testPath,
|
|
2092
|
+
name: 'toMatchInlineSnapshot',
|
|
2093
|
+
testId: String(workerState.taskId)
|
|
2094
|
+
}
|
|
2095
|
+
});
|
|
2096
|
+
});
|
|
2097
|
+
utils.addMethod(chai.Assertion.prototype, 'toThrowErrorMatchingSnapshot', function(message) {
|
|
2098
|
+
utils.flag(this, '_name', 'toThrowErrorMatchingSnapshot');
|
|
2099
|
+
const isNot = utils.flag(this, 'negate');
|
|
2100
|
+
if (isNot) throw new Error('toThrowErrorMatchingSnapshot cannot be used with "not"');
|
|
2101
|
+
const expected = utils.flag(this, 'object');
|
|
2102
|
+
const test = getTestOrThrow('toThrowErrorMatchingSnapshot', this);
|
|
2103
|
+
const promise = utils.flag(this, 'promise');
|
|
2104
|
+
const errorMessage = utils.flag(this, 'message');
|
|
2105
|
+
getSnapshotClient().assert({
|
|
2106
|
+
received: getError(expected, promise),
|
|
2107
|
+
message,
|
|
2108
|
+
errorMessage,
|
|
2109
|
+
...getTestMeta(test)
|
|
2110
|
+
});
|
|
2111
|
+
});
|
|
2112
|
+
utils.addMethod(chai.Assertion.prototype, 'toThrowErrorMatchingInlineSnapshot', function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
|
|
2113
|
+
const isNot = utils.flag(this, 'negate');
|
|
2114
|
+
if (isNot) throw new Error('toThrowErrorMatchingInlineSnapshot cannot be used with "not"');
|
|
2115
|
+
const test = getTest(this);
|
|
2116
|
+
const expected = utils.flag(this, 'object');
|
|
2117
|
+
const error = utils.flag(this, 'error');
|
|
2118
|
+
const promise = utils.flag(this, 'promise');
|
|
2119
|
+
const errorMessage = utils.flag(this, 'message');
|
|
2120
|
+
if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
|
|
2121
|
+
getSnapshotClient().assert({
|
|
2122
|
+
received: getError(expected, promise),
|
|
2123
|
+
message,
|
|
2124
|
+
inlineSnapshot,
|
|
2125
|
+
isInline: true,
|
|
2126
|
+
error,
|
|
2127
|
+
errorMessage,
|
|
2128
|
+
...test ? getTestMeta(test) : {
|
|
2129
|
+
name: 'toThrowErrorMatchingInlineSnapshot',
|
|
2130
|
+
filepath: workerState.testPath,
|
|
2131
|
+
testId: String(workerState.taskId)
|
|
2132
|
+
}
|
|
2133
|
+
});
|
|
2134
|
+
});
|
|
2135
|
+
utils.addMethod(chai.expect, 'addSnapshotSerializer', addSerializer);
|
|
2136
|
+
};
|
|
2137
|
+
};
|
|
2138
|
+
export { snapshot_namespaceObject };
|