@noma.to/qwik-mock 1.0.2 → 1.1.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/lib/lib/qwik-mock.cjs +24 -6
- package/lib/lib/qwik-mock.mjs +24 -6
- package/lib-types/index.d.ts +2 -1
- package/lib-types/lib/qwik-mock.d.ts +21 -19
- package/package.json +7 -6
- package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.cjs +0 -83
- package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs +0 -83
- package/lib/node_modules/.pnpm/@vitest_expect@4.0.18/node_modules/@vitest/expect/dist/index.cjs +0 -1785
- package/lib/node_modules/.pnpm/@vitest_expect@4.0.18/node_modules/@vitest/expect/dist/index.mjs +0 -1785
- package/lib/node_modules/.pnpm/@vitest_pretty-format@4.0.18/node_modules/@vitest/pretty-format/dist/index.cjs +0 -964
- package/lib/node_modules/.pnpm/@vitest_pretty-format@4.0.18/node_modules/@vitest/pretty-format/dist/index.mjs +0 -964
- package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/chunk-tasks.cjs +0 -60
- package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/chunk-tasks.mjs +0 -60
- package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/index.cjs +0 -1102
- package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/index.mjs +0 -1102
- package/lib/node_modules/.pnpm/@vitest_snapshot@4.0.18/node_modules/@vitest/snapshot/dist/index.cjs +0 -1289
- package/lib/node_modules/.pnpm/@vitest_snapshot@4.0.18/node_modules/@vitest/snapshot/dist/index.mjs +0 -1289
- package/lib/node_modules/.pnpm/@vitest_spy@4.0.18/node_modules/@vitest/spy/dist/index.cjs +0 -422
- package/lib/node_modules/.pnpm/@vitest_spy@4.0.18/node_modules/@vitest/spy/dist/index.mjs +0 -422
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.cjs +0 -6
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.mjs +0 -6
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.cjs +0 -98
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.mjs +0 -98
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/diff.cjs +0 -1626
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/diff.mjs +0 -1626
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/display.cjs +0 -690
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/display.mjs +0 -690
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/error.cjs +0 -39
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/error.mjs +0 -39
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/helpers.cjs +0 -151
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/helpers.mjs +0 -151
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/serialize.cjs +0 -114
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/serialize.mjs +0 -114
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/source-map.cjs +0 -125
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/source-map.mjs +0 -125
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/timers.cjs +0 -22
- package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/timers.mjs +0 -22
- package/lib/node_modules/.pnpm/chai@6.2.2/node_modules/chai/index.cjs +0 -4056
- package/lib/node_modules/.pnpm/chai@6.2.2/node_modules/chai/index.mjs +0 -4056
- package/lib/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.cjs +0 -994
- package/lib/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs +0 -994
- package/lib/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.cjs +0 -101
- package/lib/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +0 -101
- package/lib/node_modules/.pnpm/tinyrainbow@3.0.3/node_modules/tinyrainbow/dist/index.cjs +0 -84
- package/lib/node_modules/.pnpm/tinyrainbow@3.0.3/node_modules/tinyrainbow/dist/index.mjs +0 -84
- package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.cjs +0 -4
- package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.mjs +0 -4
- package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.cjs +0 -51
- package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.mjs +0 -51
- package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/utils.DvEY5TfP.cjs +0 -45
- package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/utils.DvEY5TfP.mjs +0 -45
- package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/vi.2VT5v0um.cjs +0 -2609
- package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/vi.2VT5v0um.mjs +0 -2609
package/lib/node_modules/.pnpm/@vitest_snapshot@4.0.18/node_modules/@vitest/snapshot/dist/index.mjs
DELETED
|
@@ -1,1289 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import { format, plugins } from "../../../../../@vitest_pretty-format@4.0.18/node_modules/@vitest/pretty-format/dist/index.mjs";
|
|
5
|
-
import { r as resolve } from "../../../../../pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs";
|
|
6
|
-
var comma = ",".charCodeAt(0);
|
|
7
|
-
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
8
|
-
var intToChar = new Uint8Array(64);
|
|
9
|
-
var charToInt = new Uint8Array(128);
|
|
10
|
-
for (let i = 0; i < chars.length; i++) {
|
|
11
|
-
const c = chars.charCodeAt(i);
|
|
12
|
-
intToChar[i] = c;
|
|
13
|
-
charToInt[c] = i;
|
|
14
|
-
}
|
|
15
|
-
function decodeInteger(reader, relative) {
|
|
16
|
-
let value = 0;
|
|
17
|
-
let shift = 0;
|
|
18
|
-
let integer = 0;
|
|
19
|
-
do {
|
|
20
|
-
const c = reader.next();
|
|
21
|
-
integer = charToInt[c];
|
|
22
|
-
value |= (integer & 31) << shift;
|
|
23
|
-
shift += 5;
|
|
24
|
-
} while (integer & 32);
|
|
25
|
-
const shouldNegate = value & 1;
|
|
26
|
-
value >>>= 1;
|
|
27
|
-
if (shouldNegate) {
|
|
28
|
-
value = -2147483648 | -value;
|
|
29
|
-
}
|
|
30
|
-
return relative + value;
|
|
31
|
-
}
|
|
32
|
-
function hasMoreVlq(reader, max) {
|
|
33
|
-
if (reader.pos >= max) return false;
|
|
34
|
-
return reader.peek() !== comma;
|
|
35
|
-
}
|
|
36
|
-
var StringReader = class {
|
|
37
|
-
constructor(buffer) {
|
|
38
|
-
this.pos = 0;
|
|
39
|
-
this.buffer = buffer;
|
|
40
|
-
}
|
|
41
|
-
next() {
|
|
42
|
-
return this.buffer.charCodeAt(this.pos++);
|
|
43
|
-
}
|
|
44
|
-
peek() {
|
|
45
|
-
return this.buffer.charCodeAt(this.pos);
|
|
46
|
-
}
|
|
47
|
-
indexOf(char) {
|
|
48
|
-
const { buffer, pos } = this;
|
|
49
|
-
const idx = buffer.indexOf(char, pos);
|
|
50
|
-
return idx === -1 ? buffer.length : idx;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
function decode(mappings) {
|
|
54
|
-
const { length } = mappings;
|
|
55
|
-
const reader = new StringReader(mappings);
|
|
56
|
-
const decoded = [];
|
|
57
|
-
let genColumn = 0;
|
|
58
|
-
let sourcesIndex = 0;
|
|
59
|
-
let sourceLine = 0;
|
|
60
|
-
let sourceColumn = 0;
|
|
61
|
-
let namesIndex = 0;
|
|
62
|
-
do {
|
|
63
|
-
const semi = reader.indexOf(";");
|
|
64
|
-
const line = [];
|
|
65
|
-
let sorted = true;
|
|
66
|
-
let lastCol = 0;
|
|
67
|
-
genColumn = 0;
|
|
68
|
-
while (reader.pos < semi) {
|
|
69
|
-
let seg;
|
|
70
|
-
genColumn = decodeInteger(reader, genColumn);
|
|
71
|
-
if (genColumn < lastCol) sorted = false;
|
|
72
|
-
lastCol = genColumn;
|
|
73
|
-
if (hasMoreVlq(reader, semi)) {
|
|
74
|
-
sourcesIndex = decodeInteger(reader, sourcesIndex);
|
|
75
|
-
sourceLine = decodeInteger(reader, sourceLine);
|
|
76
|
-
sourceColumn = decodeInteger(reader, sourceColumn);
|
|
77
|
-
if (hasMoreVlq(reader, semi)) {
|
|
78
|
-
namesIndex = decodeInteger(reader, namesIndex);
|
|
79
|
-
seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex];
|
|
80
|
-
} else {
|
|
81
|
-
seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
seg = [genColumn];
|
|
85
|
-
}
|
|
86
|
-
line.push(seg);
|
|
87
|
-
reader.pos++;
|
|
88
|
-
}
|
|
89
|
-
if (!sorted) sort(line);
|
|
90
|
-
decoded.push(line);
|
|
91
|
-
reader.pos = semi + 1;
|
|
92
|
-
} while (reader.pos <= length);
|
|
93
|
-
return decoded;
|
|
94
|
-
}
|
|
95
|
-
function sort(line) {
|
|
96
|
-
line.sort(sortComparator);
|
|
97
|
-
}
|
|
98
|
-
function sortComparator(a, b) {
|
|
99
|
-
return a[0] - b[0];
|
|
100
|
-
}
|
|
101
|
-
var COLUMN = 0;
|
|
102
|
-
var SOURCES_INDEX = 1;
|
|
103
|
-
var SOURCE_LINE = 2;
|
|
104
|
-
var SOURCE_COLUMN = 3;
|
|
105
|
-
var NAMES_INDEX = 4;
|
|
106
|
-
var found = false;
|
|
107
|
-
function binarySearch(haystack, needle, low, high) {
|
|
108
|
-
while (low <= high) {
|
|
109
|
-
const mid = low + (high - low >> 1);
|
|
110
|
-
const cmp = haystack[mid][COLUMN] - needle;
|
|
111
|
-
if (cmp === 0) {
|
|
112
|
-
found = true;
|
|
113
|
-
return mid;
|
|
114
|
-
}
|
|
115
|
-
if (cmp < 0) {
|
|
116
|
-
low = mid + 1;
|
|
117
|
-
} else {
|
|
118
|
-
high = mid - 1;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
found = false;
|
|
122
|
-
return low - 1;
|
|
123
|
-
}
|
|
124
|
-
function upperBound(haystack, needle, index) {
|
|
125
|
-
for (let i = index + 1; i < haystack.length; index = i++) {
|
|
126
|
-
if (haystack[i][COLUMN] !== needle) break;
|
|
127
|
-
}
|
|
128
|
-
return index;
|
|
129
|
-
}
|
|
130
|
-
function lowerBound(haystack, needle, index) {
|
|
131
|
-
for (let i = index - 1; i >= 0; index = i--) {
|
|
132
|
-
if (haystack[i][COLUMN] !== needle) break;
|
|
133
|
-
}
|
|
134
|
-
return index;
|
|
135
|
-
}
|
|
136
|
-
function memoizedBinarySearch(haystack, needle, state, key) {
|
|
137
|
-
const { lastKey, lastNeedle, lastIndex } = state;
|
|
138
|
-
let low = 0;
|
|
139
|
-
let high = haystack.length - 1;
|
|
140
|
-
if (key === lastKey) {
|
|
141
|
-
if (needle === lastNeedle) {
|
|
142
|
-
found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
|
|
143
|
-
return lastIndex;
|
|
144
|
-
}
|
|
145
|
-
if (needle >= lastNeedle) {
|
|
146
|
-
low = lastIndex === -1 ? 0 : lastIndex;
|
|
147
|
-
} else {
|
|
148
|
-
high = lastIndex;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
state.lastKey = key;
|
|
152
|
-
state.lastNeedle = needle;
|
|
153
|
-
return state.lastIndex = binarySearch(haystack, needle, low, high);
|
|
154
|
-
}
|
|
155
|
-
var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
|
|
156
|
-
var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
|
|
157
|
-
var LEAST_UPPER_BOUND = -1;
|
|
158
|
-
var GREATEST_LOWER_BOUND = 1;
|
|
159
|
-
function cast(map) {
|
|
160
|
-
return map;
|
|
161
|
-
}
|
|
162
|
-
function decodedMappings(map) {
|
|
163
|
-
var _a;
|
|
164
|
-
return (_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded));
|
|
165
|
-
}
|
|
166
|
-
function originalPositionFor(map, needle) {
|
|
167
|
-
let { line, column, bias } = needle;
|
|
168
|
-
line--;
|
|
169
|
-
if (line < 0) throw new Error(LINE_GTR_ZERO);
|
|
170
|
-
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
|
171
|
-
const decoded = decodedMappings(map);
|
|
172
|
-
if (line >= decoded.length) return OMapping(null, null, null, null);
|
|
173
|
-
const segments = decoded[line];
|
|
174
|
-
const index = traceSegmentInternal(
|
|
175
|
-
segments,
|
|
176
|
-
cast(map)._decodedMemo,
|
|
177
|
-
line,
|
|
178
|
-
column,
|
|
179
|
-
bias || GREATEST_LOWER_BOUND
|
|
180
|
-
);
|
|
181
|
-
if (index === -1) return OMapping(null, null, null, null);
|
|
182
|
-
const segment = segments[index];
|
|
183
|
-
if (segment.length === 1) return OMapping(null, null, null, null);
|
|
184
|
-
const { names, resolvedSources } = map;
|
|
185
|
-
return OMapping(
|
|
186
|
-
resolvedSources[segment[SOURCES_INDEX]],
|
|
187
|
-
segment[SOURCE_LINE] + 1,
|
|
188
|
-
segment[SOURCE_COLUMN],
|
|
189
|
-
segment.length === 5 ? names[segment[NAMES_INDEX]] : null
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
function OMapping(source, line, column, name) {
|
|
193
|
-
return { source, line, column, name };
|
|
194
|
-
}
|
|
195
|
-
function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
196
|
-
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
197
|
-
if (found) {
|
|
198
|
-
index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
|
|
199
|
-
} else if (bias === LEAST_UPPER_BOUND) index++;
|
|
200
|
-
if (index === -1 || index === segments.length) return -1;
|
|
201
|
-
return index;
|
|
202
|
-
}
|
|
203
|
-
function notNullish(v) {
|
|
204
|
-
return v != null;
|
|
205
|
-
}
|
|
206
|
-
function isPrimitive(value) {
|
|
207
|
-
return value === null || typeof value !== "function" && typeof value !== "object";
|
|
208
|
-
}
|
|
209
|
-
function isObject(item) {
|
|
210
|
-
return item != null && typeof item === "object" && !Array.isArray(item);
|
|
211
|
-
}
|
|
212
|
-
function getCallLastIndex(code) {
|
|
213
|
-
let charIndex = -1;
|
|
214
|
-
let inString = null;
|
|
215
|
-
let startedBracers = 0;
|
|
216
|
-
let endedBracers = 0;
|
|
217
|
-
let beforeChar = null;
|
|
218
|
-
while (charIndex <= code.length) {
|
|
219
|
-
beforeChar = code[charIndex];
|
|
220
|
-
charIndex++;
|
|
221
|
-
const char = code[charIndex];
|
|
222
|
-
const isCharString = char === '"' || char === "'" || char === "`";
|
|
223
|
-
if (isCharString && beforeChar !== "\\") {
|
|
224
|
-
if (inString === char) {
|
|
225
|
-
inString = null;
|
|
226
|
-
} else if (!inString) {
|
|
227
|
-
inString = char;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
if (!inString) {
|
|
231
|
-
if (char === "(") {
|
|
232
|
-
startedBracers++;
|
|
233
|
-
}
|
|
234
|
-
if (char === ")") {
|
|
235
|
-
endedBracers++;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
if (startedBracers && endedBracers && startedBracers === endedBracers) {
|
|
239
|
-
return charIndex;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
244
|
-
const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
|
|
245
|
-
const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
|
|
246
|
-
const stackIgnorePatterns = [
|
|
247
|
-
"node:internal",
|
|
248
|
-
/\/packages\/\w+\/dist\//,
|
|
249
|
-
/\/@vitest\/\w+\/dist\//,
|
|
250
|
-
"/vitest/dist/",
|
|
251
|
-
"/vitest/src/",
|
|
252
|
-
"/node_modules/chai/",
|
|
253
|
-
"/node_modules/tinyspy/",
|
|
254
|
-
"/vite/dist/node/module-runner",
|
|
255
|
-
"/rolldown-vite/dist/node/module-runner",
|
|
256
|
-
"/deps/chunk-",
|
|
257
|
-
"/deps/@vitest",
|
|
258
|
-
"/deps/loupe",
|
|
259
|
-
"/deps/chai",
|
|
260
|
-
"/browser-playwright/dist/locators.js",
|
|
261
|
-
"/browser-webdriverio/dist/locators.js",
|
|
262
|
-
"/browser-preview/dist/locators.js",
|
|
263
|
-
/node:\w+/,
|
|
264
|
-
/__vitest_test__/,
|
|
265
|
-
/__vitest_browser__/,
|
|
266
|
-
/\/deps\/vitest_/
|
|
267
|
-
];
|
|
268
|
-
function extractLocation(urlLike) {
|
|
269
|
-
if (!urlLike.includes(":")) {
|
|
270
|
-
return [urlLike];
|
|
271
|
-
}
|
|
272
|
-
const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
|
|
273
|
-
const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, ""));
|
|
274
|
-
if (!parts) {
|
|
275
|
-
return [urlLike];
|
|
276
|
-
}
|
|
277
|
-
let url = parts[1];
|
|
278
|
-
if (url.startsWith("async ")) {
|
|
279
|
-
url = url.slice(6);
|
|
280
|
-
}
|
|
281
|
-
if (url.startsWith("http:") || url.startsWith("https:")) {
|
|
282
|
-
const urlObj = new URL(url);
|
|
283
|
-
urlObj.searchParams.delete("import");
|
|
284
|
-
urlObj.searchParams.delete("browserv");
|
|
285
|
-
url = urlObj.pathname + urlObj.hash + urlObj.search;
|
|
286
|
-
}
|
|
287
|
-
if (url.startsWith("/@fs/")) {
|
|
288
|
-
const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
|
|
289
|
-
url = url.slice(isWindows ? 5 : 4);
|
|
290
|
-
}
|
|
291
|
-
return [
|
|
292
|
-
url,
|
|
293
|
-
parts[2] || void 0,
|
|
294
|
-
parts[3] || void 0
|
|
295
|
-
];
|
|
296
|
-
}
|
|
297
|
-
function parseSingleFFOrSafariStack(raw) {
|
|
298
|
-
let line = raw.trim();
|
|
299
|
-
if (SAFARI_NATIVE_CODE_REGEXP.test(line)) {
|
|
300
|
-
return null;
|
|
301
|
-
}
|
|
302
|
-
if (line.includes(" > eval")) {
|
|
303
|
-
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1");
|
|
304
|
-
}
|
|
305
|
-
if (!line.includes("@")) {
|
|
306
|
-
return null;
|
|
307
|
-
}
|
|
308
|
-
let atIndex = -1;
|
|
309
|
-
let locationPart = "";
|
|
310
|
-
let functionName;
|
|
311
|
-
for (let i = 0; i < line.length; i++) {
|
|
312
|
-
if (line[i] === "@") {
|
|
313
|
-
const candidateLocation = line.slice(i + 1);
|
|
314
|
-
if (candidateLocation.includes(":") && candidateLocation.length >= 3) {
|
|
315
|
-
atIndex = i;
|
|
316
|
-
locationPart = candidateLocation;
|
|
317
|
-
functionName = i > 0 ? line.slice(0, i) : void 0;
|
|
318
|
-
break;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
if (atIndex === -1 || !locationPart.includes(":") || locationPart.length < 3) {
|
|
323
|
-
return null;
|
|
324
|
-
}
|
|
325
|
-
const [url, lineNumber, columnNumber] = extractLocation(locationPart);
|
|
326
|
-
if (!url || !lineNumber || !columnNumber) {
|
|
327
|
-
return null;
|
|
328
|
-
}
|
|
329
|
-
return {
|
|
330
|
-
file: url,
|
|
331
|
-
method: functionName || "",
|
|
332
|
-
line: Number.parseInt(lineNumber),
|
|
333
|
-
column: Number.parseInt(columnNumber)
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
function parseSingleV8Stack(raw) {
|
|
337
|
-
let line = raw.trim();
|
|
338
|
-
if (!CHROME_IE_STACK_REGEXP.test(line)) {
|
|
339
|
-
return null;
|
|
340
|
-
}
|
|
341
|
-
if (line.includes("(eval ")) {
|
|
342
|
-
line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
|
|
343
|
-
}
|
|
344
|
-
let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
|
|
345
|
-
const location = sanitizedLine.match(/ (\(.+\)$)/);
|
|
346
|
-
sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
|
|
347
|
-
const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
|
|
348
|
-
let method = location && sanitizedLine || "";
|
|
349
|
-
let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
|
|
350
|
-
if (!file || !lineNumber || !columnNumber) {
|
|
351
|
-
return null;
|
|
352
|
-
}
|
|
353
|
-
if (method.startsWith("async ")) {
|
|
354
|
-
method = method.slice(6);
|
|
355
|
-
}
|
|
356
|
-
if (file.startsWith("file://")) {
|
|
357
|
-
file = file.slice(7);
|
|
358
|
-
}
|
|
359
|
-
file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve(file);
|
|
360
|
-
if (method) {
|
|
361
|
-
method = method.replace(/__vite_ssr_import_\d+__\./g, "").replace(/(Object\.)?__vite_ssr_export_default__\s?/g, "");
|
|
362
|
-
}
|
|
363
|
-
return {
|
|
364
|
-
method,
|
|
365
|
-
file,
|
|
366
|
-
line: Number.parseInt(lineNumber),
|
|
367
|
-
column: Number.parseInt(columnNumber)
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
function parseStacktrace(stack, options = {}) {
|
|
371
|
-
const { ignoreStackEntries = stackIgnorePatterns } = options;
|
|
372
|
-
const stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
|
|
373
|
-
return stacks.map((stack2) => {
|
|
374
|
-
var _options$getSourceMap;
|
|
375
|
-
if (options.getUrlId) {
|
|
376
|
-
stack2.file = options.getUrlId(stack2.file);
|
|
377
|
-
}
|
|
378
|
-
const map = (_options$getSourceMap = options.getSourceMap) === null || _options$getSourceMap === void 0 ? void 0 : _options$getSourceMap.call(options, stack2.file);
|
|
379
|
-
if (!map || typeof map !== "object" || !map.version) {
|
|
380
|
-
return shouldFilter(ignoreStackEntries, stack2.file) ? null : stack2;
|
|
381
|
-
}
|
|
382
|
-
const traceMap = new DecodedMap(map, stack2.file);
|
|
383
|
-
const position = getOriginalPosition(traceMap, stack2);
|
|
384
|
-
if (!position) {
|
|
385
|
-
return stack2;
|
|
386
|
-
}
|
|
387
|
-
const { line, column, source, name } = position;
|
|
388
|
-
let file = source || stack2.file;
|
|
389
|
-
if (file.match(/\/\w:\//)) {
|
|
390
|
-
file = file.slice(1);
|
|
391
|
-
}
|
|
392
|
-
if (shouldFilter(ignoreStackEntries, file)) {
|
|
393
|
-
return null;
|
|
394
|
-
}
|
|
395
|
-
if (line != null && column != null) {
|
|
396
|
-
return {
|
|
397
|
-
line,
|
|
398
|
-
column,
|
|
399
|
-
file,
|
|
400
|
-
method: name || stack2.method
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
return stack2;
|
|
404
|
-
}).filter((s) => s != null);
|
|
405
|
-
}
|
|
406
|
-
function shouldFilter(ignoreStackEntries, file) {
|
|
407
|
-
return ignoreStackEntries.some((p) => file.match(p));
|
|
408
|
-
}
|
|
409
|
-
function parseFFOrSafariStackTrace(stack) {
|
|
410
|
-
return stack.split("\n").map((line) => parseSingleFFOrSafariStack(line)).filter(notNullish);
|
|
411
|
-
}
|
|
412
|
-
function parseV8Stacktrace(stack) {
|
|
413
|
-
return stack.split("\n").map((line) => parseSingleV8Stack(line)).filter(notNullish);
|
|
414
|
-
}
|
|
415
|
-
function parseErrorStacktrace(e, options = {}) {
|
|
416
|
-
if (!e || isPrimitive(e)) {
|
|
417
|
-
return [];
|
|
418
|
-
}
|
|
419
|
-
if ("stacks" in e && e.stacks) {
|
|
420
|
-
return e.stacks;
|
|
421
|
-
}
|
|
422
|
-
const stackStr = e.stack || "";
|
|
423
|
-
let stackFrames = typeof stackStr === "string" ? parseStacktrace(stackStr, options) : [];
|
|
424
|
-
if (!stackFrames.length) {
|
|
425
|
-
const e_ = e;
|
|
426
|
-
if (e_.fileName != null && e_.lineNumber != null && e_.columnNumber != null) {
|
|
427
|
-
stackFrames = parseStacktrace(`${e_.fileName}:${e_.lineNumber}:${e_.columnNumber}`, options);
|
|
428
|
-
}
|
|
429
|
-
if (e_.sourceURL != null && e_.line != null && e_._column != null) {
|
|
430
|
-
stackFrames = parseStacktrace(`${e_.sourceURL}:${e_.line}:${e_.column}`, options);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
if (options.frameFilter) {
|
|
434
|
-
stackFrames = stackFrames.filter((f) => options.frameFilter(e, f) !== false);
|
|
435
|
-
}
|
|
436
|
-
e.stacks = stackFrames;
|
|
437
|
-
return stackFrames;
|
|
438
|
-
}
|
|
439
|
-
class DecodedMap {
|
|
440
|
-
constructor(map, from) {
|
|
441
|
-
__publicField(this, "_encoded");
|
|
442
|
-
__publicField(this, "_decoded");
|
|
443
|
-
__publicField(this, "_decodedMemo");
|
|
444
|
-
__publicField(this, "url");
|
|
445
|
-
__publicField(this, "version");
|
|
446
|
-
__publicField(this, "names", []);
|
|
447
|
-
__publicField(this, "resolvedSources");
|
|
448
|
-
this.map = map;
|
|
449
|
-
const { mappings, names, sources } = map;
|
|
450
|
-
this.version = map.version;
|
|
451
|
-
this.names = names || [];
|
|
452
|
-
this._encoded = mappings || "";
|
|
453
|
-
this._decodedMemo = memoizedState();
|
|
454
|
-
this.url = from;
|
|
455
|
-
this.resolvedSources = (sources || []).map((s) => resolve(s || "", from));
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
function memoizedState() {
|
|
459
|
-
return {
|
|
460
|
-
lastKey: -1,
|
|
461
|
-
lastNeedle: -1,
|
|
462
|
-
lastIndex: -1
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
function getOriginalPosition(map, needle) {
|
|
466
|
-
const result = originalPositionFor(map, needle);
|
|
467
|
-
if (result.column == null) {
|
|
468
|
-
return null;
|
|
469
|
-
}
|
|
470
|
-
return result;
|
|
471
|
-
}
|
|
472
|
-
const lineSplitRE = /\r?\n/;
|
|
473
|
-
function positionToOffset(source, lineNumber, columnNumber) {
|
|
474
|
-
const lines = source.split(lineSplitRE);
|
|
475
|
-
const nl = /\r\n/.test(source) ? 2 : 1;
|
|
476
|
-
let start = 0;
|
|
477
|
-
if (lineNumber > lines.length) {
|
|
478
|
-
return source.length;
|
|
479
|
-
}
|
|
480
|
-
for (let i = 0; i < lineNumber - 1; i++) {
|
|
481
|
-
start += lines[i].length + nl;
|
|
482
|
-
}
|
|
483
|
-
return start + columnNumber;
|
|
484
|
-
}
|
|
485
|
-
function offsetToLineNumber(source, offset) {
|
|
486
|
-
if (offset > source.length) {
|
|
487
|
-
throw new Error(`offset is longer than source length! offset ${offset} > length ${source.length}`);
|
|
488
|
-
}
|
|
489
|
-
const lines = source.split(lineSplitRE);
|
|
490
|
-
const nl = /\r\n/.test(source) ? 2 : 1;
|
|
491
|
-
let counted = 0;
|
|
492
|
-
let line = 0;
|
|
493
|
-
for (; line < lines.length; line++) {
|
|
494
|
-
const lineLength = lines[line].length + nl;
|
|
495
|
-
if (counted + lineLength >= offset) {
|
|
496
|
-
break;
|
|
497
|
-
}
|
|
498
|
-
counted += lineLength;
|
|
499
|
-
}
|
|
500
|
-
return line + 1;
|
|
501
|
-
}
|
|
502
|
-
async function saveInlineSnapshots(environment, snapshots) {
|
|
503
|
-
const MagicString = (await import("../../../../../magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs")).default;
|
|
504
|
-
const files = new Set(snapshots.map((i) => i.file));
|
|
505
|
-
await Promise.all(Array.from(files).map(async (file) => {
|
|
506
|
-
const snaps = snapshots.filter((i) => i.file === file);
|
|
507
|
-
const code = await environment.readSnapshotFile(file);
|
|
508
|
-
const s = new MagicString(code);
|
|
509
|
-
for (const snap of snaps) {
|
|
510
|
-
const index = positionToOffset(code, snap.line, snap.column);
|
|
511
|
-
replaceInlineSnap(code, s, index, snap.snapshot);
|
|
512
|
-
}
|
|
513
|
-
const transformed = s.toString();
|
|
514
|
-
if (transformed !== code) {
|
|
515
|
-
await environment.saveSnapshotFile(file, transformed);
|
|
516
|
-
}
|
|
517
|
-
}));
|
|
518
|
-
}
|
|
519
|
-
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]))*\{/;
|
|
520
|
-
function replaceObjectSnap(code, s, index, newSnap) {
|
|
521
|
-
let _code = code.slice(index);
|
|
522
|
-
const startMatch = startObjectRegex.exec(_code);
|
|
523
|
-
if (!startMatch) {
|
|
524
|
-
return false;
|
|
525
|
-
}
|
|
526
|
-
_code = _code.slice(startMatch.index);
|
|
527
|
-
let callEnd = getCallLastIndex(_code);
|
|
528
|
-
if (callEnd === null) {
|
|
529
|
-
return false;
|
|
530
|
-
}
|
|
531
|
-
callEnd += index + startMatch.index;
|
|
532
|
-
const shapeStart = index + startMatch.index + startMatch[0].length;
|
|
533
|
-
const shapeEnd = getObjectShapeEndIndex(code, shapeStart);
|
|
534
|
-
const snap = `, ${prepareSnapString(newSnap, code, index)}`;
|
|
535
|
-
if (shapeEnd === callEnd) {
|
|
536
|
-
s.appendLeft(callEnd, snap);
|
|
537
|
-
} else {
|
|
538
|
-
s.overwrite(shapeEnd, callEnd, snap);
|
|
539
|
-
}
|
|
540
|
-
return true;
|
|
541
|
-
}
|
|
542
|
-
function getObjectShapeEndIndex(code, index) {
|
|
543
|
-
let startBraces = 1;
|
|
544
|
-
let endBraces = 0;
|
|
545
|
-
while (startBraces !== endBraces && index < code.length) {
|
|
546
|
-
const s = code[index++];
|
|
547
|
-
if (s === "{") {
|
|
548
|
-
startBraces++;
|
|
549
|
-
} else if (s === "}") {
|
|
550
|
-
endBraces++;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
return index;
|
|
554
|
-
}
|
|
555
|
-
function prepareSnapString(snap, source, index) {
|
|
556
|
-
const lineNumber = offsetToLineNumber(source, index);
|
|
557
|
-
const line = source.split(lineSplitRE)[lineNumber - 1];
|
|
558
|
-
const indent = line.match(/^\s*/)[0] || "";
|
|
559
|
-
const indentNext = indent.includes(" ") ? `${indent} ` : `${indent} `;
|
|
560
|
-
const lines = snap.trim().replace(/\\/g, "\\\\").split(/\n/g);
|
|
561
|
-
const isOneline = lines.length <= 1;
|
|
562
|
-
const quote = "`";
|
|
563
|
-
if (isOneline) {
|
|
564
|
-
return `${quote}${lines.join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}${quote}`;
|
|
565
|
-
}
|
|
566
|
-
return `${quote}
|
|
567
|
-
${lines.map((i) => i ? indentNext + i : "").join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}
|
|
568
|
-
${indent}${quote}`;
|
|
569
|
-
}
|
|
570
|
-
const toMatchInlineName = "toMatchInlineSnapshot";
|
|
571
|
-
const toThrowErrorMatchingInlineName = "toThrowErrorMatchingInlineSnapshot";
|
|
572
|
-
function getCodeStartingAtIndex(code, index) {
|
|
573
|
-
const indexInline = index - toMatchInlineName.length;
|
|
574
|
-
if (code.slice(indexInline, index) === toMatchInlineName) {
|
|
575
|
-
return {
|
|
576
|
-
code: code.slice(indexInline),
|
|
577
|
-
index: indexInline
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
const indexThrowInline = index - toThrowErrorMatchingInlineName.length;
|
|
581
|
-
if (code.slice(index - indexThrowInline, index) === toThrowErrorMatchingInlineName) {
|
|
582
|
-
return {
|
|
583
|
-
code: code.slice(index - indexThrowInline),
|
|
584
|
-
index: index - indexThrowInline
|
|
585
|
-
};
|
|
586
|
-
}
|
|
587
|
-
return {
|
|
588
|
-
code: code.slice(index),
|
|
589
|
-
index
|
|
590
|
-
};
|
|
591
|
-
}
|
|
592
|
-
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$]*(['"`)])/;
|
|
593
|
-
function replaceInlineSnap(code, s, currentIndex, newSnap) {
|
|
594
|
-
const { code: codeStartingAtIndex, index } = getCodeStartingAtIndex(code, currentIndex);
|
|
595
|
-
const startMatch = startRegex.exec(codeStartingAtIndex);
|
|
596
|
-
const firstKeywordMatch = /toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot/.exec(codeStartingAtIndex);
|
|
597
|
-
if (!startMatch || startMatch.index !== (firstKeywordMatch === null || firstKeywordMatch === void 0 ? void 0 : firstKeywordMatch.index)) {
|
|
598
|
-
return replaceObjectSnap(code, s, index, newSnap);
|
|
599
|
-
}
|
|
600
|
-
const quote = startMatch[1];
|
|
601
|
-
const startIndex = index + startMatch.index + startMatch[0].length;
|
|
602
|
-
const snapString = prepareSnapString(newSnap, code, index);
|
|
603
|
-
if (quote === ")") {
|
|
604
|
-
s.appendRight(startIndex - 1, snapString);
|
|
605
|
-
return true;
|
|
606
|
-
}
|
|
607
|
-
const quoteEndRE = new RegExp(`(?:^|[^\\\\])${quote}`);
|
|
608
|
-
const endMatch = quoteEndRE.exec(code.slice(startIndex));
|
|
609
|
-
if (!endMatch) {
|
|
610
|
-
return false;
|
|
611
|
-
}
|
|
612
|
-
const endIndex = startIndex + endMatch.index + endMatch[0].length;
|
|
613
|
-
s.overwrite(startIndex - 1, endIndex, snapString);
|
|
614
|
-
return true;
|
|
615
|
-
}
|
|
616
|
-
const INDENTATION_REGEX = /^([^\S\n]*)\S/m;
|
|
617
|
-
function stripSnapshotIndentation(inlineSnapshot) {
|
|
618
|
-
var _lines$at;
|
|
619
|
-
const match = inlineSnapshot.match(INDENTATION_REGEX);
|
|
620
|
-
if (!match || !match[1]) {
|
|
621
|
-
return inlineSnapshot;
|
|
622
|
-
}
|
|
623
|
-
const indentation = match[1];
|
|
624
|
-
const lines = inlineSnapshot.split(/\n/g);
|
|
625
|
-
if (lines.length <= 2) {
|
|
626
|
-
return inlineSnapshot;
|
|
627
|
-
}
|
|
628
|
-
if (lines[0].trim() !== "" || ((_lines$at = lines.at(-1)) === null || _lines$at === void 0 ? void 0 : _lines$at.trim()) !== "") {
|
|
629
|
-
return inlineSnapshot;
|
|
630
|
-
}
|
|
631
|
-
for (let i = 1; i < lines.length - 1; i++) {
|
|
632
|
-
if (lines[i] !== "") {
|
|
633
|
-
if (lines[i].indexOf(indentation) !== 0) {
|
|
634
|
-
return inlineSnapshot;
|
|
635
|
-
}
|
|
636
|
-
lines[i] = lines[i].substring(indentation.length);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
lines[lines.length - 1] = "";
|
|
640
|
-
inlineSnapshot = lines.join("\n");
|
|
641
|
-
return inlineSnapshot;
|
|
642
|
-
}
|
|
643
|
-
async function saveRawSnapshots(environment, snapshots) {
|
|
644
|
-
await Promise.all(snapshots.map(async (snap) => {
|
|
645
|
-
if (!snap.readonly) {
|
|
646
|
-
await environment.saveSnapshotFile(snap.file, snap.snapshot);
|
|
647
|
-
}
|
|
648
|
-
}));
|
|
649
|
-
}
|
|
650
|
-
function getDefaultExportFromCjs(x) {
|
|
651
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
652
|
-
}
|
|
653
|
-
var naturalCompare$1 = { exports: {} };
|
|
654
|
-
var hasRequiredNaturalCompare;
|
|
655
|
-
function requireNaturalCompare() {
|
|
656
|
-
if (hasRequiredNaturalCompare) return naturalCompare$1.exports;
|
|
657
|
-
hasRequiredNaturalCompare = 1;
|
|
658
|
-
var naturalCompare2 = function(a, b) {
|
|
659
|
-
var i, codeA, codeB = 1, posA = 0, posB = 0, alphabet = String.alphabet;
|
|
660
|
-
function getCode(str, pos, code) {
|
|
661
|
-
if (code) {
|
|
662
|
-
for (i = pos; code = getCode(str, i), code < 76 && code > 65; ) ++i;
|
|
663
|
-
return +str.slice(pos - 1, i);
|
|
664
|
-
}
|
|
665
|
-
code = alphabet && alphabet.indexOf(str.charAt(pos));
|
|
666
|
-
return code > -1 ? code + 76 : (code = str.charCodeAt(pos) || 0, code < 45 || code > 127) ? code : code < 46 ? 65 : code < 48 ? code - 1 : code < 58 ? code + 18 : code < 65 ? code - 11 : code < 91 ? code + 11 : code < 97 ? code - 37 : code < 123 ? code + 5 : code - 63;
|
|
667
|
-
}
|
|
668
|
-
if ((a += "") != (b += "")) for (; codeB; ) {
|
|
669
|
-
codeA = getCode(a, posA++);
|
|
670
|
-
codeB = getCode(b, posB++);
|
|
671
|
-
if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
|
|
672
|
-
codeA = getCode(a, posA, posA);
|
|
673
|
-
codeB = getCode(b, posB, posA = i);
|
|
674
|
-
posB = i;
|
|
675
|
-
}
|
|
676
|
-
if (codeA != codeB) return codeA < codeB ? -1 : 1;
|
|
677
|
-
}
|
|
678
|
-
return 0;
|
|
679
|
-
};
|
|
680
|
-
try {
|
|
681
|
-
naturalCompare$1.exports = naturalCompare2;
|
|
682
|
-
} catch (e) {
|
|
683
|
-
String.naturalCompare = naturalCompare2;
|
|
684
|
-
}
|
|
685
|
-
return naturalCompare$1.exports;
|
|
686
|
-
}
|
|
687
|
-
var naturalCompareExports = requireNaturalCompare();
|
|
688
|
-
var naturalCompare = /* @__PURE__ */ getDefaultExportFromCjs(naturalCompareExports);
|
|
689
|
-
const serialize$1 = (val, config, indentation, depth, refs, printer) => {
|
|
690
|
-
const name = val.getMockName();
|
|
691
|
-
const nameString = name === "vi.fn()" ? "" : ` ${name}`;
|
|
692
|
-
let callsString = "";
|
|
693
|
-
if (val.mock.calls.length !== 0) {
|
|
694
|
-
const indentationNext = indentation + config.indent;
|
|
695
|
-
callsString = ` {${config.spacingOuter}${indentationNext}"calls": ${printer(val.mock.calls, config, indentationNext, depth, refs)}${config.min ? ", " : ","}${config.spacingOuter}${indentationNext}"results": ${printer(val.mock.results, config, indentationNext, depth, refs)}${config.min ? "" : ","}${config.spacingOuter}${indentation}}`;
|
|
696
|
-
}
|
|
697
|
-
return `[MockFunction${nameString}]${callsString}`;
|
|
698
|
-
};
|
|
699
|
-
const test = (val) => val && !!val._isMockFunction;
|
|
700
|
-
const plugin = {
|
|
701
|
-
serialize: serialize$1,
|
|
702
|
-
test
|
|
703
|
-
};
|
|
704
|
-
const { DOMCollection, DOMElement, Immutable, ReactElement, ReactTestComponent, AsymmetricMatcher } = plugins;
|
|
705
|
-
let PLUGINS = [
|
|
706
|
-
ReactTestComponent,
|
|
707
|
-
ReactElement,
|
|
708
|
-
DOMElement,
|
|
709
|
-
DOMCollection,
|
|
710
|
-
Immutable,
|
|
711
|
-
AsymmetricMatcher,
|
|
712
|
-
plugin
|
|
713
|
-
];
|
|
714
|
-
function addSerializer(plugin2) {
|
|
715
|
-
PLUGINS = [plugin2].concat(PLUGINS);
|
|
716
|
-
}
|
|
717
|
-
function getSerializers() {
|
|
718
|
-
return PLUGINS;
|
|
719
|
-
}
|
|
720
|
-
function testNameToKey(testName, count) {
|
|
721
|
-
return `${testName} ${count}`;
|
|
722
|
-
}
|
|
723
|
-
function keyToTestName(key) {
|
|
724
|
-
if (!/ \d+$/.test(key)) {
|
|
725
|
-
throw new Error("Snapshot keys must end with a number.");
|
|
726
|
-
}
|
|
727
|
-
return key.replace(/ \d+$/, "");
|
|
728
|
-
}
|
|
729
|
-
function getSnapshotData(content, options) {
|
|
730
|
-
const update = options.updateSnapshot;
|
|
731
|
-
const data = /* @__PURE__ */ Object.create(null);
|
|
732
|
-
let snapshotContents = "";
|
|
733
|
-
let dirty = false;
|
|
734
|
-
if (content != null) {
|
|
735
|
-
try {
|
|
736
|
-
snapshotContents = content;
|
|
737
|
-
const populate = new Function("exports", snapshotContents);
|
|
738
|
-
populate(data);
|
|
739
|
-
} catch {
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
const isInvalid = snapshotContents;
|
|
743
|
-
if ((update === "all" || update === "new") && isInvalid) {
|
|
744
|
-
dirty = true;
|
|
745
|
-
}
|
|
746
|
-
return {
|
|
747
|
-
data,
|
|
748
|
-
dirty
|
|
749
|
-
};
|
|
750
|
-
}
|
|
751
|
-
function addExtraLineBreaks(string) {
|
|
752
|
-
return string.includes("\n") ? `
|
|
753
|
-
${string}
|
|
754
|
-
` : string;
|
|
755
|
-
}
|
|
756
|
-
function removeExtraLineBreaks(string) {
|
|
757
|
-
return string.length > 2 && string[0] === "\n" && string.endsWith("\n") ? string.slice(1, -1) : string;
|
|
758
|
-
}
|
|
759
|
-
const escapeRegex = true;
|
|
760
|
-
const printFunctionName = false;
|
|
761
|
-
function serialize(val, indent = 2, formatOverrides = {}) {
|
|
762
|
-
return normalizeNewlines(format(val, {
|
|
763
|
-
escapeRegex,
|
|
764
|
-
indent,
|
|
765
|
-
plugins: getSerializers(),
|
|
766
|
-
printFunctionName,
|
|
767
|
-
...formatOverrides
|
|
768
|
-
}));
|
|
769
|
-
}
|
|
770
|
-
function escapeBacktickString(str) {
|
|
771
|
-
return str.replace(/`|\\|\$\{/g, "\\$&");
|
|
772
|
-
}
|
|
773
|
-
function printBacktickString(str) {
|
|
774
|
-
return `\`${escapeBacktickString(str)}\``;
|
|
775
|
-
}
|
|
776
|
-
function normalizeNewlines(string) {
|
|
777
|
-
return string.replace(/\r\n|\r/g, "\n");
|
|
778
|
-
}
|
|
779
|
-
async function saveSnapshotFile(environment, snapshotData, snapshotPath) {
|
|
780
|
-
const snapshots = Object.keys(snapshotData).sort(naturalCompare).map((key) => `exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`);
|
|
781
|
-
const content = `${environment.getHeader()}
|
|
782
|
-
|
|
783
|
-
${snapshots.join("\n\n")}
|
|
784
|
-
`;
|
|
785
|
-
const oldContent = await environment.readSnapshotFile(snapshotPath);
|
|
786
|
-
const skipWriting = oldContent != null && oldContent === content;
|
|
787
|
-
if (skipWriting) {
|
|
788
|
-
return;
|
|
789
|
-
}
|
|
790
|
-
await environment.saveSnapshotFile(snapshotPath, content);
|
|
791
|
-
}
|
|
792
|
-
function deepMergeArray(target = [], source = []) {
|
|
793
|
-
const mergedOutput = Array.from(target);
|
|
794
|
-
source.forEach((sourceElement, index) => {
|
|
795
|
-
const targetElement = mergedOutput[index];
|
|
796
|
-
if (Array.isArray(target[index])) {
|
|
797
|
-
mergedOutput[index] = deepMergeArray(target[index], sourceElement);
|
|
798
|
-
} else if (isObject(targetElement)) {
|
|
799
|
-
mergedOutput[index] = deepMergeSnapshot(target[index], sourceElement);
|
|
800
|
-
} else {
|
|
801
|
-
mergedOutput[index] = sourceElement;
|
|
802
|
-
}
|
|
803
|
-
});
|
|
804
|
-
return mergedOutput;
|
|
805
|
-
}
|
|
806
|
-
function deepMergeSnapshot(target, source) {
|
|
807
|
-
if (isObject(target) && isObject(source)) {
|
|
808
|
-
const mergedOutput = { ...target };
|
|
809
|
-
Object.keys(source).forEach((key) => {
|
|
810
|
-
if (isObject(source[key]) && !source[key].$$typeof) {
|
|
811
|
-
if (!(key in target)) {
|
|
812
|
-
Object.assign(mergedOutput, { [key]: source[key] });
|
|
813
|
-
} else {
|
|
814
|
-
mergedOutput[key] = deepMergeSnapshot(target[key], source[key]);
|
|
815
|
-
}
|
|
816
|
-
} else if (Array.isArray(source[key])) {
|
|
817
|
-
mergedOutput[key] = deepMergeArray(target[key], source[key]);
|
|
818
|
-
} else {
|
|
819
|
-
Object.assign(mergedOutput, { [key]: source[key] });
|
|
820
|
-
}
|
|
821
|
-
});
|
|
822
|
-
return mergedOutput;
|
|
823
|
-
} else if (Array.isArray(target) && Array.isArray(source)) {
|
|
824
|
-
return deepMergeArray(target, source);
|
|
825
|
-
}
|
|
826
|
-
return target;
|
|
827
|
-
}
|
|
828
|
-
class DefaultMap extends Map {
|
|
829
|
-
constructor(defaultFn, entries) {
|
|
830
|
-
super(entries);
|
|
831
|
-
this.defaultFn = defaultFn;
|
|
832
|
-
}
|
|
833
|
-
get(key) {
|
|
834
|
-
if (!this.has(key)) {
|
|
835
|
-
this.set(key, this.defaultFn(key));
|
|
836
|
-
}
|
|
837
|
-
return super.get(key);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
class CounterMap extends DefaultMap {
|
|
841
|
-
constructor() {
|
|
842
|
-
super(() => 0);
|
|
843
|
-
// compat for jest-image-snapshot https://github.com/vitest-dev/vitest/issues/7322
|
|
844
|
-
// `valueOf` and `Snapshot.added` setter allows
|
|
845
|
-
// snapshotState.added = snapshotState.added + 1
|
|
846
|
-
// to function as
|
|
847
|
-
// snapshotState.added.total_ = snapshotState.added.total() + 1
|
|
848
|
-
__publicField(this, "_total");
|
|
849
|
-
}
|
|
850
|
-
valueOf() {
|
|
851
|
-
return this._total = this.total();
|
|
852
|
-
}
|
|
853
|
-
increment(key) {
|
|
854
|
-
if (typeof this._total !== "undefined") {
|
|
855
|
-
this._total++;
|
|
856
|
-
}
|
|
857
|
-
this.set(key, this.get(key) + 1);
|
|
858
|
-
}
|
|
859
|
-
total() {
|
|
860
|
-
if (typeof this._total !== "undefined") {
|
|
861
|
-
return this._total;
|
|
862
|
-
}
|
|
863
|
-
let total = 0;
|
|
864
|
-
for (const x of this.values()) {
|
|
865
|
-
total += x;
|
|
866
|
-
}
|
|
867
|
-
return total;
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
function isSameStackPosition(x, y) {
|
|
871
|
-
return x.file === y.file && x.column === y.column && x.line === y.line;
|
|
872
|
-
}
|
|
873
|
-
class SnapshotState {
|
|
874
|
-
constructor(testFilePath, snapshotPath, snapshotContent, options) {
|
|
875
|
-
__publicField(this, "_counters", new CounterMap());
|
|
876
|
-
__publicField(this, "_dirty");
|
|
877
|
-
__publicField(this, "_updateSnapshot");
|
|
878
|
-
__publicField(this, "_snapshotData");
|
|
879
|
-
__publicField(this, "_initialData");
|
|
880
|
-
__publicField(this, "_inlineSnapshots");
|
|
881
|
-
__publicField(this, "_inlineSnapshotStacks");
|
|
882
|
-
__publicField(this, "_testIdToKeys", new DefaultMap(() => []));
|
|
883
|
-
__publicField(this, "_rawSnapshots");
|
|
884
|
-
__publicField(this, "_uncheckedKeys");
|
|
885
|
-
__publicField(this, "_snapshotFormat");
|
|
886
|
-
__publicField(this, "_environment");
|
|
887
|
-
__publicField(this, "_fileExists");
|
|
888
|
-
__publicField(this, "expand");
|
|
889
|
-
// getter/setter for jest-image-snapshot compat
|
|
890
|
-
// https://github.com/vitest-dev/vitest/issues/7322
|
|
891
|
-
__publicField(this, "_added", new CounterMap());
|
|
892
|
-
__publicField(this, "_matched", new CounterMap());
|
|
893
|
-
__publicField(this, "_unmatched", new CounterMap());
|
|
894
|
-
__publicField(this, "_updated", new CounterMap());
|
|
895
|
-
this.testFilePath = testFilePath;
|
|
896
|
-
this.snapshotPath = snapshotPath;
|
|
897
|
-
const { data, dirty } = getSnapshotData(snapshotContent, options);
|
|
898
|
-
this._fileExists = snapshotContent != null;
|
|
899
|
-
this._initialData = { ...data };
|
|
900
|
-
this._snapshotData = { ...data };
|
|
901
|
-
this._dirty = dirty;
|
|
902
|
-
this._inlineSnapshots = [];
|
|
903
|
-
this._inlineSnapshotStacks = [];
|
|
904
|
-
this._rawSnapshots = [];
|
|
905
|
-
this._uncheckedKeys = new Set(Object.keys(this._snapshotData));
|
|
906
|
-
this.expand = options.expand || false;
|
|
907
|
-
this._updateSnapshot = options.updateSnapshot;
|
|
908
|
-
this._snapshotFormat = {
|
|
909
|
-
printBasicPrototype: false,
|
|
910
|
-
escapeString: false,
|
|
911
|
-
...options.snapshotFormat
|
|
912
|
-
};
|
|
913
|
-
this._environment = options.snapshotEnvironment;
|
|
914
|
-
}
|
|
915
|
-
get added() {
|
|
916
|
-
return this._added;
|
|
917
|
-
}
|
|
918
|
-
set added(value) {
|
|
919
|
-
this._added._total = value;
|
|
920
|
-
}
|
|
921
|
-
get matched() {
|
|
922
|
-
return this._matched;
|
|
923
|
-
}
|
|
924
|
-
set matched(value) {
|
|
925
|
-
this._matched._total = value;
|
|
926
|
-
}
|
|
927
|
-
get unmatched() {
|
|
928
|
-
return this._unmatched;
|
|
929
|
-
}
|
|
930
|
-
set unmatched(value) {
|
|
931
|
-
this._unmatched._total = value;
|
|
932
|
-
}
|
|
933
|
-
get updated() {
|
|
934
|
-
return this._updated;
|
|
935
|
-
}
|
|
936
|
-
set updated(value) {
|
|
937
|
-
this._updated._total = value;
|
|
938
|
-
}
|
|
939
|
-
static async create(testFilePath, options) {
|
|
940
|
-
const snapshotPath = await options.snapshotEnvironment.resolvePath(testFilePath);
|
|
941
|
-
const content = await options.snapshotEnvironment.readSnapshotFile(snapshotPath);
|
|
942
|
-
return new SnapshotState(testFilePath, snapshotPath, content, options);
|
|
943
|
-
}
|
|
944
|
-
get environment() {
|
|
945
|
-
return this._environment;
|
|
946
|
-
}
|
|
947
|
-
markSnapshotsAsCheckedForTest(testName) {
|
|
948
|
-
this._uncheckedKeys.forEach((uncheckedKey) => {
|
|
949
|
-
if (/ \d+$| > /.test(uncheckedKey.slice(testName.length))) {
|
|
950
|
-
this._uncheckedKeys.delete(uncheckedKey);
|
|
951
|
-
}
|
|
952
|
-
});
|
|
953
|
-
}
|
|
954
|
-
clearTest(testId) {
|
|
955
|
-
this._inlineSnapshots = this._inlineSnapshots.filter((s) => s.testId !== testId);
|
|
956
|
-
this._inlineSnapshotStacks = this._inlineSnapshotStacks.filter((s) => s.testId !== testId);
|
|
957
|
-
for (const key of this._testIdToKeys.get(testId)) {
|
|
958
|
-
const name = keyToTestName(key);
|
|
959
|
-
const count = this._counters.get(name);
|
|
960
|
-
if (count > 0) {
|
|
961
|
-
if (key in this._snapshotData || key in this._initialData) {
|
|
962
|
-
this._snapshotData[key] = this._initialData[key];
|
|
963
|
-
}
|
|
964
|
-
this._counters.set(name, count - 1);
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
this._testIdToKeys.delete(testId);
|
|
968
|
-
this.added.delete(testId);
|
|
969
|
-
this.updated.delete(testId);
|
|
970
|
-
this.matched.delete(testId);
|
|
971
|
-
this.unmatched.delete(testId);
|
|
972
|
-
}
|
|
973
|
-
_inferInlineSnapshotStack(stacks) {
|
|
974
|
-
const promiseIndex = stacks.findIndex((i) => i.method.match(/__VITEST_(RESOLVES|REJECTS)__/));
|
|
975
|
-
if (promiseIndex !== -1) {
|
|
976
|
-
return stacks[promiseIndex + 3];
|
|
977
|
-
}
|
|
978
|
-
const stackIndex = stacks.findIndex((i) => i.method.includes("__INLINE_SNAPSHOT__"));
|
|
979
|
-
return stackIndex !== -1 ? stacks[stackIndex + 2] : null;
|
|
980
|
-
}
|
|
981
|
-
_addSnapshot(key, receivedSerialized, options) {
|
|
982
|
-
this._dirty = true;
|
|
983
|
-
if (options.stack) {
|
|
984
|
-
this._inlineSnapshots.push({
|
|
985
|
-
snapshot: receivedSerialized,
|
|
986
|
-
testId: options.testId,
|
|
987
|
-
...options.stack
|
|
988
|
-
});
|
|
989
|
-
} else if (options.rawSnapshot) {
|
|
990
|
-
this._rawSnapshots.push({
|
|
991
|
-
...options.rawSnapshot,
|
|
992
|
-
snapshot: receivedSerialized
|
|
993
|
-
});
|
|
994
|
-
} else {
|
|
995
|
-
this._snapshotData[key] = receivedSerialized;
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
async save() {
|
|
999
|
-
const hasExternalSnapshots = Object.keys(this._snapshotData).length;
|
|
1000
|
-
const hasInlineSnapshots = this._inlineSnapshots.length;
|
|
1001
|
-
const hasRawSnapshots = this._rawSnapshots.length;
|
|
1002
|
-
const isEmpty = !hasExternalSnapshots && !hasInlineSnapshots && !hasRawSnapshots;
|
|
1003
|
-
const status = {
|
|
1004
|
-
deleted: false,
|
|
1005
|
-
saved: false
|
|
1006
|
-
};
|
|
1007
|
-
if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) {
|
|
1008
|
-
if (hasExternalSnapshots) {
|
|
1009
|
-
await saveSnapshotFile(this._environment, this._snapshotData, this.snapshotPath);
|
|
1010
|
-
this._fileExists = true;
|
|
1011
|
-
}
|
|
1012
|
-
if (hasInlineSnapshots) {
|
|
1013
|
-
await saveInlineSnapshots(this._environment, this._inlineSnapshots);
|
|
1014
|
-
}
|
|
1015
|
-
if (hasRawSnapshots) {
|
|
1016
|
-
await saveRawSnapshots(this._environment, this._rawSnapshots);
|
|
1017
|
-
}
|
|
1018
|
-
status.saved = true;
|
|
1019
|
-
} else if (!hasExternalSnapshots && this._fileExists) {
|
|
1020
|
-
if (this._updateSnapshot === "all") {
|
|
1021
|
-
await this._environment.removeSnapshotFile(this.snapshotPath);
|
|
1022
|
-
this._fileExists = false;
|
|
1023
|
-
}
|
|
1024
|
-
status.deleted = true;
|
|
1025
|
-
}
|
|
1026
|
-
return status;
|
|
1027
|
-
}
|
|
1028
|
-
getUncheckedCount() {
|
|
1029
|
-
return this._uncheckedKeys.size || 0;
|
|
1030
|
-
}
|
|
1031
|
-
getUncheckedKeys() {
|
|
1032
|
-
return Array.from(this._uncheckedKeys);
|
|
1033
|
-
}
|
|
1034
|
-
removeUncheckedKeys() {
|
|
1035
|
-
if (this._updateSnapshot === "all" && this._uncheckedKeys.size) {
|
|
1036
|
-
this._dirty = true;
|
|
1037
|
-
this._uncheckedKeys.forEach((key) => delete this._snapshotData[key]);
|
|
1038
|
-
this._uncheckedKeys.clear();
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
match({ testId, testName, received, key, inlineSnapshot, isInline, error, rawSnapshot }) {
|
|
1042
|
-
this._counters.increment(testName);
|
|
1043
|
-
const count = this._counters.get(testName);
|
|
1044
|
-
if (!key) {
|
|
1045
|
-
key = testNameToKey(testName, count);
|
|
1046
|
-
}
|
|
1047
|
-
this._testIdToKeys.get(testId).push(key);
|
|
1048
|
-
if (!(isInline && this._snapshotData[key] !== void 0)) {
|
|
1049
|
-
this._uncheckedKeys.delete(key);
|
|
1050
|
-
}
|
|
1051
|
-
let receivedSerialized = rawSnapshot && typeof received === "string" ? received : serialize(received, void 0, this._snapshotFormat);
|
|
1052
|
-
if (!rawSnapshot) {
|
|
1053
|
-
receivedSerialized = addExtraLineBreaks(receivedSerialized);
|
|
1054
|
-
}
|
|
1055
|
-
if (rawSnapshot) {
|
|
1056
|
-
if (rawSnapshot.content && rawSnapshot.content.match(/\r\n/) && !receivedSerialized.match(/\r\n/)) {
|
|
1057
|
-
rawSnapshot.content = normalizeNewlines(rawSnapshot.content);
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
const expected = isInline ? inlineSnapshot : rawSnapshot ? rawSnapshot.content : this._snapshotData[key];
|
|
1061
|
-
const expectedTrimmed = rawSnapshot ? expected : expected === null || expected === void 0 ? void 0 : expected.trim();
|
|
1062
|
-
const pass = expectedTrimmed === (rawSnapshot ? receivedSerialized : receivedSerialized.trim());
|
|
1063
|
-
const hasSnapshot = expected !== void 0;
|
|
1064
|
-
const snapshotIsPersisted = isInline || this._fileExists || rawSnapshot && rawSnapshot.content != null;
|
|
1065
|
-
if (pass && !isInline && !rawSnapshot) {
|
|
1066
|
-
this._snapshotData[key] = receivedSerialized;
|
|
1067
|
-
}
|
|
1068
|
-
let stack;
|
|
1069
|
-
if (isInline) {
|
|
1070
|
-
var _this$environment$pro, _this$environment;
|
|
1071
|
-
const stacks = parseErrorStacktrace(error || new Error("snapshot"), { ignoreStackEntries: [] });
|
|
1072
|
-
const _stack = this._inferInlineSnapshotStack(stacks);
|
|
1073
|
-
if (!_stack) {
|
|
1074
|
-
throw new Error(`@vitest/snapshot: Couldn't infer stack frame for inline snapshot.
|
|
1075
|
-
${JSON.stringify(stacks)}`);
|
|
1076
|
-
}
|
|
1077
|
-
stack = ((_this$environment$pro = (_this$environment = this.environment).processStackTrace) === null || _this$environment$pro === void 0 ? void 0 : _this$environment$pro.call(_this$environment, _stack)) || _stack;
|
|
1078
|
-
stack.column--;
|
|
1079
|
-
const snapshotsWithSameStack = this._inlineSnapshotStacks.filter((s) => isSameStackPosition(s, stack));
|
|
1080
|
-
if (snapshotsWithSameStack.length > 0) {
|
|
1081
|
-
this._inlineSnapshots = this._inlineSnapshots.filter((s) => !isSameStackPosition(s, stack));
|
|
1082
|
-
const differentSnapshot = snapshotsWithSameStack.find((s) => s.snapshot !== receivedSerialized);
|
|
1083
|
-
if (differentSnapshot) {
|
|
1084
|
-
throw Object.assign(new Error("toMatchInlineSnapshot with different snapshots cannot be called at the same location"), {
|
|
1085
|
-
actual: receivedSerialized,
|
|
1086
|
-
expected: differentSnapshot.snapshot
|
|
1087
|
-
});
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
this._inlineSnapshotStacks.push({
|
|
1091
|
-
...stack,
|
|
1092
|
-
testId,
|
|
1093
|
-
snapshot: receivedSerialized
|
|
1094
|
-
});
|
|
1095
|
-
}
|
|
1096
|
-
if (hasSnapshot && this._updateSnapshot === "all" || (!hasSnapshot || !snapshotIsPersisted) && (this._updateSnapshot === "new" || this._updateSnapshot === "all")) {
|
|
1097
|
-
if (this._updateSnapshot === "all") {
|
|
1098
|
-
if (!pass) {
|
|
1099
|
-
if (hasSnapshot) {
|
|
1100
|
-
this.updated.increment(testId);
|
|
1101
|
-
} else {
|
|
1102
|
-
this.added.increment(testId);
|
|
1103
|
-
}
|
|
1104
|
-
this._addSnapshot(key, receivedSerialized, {
|
|
1105
|
-
stack,
|
|
1106
|
-
testId,
|
|
1107
|
-
rawSnapshot
|
|
1108
|
-
});
|
|
1109
|
-
} else {
|
|
1110
|
-
this.matched.increment(testId);
|
|
1111
|
-
}
|
|
1112
|
-
} else {
|
|
1113
|
-
this._addSnapshot(key, receivedSerialized, {
|
|
1114
|
-
stack,
|
|
1115
|
-
testId,
|
|
1116
|
-
rawSnapshot
|
|
1117
|
-
});
|
|
1118
|
-
this.added.increment(testId);
|
|
1119
|
-
}
|
|
1120
|
-
return {
|
|
1121
|
-
actual: "",
|
|
1122
|
-
count,
|
|
1123
|
-
expected: "",
|
|
1124
|
-
key,
|
|
1125
|
-
pass: true
|
|
1126
|
-
};
|
|
1127
|
-
} else {
|
|
1128
|
-
if (!pass) {
|
|
1129
|
-
this.unmatched.increment(testId);
|
|
1130
|
-
return {
|
|
1131
|
-
actual: rawSnapshot ? receivedSerialized : removeExtraLineBreaks(receivedSerialized),
|
|
1132
|
-
count,
|
|
1133
|
-
expected: expectedTrimmed !== void 0 ? rawSnapshot ? expectedTrimmed : removeExtraLineBreaks(expectedTrimmed) : void 0,
|
|
1134
|
-
key,
|
|
1135
|
-
pass: false
|
|
1136
|
-
};
|
|
1137
|
-
} else {
|
|
1138
|
-
this.matched.increment(testId);
|
|
1139
|
-
return {
|
|
1140
|
-
actual: "",
|
|
1141
|
-
count,
|
|
1142
|
-
expected: "",
|
|
1143
|
-
key,
|
|
1144
|
-
pass: true
|
|
1145
|
-
};
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
async pack() {
|
|
1150
|
-
const snapshot = {
|
|
1151
|
-
filepath: this.testFilePath,
|
|
1152
|
-
added: 0,
|
|
1153
|
-
fileDeleted: false,
|
|
1154
|
-
matched: 0,
|
|
1155
|
-
unchecked: 0,
|
|
1156
|
-
uncheckedKeys: [],
|
|
1157
|
-
unmatched: 0,
|
|
1158
|
-
updated: 0
|
|
1159
|
-
};
|
|
1160
|
-
const uncheckedCount = this.getUncheckedCount();
|
|
1161
|
-
const uncheckedKeys = this.getUncheckedKeys();
|
|
1162
|
-
if (uncheckedCount) {
|
|
1163
|
-
this.removeUncheckedKeys();
|
|
1164
|
-
}
|
|
1165
|
-
const status = await this.save();
|
|
1166
|
-
snapshot.fileDeleted = status.deleted;
|
|
1167
|
-
snapshot.added = this.added.total();
|
|
1168
|
-
snapshot.matched = this.matched.total();
|
|
1169
|
-
snapshot.unmatched = this.unmatched.total();
|
|
1170
|
-
snapshot.updated = this.updated.total();
|
|
1171
|
-
snapshot.unchecked = !status.deleted ? uncheckedCount : 0;
|
|
1172
|
-
snapshot.uncheckedKeys = Array.from(uncheckedKeys);
|
|
1173
|
-
return snapshot;
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
function createMismatchError(message, expand, actual, expected) {
|
|
1177
|
-
const error = new Error(message);
|
|
1178
|
-
Object.defineProperty(error, "actual", {
|
|
1179
|
-
value: actual,
|
|
1180
|
-
enumerable: true,
|
|
1181
|
-
configurable: true,
|
|
1182
|
-
writable: true
|
|
1183
|
-
});
|
|
1184
|
-
Object.defineProperty(error, "expected", {
|
|
1185
|
-
value: expected,
|
|
1186
|
-
enumerable: true,
|
|
1187
|
-
configurable: true,
|
|
1188
|
-
writable: true
|
|
1189
|
-
});
|
|
1190
|
-
Object.defineProperty(error, "diffOptions", { value: { expand } });
|
|
1191
|
-
return error;
|
|
1192
|
-
}
|
|
1193
|
-
class SnapshotClient {
|
|
1194
|
-
constructor(options = {}) {
|
|
1195
|
-
__publicField(this, "snapshotStateMap", /* @__PURE__ */ new Map());
|
|
1196
|
-
this.options = options;
|
|
1197
|
-
}
|
|
1198
|
-
async setup(filepath, options) {
|
|
1199
|
-
if (this.snapshotStateMap.has(filepath)) {
|
|
1200
|
-
return;
|
|
1201
|
-
}
|
|
1202
|
-
this.snapshotStateMap.set(filepath, await SnapshotState.create(filepath, options));
|
|
1203
|
-
}
|
|
1204
|
-
async finish(filepath) {
|
|
1205
|
-
const state = this.getSnapshotState(filepath);
|
|
1206
|
-
const result = await state.pack();
|
|
1207
|
-
this.snapshotStateMap.delete(filepath);
|
|
1208
|
-
return result;
|
|
1209
|
-
}
|
|
1210
|
-
skipTest(filepath, testName) {
|
|
1211
|
-
const state = this.getSnapshotState(filepath);
|
|
1212
|
-
state.markSnapshotsAsCheckedForTest(testName);
|
|
1213
|
-
}
|
|
1214
|
-
clearTest(filepath, testId) {
|
|
1215
|
-
const state = this.getSnapshotState(filepath);
|
|
1216
|
-
state.clearTest(testId);
|
|
1217
|
-
}
|
|
1218
|
-
getSnapshotState(filepath) {
|
|
1219
|
-
const state = this.snapshotStateMap.get(filepath);
|
|
1220
|
-
if (!state) {
|
|
1221
|
-
throw new Error(`The snapshot state for '${filepath}' is not found. Did you call 'SnapshotClient.setup()'?`);
|
|
1222
|
-
}
|
|
1223
|
-
return state;
|
|
1224
|
-
}
|
|
1225
|
-
assert(options) {
|
|
1226
|
-
const { filepath, name, testId = name, message, isInline = false, properties, inlineSnapshot, error, errorMessage, rawSnapshot } = options;
|
|
1227
|
-
let { received } = options;
|
|
1228
|
-
if (!filepath) {
|
|
1229
|
-
throw new Error("Snapshot cannot be used outside of test");
|
|
1230
|
-
}
|
|
1231
|
-
const snapshotState = this.getSnapshotState(filepath);
|
|
1232
|
-
if (typeof properties === "object") {
|
|
1233
|
-
if (typeof received !== "object" || !received) {
|
|
1234
|
-
throw new Error("Received value must be an object when the matcher has properties");
|
|
1235
|
-
}
|
|
1236
|
-
try {
|
|
1237
|
-
var _this$options$isEqual, _this$options;
|
|
1238
|
-
const pass2 = ((_this$options$isEqual = (_this$options = this.options).isEqual) === null || _this$options$isEqual === void 0 ? void 0 : _this$options$isEqual.call(_this$options, received, properties)) ?? false;
|
|
1239
|
-
if (!pass2) {
|
|
1240
|
-
throw createMismatchError("Snapshot properties mismatched", snapshotState.expand, received, properties);
|
|
1241
|
-
} else {
|
|
1242
|
-
received = deepMergeSnapshot(received, properties);
|
|
1243
|
-
}
|
|
1244
|
-
} catch (err) {
|
|
1245
|
-
err.message = errorMessage || "Snapshot mismatched";
|
|
1246
|
-
throw err;
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
const testName = [name, ...message ? [message] : []].join(" > ");
|
|
1250
|
-
const { actual, expected, key, pass } = snapshotState.match({
|
|
1251
|
-
testId,
|
|
1252
|
-
testName,
|
|
1253
|
-
received,
|
|
1254
|
-
isInline,
|
|
1255
|
-
error,
|
|
1256
|
-
inlineSnapshot,
|
|
1257
|
-
rawSnapshot
|
|
1258
|
-
});
|
|
1259
|
-
if (!pass) {
|
|
1260
|
-
throw createMismatchError(`Snapshot \`${key || "unknown"}\` mismatched`, snapshotState.expand, rawSnapshot ? actual : actual === null || actual === void 0 ? void 0 : actual.trim(), rawSnapshot ? expected : expected === null || expected === void 0 ? void 0 : expected.trim());
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
async assertRaw(options) {
|
|
1264
|
-
if (!options.rawSnapshot) {
|
|
1265
|
-
throw new Error("Raw snapshot is required");
|
|
1266
|
-
}
|
|
1267
|
-
const { filepath, rawSnapshot } = options;
|
|
1268
|
-
if (rawSnapshot.content == null) {
|
|
1269
|
-
if (!filepath) {
|
|
1270
|
-
throw new Error("Snapshot cannot be used outside of test");
|
|
1271
|
-
}
|
|
1272
|
-
const snapshotState = this.getSnapshotState(filepath);
|
|
1273
|
-
options.filepath || (options.filepath = filepath);
|
|
1274
|
-
rawSnapshot.file = await snapshotState.environment.resolveRawPath(filepath, rawSnapshot.file);
|
|
1275
|
-
rawSnapshot.content = await snapshotState.environment.readSnapshotFile(rawSnapshot.file) ?? void 0;
|
|
1276
|
-
}
|
|
1277
|
-
return this.assert(options);
|
|
1278
|
-
}
|
|
1279
|
-
clear() {
|
|
1280
|
-
this.snapshotStateMap.clear();
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
export {
|
|
1284
|
-
SnapshotClient,
|
|
1285
|
-
SnapshotState,
|
|
1286
|
-
addSerializer,
|
|
1287
|
-
getSerializers,
|
|
1288
|
-
stripSnapshotIndentation
|
|
1289
|
-
};
|