@vitest/snapshot 0.33.0 → 0.34.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.
Files changed (2) hide show
  1. package/dist/index.js +641 -160
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -134,166 +134,7 @@ try {
134
134
  nodeInspect = false;
135
135
  }
136
136
 
137
- function normalizeWindowsPath(input = "") {
138
- if (!input || !input.includes("\\")) {
139
- return input;
140
- }
141
- return input.replace(/\\/g, "/");
142
- }
143
- const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
144
- function cwd() {
145
- if (typeof process !== "undefined") {
146
- return process.cwd().replace(/\\/g, "/");
147
- }
148
- return "/";
149
- }
150
- const resolve = function(...arguments_) {
151
- arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
152
- let resolvedPath = "";
153
- let resolvedAbsolute = false;
154
- for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
155
- const path = index >= 0 ? arguments_[index] : cwd();
156
- if (!path || path.length === 0) {
157
- continue;
158
- }
159
- resolvedPath = `${path}/${resolvedPath}`;
160
- resolvedAbsolute = isAbsolute(path);
161
- }
162
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
163
- if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
164
- return `/${resolvedPath}`;
165
- }
166
- return resolvedPath.length > 0 ? resolvedPath : ".";
167
- };
168
- function normalizeString(path, allowAboveRoot) {
169
- let res = "";
170
- let lastSegmentLength = 0;
171
- let lastSlash = -1;
172
- let dots = 0;
173
- let char = null;
174
- for (let index = 0; index <= path.length; ++index) {
175
- if (index < path.length) {
176
- char = path[index];
177
- } else if (char === "/") {
178
- break;
179
- } else {
180
- char = "/";
181
- }
182
- if (char === "/") {
183
- if (lastSlash === index - 1 || dots === 1)
184
- ;
185
- else if (dots === 2) {
186
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
187
- if (res.length > 2) {
188
- const lastSlashIndex = res.lastIndexOf("/");
189
- if (lastSlashIndex === -1) {
190
- res = "";
191
- lastSegmentLength = 0;
192
- } else {
193
- res = res.slice(0, lastSlashIndex);
194
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
195
- }
196
- lastSlash = index;
197
- dots = 0;
198
- continue;
199
- } else if (res.length > 0) {
200
- res = "";
201
- lastSegmentLength = 0;
202
- lastSlash = index;
203
- dots = 0;
204
- continue;
205
- }
206
- }
207
- if (allowAboveRoot) {
208
- res += res.length > 0 ? "/.." : "..";
209
- lastSegmentLength = 2;
210
- }
211
- } else {
212
- if (res.length > 0) {
213
- res += `/${path.slice(lastSlash + 1, index)}`;
214
- } else {
215
- res = path.slice(lastSlash + 1, index);
216
- }
217
- lastSegmentLength = index - lastSlash - 1;
218
- }
219
- lastSlash = index;
220
- dots = 0;
221
- } else if (char === "." && dots !== -1) {
222
- ++dots;
223
- } else {
224
- dots = -1;
225
- }
226
- }
227
- return res;
228
- }
229
- const isAbsolute = function(p) {
230
- return _IS_ABSOLUTE_RE.test(p);
231
- };
232
137
  const lineSplitRE = /\r?\n/;
233
- const stackIgnorePatterns = [
234
- "node:internal",
235
- /\/packages\/\w+\/dist\//,
236
- /\/@vitest\/\w+\/dist\//,
237
- "/vitest/dist/",
238
- "/vitest/src/",
239
- "/vite-node/dist/",
240
- "/vite-node/src/",
241
- "/node_modules/chai/",
242
- "/node_modules/tinypool/",
243
- "/node_modules/tinyspy/"
244
- ];
245
- function extractLocation(urlLike) {
246
- if (!urlLike.includes(":"))
247
- return [urlLike];
248
- const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
249
- const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, ""));
250
- if (!parts)
251
- return [urlLike];
252
- return [parts[1], parts[2] || void 0, parts[3] || void 0];
253
- }
254
- function parseSingleStack(raw) {
255
- let line = raw.trim();
256
- if (line.includes("(eval "))
257
- line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
258
- let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
259
- const location = sanitizedLine.match(/ (\(.+\)$)/);
260
- sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
261
- const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
262
- let method = location && sanitizedLine || "";
263
- let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
264
- if (!file || !lineNumber || !columnNumber)
265
- return null;
266
- if (method.startsWith("async "))
267
- method = method.slice(6);
268
- if (file.startsWith("file://"))
269
- file = file.slice(7);
270
- file = resolve(file);
271
- return {
272
- method,
273
- file,
274
- line: Number.parseInt(lineNumber),
275
- column: Number.parseInt(columnNumber)
276
- };
277
- }
278
- function parseStacktrace(stack, ignore = stackIgnorePatterns) {
279
- const stackFrames = stack.split("\n").map((raw) => {
280
- const stack2 = parseSingleStack(raw);
281
- if (!stack2 || ignore.length && ignore.some((p) => stack2.file.match(p)))
282
- return null;
283
- return stack2;
284
- }).filter(notNullish);
285
- return stackFrames;
286
- }
287
- function parseErrorStacktrace(e, ignore = stackIgnorePatterns) {
288
- if (!e || isPrimitive(e))
289
- return [];
290
- if (e.stacks)
291
- return e.stacks;
292
- const stackStr = e.stack || e.stackStr || "";
293
- const stackFrames = parseStacktrace(stackStr, ignore);
294
- e.stacks = stackFrames;
295
- return stackFrames;
296
- }
297
138
  function positionToOffset(source, lineNumber, columnNumber) {
298
139
  const lines = source.split(lineSplitRE);
299
140
  const nl = /\r\n/.test(source) ? 2 : 1;
@@ -493,6 +334,646 @@ function deepMergeSnapshot(target, source) {
493
334
  return target;
494
335
  }
495
336
 
337
+ function normalizeWindowsPath(input = "") {
338
+ if (!input || !input.includes("\\")) {
339
+ return input;
340
+ }
341
+ return input.replace(/\\/g, "/");
342
+ }
343
+ const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
344
+ function cwd() {
345
+ if (typeof process !== "undefined") {
346
+ return process.cwd().replace(/\\/g, "/");
347
+ }
348
+ return "/";
349
+ }
350
+ const resolve$2 = function(...arguments_) {
351
+ arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
352
+ let resolvedPath = "";
353
+ let resolvedAbsolute = false;
354
+ for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
355
+ const path = index >= 0 ? arguments_[index] : cwd();
356
+ if (!path || path.length === 0) {
357
+ continue;
358
+ }
359
+ resolvedPath = `${path}/${resolvedPath}`;
360
+ resolvedAbsolute = isAbsolute(path);
361
+ }
362
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
363
+ if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
364
+ return `/${resolvedPath}`;
365
+ }
366
+ return resolvedPath.length > 0 ? resolvedPath : ".";
367
+ };
368
+ function normalizeString(path, allowAboveRoot) {
369
+ let res = "";
370
+ let lastSegmentLength = 0;
371
+ let lastSlash = -1;
372
+ let dots = 0;
373
+ let char = null;
374
+ for (let index = 0; index <= path.length; ++index) {
375
+ if (index < path.length) {
376
+ char = path[index];
377
+ } else if (char === "/") {
378
+ break;
379
+ } else {
380
+ char = "/";
381
+ }
382
+ if (char === "/") {
383
+ if (lastSlash === index - 1 || dots === 1)
384
+ ;
385
+ else if (dots === 2) {
386
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
387
+ if (res.length > 2) {
388
+ const lastSlashIndex = res.lastIndexOf("/");
389
+ if (lastSlashIndex === -1) {
390
+ res = "";
391
+ lastSegmentLength = 0;
392
+ } else {
393
+ res = res.slice(0, lastSlashIndex);
394
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
395
+ }
396
+ lastSlash = index;
397
+ dots = 0;
398
+ continue;
399
+ } else if (res.length > 0) {
400
+ res = "";
401
+ lastSegmentLength = 0;
402
+ lastSlash = index;
403
+ dots = 0;
404
+ continue;
405
+ }
406
+ }
407
+ if (allowAboveRoot) {
408
+ res += res.length > 0 ? "/.." : "..";
409
+ lastSegmentLength = 2;
410
+ }
411
+ } else {
412
+ if (res.length > 0) {
413
+ res += `/${path.slice(lastSlash + 1, index)}`;
414
+ } else {
415
+ res = path.slice(lastSlash + 1, index);
416
+ }
417
+ lastSegmentLength = index - lastSlash - 1;
418
+ }
419
+ lastSlash = index;
420
+ dots = 0;
421
+ } else if (char === "." && dots !== -1) {
422
+ ++dots;
423
+ } else {
424
+ dots = -1;
425
+ }
426
+ }
427
+ return res;
428
+ }
429
+ const isAbsolute = function(p) {
430
+ return _IS_ABSOLUTE_RE.test(p);
431
+ };
432
+ const comma = ",".charCodeAt(0);
433
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
434
+ const intToChar = new Uint8Array(64);
435
+ const charToInt = new Uint8Array(128);
436
+ for (let i = 0; i < chars.length; i++) {
437
+ const c = chars.charCodeAt(i);
438
+ intToChar[i] = c;
439
+ charToInt[c] = i;
440
+ }
441
+ function decode(mappings) {
442
+ const state = new Int32Array(5);
443
+ const decoded = [];
444
+ let index = 0;
445
+ do {
446
+ const semi = indexOf(mappings, index);
447
+ const line = [];
448
+ let sorted = true;
449
+ let lastCol = 0;
450
+ state[0] = 0;
451
+ for (let i = index; i < semi; i++) {
452
+ let seg;
453
+ i = decodeInteger(mappings, i, state, 0);
454
+ const col = state[0];
455
+ if (col < lastCol)
456
+ sorted = false;
457
+ lastCol = col;
458
+ if (hasMoreVlq(mappings, i, semi)) {
459
+ i = decodeInteger(mappings, i, state, 1);
460
+ i = decodeInteger(mappings, i, state, 2);
461
+ i = decodeInteger(mappings, i, state, 3);
462
+ if (hasMoreVlq(mappings, i, semi)) {
463
+ i = decodeInteger(mappings, i, state, 4);
464
+ seg = [col, state[1], state[2], state[3], state[4]];
465
+ } else {
466
+ seg = [col, state[1], state[2], state[3]];
467
+ }
468
+ } else {
469
+ seg = [col];
470
+ }
471
+ line.push(seg);
472
+ }
473
+ if (!sorted)
474
+ sort(line);
475
+ decoded.push(line);
476
+ index = semi + 1;
477
+ } while (index <= mappings.length);
478
+ return decoded;
479
+ }
480
+ function indexOf(mappings, index) {
481
+ const idx = mappings.indexOf(";", index);
482
+ return idx === -1 ? mappings.length : idx;
483
+ }
484
+ function decodeInteger(mappings, pos, state, j) {
485
+ let value = 0;
486
+ let shift = 0;
487
+ let integer = 0;
488
+ do {
489
+ const c = mappings.charCodeAt(pos++);
490
+ integer = charToInt[c];
491
+ value |= (integer & 31) << shift;
492
+ shift += 5;
493
+ } while (integer & 32);
494
+ const shouldNegate = value & 1;
495
+ value >>>= 1;
496
+ if (shouldNegate) {
497
+ value = -2147483648 | -value;
498
+ }
499
+ state[j] += value;
500
+ return pos;
501
+ }
502
+ function hasMoreVlq(mappings, i, length) {
503
+ if (i >= length)
504
+ return false;
505
+ return mappings.charCodeAt(i) !== comma;
506
+ }
507
+ function sort(line) {
508
+ line.sort(sortComparator$1);
509
+ }
510
+ function sortComparator$1(a, b) {
511
+ return a[0] - b[0];
512
+ }
513
+ const schemeRegex = /^[\w+.-]+:\/\//;
514
+ const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
515
+ const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
516
+ var UrlType;
517
+ (function(UrlType2) {
518
+ UrlType2[UrlType2["Empty"] = 1] = "Empty";
519
+ UrlType2[UrlType2["Hash"] = 2] = "Hash";
520
+ UrlType2[UrlType2["Query"] = 3] = "Query";
521
+ UrlType2[UrlType2["RelativePath"] = 4] = "RelativePath";
522
+ UrlType2[UrlType2["AbsolutePath"] = 5] = "AbsolutePath";
523
+ UrlType2[UrlType2["SchemeRelative"] = 6] = "SchemeRelative";
524
+ UrlType2[UrlType2["Absolute"] = 7] = "Absolute";
525
+ })(UrlType || (UrlType = {}));
526
+ function isAbsoluteUrl(input) {
527
+ return schemeRegex.test(input);
528
+ }
529
+ function isSchemeRelativeUrl(input) {
530
+ return input.startsWith("//");
531
+ }
532
+ function isAbsolutePath(input) {
533
+ return input.startsWith("/");
534
+ }
535
+ function isFileUrl(input) {
536
+ return input.startsWith("file:");
537
+ }
538
+ function isRelative(input) {
539
+ return /^[.?#]/.test(input);
540
+ }
541
+ function parseAbsoluteUrl(input) {
542
+ const match = urlRegex.exec(input);
543
+ return makeUrl(match[1], match[2] || "", match[3], match[4] || "", match[5] || "/", match[6] || "", match[7] || "");
544
+ }
545
+ function parseFileUrl(input) {
546
+ const match = fileRegex.exec(input);
547
+ const path = match[2];
548
+ return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(path) ? path : "/" + path, match[3] || "", match[4] || "");
549
+ }
550
+ function makeUrl(scheme, user, host, port, path, query, hash) {
551
+ return {
552
+ scheme,
553
+ user,
554
+ host,
555
+ port,
556
+ path,
557
+ query,
558
+ hash,
559
+ type: UrlType.Absolute
560
+ };
561
+ }
562
+ function parseUrl(input) {
563
+ if (isSchemeRelativeUrl(input)) {
564
+ const url2 = parseAbsoluteUrl("http:" + input);
565
+ url2.scheme = "";
566
+ url2.type = UrlType.SchemeRelative;
567
+ return url2;
568
+ }
569
+ if (isAbsolutePath(input)) {
570
+ const url2 = parseAbsoluteUrl("http://foo.com" + input);
571
+ url2.scheme = "";
572
+ url2.host = "";
573
+ url2.type = UrlType.AbsolutePath;
574
+ return url2;
575
+ }
576
+ if (isFileUrl(input))
577
+ return parseFileUrl(input);
578
+ if (isAbsoluteUrl(input))
579
+ return parseAbsoluteUrl(input);
580
+ const url = parseAbsoluteUrl("http://foo.com/" + input);
581
+ url.scheme = "";
582
+ url.host = "";
583
+ url.type = input ? input.startsWith("?") ? UrlType.Query : input.startsWith("#") ? UrlType.Hash : UrlType.RelativePath : UrlType.Empty;
584
+ return url;
585
+ }
586
+ function stripPathFilename(path) {
587
+ if (path.endsWith("/.."))
588
+ return path;
589
+ const index = path.lastIndexOf("/");
590
+ return path.slice(0, index + 1);
591
+ }
592
+ function mergePaths(url, base) {
593
+ normalizePath(base, base.type);
594
+ if (url.path === "/") {
595
+ url.path = base.path;
596
+ } else {
597
+ url.path = stripPathFilename(base.path) + url.path;
598
+ }
599
+ }
600
+ function normalizePath(url, type) {
601
+ const rel = type <= UrlType.RelativePath;
602
+ const pieces = url.path.split("/");
603
+ let pointer = 1;
604
+ let positive = 0;
605
+ let addTrailingSlash = false;
606
+ for (let i = 1; i < pieces.length; i++) {
607
+ const piece = pieces[i];
608
+ if (!piece) {
609
+ addTrailingSlash = true;
610
+ continue;
611
+ }
612
+ addTrailingSlash = false;
613
+ if (piece === ".")
614
+ continue;
615
+ if (piece === "..") {
616
+ if (positive) {
617
+ addTrailingSlash = true;
618
+ positive--;
619
+ pointer--;
620
+ } else if (rel) {
621
+ pieces[pointer++] = piece;
622
+ }
623
+ continue;
624
+ }
625
+ pieces[pointer++] = piece;
626
+ positive++;
627
+ }
628
+ let path = "";
629
+ for (let i = 1; i < pointer; i++) {
630
+ path += "/" + pieces[i];
631
+ }
632
+ if (!path || addTrailingSlash && !path.endsWith("/..")) {
633
+ path += "/";
634
+ }
635
+ url.path = path;
636
+ }
637
+ function resolve$1(input, base) {
638
+ if (!input && !base)
639
+ return "";
640
+ const url = parseUrl(input);
641
+ let inputType = url.type;
642
+ if (base && inputType !== UrlType.Absolute) {
643
+ const baseUrl = parseUrl(base);
644
+ const baseType = baseUrl.type;
645
+ switch (inputType) {
646
+ case UrlType.Empty:
647
+ url.hash = baseUrl.hash;
648
+ case UrlType.Hash:
649
+ url.query = baseUrl.query;
650
+ case UrlType.Query:
651
+ case UrlType.RelativePath:
652
+ mergePaths(url, baseUrl);
653
+ case UrlType.AbsolutePath:
654
+ url.user = baseUrl.user;
655
+ url.host = baseUrl.host;
656
+ url.port = baseUrl.port;
657
+ case UrlType.SchemeRelative:
658
+ url.scheme = baseUrl.scheme;
659
+ }
660
+ if (baseType > inputType)
661
+ inputType = baseType;
662
+ }
663
+ normalizePath(url, inputType);
664
+ const queryHash = url.query + url.hash;
665
+ switch (inputType) {
666
+ case UrlType.Hash:
667
+ case UrlType.Query:
668
+ return queryHash;
669
+ case UrlType.RelativePath: {
670
+ const path = url.path.slice(1);
671
+ if (!path)
672
+ return queryHash || ".";
673
+ if (isRelative(base || input) && !isRelative(path)) {
674
+ return "./" + path + queryHash;
675
+ }
676
+ return path + queryHash;
677
+ }
678
+ case UrlType.AbsolutePath:
679
+ return url.path + queryHash;
680
+ default:
681
+ return url.scheme + "//" + url.user + url.host + url.port + url.path + queryHash;
682
+ }
683
+ }
684
+ function resolve(input, base) {
685
+ if (base && !base.endsWith("/"))
686
+ base += "/";
687
+ return resolve$1(input, base);
688
+ }
689
+ function stripFilename(path) {
690
+ if (!path)
691
+ return "";
692
+ const index = path.lastIndexOf("/");
693
+ return path.slice(0, index + 1);
694
+ }
695
+ const COLUMN = 0;
696
+ const SOURCES_INDEX = 1;
697
+ const SOURCE_LINE = 2;
698
+ const SOURCE_COLUMN = 3;
699
+ const NAMES_INDEX = 4;
700
+ function maybeSort(mappings, owned) {
701
+ const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
702
+ if (unsortedIndex === mappings.length)
703
+ return mappings;
704
+ if (!owned)
705
+ mappings = mappings.slice();
706
+ for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
707
+ mappings[i] = sortSegments(mappings[i], owned);
708
+ }
709
+ return mappings;
710
+ }
711
+ function nextUnsortedSegmentLine(mappings, start) {
712
+ for (let i = start; i < mappings.length; i++) {
713
+ if (!isSorted(mappings[i]))
714
+ return i;
715
+ }
716
+ return mappings.length;
717
+ }
718
+ function isSorted(line) {
719
+ for (let j = 1; j < line.length; j++) {
720
+ if (line[j][COLUMN] < line[j - 1][COLUMN]) {
721
+ return false;
722
+ }
723
+ }
724
+ return true;
725
+ }
726
+ function sortSegments(line, owned) {
727
+ if (!owned)
728
+ line = line.slice();
729
+ return line.sort(sortComparator);
730
+ }
731
+ function sortComparator(a, b) {
732
+ return a[COLUMN] - b[COLUMN];
733
+ }
734
+ let found = false;
735
+ function binarySearch(haystack, needle, low, high) {
736
+ while (low <= high) {
737
+ const mid = low + (high - low >> 1);
738
+ const cmp = haystack[mid][COLUMN] - needle;
739
+ if (cmp === 0) {
740
+ found = true;
741
+ return mid;
742
+ }
743
+ if (cmp < 0) {
744
+ low = mid + 1;
745
+ } else {
746
+ high = mid - 1;
747
+ }
748
+ }
749
+ found = false;
750
+ return low - 1;
751
+ }
752
+ function upperBound(haystack, needle, index) {
753
+ for (let i = index + 1; i < haystack.length; index = i++) {
754
+ if (haystack[i][COLUMN] !== needle)
755
+ break;
756
+ }
757
+ return index;
758
+ }
759
+ function lowerBound(haystack, needle, index) {
760
+ for (let i = index - 1; i >= 0; index = i--) {
761
+ if (haystack[i][COLUMN] !== needle)
762
+ break;
763
+ }
764
+ return index;
765
+ }
766
+ function memoizedState() {
767
+ return {
768
+ lastKey: -1,
769
+ lastNeedle: -1,
770
+ lastIndex: -1
771
+ };
772
+ }
773
+ function memoizedBinarySearch(haystack, needle, state, key) {
774
+ const { lastKey, lastNeedle, lastIndex } = state;
775
+ let low = 0;
776
+ let high = haystack.length - 1;
777
+ if (key === lastKey) {
778
+ if (needle === lastNeedle) {
779
+ found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
780
+ return lastIndex;
781
+ }
782
+ if (needle >= lastNeedle) {
783
+ low = lastIndex === -1 ? 0 : lastIndex;
784
+ } else {
785
+ high = lastIndex;
786
+ }
787
+ }
788
+ state.lastKey = key;
789
+ state.lastNeedle = needle;
790
+ return state.lastIndex = binarySearch(haystack, needle, low, high);
791
+ }
792
+ const LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
793
+ const COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
794
+ const LEAST_UPPER_BOUND = -1;
795
+ const GREATEST_LOWER_BOUND = 1;
796
+ let decodedMappings;
797
+ let originalPositionFor;
798
+ class TraceMap {
799
+ constructor(map, mapUrl) {
800
+ const isString = typeof map === "string";
801
+ if (!isString && map._decodedMemo)
802
+ return map;
803
+ const parsed = isString ? JSON.parse(map) : map;
804
+ const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
805
+ this.version = version;
806
+ this.file = file;
807
+ this.names = names;
808
+ this.sourceRoot = sourceRoot;
809
+ this.sources = sources;
810
+ this.sourcesContent = sourcesContent;
811
+ const from = resolve(sourceRoot || "", stripFilename(mapUrl));
812
+ this.resolvedSources = sources.map((s) => resolve(s || "", from));
813
+ const { mappings } = parsed;
814
+ if (typeof mappings === "string") {
815
+ this._encoded = mappings;
816
+ this._decoded = void 0;
817
+ } else {
818
+ this._encoded = void 0;
819
+ this._decoded = maybeSort(mappings, isString);
820
+ }
821
+ this._decodedMemo = memoizedState();
822
+ this._bySources = void 0;
823
+ this._bySourceMemos = void 0;
824
+ }
825
+ }
826
+ (() => {
827
+ decodedMappings = (map) => {
828
+ return map._decoded || (map._decoded = decode(map._encoded));
829
+ };
830
+ originalPositionFor = (map, { line, column, bias }) => {
831
+ line--;
832
+ if (line < 0)
833
+ throw new Error(LINE_GTR_ZERO);
834
+ if (column < 0)
835
+ throw new Error(COL_GTR_EQ_ZERO);
836
+ const decoded = decodedMappings(map);
837
+ if (line >= decoded.length)
838
+ return OMapping(null, null, null, null);
839
+ const segments = decoded[line];
840
+ const index = traceSegmentInternal(segments, map._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
841
+ if (index === -1)
842
+ return OMapping(null, null, null, null);
843
+ const segment = segments[index];
844
+ if (segment.length === 1)
845
+ return OMapping(null, null, null, null);
846
+ const { names, resolvedSources } = map;
847
+ return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
848
+ };
849
+ })();
850
+ function OMapping(source, line, column, name) {
851
+ return { source, line, column, name };
852
+ }
853
+ function traceSegmentInternal(segments, memo, line, column, bias) {
854
+ let index = memoizedBinarySearch(segments, column, memo, line);
855
+ if (found) {
856
+ index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
857
+ } else if (bias === LEAST_UPPER_BOUND)
858
+ index++;
859
+ if (index === -1 || index === segments.length)
860
+ return -1;
861
+ return index;
862
+ }
863
+ const CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m;
864
+ const SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code])?$/;
865
+ const stackIgnorePatterns = [
866
+ "node:internal",
867
+ /\/packages\/\w+\/dist\//,
868
+ /\/@vitest\/\w+\/dist\//,
869
+ "/vitest/dist/",
870
+ "/vitest/src/",
871
+ "/vite-node/dist/",
872
+ "/vite-node/src/",
873
+ "/node_modules/chai/",
874
+ "/node_modules/tinypool/",
875
+ "/node_modules/tinyspy/",
876
+ "/deps/chai.js",
877
+ /__vitest_browser__/
878
+ ];
879
+ function extractLocation(urlLike) {
880
+ if (!urlLike.includes(":"))
881
+ return [urlLike];
882
+ const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
883
+ const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, ""));
884
+ if (!parts)
885
+ return [urlLike];
886
+ let url = parts[1];
887
+ if (url.startsWith("http:") || url.startsWith("https:")) {
888
+ const urlObj = new URL(url);
889
+ url = urlObj.pathname;
890
+ }
891
+ if (url.startsWith("/@fs/")) {
892
+ url = url.slice(typeof process !== "undefined" && process.platform === "win32" ? 5 : 4);
893
+ }
894
+ return [url, parts[2] || void 0, parts[3] || void 0];
895
+ }
896
+ function parseSingleFFOrSafariStack(raw) {
897
+ let line = raw.trim();
898
+ if (SAFARI_NATIVE_CODE_REGEXP.test(line))
899
+ return null;
900
+ if (line.includes(" > eval"))
901
+ line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1");
902
+ if (!line.includes("@") && !line.includes(":"))
903
+ return null;
904
+ const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(?:@)/;
905
+ const matches = line.match(functionNameRegex);
906
+ const functionName = matches && matches[1] ? matches[1] : void 0;
907
+ const [url, lineNumber, columnNumber] = extractLocation(line.replace(functionNameRegex, ""));
908
+ if (!url || !lineNumber || !columnNumber)
909
+ return null;
910
+ return {
911
+ file: url,
912
+ method: functionName || "",
913
+ line: Number.parseInt(lineNumber),
914
+ column: Number.parseInt(columnNumber)
915
+ };
916
+ }
917
+ function parseSingleV8Stack(raw) {
918
+ let line = raw.trim();
919
+ if (!CHROME_IE_STACK_REGEXP.test(line))
920
+ return null;
921
+ if (line.includes("(eval "))
922
+ line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
923
+ let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
924
+ const location = sanitizedLine.match(/ (\(.+\)$)/);
925
+ sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
926
+ const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
927
+ let method = location && sanitizedLine || "";
928
+ let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
929
+ if (!file || !lineNumber || !columnNumber)
930
+ return null;
931
+ if (method.startsWith("async "))
932
+ method = method.slice(6);
933
+ if (file.startsWith("file://"))
934
+ file = file.slice(7);
935
+ file = resolve$2(file);
936
+ return {
937
+ method,
938
+ file,
939
+ line: Number.parseInt(lineNumber),
940
+ column: Number.parseInt(columnNumber)
941
+ };
942
+ }
943
+ function parseStacktrace(stack, options = {}) {
944
+ const { ignoreStackEntries = stackIgnorePatterns } = options;
945
+ let stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
946
+ if (ignoreStackEntries.length)
947
+ stacks = stacks.filter((stack2) => !ignoreStackEntries.some((p) => stack2.file.match(p)));
948
+ return stacks.map((stack2) => {
949
+ var _a;
950
+ const map = (_a = options.getSourceMap) == null ? void 0 : _a.call(options, stack2.file);
951
+ if (!map || typeof map !== "object" || !map.version)
952
+ return stack2;
953
+ const traceMap = new TraceMap(map);
954
+ const { line, column } = originalPositionFor(traceMap, stack2);
955
+ if (line != null && column != null)
956
+ return { ...stack2, line, column };
957
+ return stack2;
958
+ });
959
+ }
960
+ function parseFFOrSafariStackTrace(stack) {
961
+ return stack.split("\n").map((line) => parseSingleFFOrSafariStack(line)).filter(notNullish);
962
+ }
963
+ function parseV8Stacktrace(stack) {
964
+ return stack.split("\n").map((line) => parseSingleV8Stack(line)).filter(notNullish);
965
+ }
966
+ function parseErrorStacktrace(e, options = {}) {
967
+ if (!e || isPrimitive(e))
968
+ return [];
969
+ if (e.stacks)
970
+ return e.stacks;
971
+ const stackStr = e.stack || e.stackStr || "";
972
+ const stackFrames = parseStacktrace(stackStr, options);
973
+ e.stacks = stackFrames;
974
+ return stackFrames;
975
+ }
976
+
496
977
  async function saveInlineSnapshots(environment, snapshots) {
497
978
  const MagicString = (await import('magic-string')).default;
498
979
  const files = new Set(snapshots.map((i) => i.file));
@@ -659,7 +1140,7 @@ class SnapshotState {
659
1140
  _addSnapshot(key, receivedSerialized, options) {
660
1141
  this._dirty = true;
661
1142
  if (options.isInline) {
662
- const stacks = parseErrorStacktrace(options.error || new Error("snapshot"), []);
1143
+ const stacks = parseErrorStacktrace(options.error || new Error("snapshot"), { ignoreStackEntries: [] });
663
1144
  const stack = this._inferInlineSnapshotStack(stacks);
664
1145
  if (!stack) {
665
1146
  throw new Error(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/snapshot",
3
3
  "type": "module",
4
- "version": "0.33.0",
4
+ "version": "0.34.1",
5
5
  "description": "Vitest snapshot manager",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -45,7 +45,7 @@
45
45
  "devDependencies": {
46
46
  "@types/natural-compare": "^1.4.1",
47
47
  "natural-compare": "^1.4.0",
48
- "@vitest/utils": "0.33.0"
48
+ "@vitest/utils": "0.34.1"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "rimraf dist && rollup -c",