@vitest/snapshot 4.0.0-beta.2 → 4.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -4
- package/dist/index.js +161 -195
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -66,13 +66,13 @@ declare class SnapshotState {
|
|
|
66
66
|
private _unmatched;
|
|
67
67
|
private _updated;
|
|
68
68
|
get added(): CounterMap<string>;
|
|
69
|
-
set added(value:
|
|
69
|
+
set added(value: number);
|
|
70
70
|
get matched(): CounterMap<string>;
|
|
71
|
-
set matched(value:
|
|
71
|
+
set matched(value: number);
|
|
72
72
|
get unmatched(): CounterMap<string>;
|
|
73
|
-
set unmatched(value:
|
|
73
|
+
set unmatched(value: number);
|
|
74
74
|
get updated(): CounterMap<string>;
|
|
75
|
-
set updated(value:
|
|
75
|
+
set updated(value: number);
|
|
76
76
|
private constructor();
|
|
77
77
|
static create(testFilePath: string, options: SnapshotStateOptions): Promise<SnapshotState>;
|
|
78
78
|
get environment(): SnapshotEnvironment;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolve as resolve$
|
|
1
|
+
import { resolve as resolve$1 } from 'pathe';
|
|
2
2
|
import { plugins, format } from '@vitest/pretty-format';
|
|
3
3
|
|
|
4
4
|
const comma = ','.charCodeAt(0);
|
|
@@ -283,7 +283,7 @@ function normalizePath(url, type) {
|
|
|
283
283
|
/**
|
|
284
284
|
* Attempts to resolve `input` URL/path relative to `base`.
|
|
285
285
|
*/
|
|
286
|
-
function resolve
|
|
286
|
+
function resolve(input, base) {
|
|
287
287
|
if (!input && !base)
|
|
288
288
|
return '';
|
|
289
289
|
const url = parseUrl(input);
|
|
@@ -343,238 +343,204 @@ function resolve$1(input, base) {
|
|
|
343
343
|
}
|
|
344
344
|
}
|
|
345
345
|
|
|
346
|
-
|
|
347
|
-
// The base is always treated as a directory, if it's not empty.
|
|
348
|
-
// https://github.com/mozilla/source-map/blob/8cb3ee57/lib/util.js#L327
|
|
349
|
-
// https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
|
|
350
|
-
if (base && !base.endsWith('/'))
|
|
351
|
-
base += '/';
|
|
352
|
-
return resolve$1(input, base);
|
|
353
|
-
}
|
|
346
|
+
// src/trace-mapping.ts
|
|
354
347
|
|
|
355
|
-
|
|
356
|
-
* Removes everything after the last "/", but leaves the slash.
|
|
357
|
-
*/
|
|
348
|
+
// src/strip-filename.ts
|
|
358
349
|
function stripFilename(path) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
return path.slice(0, index + 1);
|
|
350
|
+
if (!path) return "";
|
|
351
|
+
const index = path.lastIndexOf("/");
|
|
352
|
+
return path.slice(0, index + 1);
|
|
363
353
|
}
|
|
364
354
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
const
|
|
368
|
-
const
|
|
369
|
-
|
|
355
|
+
// src/resolve.ts
|
|
356
|
+
function resolver(mapUrl, sourceRoot) {
|
|
357
|
+
const from = stripFilename(mapUrl);
|
|
358
|
+
const prefix = sourceRoot ? sourceRoot + "/" : "";
|
|
359
|
+
return (source) => resolve(prefix + (source || ""), from);
|
|
360
|
+
}
|
|
370
361
|
|
|
362
|
+
// src/sourcemap-segment.ts
|
|
363
|
+
var COLUMN = 0;
|
|
364
|
+
var SOURCES_INDEX = 1;
|
|
365
|
+
var SOURCE_LINE = 2;
|
|
366
|
+
var SOURCE_COLUMN = 3;
|
|
367
|
+
var NAMES_INDEX = 4;
|
|
368
|
+
|
|
369
|
+
// src/sort.ts
|
|
371
370
|
function maybeSort(mappings, owned) {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
|
|
380
|
-
mappings[i] = sortSegments(mappings[i], owned);
|
|
381
|
-
}
|
|
382
|
-
return mappings;
|
|
371
|
+
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
|
|
372
|
+
if (unsortedIndex === mappings.length) return mappings;
|
|
373
|
+
if (!owned) mappings = mappings.slice();
|
|
374
|
+
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
|
|
375
|
+
mappings[i] = sortSegments(mappings[i], owned);
|
|
376
|
+
}
|
|
377
|
+
return mappings;
|
|
383
378
|
}
|
|
384
379
|
function nextUnsortedSegmentLine(mappings, start) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
return mappings.length;
|
|
380
|
+
for (let i = start; i < mappings.length; i++) {
|
|
381
|
+
if (!isSorted(mappings[i])) return i;
|
|
382
|
+
}
|
|
383
|
+
return mappings.length;
|
|
390
384
|
}
|
|
391
385
|
function isSorted(line) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
}
|
|
386
|
+
for (let j = 1; j < line.length; j++) {
|
|
387
|
+
if (line[j][COLUMN] < line[j - 1][COLUMN]) {
|
|
388
|
+
return false;
|
|
396
389
|
}
|
|
397
|
-
|
|
390
|
+
}
|
|
391
|
+
return true;
|
|
398
392
|
}
|
|
399
393
|
function sortSegments(line, owned) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
return line.sort(sortComparator);
|
|
394
|
+
if (!owned) line = line.slice();
|
|
395
|
+
return line.sort(sortComparator);
|
|
403
396
|
}
|
|
404
397
|
function sortComparator(a, b) {
|
|
405
|
-
|
|
398
|
+
return a[COLUMN] - b[COLUMN];
|
|
406
399
|
}
|
|
407
400
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
* A binary search implementation that returns the index if a match is found.
|
|
411
|
-
* If no match is found, then the left-index (the index associated with the item that comes just
|
|
412
|
-
* before the desired index) is returned. To maintain proper sort order, a splice would happen at
|
|
413
|
-
* the next index:
|
|
414
|
-
*
|
|
415
|
-
* ```js
|
|
416
|
-
* const array = [1, 3];
|
|
417
|
-
* const needle = 2;
|
|
418
|
-
* const index = binarySearch(array, needle, (item, needle) => item - needle);
|
|
419
|
-
*
|
|
420
|
-
* assert.equal(index, 0);
|
|
421
|
-
* array.splice(index + 1, 0, needle);
|
|
422
|
-
* assert.deepEqual(array, [1, 2, 3]);
|
|
423
|
-
* ```
|
|
424
|
-
*/
|
|
401
|
+
// src/binary-search.ts
|
|
402
|
+
var found = false;
|
|
425
403
|
function binarySearch(haystack, needle, low, high) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
if (cmp < 0) {
|
|
434
|
-
low = mid + 1;
|
|
435
|
-
}
|
|
436
|
-
else {
|
|
437
|
-
high = mid - 1;
|
|
438
|
-
}
|
|
404
|
+
while (low <= high) {
|
|
405
|
+
const mid = low + (high - low >> 1);
|
|
406
|
+
const cmp = haystack[mid][COLUMN] - needle;
|
|
407
|
+
if (cmp === 0) {
|
|
408
|
+
found = true;
|
|
409
|
+
return mid;
|
|
439
410
|
}
|
|
440
|
-
|
|
441
|
-
|
|
411
|
+
if (cmp < 0) {
|
|
412
|
+
low = mid + 1;
|
|
413
|
+
} else {
|
|
414
|
+
high = mid - 1;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
found = false;
|
|
418
|
+
return low - 1;
|
|
442
419
|
}
|
|
443
420
|
function upperBound(haystack, needle, index) {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
return index;
|
|
421
|
+
for (let i = index + 1; i < haystack.length; index = i++) {
|
|
422
|
+
if (haystack[i][COLUMN] !== needle) break;
|
|
423
|
+
}
|
|
424
|
+
return index;
|
|
449
425
|
}
|
|
450
426
|
function lowerBound(haystack, needle, index) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
return index;
|
|
427
|
+
for (let i = index - 1; i >= 0; index = i--) {
|
|
428
|
+
if (haystack[i][COLUMN] !== needle) break;
|
|
429
|
+
}
|
|
430
|
+
return index;
|
|
456
431
|
}
|
|
457
432
|
function memoizedState() {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
433
|
+
return {
|
|
434
|
+
lastKey: -1,
|
|
435
|
+
lastNeedle: -1,
|
|
436
|
+
lastIndex: -1
|
|
437
|
+
};
|
|
463
438
|
}
|
|
464
|
-
/**
|
|
465
|
-
* This overly complicated beast is just to record the last tested line/column and the resulting
|
|
466
|
-
* index, allowing us to skip a few tests if mappings are monotonically increasing.
|
|
467
|
-
*/
|
|
468
439
|
function memoizedBinarySearch(haystack, needle, state, key) {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
else {
|
|
482
|
-
high = lastIndex;
|
|
483
|
-
}
|
|
440
|
+
const { lastKey, lastNeedle, lastIndex } = state;
|
|
441
|
+
let low = 0;
|
|
442
|
+
let high = haystack.length - 1;
|
|
443
|
+
if (key === lastKey) {
|
|
444
|
+
if (needle === lastNeedle) {
|
|
445
|
+
found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
|
|
446
|
+
return lastIndex;
|
|
447
|
+
}
|
|
448
|
+
if (needle >= lastNeedle) {
|
|
449
|
+
low = lastIndex === -1 ? 0 : lastIndex;
|
|
450
|
+
} else {
|
|
451
|
+
high = lastIndex;
|
|
484
452
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
453
|
+
}
|
|
454
|
+
state.lastKey = key;
|
|
455
|
+
state.lastNeedle = needle;
|
|
456
|
+
return state.lastIndex = binarySearch(haystack, needle, low, high);
|
|
488
457
|
}
|
|
489
458
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
const GREATEST_LOWER_BOUND = 1;
|
|
494
|
-
class TraceMap {
|
|
495
|
-
constructor(map, mapUrl) {
|
|
496
|
-
const isString = typeof map === 'string';
|
|
497
|
-
if (!isString && map._decodedMemo)
|
|
498
|
-
return map;
|
|
499
|
-
const parsed = (isString ? JSON.parse(map) : map);
|
|
500
|
-
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|
501
|
-
this.version = version;
|
|
502
|
-
this.file = file;
|
|
503
|
-
this.names = names || [];
|
|
504
|
-
this.sourceRoot = sourceRoot;
|
|
505
|
-
this.sources = sources;
|
|
506
|
-
this.sourcesContent = sourcesContent;
|
|
507
|
-
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || undefined;
|
|
508
|
-
const from = resolve(sourceRoot || '', stripFilename(mapUrl));
|
|
509
|
-
this.resolvedSources = sources.map((s) => resolve(s || '', from));
|
|
510
|
-
const { mappings } = parsed;
|
|
511
|
-
if (typeof mappings === 'string') {
|
|
512
|
-
this._encoded = mappings;
|
|
513
|
-
this._decoded = undefined;
|
|
514
|
-
}
|
|
515
|
-
else {
|
|
516
|
-
this._encoded = undefined;
|
|
517
|
-
this._decoded = maybeSort(mappings, isString);
|
|
518
|
-
}
|
|
519
|
-
this._decodedMemo = memoizedState();
|
|
520
|
-
this._bySources = undefined;
|
|
521
|
-
this._bySourceMemos = undefined;
|
|
522
|
-
}
|
|
459
|
+
// src/types.ts
|
|
460
|
+
function parse(map) {
|
|
461
|
+
return typeof map === "string" ? JSON.parse(map) : map;
|
|
523
462
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
463
|
+
|
|
464
|
+
// src/trace-mapping.ts
|
|
465
|
+
var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
|
|
466
|
+
var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
|
|
467
|
+
var LEAST_UPPER_BOUND = -1;
|
|
468
|
+
var GREATEST_LOWER_BOUND = 1;
|
|
469
|
+
var TraceMap = class {
|
|
470
|
+
constructor(map, mapUrl) {
|
|
471
|
+
const isString = typeof map === "string";
|
|
472
|
+
if (!isString && map._decodedMemo) return map;
|
|
473
|
+
const parsed = parse(map);
|
|
474
|
+
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|
475
|
+
this.version = version;
|
|
476
|
+
this.file = file;
|
|
477
|
+
this.names = names || [];
|
|
478
|
+
this.sourceRoot = sourceRoot;
|
|
479
|
+
this.sources = sources;
|
|
480
|
+
this.sourcesContent = sourcesContent;
|
|
481
|
+
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
|
482
|
+
const resolve = resolver(mapUrl, sourceRoot);
|
|
483
|
+
this.resolvedSources = sources.map(resolve);
|
|
484
|
+
const { mappings } = parsed;
|
|
485
|
+
if (typeof mappings === "string") {
|
|
486
|
+
this._encoded = mappings;
|
|
487
|
+
this._decoded = void 0;
|
|
488
|
+
} else if (Array.isArray(mappings)) {
|
|
489
|
+
this._encoded = void 0;
|
|
490
|
+
this._decoded = maybeSort(mappings, isString);
|
|
491
|
+
} else if (parsed.sections) {
|
|
492
|
+
throw new Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);
|
|
493
|
+
} else {
|
|
494
|
+
throw new Error(`invalid source map: ${JSON.stringify(parsed)}`);
|
|
495
|
+
}
|
|
496
|
+
this._decodedMemo = memoizedState();
|
|
497
|
+
this._bySources = void 0;
|
|
498
|
+
this._bySourceMemos = void 0;
|
|
499
|
+
}
|
|
500
|
+
};
|
|
528
501
|
function cast(map) {
|
|
529
|
-
|
|
502
|
+
return map;
|
|
530
503
|
}
|
|
531
|
-
/**
|
|
532
|
-
* Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
|
|
533
|
-
*/
|
|
534
504
|
function decodedMappings(map) {
|
|
535
|
-
|
|
536
|
-
|
|
505
|
+
var _a;
|
|
506
|
+
return (_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded));
|
|
537
507
|
}
|
|
538
|
-
/**
|
|
539
|
-
* A higher-level API to find the source/line/column associated with a generated line/column
|
|
540
|
-
* (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
|
|
541
|
-
* `source-map` library.
|
|
542
|
-
*/
|
|
543
508
|
function originalPositionFor(map, needle) {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
509
|
+
let { line, column, bias } = needle;
|
|
510
|
+
line--;
|
|
511
|
+
if (line < 0) throw new Error(LINE_GTR_ZERO);
|
|
512
|
+
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
|
513
|
+
const decoded = decodedMappings(map);
|
|
514
|
+
if (line >= decoded.length) return OMapping(null, null, null, null);
|
|
515
|
+
const segments = decoded[line];
|
|
516
|
+
const index = traceSegmentInternal(
|
|
517
|
+
segments,
|
|
518
|
+
cast(map)._decodedMemo,
|
|
519
|
+
line,
|
|
520
|
+
column,
|
|
521
|
+
bias || GREATEST_LOWER_BOUND
|
|
522
|
+
);
|
|
523
|
+
if (index === -1) return OMapping(null, null, null, null);
|
|
524
|
+
const segment = segments[index];
|
|
525
|
+
if (segment.length === 1) return OMapping(null, null, null, null);
|
|
526
|
+
const { names, resolvedSources } = map;
|
|
527
|
+
return OMapping(
|
|
528
|
+
resolvedSources[segment[SOURCES_INDEX]],
|
|
529
|
+
segment[SOURCE_LINE] + 1,
|
|
530
|
+
segment[SOURCE_COLUMN],
|
|
531
|
+
segment.length === 5 ? names[segment[NAMES_INDEX]] : null
|
|
532
|
+
);
|
|
564
533
|
}
|
|
565
534
|
function OMapping(source, line, column, name) {
|
|
566
|
-
|
|
535
|
+
return { source, line, column, name };
|
|
567
536
|
}
|
|
568
537
|
function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
if (index === -1 || index === segments.length)
|
|
576
|
-
return -1;
|
|
577
|
-
return index;
|
|
538
|
+
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
539
|
+
if (found) {
|
|
540
|
+
index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
|
|
541
|
+
} else if (bias === LEAST_UPPER_BOUND) index++;
|
|
542
|
+
if (index === -1 || index === segments.length) return -1;
|
|
543
|
+
return index;
|
|
578
544
|
}
|
|
579
545
|
|
|
580
546
|
/**
|
|
@@ -742,7 +708,7 @@ function parseSingleV8Stack(raw) {
|
|
|
742
708
|
file = file.slice(7);
|
|
743
709
|
}
|
|
744
710
|
// normalize Windows path (\ -> /)
|
|
745
|
-
file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve$
|
|
711
|
+
file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve$1(file);
|
|
746
712
|
if (method) {
|
|
747
713
|
method = method.replace(/__vite_ssr_import_\d+__\./g, "");
|
|
748
714
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/snapshot",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.4",
|
|
5
5
|
"description": "Vitest snapshot manager",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"magic-string": "^0.30.17",
|
|
42
42
|
"pathe": "^2.0.3",
|
|
43
|
-
"@vitest/pretty-format": "4.0.0-beta.
|
|
43
|
+
"@vitest/pretty-format": "4.0.0-beta.4"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/natural-compare": "^1.4.3",
|
|
47
47
|
"natural-compare": "^1.4.0",
|
|
48
|
-
"@vitest/utils": "4.0.0-beta.
|
|
48
|
+
"@vitest/utils": "4.0.0-beta.4"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "rimraf dist && rollup -c",
|