@vitest/snapshot 2.0.0-beta.2 → 2.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.js +17 -11
- 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(
|
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 .*(
|
949
|
-
const SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(
|
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,7 +958,12 @@ 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",
|
963
|
+
"/deps/vitest___chai.js",
|
964
|
+
"/deps/p-limit.js",
|
965
|
+
/node:\w+/,
|
966
|
+
/__vitest_test__/,
|
962
967
|
/__vitest_browser__/
|
963
968
|
];
|
964
969
|
function extractLocation(urlLike) {
|
@@ -974,7 +979,8 @@ function extractLocation(urlLike) {
|
|
974
979
|
url = urlObj.pathname;
|
975
980
|
}
|
976
981
|
if (url.startsWith("/@fs/")) {
|
977
|
-
|
982
|
+
const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
|
983
|
+
url = url.slice(isWindows ? 5 : 4);
|
978
984
|
}
|
979
985
|
return [url, parts[2] || void 0, parts[3] || void 0];
|
980
986
|
}
|
@@ -986,7 +992,7 @@ function parseSingleFFOrSafariStack(raw) {
|
|
986
992
|
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1");
|
987
993
|
if (!line.includes("@") && !line.includes(":"))
|
988
994
|
return null;
|
989
|
-
const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(
|
995
|
+
const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(@)/;
|
990
996
|
const matches = line.match(functionNameRegex);
|
991
997
|
const functionName = matches && matches[1] ? matches[1] : void 0;
|
992
998
|
const [url, lineNumber, columnNumber] = extractLocation(line.replace(functionNameRegex, ""));
|
@@ -1079,7 +1085,7 @@ async function saveInlineSnapshots(environment, snapshots) {
|
|
1079
1085
|
await environment.saveSnapshotFile(file, transformed);
|
1080
1086
|
}));
|
1081
1087
|
}
|
1082
|
-
const startObjectRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\S
|
1088
|
+
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
1089
|
function replaceObjectSnap(code, s, index, newSnap) {
|
1084
1090
|
let _code = code.slice(index);
|
1085
1091
|
const startMatch = startObjectRegex.exec(_code);
|
@@ -1121,12 +1127,12 @@ function prepareSnapString(snap, source, index) {
|
|
1121
1127
|
const isOneline = lines.length <= 1;
|
1122
1128
|
const quote = "`";
|
1123
1129
|
if (isOneline)
|
1124
|
-
return `${quote}${lines.join("\n").replace(/`/g, "\\`").replace(
|
1130
|
+
return `${quote}${lines.join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}${quote}`;
|
1125
1131
|
return `${quote}
|
1126
|
-
${lines.map((i) => i ? indentNext + i : "").join("\n").replace(/`/g, "\\`").replace(
|
1132
|
+
${lines.map((i) => i ? indentNext + i : "").join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}
|
1127
1133
|
${indent}${quote}`;
|
1128
1134
|
}
|
1129
|
-
const startRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\S
|
1135
|
+
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
1136
|
function replaceInlineSnap(code, s, index, newSnap) {
|
1131
1137
|
const codeStartingAtIndex = code.slice(index);
|
1132
1138
|
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.
|
4
|
+
"version": "2.0.0-beta.4",
|
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.
|
48
|
+
"@vitest/utils": "2.0.0-beta.4"
|
49
49
|
},
|
50
50
|
"scripts": {
|
51
51
|
"build": "rimraf dist && rollup -c",
|