@vitest/snapshot 2.0.0-beta.1 → 2.0.0-beta.10

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 +21 -12
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -310,7 +310,7 @@ function serialize(val, indent = 2, formatOverrides = {}) {
310
310
  );
311
311
  }
312
312
  function escapeBacktickString(str) {
313
- return str.replace(/`|\\|\${/g, "\\$&");
313
+ return str.replace(/`|\\|\$\{/g, "\\$&");
314
314
  }
315
315
  function printBacktickString(str) {
316
316
  return `\`${escapeBacktickString(str)}\``;
@@ -338,7 +338,7 @@ ${snapshots.join("\n\n")}
338
338
  function prepareExpected(expected) {
339
339
  function findStartIndent() {
340
340
  var _a, _b;
341
- const matchObject = /^( +)}\s+$/m.exec(expected || "");
341
+ const matchObject = /^( +)\}\s+$/m.exec(expected || "");
342
342
  const objectIndent = (_a = matchObject == null ? void 0 : matchObject[1]) == null ? void 0 : _a.length;
343
343
  if (objectIndent)
344
344
  return objectIndent;
@@ -348,7 +348,7 @@ function prepareExpected(expected) {
348
348
  const startIndent = findStartIndent();
349
349
  let expectedTrimmed = expected == null ? void 0 : expected.trim();
350
350
  if (startIndent) {
351
- expectedTrimmed = expectedTrimmed == null ? void 0 : expectedTrimmed.replace(new RegExp(`^${" ".repeat(startIndent)}`, "gm"), "").replace(/ +}$/, "}");
351
+ expectedTrimmed = expectedTrimmed == null ? void 0 : expectedTrimmed.replace(new RegExp(`^${" ".repeat(startIndent)}`, "gm"), "").replace(/ +\}$/, "}");
352
352
  }
353
353
  return expectedTrimmed;
354
354
  }
@@ -945,8 +945,8 @@ function traceSegmentInternal(segments, memo, line, column, bias) {
945
945
  return index;
946
946
  }
947
947
 
948
- const CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m;
949
- const SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code])?$/;
948
+ const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
949
+ const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
950
950
  const stackIgnorePatterns = [
951
951
  "node:internal",
952
952
  /\/packages\/\w+\/dist\//,
@@ -958,8 +958,14 @@ const stackIgnorePatterns = [
958
958
  "/node_modules/chai/",
959
959
  "/node_modules/tinypool/",
960
960
  "/node_modules/tinyspy/",
961
+ // browser related deps
961
962
  "/deps/chai.js",
962
- /__vitest_browser__/
963
+ "/deps/vitest___chai.js",
964
+ "/deps/p-limit.js",
965
+ /node:\w+/,
966
+ /__vitest_test__/,
967
+ /__vitest_browser__/,
968
+ /\/deps\/vitest_/
963
969
  ];
964
970
  function extractLocation(urlLike) {
965
971
  if (!urlLike.includes(":"))
@@ -969,12 +975,15 @@ function extractLocation(urlLike) {
969
975
  if (!parts)
970
976
  return [urlLike];
971
977
  let url = parts[1];
978
+ if (url.startsWith("async "))
979
+ url = url.slice(6);
972
980
  if (url.startsWith("http:") || url.startsWith("https:")) {
973
981
  const urlObj = new URL(url);
974
982
  url = urlObj.pathname;
975
983
  }
976
984
  if (url.startsWith("/@fs/")) {
977
- url = url.slice(typeof process !== "undefined" && process.platform === "win32" ? 5 : 4);
985
+ const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
986
+ url = url.slice(isWindows ? 5 : 4);
978
987
  }
979
988
  return [url, parts[2] || void 0, parts[3] || void 0];
980
989
  }
@@ -986,7 +995,7 @@ function parseSingleFFOrSafariStack(raw) {
986
995
  line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1");
987
996
  if (!line.includes("@") && !line.includes(":"))
988
997
  return null;
989
- const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(?:@)/;
998
+ const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(@)/;
990
999
  const matches = line.match(functionNameRegex);
991
1000
  const functionName = matches && matches[1] ? matches[1] : void 0;
992
1001
  const [url, lineNumber, columnNumber] = extractLocation(line.replace(functionNameRegex, ""));
@@ -1079,7 +1088,7 @@ async function saveInlineSnapshots(environment, snapshots) {
1079
1088
  await environment.saveSnapshotFile(file, transformed);
1080
1089
  }));
1081
1090
  }
1082
- const startObjectRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\S\s]*\*\/\s*|\/\/.*\s+)*\s*({)/m;
1091
+ const startObjectRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*\{/;
1083
1092
  function replaceObjectSnap(code, s, index, newSnap) {
1084
1093
  let _code = code.slice(index);
1085
1094
  const startMatch = startObjectRegex.exec(_code);
@@ -1121,12 +1130,12 @@ function prepareSnapString(snap, source, index) {
1121
1130
  const isOneline = lines.length <= 1;
1122
1131
  const quote = "`";
1123
1132
  if (isOneline)
1124
- return `${quote}${lines.join("\n").replace(/`/g, "\\`").replace(/\${/g, "\\${")}${quote}`;
1133
+ return `${quote}${lines.join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}${quote}`;
1125
1134
  return `${quote}
1126
- ${lines.map((i) => i ? indentNext + i : "").join("\n").replace(/`/g, "\\`").replace(/\${/g, "\\${")}
1135
+ ${lines.map((i) => i ? indentNext + i : "").join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}
1127
1136
  ${indent}${quote}`;
1128
1137
  }
1129
- const startRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\S\s]*\*\/\s*|\/\/.*\s+)*\s*[\w_$]*(['"`\)])/m;
1138
+ const startRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*[\w$]*(['"`)])/;
1130
1139
  function replaceInlineSnap(code, s, index, newSnap) {
1131
1140
  const codeStartingAtIndex = code.slice(index);
1132
1141
  const startMatch = startRegex.exec(codeStartingAtIndex);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/snapshot",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.1",
4
+ "version": "2.0.0-beta.10",
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.3",
47
47
  "natural-compare": "^1.4.0",
48
- "@vitest/utils": "2.0.0-beta.1"
48
+ "@vitest/utils": "2.0.0-beta.10"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "rimraf dist && rollup -c",