@vitest/snapshot 2.1.0-beta.5 → 2.1.0-beta.7
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 +1 -0
- package/dist/index.js +95 -70
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -501,74 +501,92 @@ for (let i = 0; i < chars.length; i++) {
|
|
501
501
|
intToChar[i] = c;
|
502
502
|
charToInt[c] = i;
|
503
503
|
}
|
504
|
+
function decodeInteger(reader, relative) {
|
505
|
+
let value = 0;
|
506
|
+
let shift = 0;
|
507
|
+
let integer = 0;
|
508
|
+
do {
|
509
|
+
const c = reader.next();
|
510
|
+
integer = charToInt[c];
|
511
|
+
value |= (integer & 31) << shift;
|
512
|
+
shift += 5;
|
513
|
+
} while (integer & 32);
|
514
|
+
const shouldNegate = value & 1;
|
515
|
+
value >>>= 1;
|
516
|
+
if (shouldNegate) {
|
517
|
+
value = -0x80000000 | -value;
|
518
|
+
}
|
519
|
+
return relative + value;
|
520
|
+
}
|
521
|
+
function hasMoreVlq(reader, max) {
|
522
|
+
if (reader.pos >= max)
|
523
|
+
return false;
|
524
|
+
return reader.peek() !== comma;
|
525
|
+
}
|
526
|
+
class StringReader {
|
527
|
+
constructor(buffer) {
|
528
|
+
this.pos = 0;
|
529
|
+
this.buffer = buffer;
|
530
|
+
}
|
531
|
+
next() {
|
532
|
+
return this.buffer.charCodeAt(this.pos++);
|
533
|
+
}
|
534
|
+
peek() {
|
535
|
+
return this.buffer.charCodeAt(this.pos);
|
536
|
+
}
|
537
|
+
indexOf(char) {
|
538
|
+
const { buffer, pos } = this;
|
539
|
+
const idx = buffer.indexOf(char, pos);
|
540
|
+
return idx === -1 ? buffer.length : idx;
|
541
|
+
}
|
542
|
+
}
|
543
|
+
|
504
544
|
function decode(mappings) {
|
505
|
-
const
|
545
|
+
const { length } = mappings;
|
546
|
+
const reader = new StringReader(mappings);
|
506
547
|
const decoded = [];
|
507
|
-
let
|
548
|
+
let genColumn = 0;
|
549
|
+
let sourcesIndex = 0;
|
550
|
+
let sourceLine = 0;
|
551
|
+
let sourceColumn = 0;
|
552
|
+
let namesIndex = 0;
|
508
553
|
do {
|
509
|
-
const semi = indexOf(
|
554
|
+
const semi = reader.indexOf(';');
|
510
555
|
const line = [];
|
511
556
|
let sorted = true;
|
512
557
|
let lastCol = 0;
|
513
|
-
|
514
|
-
|
558
|
+
genColumn = 0;
|
559
|
+
while (reader.pos < semi) {
|
515
560
|
let seg;
|
516
|
-
|
517
|
-
|
518
|
-
if (col < lastCol)
|
561
|
+
genColumn = decodeInteger(reader, genColumn);
|
562
|
+
if (genColumn < lastCol)
|
519
563
|
sorted = false;
|
520
|
-
lastCol =
|
521
|
-
if (hasMoreVlq(
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
if (hasMoreVlq(
|
526
|
-
|
527
|
-
seg = [
|
564
|
+
lastCol = genColumn;
|
565
|
+
if (hasMoreVlq(reader, semi)) {
|
566
|
+
sourcesIndex = decodeInteger(reader, sourcesIndex);
|
567
|
+
sourceLine = decodeInteger(reader, sourceLine);
|
568
|
+
sourceColumn = decodeInteger(reader, sourceColumn);
|
569
|
+
if (hasMoreVlq(reader, semi)) {
|
570
|
+
namesIndex = decodeInteger(reader, namesIndex);
|
571
|
+
seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex];
|
528
572
|
}
|
529
573
|
else {
|
530
|
-
seg = [
|
574
|
+
seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];
|
531
575
|
}
|
532
576
|
}
|
533
577
|
else {
|
534
|
-
seg = [
|
578
|
+
seg = [genColumn];
|
535
579
|
}
|
536
580
|
line.push(seg);
|
581
|
+
reader.pos++;
|
537
582
|
}
|
538
583
|
if (!sorted)
|
539
584
|
sort(line);
|
540
585
|
decoded.push(line);
|
541
|
-
|
542
|
-
} while (
|
586
|
+
reader.pos = semi + 1;
|
587
|
+
} while (reader.pos <= length);
|
543
588
|
return decoded;
|
544
589
|
}
|
545
|
-
function indexOf(mappings, index) {
|
546
|
-
const idx = mappings.indexOf(';', index);
|
547
|
-
return idx === -1 ? mappings.length : idx;
|
548
|
-
}
|
549
|
-
function decodeInteger(mappings, pos, state, j) {
|
550
|
-
let value = 0;
|
551
|
-
let shift = 0;
|
552
|
-
let integer = 0;
|
553
|
-
do {
|
554
|
-
const c = mappings.charCodeAt(pos++);
|
555
|
-
integer = charToInt[c];
|
556
|
-
value |= (integer & 31) << shift;
|
557
|
-
shift += 5;
|
558
|
-
} while (integer & 32);
|
559
|
-
const shouldNegate = value & 1;
|
560
|
-
value >>>= 1;
|
561
|
-
if (shouldNegate) {
|
562
|
-
value = -0x80000000 | -value;
|
563
|
-
}
|
564
|
-
state[j] += value;
|
565
|
-
return pos;
|
566
|
-
}
|
567
|
-
function hasMoreVlq(mappings, i, length) {
|
568
|
-
if (i >= length)
|
569
|
-
return false;
|
570
|
-
return mappings.charCodeAt(i) !== comma;
|
571
|
-
}
|
572
590
|
function sort(line) {
|
573
591
|
line.sort(sortComparator$1);
|
574
592
|
}
|
@@ -1376,6 +1394,7 @@ class SnapshotState {
|
|
1376
1394
|
this._snapshotData = data;
|
1377
1395
|
this._dirty = dirty;
|
1378
1396
|
this._inlineSnapshots = [];
|
1397
|
+
this._inlineSnapshotStacks = [];
|
1379
1398
|
this._rawSnapshots = [];
|
1380
1399
|
this._uncheckedKeys = new Set(Object.keys(this._snapshotData));
|
1381
1400
|
this._counters = /* @__PURE__ */ new Map();
|
@@ -1398,6 +1417,7 @@ class SnapshotState {
|
|
1398
1417
|
_snapshotData;
|
1399
1418
|
_initialData;
|
1400
1419
|
_inlineSnapshots;
|
1420
|
+
_inlineSnapshotStacks;
|
1401
1421
|
_rawSnapshots;
|
1402
1422
|
_uncheckedKeys;
|
1403
1423
|
_snapshotFormat;
|
@@ -1440,28 +1460,11 @@ class SnapshotState {
|
|
1440
1460
|
return stackIndex !== -1 ? stacks[stackIndex + 2] : null;
|
1441
1461
|
}
|
1442
1462
|
_addSnapshot(key, receivedSerialized, options) {
|
1443
|
-
var _a, _b;
|
1444
1463
|
this._dirty = true;
|
1445
|
-
if (options.
|
1446
|
-
const error = options.error || new Error("snapshot");
|
1447
|
-
const stacks = parseErrorStacktrace(
|
1448
|
-
error,
|
1449
|
-
{ ignoreStackEntries: [] }
|
1450
|
-
);
|
1451
|
-
const _stack = this._inferInlineSnapshotStack(stacks);
|
1452
|
-
if (!_stack) {
|
1453
|
-
throw new Error(
|
1454
|
-
`@vitest/snapshot: Couldn't infer stack frame for inline snapshot.
|
1455
|
-
${JSON.stringify(
|
1456
|
-
stacks
|
1457
|
-
)}`
|
1458
|
-
);
|
1459
|
-
}
|
1460
|
-
const stack = ((_b = (_a = this.environment).processStackTrace) == null ? void 0 : _b.call(_a, _stack)) || _stack;
|
1461
|
-
stack.column--;
|
1464
|
+
if (options.stack) {
|
1462
1465
|
this._inlineSnapshots.push({
|
1463
1466
|
snapshot: receivedSerialized,
|
1464
|
-
...stack
|
1467
|
+
...options.stack
|
1465
1468
|
});
|
1466
1469
|
} else if (options.rawSnapshot) {
|
1467
1470
|
this._rawSnapshots.push({
|
@@ -1537,6 +1540,7 @@ ${JSON.stringify(
|
|
1537
1540
|
error,
|
1538
1541
|
rawSnapshot
|
1539
1542
|
}) {
|
1543
|
+
var _a, _b;
|
1540
1544
|
this._counters.set(testName, (this._counters.get(testName) || 0) + 1);
|
1541
1545
|
const count = Number(this._counters.get(testName));
|
1542
1546
|
if (!key) {
|
@@ -1562,6 +1566,29 @@ ${JSON.stringify(
|
|
1562
1566
|
if (pass && !isInline && !rawSnapshot) {
|
1563
1567
|
this._snapshotData[key] = receivedSerialized;
|
1564
1568
|
}
|
1569
|
+
let stack;
|
1570
|
+
if (isInline) {
|
1571
|
+
const stacks = parseErrorStacktrace(
|
1572
|
+
error || new Error("snapshot"),
|
1573
|
+
{ ignoreStackEntries: [] }
|
1574
|
+
);
|
1575
|
+
const _stack = this._inferInlineSnapshotStack(stacks);
|
1576
|
+
if (!_stack) {
|
1577
|
+
throw new Error(
|
1578
|
+
`@vitest/snapshot: Couldn't infer stack frame for inline snapshot.
|
1579
|
+
${JSON.stringify(
|
1580
|
+
stacks
|
1581
|
+
)}`
|
1582
|
+
);
|
1583
|
+
}
|
1584
|
+
stack = ((_b = (_a = this.environment).processStackTrace) == null ? void 0 : _b.call(_a, _stack)) || _stack;
|
1585
|
+
stack.column--;
|
1586
|
+
if (this._inlineSnapshotStacks.some((s) => s.file === stack.file && s.line === stack.line && s.column === stack.column)) {
|
1587
|
+
this._inlineSnapshots = this._inlineSnapshots.filter((s) => !(s.file === stack.file && s.line === stack.line && s.column === stack.column));
|
1588
|
+
throw new Error("toMatchInlineSnapshot cannot be called multiple times at the same location.");
|
1589
|
+
}
|
1590
|
+
this._inlineSnapshotStacks.push(stack);
|
1591
|
+
}
|
1565
1592
|
if (hasSnapshot && this._updateSnapshot === "all" || (!hasSnapshot || !snapshotIsPersisted) && (this._updateSnapshot === "new" || this._updateSnapshot === "all")) {
|
1566
1593
|
if (this._updateSnapshot === "all") {
|
1567
1594
|
if (!pass) {
|
@@ -1571,8 +1598,7 @@ ${JSON.stringify(
|
|
1571
1598
|
this.added++;
|
1572
1599
|
}
|
1573
1600
|
this._addSnapshot(key, receivedSerialized, {
|
1574
|
-
|
1575
|
-
isInline,
|
1601
|
+
stack,
|
1576
1602
|
rawSnapshot
|
1577
1603
|
});
|
1578
1604
|
} else {
|
@@ -1580,8 +1606,7 @@ ${JSON.stringify(
|
|
1580
1606
|
}
|
1581
1607
|
} else {
|
1582
1608
|
this._addSnapshot(key, receivedSerialized, {
|
1583
|
-
|
1584
|
-
isInline,
|
1609
|
+
stack,
|
1585
1610
|
rawSnapshot
|
1586
1611
|
});
|
1587
1612
|
this.added++;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/snapshot",
|
3
3
|
"type": "module",
|
4
|
-
"version": "2.1.0-beta.
|
4
|
+
"version": "2.1.0-beta.7",
|
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.11",
|
42
42
|
"pathe": "^1.1.2",
|
43
|
-
"@vitest/pretty-format": "2.1.0-beta.
|
43
|
+
"@vitest/pretty-format": "2.1.0-beta.7"
|
44
44
|
},
|
45
45
|
"devDependencies": {
|
46
46
|
"@types/natural-compare": "^1.4.3",
|
47
47
|
"natural-compare": "^1.4.0",
|
48
|
-
"@vitest/utils": "2.1.0-beta.
|
48
|
+
"@vitest/utils": "2.1.0-beta.7"
|
49
49
|
},
|
50
50
|
"scripts": {
|
51
51
|
"build": "rimraf dist && rollup -c",
|