@vitest/snapshot 3.0.6 → 3.0.8

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 +46 -17
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -657,7 +657,9 @@ function extractLocation(urlLike) {
657
657
  }
658
658
  if (url.startsWith("http:") || url.startsWith("https:")) {
659
659
  const urlObj = new URL(url);
660
- url = urlObj.pathname;
660
+ urlObj.searchParams.delete("import");
661
+ urlObj.searchParams.delete("browserv");
662
+ url = urlObj.pathname + urlObj.hash + urlObj.search;
661
663
  }
662
664
  if (url.startsWith("/@fs/")) {
663
665
  const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
@@ -733,28 +735,40 @@ function parseSingleV8Stack(raw) {
733
735
  }
734
736
  function parseStacktrace(stack, options = {}) {
735
737
  const { ignoreStackEntries = stackIgnorePatterns } = options;
736
- let stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
737
- if (ignoreStackEntries.length) {
738
- stacks = stacks.filter(
739
- (stack2) => !ignoreStackEntries.some((p) => stack2.file.match(p))
740
- );
741
- }
738
+ const stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
742
739
  return stacks.map((stack2) => {
743
740
  var _a;
744
- if (options.getFileName) {
745
- stack2.file = options.getFileName(stack2.file);
741
+ if (options.getUrlId) {
742
+ stack2.file = options.getUrlId(stack2.file);
746
743
  }
747
744
  const map = (_a = options.getSourceMap) == null ? void 0 : _a.call(options, stack2.file);
748
745
  if (!map || typeof map !== "object" || !map.version) {
749
- return stack2;
746
+ return shouldFilter(ignoreStackEntries, stack2.file) ? null : stack2;
750
747
  }
751
748
  const traceMap = new TraceMap(map);
752
- const { line, column } = originalPositionFor(traceMap, stack2);
749
+ const { line, column, source, name } = originalPositionFor(traceMap, stack2);
750
+ let file = stack2.file;
751
+ if (source) {
752
+ const fileUrl = stack2.file.startsWith("file://") ? stack2.file : `file://${stack2.file}`;
753
+ const sourceRootUrl = map.sourceRoot ? new URL(map.sourceRoot, fileUrl) : fileUrl;
754
+ file = new URL(source, sourceRootUrl).pathname;
755
+ }
756
+ if (shouldFilter(ignoreStackEntries, file)) {
757
+ return null;
758
+ }
753
759
  if (line != null && column != null) {
754
- return { ...stack2, line, column };
760
+ return {
761
+ line,
762
+ column,
763
+ file,
764
+ method: name || stack2.method
765
+ };
755
766
  }
756
767
  return stack2;
757
- });
768
+ }).filter((s) => s != null);
769
+ }
770
+ function shouldFilter(ignoreStackEntries, file) {
771
+ return ignoreStackEntries.some((p) => file.match(p));
758
772
  }
759
773
  function parseFFOrSafariStackTrace(stack) {
760
774
  return stack.split("\n").map((line) => parseSingleFFOrSafariStack(line)).filter(notNullish);
@@ -1834,6 +1848,9 @@ class CounterMap extends DefaultMap {
1834
1848
  }
1835
1849
  }
1836
1850
 
1851
+ function isSameStackPosition(x, y) {
1852
+ return x.file === y.file && x.column === y.column && x.line === y.line;
1853
+ }
1837
1854
  class SnapshotState {
1838
1855
  constructor(testFilePath, snapshotPath, snapshotContent, options) {
1839
1856
  this.testFilePath = testFilePath;
@@ -2068,11 +2085,23 @@ ${JSON.stringify(
2068
2085
  }
2069
2086
  stack = ((_b = (_a = this.environment).processStackTrace) == null ? void 0 : _b.call(_a, _stack)) || _stack;
2070
2087
  stack.column--;
2071
- if (this._inlineSnapshotStacks.some((s) => s.file === stack.file && s.line === stack.line && s.column === stack.column)) {
2072
- this._inlineSnapshots = this._inlineSnapshots.filter((s) => !(s.file === stack.file && s.line === stack.line && s.column === stack.column));
2073
- throw new Error("toMatchInlineSnapshot cannot be called multiple times at the same location.");
2088
+ const snapshotsWithSameStack = this._inlineSnapshotStacks.filter((s) => isSameStackPosition(s, stack));
2089
+ if (snapshotsWithSameStack.length > 0) {
2090
+ this._inlineSnapshots = this._inlineSnapshots.filter((s) => !isSameStackPosition(s, stack));
2091
+ const differentSnapshot = snapshotsWithSameStack.find((s) => s.snapshot !== receivedSerialized);
2092
+ if (differentSnapshot) {
2093
+ throw Object.assign(
2094
+ new Error(
2095
+ "toMatchInlineSnapshot with different snapshots cannot be called at the same location"
2096
+ ),
2097
+ {
2098
+ actual: receivedSerialized,
2099
+ expected: differentSnapshot.snapshot
2100
+ }
2101
+ );
2102
+ }
2074
2103
  }
2075
- this._inlineSnapshotStacks.push({ ...stack, testId });
2104
+ this._inlineSnapshotStacks.push({ ...stack, testId, snapshot: receivedSerialized });
2076
2105
  }
2077
2106
  if (hasSnapshot && this._updateSnapshot === "all" || (!hasSnapshot || !snapshotIsPersisted) && (this._updateSnapshot === "new" || this._updateSnapshot === "all")) {
2078
2107
  if (this._updateSnapshot === "all") {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/snapshot",
3
3
  "type": "module",
4
- "version": "3.0.6",
4
+ "version": "3.0.8",
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": "3.0.6"
43
+ "@vitest/pretty-format": "3.0.8"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/natural-compare": "^1.4.3",
47
47
  "natural-compare": "^1.4.0",
48
- "@vitest/utils": "3.0.6"
48
+ "@vitest/utils": "3.0.8"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "rimraf dist && rollup -c",