@vitest/snapshot 3.0.5 → 3.0.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/environment.js
CHANGED
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { S as SnapshotStateOptions, a as SnapshotMatchOptions, b as SnapshotResult, R as RawSnapshotInfo } from './rawSnapshot-
|
2
|
-
export { c as SnapshotData, d as SnapshotSerializer, e as SnapshotSummary, f as SnapshotUpdateState, U as UncheckedSnapshot } from './rawSnapshot-
|
1
|
+
import { S as SnapshotStateOptions, a as SnapshotMatchOptions, b as SnapshotResult, R as RawSnapshotInfo } from './rawSnapshot-DOKg5unn.js';
|
2
|
+
export { c as SnapshotData, d as SnapshotSerializer, e as SnapshotSummary, f as SnapshotUpdateState, U as UncheckedSnapshot } from './rawSnapshot-DOKg5unn.js';
|
3
3
|
import { S as SnapshotEnvironment } from './environment-Ddx0EDtY.js';
|
4
4
|
import { Plugin, Plugins } from '@vitest/pretty-format';
|
5
5
|
|
@@ -10,6 +10,26 @@ interface ParsedStack {
|
|
10
10
|
column: number;
|
11
11
|
}
|
12
12
|
|
13
|
+
/**
|
14
|
+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
15
|
+
*
|
16
|
+
* This source code is licensed under the MIT license found in the
|
17
|
+
* LICENSE file in the root directory of this source tree.
|
18
|
+
*/
|
19
|
+
|
20
|
+
declare class DefaultMap<K, V> extends Map<K, V> {
|
21
|
+
private defaultFn;
|
22
|
+
constructor(defaultFn: (key: K) => V, entries?: Iterable<readonly [K, V]>);
|
23
|
+
get(key: K): V;
|
24
|
+
}
|
25
|
+
declare class CounterMap<K> extends DefaultMap<K, number> {
|
26
|
+
constructor();
|
27
|
+
_total: number | undefined;
|
28
|
+
valueOf(): number;
|
29
|
+
increment(key: K): void;
|
30
|
+
total(): number;
|
31
|
+
}
|
32
|
+
|
13
33
|
/**
|
14
34
|
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
15
35
|
*
|
@@ -44,11 +64,19 @@ declare class SnapshotState {
|
|
44
64
|
private _snapshotFormat;
|
45
65
|
private _environment;
|
46
66
|
private _fileExists;
|
47
|
-
private added;
|
48
|
-
private matched;
|
49
|
-
private unmatched;
|
50
|
-
private updated;
|
51
67
|
expand: boolean;
|
68
|
+
private _added;
|
69
|
+
private _matched;
|
70
|
+
private _unmatched;
|
71
|
+
private _updated;
|
72
|
+
get added(): CounterMap<string>;
|
73
|
+
set added(value: number);
|
74
|
+
get matched(): CounterMap<string>;
|
75
|
+
set matched(value: number);
|
76
|
+
get unmatched(): CounterMap<string>;
|
77
|
+
set unmatched(value: number);
|
78
|
+
get updated(): CounterMap<string>;
|
79
|
+
set updated(value: number);
|
52
80
|
private constructor();
|
53
81
|
static create(testFilePath: string, options: SnapshotStateOptions): Promise<SnapshotState>;
|
54
82
|
get environment(): SnapshotEnvironment;
|
package/dist/index.js
CHANGED
@@ -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] || void 0, parts[3] || void 0];
|
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] : void 0;
|
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) ? void 0 : 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 ? void 0 : _a.call(options, stack2.file);
|
748
748
|
if (!map || typeof map !== "object" || !map.version) {
|
749
749
|
return stack2;
|
750
750
|
}
|
@@ -814,6 +814,15 @@ catch (noNodeInspect) {
|
|
814
814
|
nodeInspect = false;
|
815
815
|
}
|
816
816
|
|
817
|
+
const {
|
818
|
+
AsymmetricMatcher: AsymmetricMatcher$1,
|
819
|
+
DOMCollection: DOMCollection$1,
|
820
|
+
DOMElement: DOMElement$1,
|
821
|
+
Immutable: Immutable$1,
|
822
|
+
ReactElement: ReactElement$1,
|
823
|
+
ReactTestComponent: ReactTestComponent$1
|
824
|
+
} = plugins;
|
825
|
+
|
817
826
|
function getDefaultExportFromCjs (x) {
|
818
827
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
819
828
|
}
|
@@ -873,7 +882,7 @@ function requireJsTokens () {
|
|
873
882
|
yield ({
|
874
883
|
type: "RegularExpressionLiteral",
|
875
884
|
value: match[0],
|
876
|
-
closed: match[1] !==
|
885
|
+
closed: match[1] !== void 0 && match[1] !== "\\"
|
877
886
|
});
|
878
887
|
continue;
|
879
888
|
}
|
@@ -1011,7 +1020,7 @@ function requireJsTokens () {
|
|
1011
1020
|
yield ({
|
1012
1021
|
type: "StringLiteral",
|
1013
1022
|
value: match[0],
|
1014
|
-
closed: match[2] !==
|
1023
|
+
closed: match[2] !== void 0
|
1015
1024
|
});
|
1016
1025
|
continue;
|
1017
1026
|
}
|
@@ -1112,7 +1121,7 @@ function requireJsTokens () {
|
|
1112
1121
|
yield ({
|
1113
1122
|
type: "JSXString",
|
1114
1123
|
value: match[0],
|
1115
|
-
closed: match[2] !==
|
1124
|
+
closed: match[2] !== void 0
|
1116
1125
|
});
|
1117
1126
|
continue;
|
1118
1127
|
}
|
@@ -1187,7 +1196,7 @@ function requireJsTokens () {
|
|
1187
1196
|
yield ({
|
1188
1197
|
type: "MultiLineComment",
|
1189
1198
|
value: match[0],
|
1190
|
-
closed: match[1] !==
|
1199
|
+
closed: match[1] !== void 0
|
1191
1200
|
});
|
1192
1201
|
continue;
|
1193
1202
|
}
|
@@ -1210,7 +1219,7 @@ function requireJsTokens () {
|
|
1210
1219
|
value: firstCodePoint
|
1211
1220
|
});
|
1212
1221
|
}
|
1213
|
-
return
|
1222
|
+
return void 0;
|
1214
1223
|
};
|
1215
1224
|
return jsTokens_1;
|
1216
1225
|
}
|
@@ -1319,8 +1328,8 @@ function a(n) {
|
|
1319
1328
|
a.open = "";
|
1320
1329
|
a.close = "";
|
1321
1330
|
function C(n = false) {
|
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 ?
|
1331
|
+
let e = typeof process != "undefined" ? process : void 0, i = (e == null ? void 0 : e.env) || {}, g = (e == null ? void 0 : e.argv) || [];
|
1332
|
+
return !("NO_COLOR" in i || g.includes("--no-color")) && ("FORCE_COLOR" in i || g.includes("--color") || (e == null ? void 0 : e.platform) === "win32" || n && i.TERM !== "dumb" || "CI" in i) || typeof window != "undefined" && !!window.chrome;
|
1324
1333
|
}
|
1325
1334
|
function p(n = false) {
|
1326
1335
|
let e = C(n), i = (r, t, c, o) => {
|
@@ -1481,7 +1490,7 @@ function replaceInlineSnap(code, s, currentIndex, newSnap) {
|
|
1481
1490
|
const firstKeywordMatch = /toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot/.exec(
|
1482
1491
|
codeStartingAtIndex
|
1483
1492
|
);
|
1484
|
-
if (!startMatch || startMatch.index !== (firstKeywordMatch == null ?
|
1493
|
+
if (!startMatch || startMatch.index !== (firstKeywordMatch == null ? void 0 : firstKeywordMatch.index)) {
|
1485
1494
|
return replaceObjectSnap(code, s, index, newSnap);
|
1486
1495
|
}
|
1487
1496
|
const quote = startMatch[1];
|
@@ -1732,17 +1741,17 @@ function prepareExpected(expected) {
|
|
1732
1741
|
function findStartIndent() {
|
1733
1742
|
var _a, _b;
|
1734
1743
|
const matchObject = /^( +)\}\s+$/m.exec(expected || "");
|
1735
|
-
const objectIndent = (_a = matchObject == null ?
|
1744
|
+
const objectIndent = (_a = matchObject == null ? void 0 : matchObject[1]) == null ? void 0 : _a.length;
|
1736
1745
|
if (objectIndent) {
|
1737
1746
|
return objectIndent;
|
1738
1747
|
}
|
1739
1748
|
const matchText = /^\n( +)"/.exec(expected || "");
|
1740
|
-
return ((_b = matchText == null ?
|
1749
|
+
return ((_b = matchText == null ? void 0 : matchText[1]) == null ? void 0 : _b.length) || 0;
|
1741
1750
|
}
|
1742
1751
|
const startIndent = findStartIndent();
|
1743
|
-
let expectedTrimmed = expected == null ?
|
1752
|
+
let expectedTrimmed = expected == null ? void 0 : expected.trim();
|
1744
1753
|
if (startIndent) {
|
1745
|
-
expectedTrimmed = expectedTrimmed == null ?
|
1754
|
+
expectedTrimmed = expectedTrimmed == null ? void 0 : expectedTrimmed.replace(new RegExp(`^${" ".repeat(startIndent)}`, "gm"), "").replace(/ +\}$/, "}");
|
1746
1755
|
}
|
1747
1756
|
return expectedTrimmed;
|
1748
1757
|
}
|
@@ -1798,10 +1807,25 @@ class CounterMap extends DefaultMap {
|
|
1798
1807
|
constructor() {
|
1799
1808
|
super(() => 0);
|
1800
1809
|
}
|
1810
|
+
// compat for jest-image-snapshot https://github.com/vitest-dev/vitest/issues/7322
|
1811
|
+
// `valueOf` and `Snapshot.added` setter allows
|
1812
|
+
// snapshotState.added = snapshotState.added + 1
|
1813
|
+
// to function as
|
1814
|
+
// snapshotState.added.total_ = snapshotState.added.total() + 1
|
1815
|
+
_total;
|
1816
|
+
valueOf() {
|
1817
|
+
return this._total = this.total();
|
1818
|
+
}
|
1801
1819
|
increment(key) {
|
1820
|
+
if (typeof this._total !== "undefined") {
|
1821
|
+
this._total++;
|
1822
|
+
}
|
1802
1823
|
this.set(key, this.get(key) + 1);
|
1803
1824
|
}
|
1804
1825
|
total() {
|
1826
|
+
if (typeof this._total !== "undefined") {
|
1827
|
+
return this._total;
|
1828
|
+
}
|
1805
1829
|
let total = 0;
|
1806
1830
|
for (const x of this.values()) {
|
1807
1831
|
total += x;
|
@@ -1845,11 +1869,37 @@ class SnapshotState {
|
|
1845
1869
|
_snapshotFormat;
|
1846
1870
|
_environment;
|
1847
1871
|
_fileExists;
|
1848
|
-
added = new CounterMap();
|
1849
|
-
matched = new CounterMap();
|
1850
|
-
unmatched = new CounterMap();
|
1851
|
-
updated = new CounterMap();
|
1852
1872
|
expand;
|
1873
|
+
// getter/setter for jest-image-snapshot compat
|
1874
|
+
// https://github.com/vitest-dev/vitest/issues/7322
|
1875
|
+
_added = new CounterMap();
|
1876
|
+
_matched = new CounterMap();
|
1877
|
+
_unmatched = new CounterMap();
|
1878
|
+
_updated = new CounterMap();
|
1879
|
+
get added() {
|
1880
|
+
return this._added;
|
1881
|
+
}
|
1882
|
+
set added(value) {
|
1883
|
+
this._added._total = value;
|
1884
|
+
}
|
1885
|
+
get matched() {
|
1886
|
+
return this._matched;
|
1887
|
+
}
|
1888
|
+
set matched(value) {
|
1889
|
+
this._matched._total = value;
|
1890
|
+
}
|
1891
|
+
get unmatched() {
|
1892
|
+
return this._unmatched;
|
1893
|
+
}
|
1894
|
+
set unmatched(value) {
|
1895
|
+
this._unmatched._total = value;
|
1896
|
+
}
|
1897
|
+
get updated() {
|
1898
|
+
return this._updated;
|
1899
|
+
}
|
1900
|
+
set updated(value) {
|
1901
|
+
this._updated._total = value;
|
1902
|
+
}
|
1853
1903
|
static async create(testFilePath, options) {
|
1854
1904
|
const snapshotPath = await options.snapshotEnvironment.resolvePath(
|
1855
1905
|
testFilePath
|
@@ -1981,10 +2031,10 @@ class SnapshotState {
|
|
1981
2031
|
key = testNameToKey(testName, count);
|
1982
2032
|
}
|
1983
2033
|
this._testIdToKeys.get(testId).push(key);
|
1984
|
-
if (!(isInline && this._snapshotData[key] !==
|
2034
|
+
if (!(isInline && this._snapshotData[key] !== void 0)) {
|
1985
2035
|
this._uncheckedKeys.delete(key);
|
1986
2036
|
}
|
1987
|
-
let receivedSerialized = rawSnapshot && typeof received === "string" ? received : serialize(received,
|
2037
|
+
let receivedSerialized = rawSnapshot && typeof received === "string" ? received : serialize(received, void 0, this._snapshotFormat);
|
1988
2038
|
if (!rawSnapshot) {
|
1989
2039
|
receivedSerialized = addExtraLineBreaks(receivedSerialized);
|
1990
2040
|
}
|
@@ -1996,7 +2046,7 @@ class SnapshotState {
|
|
1996
2046
|
const expected = isInline ? inlineSnapshot : rawSnapshot ? rawSnapshot.content : this._snapshotData[key];
|
1997
2047
|
const expectedTrimmed = rawSnapshot ? expected : prepareExpected(expected);
|
1998
2048
|
const pass = expectedTrimmed === (rawSnapshot ? receivedSerialized : prepareExpected(receivedSerialized));
|
1999
|
-
const hasSnapshot = expected !==
|
2049
|
+
const hasSnapshot = expected !== void 0;
|
2000
2050
|
const snapshotIsPersisted = isInline || this._fileExists || rawSnapshot && rawSnapshot.content != null;
|
2001
2051
|
if (pass && !isInline && !rawSnapshot) {
|
2002
2052
|
this._snapshotData[key] = receivedSerialized;
|
@@ -2016,7 +2066,7 @@ ${JSON.stringify(
|
|
2016
2066
|
)}`
|
2017
2067
|
);
|
2018
2068
|
}
|
2019
|
-
stack = ((_b = (_a = this.environment).processStackTrace) == null ?
|
2069
|
+
stack = ((_b = (_a = this.environment).processStackTrace) == null ? void 0 : _b.call(_a, _stack)) || _stack;
|
2020
2070
|
stack.column--;
|
2021
2071
|
if (this._inlineSnapshotStacks.some((s) => s.file === stack.file && s.line === stack.line && s.column === stack.column)) {
|
2022
2072
|
this._inlineSnapshots = this._inlineSnapshots.filter((s) => !(s.file === stack.file && s.line === stack.line && s.column === stack.column));
|
@@ -2061,7 +2111,7 @@ ${JSON.stringify(
|
|
2061
2111
|
return {
|
2062
2112
|
actual: rawSnapshot ? receivedSerialized : removeExtraLineBreaks(receivedSerialized),
|
2063
2113
|
count,
|
2064
|
-
expected: expectedTrimmed !==
|
2114
|
+
expected: expectedTrimmed !== void 0 ? rawSnapshot ? expectedTrimmed : removeExtraLineBreaks(expectedTrimmed) : void 0,
|
2065
2115
|
key,
|
2066
2116
|
pass: false
|
2067
2117
|
};
|
@@ -2215,8 +2265,8 @@ class SnapshotClient {
|
|
2215
2265
|
throw createMismatchError(
|
2216
2266
|
`Snapshot \`${key || "unknown"}\` mismatched`,
|
2217
2267
|
snapshotState.expand,
|
2218
|
-
rawSnapshot ? actual : actual == null ?
|
2219
|
-
rawSnapshot ? expected : expected == null ?
|
2268
|
+
rawSnapshot ? actual : actual == null ? void 0 : actual.trim(),
|
2269
|
+
rawSnapshot ? expected : expected == null ? void 0 : expected.trim()
|
2220
2270
|
);
|
2221
2271
|
}
|
2222
2272
|
}
|
@@ -2235,7 +2285,7 @@ class SnapshotClient {
|
|
2235
2285
|
filepath,
|
2236
2286
|
rawSnapshot.file
|
2237
2287
|
);
|
2238
|
-
rawSnapshot.content = await snapshotState.environment.readSnapshotFile(rawSnapshot.file) ??
|
2288
|
+
rawSnapshot.content = await snapshotState.environment.readSnapshotFile(rawSnapshot.file) ?? void 0;
|
2239
2289
|
}
|
2240
2290
|
return this.assert(options);
|
2241
2291
|
}
|
package/dist/manager.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { S as SnapshotStateOptions, e as SnapshotSummary, b as SnapshotResult } from './rawSnapshot-
|
1
|
+
import { S as SnapshotStateOptions, e as SnapshotSummary, b as SnapshotResult } from './rawSnapshot-DOKg5unn.js';
|
2
2
|
import '@vitest/pretty-format';
|
3
3
|
import './environment-Ddx0EDtY.js';
|
4
4
|
|
package/dist/manager.js
CHANGED
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.6",
|
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.3",
|
43
|
+
"@vitest/pretty-format": "3.0.6"
|
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.6"
|
49
49
|
},
|
50
50
|
"scripts": {
|
51
51
|
"build": "rimraf dist && rollup -c",
|