@vitest/snapshot 3.0.0-beta.4 → 3.0.1
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 +28 -29
- package/package.json +4 -4
package/dist/index.js
CHANGED
@@ -23,7 +23,7 @@ function decodeInteger(reader, relative) {
|
|
23
23
|
const shouldNegate = value & 1;
|
24
24
|
value >>>= 1;
|
25
25
|
if (shouldNegate) {
|
26
|
-
value = -
|
26
|
+
value = -2147483648 | -value;
|
27
27
|
}
|
28
28
|
return relative + value;
|
29
29
|
}
|
@@ -663,7 +663,7 @@ function extractLocation(urlLike) {
|
|
663
663
|
const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
|
664
664
|
url = url.slice(isWindows ? 5 : 4);
|
665
665
|
}
|
666
|
-
return [url, parts[2] ||
|
666
|
+
return [url, parts[2] || undefined, parts[3] || undefined];
|
667
667
|
}
|
668
668
|
function parseSingleFFOrSafariStack(raw) {
|
669
669
|
let line = raw.trim();
|
@@ -681,7 +681,7 @@ function parseSingleFFOrSafariStack(raw) {
|
|
681
681
|
}
|
682
682
|
const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(@)/;
|
683
683
|
const matches = line.match(functionNameRegex);
|
684
|
-
const functionName = matches && matches[1] ? matches[1] :
|
684
|
+
const functionName = matches && matches[1] ? matches[1] : undefined;
|
685
685
|
const [url, lineNumber, columnNumber] = extractLocation(
|
686
686
|
line.replace(functionNameRegex, "")
|
687
687
|
);
|
@@ -710,7 +710,7 @@ function parseSingleV8Stack(raw) {
|
|
710
710
|
location ? location[1] : sanitizedLine
|
711
711
|
);
|
712
712
|
let method = location && sanitizedLine || "";
|
713
|
-
let file = url && ["eval", "<anonymous>"].includes(url) ?
|
713
|
+
let file = url && ["eval", "<anonymous>"].includes(url) ? undefined : url;
|
714
714
|
if (!file || !lineNumber || !columnNumber) {
|
715
715
|
return null;
|
716
716
|
}
|
@@ -744,7 +744,7 @@ function parseStacktrace(stack, options = {}) {
|
|
744
744
|
if (options.getFileName) {
|
745
745
|
stack2.file = options.getFileName(stack2.file);
|
746
746
|
}
|
747
|
-
const map = (_a = options.getSourceMap) == null ?
|
747
|
+
const map = (_a = options.getSourceMap) == null ? undefined : _a.call(options, stack2.file);
|
748
748
|
if (!map || typeof map !== "object" || !map.version) {
|
749
749
|
return stack2;
|
750
750
|
}
|
@@ -873,7 +873,7 @@ function requireJsTokens () {
|
|
873
873
|
yield ({
|
874
874
|
type: "RegularExpressionLiteral",
|
875
875
|
value: match[0],
|
876
|
-
closed: match[1] !==
|
876
|
+
closed: match[1] !== undefined && match[1] !== "\\"
|
877
877
|
});
|
878
878
|
continue;
|
879
879
|
}
|
@@ -1011,7 +1011,7 @@ function requireJsTokens () {
|
|
1011
1011
|
yield ({
|
1012
1012
|
type: "StringLiteral",
|
1013
1013
|
value: match[0],
|
1014
|
-
closed: match[2] !==
|
1014
|
+
closed: match[2] !== undefined
|
1015
1015
|
});
|
1016
1016
|
continue;
|
1017
1017
|
}
|
@@ -1112,7 +1112,7 @@ function requireJsTokens () {
|
|
1112
1112
|
yield ({
|
1113
1113
|
type: "JSXString",
|
1114
1114
|
value: match[0],
|
1115
|
-
closed: match[2] !==
|
1115
|
+
closed: match[2] !== undefined
|
1116
1116
|
});
|
1117
1117
|
continue;
|
1118
1118
|
}
|
@@ -1187,7 +1187,7 @@ function requireJsTokens () {
|
|
1187
1187
|
yield ({
|
1188
1188
|
type: "MultiLineComment",
|
1189
1189
|
value: match[0],
|
1190
|
-
closed: match[1] !==
|
1190
|
+
closed: match[1] !== undefined
|
1191
1191
|
});
|
1192
1192
|
continue;
|
1193
1193
|
}
|
@@ -1210,7 +1210,7 @@ function requireJsTokens () {
|
|
1210
1210
|
value: firstCodePoint
|
1211
1211
|
});
|
1212
1212
|
}
|
1213
|
-
return
|
1213
|
+
return undefined;
|
1214
1214
|
};
|
1215
1215
|
return jsTokens_1;
|
1216
1216
|
}
|
@@ -1318,11 +1318,11 @@ function a(n) {
|
|
1318
1318
|
}
|
1319
1319
|
a.open = "";
|
1320
1320
|
a.close = "";
|
1321
|
-
function C(n =
|
1322
|
-
let e = typeof process != "undefined" ? process :
|
1323
|
-
return !("NO_COLOR" in i || g.includes("--no-color")) && ("FORCE_COLOR" in i || g.includes("--color") || (e == null ?
|
1321
|
+
function C(n = false) {
|
1322
|
+
let e = typeof process != "undefined" ? process : undefined, i = (e == null ? undefined : e.env) || {}, g = (e == null ? undefined : e.argv) || [];
|
1323
|
+
return !("NO_COLOR" in i || g.includes("--no-color")) && ("FORCE_COLOR" in i || g.includes("--color") || (e == null ? undefined : e.platform) === "win32" || n && i.TERM !== "dumb" || "CI" in i) || typeof window != "undefined" && !!window.chrome;
|
1324
1324
|
}
|
1325
|
-
function p(n =
|
1325
|
+
function p(n = false) {
|
1326
1326
|
let e = C(n), i = (r, t, c, o) => {
|
1327
1327
|
let l = "", s = 0;
|
1328
1328
|
do
|
@@ -1347,8 +1347,7 @@ function p(n = !1) {
|
|
1347
1347
|
return u;
|
1348
1348
|
}
|
1349
1349
|
|
1350
|
-
|
1351
|
-
p(!1);
|
1350
|
+
p();
|
1352
1351
|
|
1353
1352
|
const lineSplitRE = /\r?\n/;
|
1354
1353
|
function positionToOffset(source, lineNumber, columnNumber) {
|
@@ -1482,7 +1481,7 @@ function replaceInlineSnap(code, s, currentIndex, newSnap) {
|
|
1482
1481
|
const firstKeywordMatch = /toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot/.exec(
|
1483
1482
|
codeStartingAtIndex
|
1484
1483
|
);
|
1485
|
-
if (!startMatch || startMatch.index !== (firstKeywordMatch == null ?
|
1484
|
+
if (!startMatch || startMatch.index !== (firstKeywordMatch == null ? undefined : firstKeywordMatch.index)) {
|
1486
1485
|
return replaceObjectSnap(code, s, index, newSnap);
|
1487
1486
|
}
|
1488
1487
|
const quote = startMatch[1];
|
@@ -1733,17 +1732,17 @@ function prepareExpected(expected) {
|
|
1733
1732
|
function findStartIndent() {
|
1734
1733
|
var _a, _b;
|
1735
1734
|
const matchObject = /^( +)\}\s+$/m.exec(expected || "");
|
1736
|
-
const objectIndent = (_a = matchObject == null ?
|
1735
|
+
const objectIndent = (_a = matchObject == null ? undefined : matchObject[1]) == null ? undefined : _a.length;
|
1737
1736
|
if (objectIndent) {
|
1738
1737
|
return objectIndent;
|
1739
1738
|
}
|
1740
1739
|
const matchText = /^\n( +)"/.exec(expected || "");
|
1741
|
-
return ((_b = matchText == null ?
|
1740
|
+
return ((_b = matchText == null ? undefined : matchText[1]) == null ? undefined : _b.length) || 0;
|
1742
1741
|
}
|
1743
1742
|
const startIndent = findStartIndent();
|
1744
|
-
let expectedTrimmed = expected == null ?
|
1743
|
+
let expectedTrimmed = expected == null ? undefined : expected.trim();
|
1745
1744
|
if (startIndent) {
|
1746
|
-
expectedTrimmed = expectedTrimmed == null ?
|
1745
|
+
expectedTrimmed = expectedTrimmed == null ? undefined : expectedTrimmed.replace(new RegExp(`^${" ".repeat(startIndent)}`, "gm"), "").replace(/ +\}$/, "}");
|
1747
1746
|
}
|
1748
1747
|
return expectedTrimmed;
|
1749
1748
|
}
|
@@ -1982,10 +1981,10 @@ class SnapshotState {
|
|
1982
1981
|
key = testNameToKey(testName, count);
|
1983
1982
|
}
|
1984
1983
|
this._testIdToKeys.get(testId).push(key);
|
1985
|
-
if (!(isInline && this._snapshotData[key] !==
|
1984
|
+
if (!(isInline && this._snapshotData[key] !== undefined)) {
|
1986
1985
|
this._uncheckedKeys.delete(key);
|
1987
1986
|
}
|
1988
|
-
let receivedSerialized = rawSnapshot && typeof received === "string" ? received : serialize(received,
|
1987
|
+
let receivedSerialized = rawSnapshot && typeof received === "string" ? received : serialize(received, undefined, this._snapshotFormat);
|
1989
1988
|
if (!rawSnapshot) {
|
1990
1989
|
receivedSerialized = addExtraLineBreaks(receivedSerialized);
|
1991
1990
|
}
|
@@ -1997,7 +1996,7 @@ class SnapshotState {
|
|
1997
1996
|
const expected = isInline ? inlineSnapshot : rawSnapshot ? rawSnapshot.content : this._snapshotData[key];
|
1998
1997
|
const expectedTrimmed = rawSnapshot ? expected : prepareExpected(expected);
|
1999
1998
|
const pass = expectedTrimmed === (rawSnapshot ? receivedSerialized : prepareExpected(receivedSerialized));
|
2000
|
-
const hasSnapshot = expected !==
|
1999
|
+
const hasSnapshot = expected !== undefined;
|
2001
2000
|
const snapshotIsPersisted = isInline || this._fileExists || rawSnapshot && rawSnapshot.content != null;
|
2002
2001
|
if (pass && !isInline && !rawSnapshot) {
|
2003
2002
|
this._snapshotData[key] = receivedSerialized;
|
@@ -2017,7 +2016,7 @@ ${JSON.stringify(
|
|
2017
2016
|
)}`
|
2018
2017
|
);
|
2019
2018
|
}
|
2020
|
-
stack = ((_b = (_a = this.environment).processStackTrace) == null ?
|
2019
|
+
stack = ((_b = (_a = this.environment).processStackTrace) == null ? undefined : _b.call(_a, _stack)) || _stack;
|
2021
2020
|
stack.column--;
|
2022
2021
|
if (this._inlineSnapshotStacks.some((s) => s.file === stack.file && s.line === stack.line && s.column === stack.column)) {
|
2023
2022
|
this._inlineSnapshots = this._inlineSnapshots.filter((s) => !(s.file === stack.file && s.line === stack.line && s.column === stack.column));
|
@@ -2062,7 +2061,7 @@ ${JSON.stringify(
|
|
2062
2061
|
return {
|
2063
2062
|
actual: rawSnapshot ? receivedSerialized : removeExtraLineBreaks(receivedSerialized),
|
2064
2063
|
count,
|
2065
|
-
expected: expectedTrimmed !==
|
2064
|
+
expected: expectedTrimmed !== undefined ? rawSnapshot ? expectedTrimmed : removeExtraLineBreaks(expectedTrimmed) : undefined,
|
2066
2065
|
key,
|
2067
2066
|
pass: false
|
2068
2067
|
};
|
@@ -2216,8 +2215,8 @@ class SnapshotClient {
|
|
2216
2215
|
throw createMismatchError(
|
2217
2216
|
`Snapshot \`${key || "unknown"}\` mismatched`,
|
2218
2217
|
snapshotState.expand,
|
2219
|
-
rawSnapshot ? actual : actual == null ?
|
2220
|
-
rawSnapshot ? expected : expected == null ?
|
2218
|
+
rawSnapshot ? actual : actual == null ? undefined : actual.trim(),
|
2219
|
+
rawSnapshot ? expected : expected == null ? undefined : expected.trim()
|
2221
2220
|
);
|
2222
2221
|
}
|
2223
2222
|
}
|
@@ -2236,7 +2235,7 @@ class SnapshotClient {
|
|
2236
2235
|
filepath,
|
2237
2236
|
rawSnapshot.file
|
2238
2237
|
);
|
2239
|
-
rawSnapshot.content = await snapshotState.environment.readSnapshotFile(rawSnapshot.file) ??
|
2238
|
+
rawSnapshot.content = await snapshotState.environment.readSnapshotFile(rawSnapshot.file) ?? undefined;
|
2240
2239
|
}
|
2241
2240
|
return this.assert(options);
|
2242
2241
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/snapshot",
|
3
3
|
"type": "module",
|
4
|
-
"version": "3.0.
|
4
|
+
"version": "3.0.1",
|
5
5
|
"description": "Vitest snapshot manager",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -39,13 +39,13 @@
|
|
39
39
|
],
|
40
40
|
"dependencies": {
|
41
41
|
"magic-string": "^0.30.17",
|
42
|
-
"pathe": "^2.0.
|
43
|
-
"@vitest/pretty-format": "3.0.
|
42
|
+
"pathe": "^2.0.1",
|
43
|
+
"@vitest/pretty-format": "3.0.1"
|
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.
|
48
|
+
"@vitest/utils": "3.0.1"
|
49
49
|
},
|
50
50
|
"scripts": {
|
51
51
|
"build": "rimraf dist && rollup -c",
|