@vitest/snapshot 2.1.0-beta.5 → 2.1.0-beta.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/dist/index.d.ts CHANGED
@@ -37,6 +37,7 @@ declare class SnapshotState {
37
37
  private _snapshotData;
38
38
  private _initialData;
39
39
  private _inlineSnapshots;
40
+ private _inlineSnapshotStacks;
40
41
  private _rawSnapshots;
41
42
  private _uncheckedKeys;
42
43
  private _snapshotFormat;
package/dist/index.js CHANGED
@@ -1376,6 +1376,7 @@ class SnapshotState {
1376
1376
  this._snapshotData = data;
1377
1377
  this._dirty = dirty;
1378
1378
  this._inlineSnapshots = [];
1379
+ this._inlineSnapshotStacks = [];
1379
1380
  this._rawSnapshots = [];
1380
1381
  this._uncheckedKeys = new Set(Object.keys(this._snapshotData));
1381
1382
  this._counters = /* @__PURE__ */ new Map();
@@ -1398,6 +1399,7 @@ class SnapshotState {
1398
1399
  _snapshotData;
1399
1400
  _initialData;
1400
1401
  _inlineSnapshots;
1402
+ _inlineSnapshotStacks;
1401
1403
  _rawSnapshots;
1402
1404
  _uncheckedKeys;
1403
1405
  _snapshotFormat;
@@ -1440,28 +1442,11 @@ class SnapshotState {
1440
1442
  return stackIndex !== -1 ? stacks[stackIndex + 2] : null;
1441
1443
  }
1442
1444
  _addSnapshot(key, receivedSerialized, options) {
1443
- var _a, _b;
1444
1445
  this._dirty = true;
1445
- if (options.isInline) {
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--;
1446
+ if (options.stack) {
1462
1447
  this._inlineSnapshots.push({
1463
1448
  snapshot: receivedSerialized,
1464
- ...stack
1449
+ ...options.stack
1465
1450
  });
1466
1451
  } else if (options.rawSnapshot) {
1467
1452
  this._rawSnapshots.push({
@@ -1537,6 +1522,7 @@ ${JSON.stringify(
1537
1522
  error,
1538
1523
  rawSnapshot
1539
1524
  }) {
1525
+ var _a, _b;
1540
1526
  this._counters.set(testName, (this._counters.get(testName) || 0) + 1);
1541
1527
  const count = Number(this._counters.get(testName));
1542
1528
  if (!key) {
@@ -1562,6 +1548,29 @@ ${JSON.stringify(
1562
1548
  if (pass && !isInline && !rawSnapshot) {
1563
1549
  this._snapshotData[key] = receivedSerialized;
1564
1550
  }
1551
+ let stack;
1552
+ if (isInline) {
1553
+ const stacks = parseErrorStacktrace(
1554
+ error || new Error("snapshot"),
1555
+ { ignoreStackEntries: [] }
1556
+ );
1557
+ const _stack = this._inferInlineSnapshotStack(stacks);
1558
+ if (!_stack) {
1559
+ throw new Error(
1560
+ `@vitest/snapshot: Couldn't infer stack frame for inline snapshot.
1561
+ ${JSON.stringify(
1562
+ stacks
1563
+ )}`
1564
+ );
1565
+ }
1566
+ stack = ((_b = (_a = this.environment).processStackTrace) == null ? void 0 : _b.call(_a, _stack)) || _stack;
1567
+ stack.column--;
1568
+ if (this._inlineSnapshotStacks.some((s) => s.file === stack.file && s.line === stack.line && s.column === stack.column)) {
1569
+ this._inlineSnapshots = this._inlineSnapshots.filter((s) => !(s.file === stack.file && s.line === stack.line && s.column === stack.column));
1570
+ throw new Error("toMatchInlineSnapshot cannot be called multiple times at the same location.");
1571
+ }
1572
+ this._inlineSnapshotStacks.push(stack);
1573
+ }
1565
1574
  if (hasSnapshot && this._updateSnapshot === "all" || (!hasSnapshot || !snapshotIsPersisted) && (this._updateSnapshot === "new" || this._updateSnapshot === "all")) {
1566
1575
  if (this._updateSnapshot === "all") {
1567
1576
  if (!pass) {
@@ -1571,8 +1580,7 @@ ${JSON.stringify(
1571
1580
  this.added++;
1572
1581
  }
1573
1582
  this._addSnapshot(key, receivedSerialized, {
1574
- error,
1575
- isInline,
1583
+ stack,
1576
1584
  rawSnapshot
1577
1585
  });
1578
1586
  } else {
@@ -1580,8 +1588,7 @@ ${JSON.stringify(
1580
1588
  }
1581
1589
  } else {
1582
1590
  this._addSnapshot(key, receivedSerialized, {
1583
- error,
1584
- isInline,
1591
+ stack,
1585
1592
  rawSnapshot
1586
1593
  });
1587
1594
  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.5",
4
+ "version": "2.1.0-beta.6",
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.5"
43
+ "@vitest/pretty-format": "2.1.0-beta.6"
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.5"
48
+ "@vitest/utils": "2.1.0-beta.6"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "rimraf dist && rollup -c",