vitest 5.0.5 → 5.1.0
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/LICENSE.md +1 -1
- package/dist/browser.d.ts +6 -5
- package/dist/browser.js +6 -6
- package/dist/chunks/{base.CzXt2BO_.js → base.Cof-UHJf.js} +17 -21
- package/dist/chunks/{browser.d.FGQ9_rK6.d.ts → browser.d.C7tWgUvw.d.ts} +4 -3
- package/dist/chunks/{cac.CLrZKo1g.js → cac.BYbt0aJp.js} +30 -16
- package/dist/chunks/{cli-api.De07GUeT.js → cli-api.COfZo8lK.js} +5226 -4385
- package/dist/chunks/{config.d.QBNYCgFU.d.ts → config.d.B3YV4t0O.d.ts} +169 -93
- package/dist/chunks/{console.DtI4yxfN.js → console.CQZ877Hi.js} +6 -3
- package/dist/chunks/{constants.-juJ8b_4.js → constants.DLYM6cZY.js} +1 -1
- package/dist/chunks/{coverage.-bm5IxnW.js → coverage.9iqXE2gN.js} +1 -1
- package/dist/chunks/{coverage.cTDc4uSS.js → coverage.jGCktcGP.js} +1 -1
- package/dist/chunks/{creator.C5g4egeG.js → creator.DHWmytIK.js} +11 -11
- package/dist/chunks/{doctor.BK86Cncq.js → doctor.B-oPbwps.js} +2 -2
- package/dist/chunks/{environment.d.BY56MoGs.d.ts → environment.d.BFQtFKdZ.d.ts} +1 -1
- package/dist/chunks/{globals.CXEE6_2C.js → globals.ZKtKSkEf.js} +7 -6
- package/dist/chunks/{index.CK-t0WMg.js → index.Bi0NXYPf.js} +165 -62
- package/dist/chunks/{index.aTZaPVhf.js → index.CZzC1gGg.js} +299 -440
- package/dist/chunks/{index.1TqnEahn.js → index.Di8au7q4.js} +104 -72
- package/dist/chunks/{index.CoUIxZd4.js → index.w_oBZ9N8.js} +5 -5
- package/dist/chunks/{init-forks.CRxIPOJR.js → init-forks.BaDXQSD8.js} +1 -1
- package/dist/chunks/{init-threads.Dv3kwST_.js → init-threads.ZX_Vov0z.js} +1 -1
- package/dist/chunks/{init.PvxYpuCm.js → init.CO4AB7HZ.js} +4 -4
- package/dist/chunks/{module-dependencies.CwNPkcV4.js → module-dependencies._2Eei3FO.js} +1 -1
- package/dist/chunks/{native.cdzHIdmv.js → native.upB-V0CK.js} +1 -1
- package/dist/chunks/{nativeModuleMocker.BxrHJNAF.js → nativeModuleMocker.Dh5azSB4.js} +4 -3
- package/dist/chunks/{nativeModuleRunner.xi64Afb2.js → nativeModuleRunner.9xPIMzi7.js} +1 -1
- package/dist/chunks/{node.uQulW0ei.js → node.B9mkVmLH.js} +1 -1
- package/dist/chunks/{pathe.M-eThtNZ.Ba-7h1rE.js → pathe.M-eThtNZ.zq3TM4NT.js} +1 -1
- package/dist/chunks/{plugin.d.C8mmycim.d.ts → plugin.d.LRFSN46m.d.ts} +191 -32
- package/dist/chunks/rawSnapshot.DqSiqIEx.js +356 -0
- package/dist/chunks/{resolver.CtCcxIy1.js → resolver.BzpmeQeT.js} +1 -1
- package/dist/chunks/{rpc.DpkUyY1N.js → rpc.Uhkwr2NM.js} +2 -2
- package/dist/chunks/{rpc.d.Cft1biqy.d.ts → rpc.d.3FOhdFx8.d.ts} +1 -1
- package/dist/chunks/{run.BPv-BBRv.js → run.CjdgFZiW.js} +28 -7
- package/dist/chunks/{setup-common.HGAqWOnX.js → setup-common.CqAQCXzx.js} +2 -2
- package/dist/chunks/{source-map.DdKI5IHB.js → source-map.DakdQc29.js} +43 -37
- package/dist/chunks/{source-map.d.kzFtk_dj.d.ts → source-map.d.BkG8YK_3.d.ts} +2 -1
- package/dist/chunks/{task-utils.d.PFh2BV6Q.d.ts → task-utils.d.D-gFPNFi.d.ts} +2 -1
- package/dist/chunks/{utils.DSfl_w8V.js → utils.BBk_icFG.js} +6 -3
- package/dist/chunks/{vm.FGl2rw_t.js → vm.b4MbCAJQ.js} +27 -14
- package/dist/chunks/{worker.d.BH-r1bPu.d.ts → worker.d.CyJRpyfZ.d.ts} +3 -3
- package/dist/cli.js +3 -3
- package/dist/config.cjs +1 -1
- package/dist/config.d.ts +11 -11
- package/dist/config.js +1 -1
- package/dist/index.d.ts +21 -15
- package/dist/index.js +6 -5
- package/dist/module-evaluator.d.ts +3 -2
- package/dist/node.d.ts +30 -12
- package/dist/node.js +16 -14
- package/dist/runtime.d.ts +4 -4
- package/dist/runtime.js +5 -4
- package/dist/task-utils.js +10 -4
- package/dist/worker.d.ts +4 -4
- package/dist/worker.js +14 -13
- package/dist/workers/forks.js +15 -14
- package/dist/workers/runVmTests.js +16 -12
- package/dist/workers/threads.js +15 -14
- package/dist/workers/vmForks.js +11 -10
- package/dist/workers/vmThreads.js +11 -10
- package/package.json +17 -17
|
@@ -1,370 +1,20 @@
|
|
|
1
|
-
import { b as printDiffOrStringify, d as diff, a as processError,
|
|
1
|
+
import { b as printDiffOrStringify, d as diff, a as processError, g as getRunningTests, c as getCurrentTest, r as recordArtifact, T as TestSyntaxError, e as createTaskCollector, f as getCurrentSuite, h as createChainable, i as getHooks, j as getFn, m as matchesTags, k as afterAll, l as afterEach, n as aroundAll, o as aroundEach, q as beforeAll, t as beforeEach, u as describe, v as it, w as onTestFailed, x as onTestFinished, y as suite, z as test } from './run.CjdgFZiW.js';
|
|
2
2
|
import { i as isChildProcess, r as resetModules, g as getWorkerState } from './utils.DYj33du9.js';
|
|
3
|
-
import { e as parseErrorStacktrace, a as getSafeTimers, f as parseSingleStack, h as delay } from './source-map.
|
|
3
|
+
import { e as parseErrorStacktrace, a as getSafeTimers, f as parseSingleStack, h as delay } from './source-map.DakdQc29.js';
|
|
4
4
|
import { i as isMockFunction, f as fn, a as spyOn, r as restoreAllMocks, b as resetAllMocks, c as clearAllMocks } from './spy.DDMXghXv.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { g as getType, f as isObject, D as noop, y as assertTypes, x as ordinal, E as createSimpleStackTrace, i as isAbsolute, a as relative, n as normalize } from './pathe.M-eThtNZ.zq3TM4NT.js';
|
|
6
|
+
import { a as commonjsGlobal } from './index.D0heQG4v.js';
|
|
7
7
|
import { s as stringify, i as inspect } from './display.BlTmubjj.js';
|
|
8
8
|
import { $ } from './tinyrainbow.Do8I1XRG.js';
|
|
9
9
|
import * as chai from 'chai';
|
|
10
10
|
import { use, util } from 'chai';
|
|
11
11
|
import { getNames, getTests, getTestName, createFileTask } from '../task-utils.js';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { r as rpc, V as VitestEvaluatedModules } from './rpc.
|
|
12
|
+
import { a as addSerializer } from './plugins.DPQHVT0p.js';
|
|
13
|
+
import { C as CounterMap, D as DefaultMap, e as evaluateSnapshotFile, k as keyToTestName, s as saveSnapshotFile, a as saveInlineSnapshots, b as saveRawSnapshots, t as testNameToKey, c as serialize, d as addExtraLineBreaks, n as normalizeNewlines, r as removeExtraLineBreaks, f as deepMergeSnapshot, g as stripSnapshotIndentation } from './rawSnapshot.DqSiqIEx.js';
|
|
14
|
+
import { r as rpc, V as VitestEvaluatedModules } from './rpc.Uhkwr2NM.js';
|
|
15
15
|
import { Bench } from 'tinybench';
|
|
16
16
|
import { expectTypeOf } from 'expect-type';
|
|
17
17
|
|
|
18
|
-
var naturalCompare$1 = {exports: {}};
|
|
19
|
-
|
|
20
|
-
var hasRequiredNaturalCompare;
|
|
21
|
-
|
|
22
|
-
function requireNaturalCompare () {
|
|
23
|
-
if (hasRequiredNaturalCompare) return naturalCompare$1.exports;
|
|
24
|
-
hasRequiredNaturalCompare = 1;
|
|
25
|
-
/*
|
|
26
|
-
* @version 1.4.0
|
|
27
|
-
* @date 2015-10-26
|
|
28
|
-
* @stability 3 - Stable
|
|
29
|
-
* @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
|
|
30
|
-
* @license MIT License
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var naturalCompare = function(a, b) {
|
|
35
|
-
var i, codeA
|
|
36
|
-
, codeB = 1
|
|
37
|
-
, posA = 0
|
|
38
|
-
, posB = 0
|
|
39
|
-
, alphabet = String.alphabet;
|
|
40
|
-
|
|
41
|
-
function getCode(str, pos, code) {
|
|
42
|
-
if (code) {
|
|
43
|
-
for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
|
|
44
|
-
return +str.slice(pos - 1, i)
|
|
45
|
-
}
|
|
46
|
-
code = alphabet && alphabet.indexOf(str.charAt(pos));
|
|
47
|
-
return code > -1 ? code + 76 : ((code = str.charCodeAt(pos) || 0), code < 45 || code > 127) ? code
|
|
48
|
-
: code < 46 ? 65 // -
|
|
49
|
-
: code < 48 ? code - 1
|
|
50
|
-
: code < 58 ? code + 18 // 0-9
|
|
51
|
-
: code < 65 ? code - 11
|
|
52
|
-
: code < 91 ? code + 11 // A-Z
|
|
53
|
-
: code < 97 ? code - 37
|
|
54
|
-
: code < 123 ? code + 5 // a-z
|
|
55
|
-
: code - 63
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if ((a+="") != (b+="")) for (;codeB;) {
|
|
60
|
-
codeA = getCode(a, posA++);
|
|
61
|
-
codeB = getCode(b, posB++);
|
|
62
|
-
|
|
63
|
-
if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
|
|
64
|
-
codeA = getCode(a, posA, posA);
|
|
65
|
-
codeB = getCode(b, posB, posA = i);
|
|
66
|
-
posB = i;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (codeA != codeB) return (codeA < codeB) ? -1 : 1
|
|
70
|
-
}
|
|
71
|
-
return 0
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
naturalCompare$1.exports = naturalCompare;
|
|
76
|
-
} catch (e) {
|
|
77
|
-
String.naturalCompare = naturalCompare;
|
|
78
|
-
}
|
|
79
|
-
return naturalCompare$1.exports;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
var naturalCompareExports = requireNaturalCompare();
|
|
83
|
-
var naturalCompare = /*@__PURE__*/getDefaultExportFromCjs(naturalCompareExports);
|
|
84
|
-
|
|
85
|
-
// TODO: rewrite and clean up
|
|
86
|
-
function testNameToKey(testName, count) {
|
|
87
|
-
return `${testName} ${count}`;
|
|
88
|
-
}
|
|
89
|
-
function keyToTestName(key) {
|
|
90
|
-
if (!/ \d+$/.test(key)) throw new Error("Snapshot keys must end with a number.");
|
|
91
|
-
return key.replace(/ \d+$/, "");
|
|
92
|
-
}
|
|
93
|
-
// Evaluate a snapshot file's content into its snapshot key/value pairs.
|
|
94
|
-
function evaluateSnapshotFile(filepath, content) {
|
|
95
|
-
const data = Object.create(null);
|
|
96
|
-
try {
|
|
97
|
-
new Function("exports", content)(data);
|
|
98
|
-
} catch (cause) {
|
|
99
|
-
throw new Error(`Invalid snapshot file, please manually fix or delete it: ${filepath}`, { cause });
|
|
100
|
-
}
|
|
101
|
-
return data;
|
|
102
|
-
}
|
|
103
|
-
// Add extra line breaks at beginning and end of multiline snapshot
|
|
104
|
-
// to make the content easier to read.
|
|
105
|
-
function addExtraLineBreaks(string) {
|
|
106
|
-
return string.includes("\n") ? `\n${string}\n` : string;
|
|
107
|
-
}
|
|
108
|
-
// Remove extra line breaks at beginning and end of multiline snapshot.
|
|
109
|
-
// Instead of trim, which can remove additional newlines or spaces
|
|
110
|
-
// at beginning or end of the content from a custom serializer.
|
|
111
|
-
function removeExtraLineBreaks(string) {
|
|
112
|
-
return string.length > 2 && string[0] === "\n" && string.endsWith("\n") ? string.slice(1, -1) : string;
|
|
113
|
-
}
|
|
114
|
-
// export const removeLinesBeforeExternalMatcherTrap = (stack: string): string => {
|
|
115
|
-
// const lines = stack.split('\n')
|
|
116
|
-
// for (let i = 0; i < lines.length; i += 1) {
|
|
117
|
-
// // It's a function name specified in `packages/expect/src/index.ts`
|
|
118
|
-
// // for external custom matchers.
|
|
119
|
-
// if (lines[i].includes('__EXTERNAL_MATCHER_TRAP__'))
|
|
120
|
-
// return lines.slice(i + 1).join('\n')
|
|
121
|
-
// }
|
|
122
|
-
// return stack
|
|
123
|
-
// }
|
|
124
|
-
const escapeRegex = true;
|
|
125
|
-
const printFunctionName = false;
|
|
126
|
-
function serialize(val, indent = 2, formatOverrides = {}) {
|
|
127
|
-
return normalizeNewlines(format(val, {
|
|
128
|
-
escapeRegex,
|
|
129
|
-
indent,
|
|
130
|
-
plugins: getSerializers(),
|
|
131
|
-
printFunctionName,
|
|
132
|
-
...formatOverrides
|
|
133
|
-
}));
|
|
134
|
-
}
|
|
135
|
-
function escapeBacktickString(str) {
|
|
136
|
-
// a raw CR inside a template literal is read back as LF
|
|
137
|
-
return str.replace(/`|\\|\$\{/g, "\\$&").replace(/\r/g, "\\r");
|
|
138
|
-
}
|
|
139
|
-
function printBacktickString(str) {
|
|
140
|
-
return `\`${escapeBacktickString(str)}\``;
|
|
141
|
-
}
|
|
142
|
-
function normalizeNewlines(string) {
|
|
143
|
-
return string.replace(/\r\n|\r/g, "\n");
|
|
144
|
-
}
|
|
145
|
-
async function saveSnapshotFile(environment, snapshotData, snapshotPath) {
|
|
146
|
-
const snapshots = Object.keys(snapshotData).sort(naturalCompare).map((key) => `exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`);
|
|
147
|
-
const content = `${environment.getHeader()}\n\n${snapshots.join("\n\n")}\n`;
|
|
148
|
-
const oldContent = await environment.readSnapshotFile(snapshotPath);
|
|
149
|
-
if (oldContent != null && oldContent === content) return;
|
|
150
|
-
await environment.saveSnapshotFile(snapshotPath, content);
|
|
151
|
-
}
|
|
152
|
-
function deepMergeArray(target = [], source = []) {
|
|
153
|
-
const mergedOutput = Array.from(target);
|
|
154
|
-
source.forEach((sourceElement, index) => {
|
|
155
|
-
const targetElement = mergedOutput[index];
|
|
156
|
-
if (Array.isArray(target[index])) mergedOutput[index] = deepMergeArray(target[index], sourceElement);
|
|
157
|
-
else if (isObject(targetElement)) mergedOutput[index] = deepMergeSnapshot(target[index], sourceElement);
|
|
158
|
-
else
|
|
159
|
-
// Source does not exist in target or target is primitive and cannot be deep merged
|
|
160
|
-
mergedOutput[index] = sourceElement;
|
|
161
|
-
});
|
|
162
|
-
return mergedOutput;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Deep merge, but considers asymmetric matchers. Unlike base util's deep merge,
|
|
166
|
-
* will merge any object-like instance.
|
|
167
|
-
* Compatible with Jest's snapshot matcher. Should not be used outside of snapshot.
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```ts
|
|
171
|
-
* toMatchSnapshot({
|
|
172
|
-
* name: expect.stringContaining('text')
|
|
173
|
-
* })
|
|
174
|
-
* ```
|
|
175
|
-
*/
|
|
176
|
-
function deepMergeSnapshot(target, source) {
|
|
177
|
-
if (isObject(target) && isObject(source)) {
|
|
178
|
-
const mergedOutput = { ...target };
|
|
179
|
-
Object.keys(source).forEach((key) => {
|
|
180
|
-
if (isObject(source[key]) && !source[key].$$typeof) {
|
|
181
|
-
if (!(key in target)) Object.assign(mergedOutput, { [key]: source[key] });
|
|
182
|
-
else mergedOutput[key] = deepMergeSnapshot(target[key], source[key]);
|
|
183
|
-
} else if (Array.isArray(source[key])) mergedOutput[key] = deepMergeArray(target[key], source[key]);
|
|
184
|
-
else Object.assign(mergedOutput, { [key]: source[key] });
|
|
185
|
-
});
|
|
186
|
-
return mergedOutput;
|
|
187
|
-
} else if (Array.isArray(target) && Array.isArray(source)) return deepMergeArray(target, source);
|
|
188
|
-
return target;
|
|
189
|
-
}
|
|
190
|
-
class DefaultMap extends Map {
|
|
191
|
-
defaultFn;
|
|
192
|
-
constructor(defaultFn, entries) {
|
|
193
|
-
super(entries);
|
|
194
|
-
this.defaultFn = defaultFn;
|
|
195
|
-
}
|
|
196
|
-
get(key) {
|
|
197
|
-
if (!this.has(key)) this.set(key, this.defaultFn(key));
|
|
198
|
-
return super.get(key);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
class CounterMap extends DefaultMap {
|
|
202
|
-
constructor() {
|
|
203
|
-
super(() => 0);
|
|
204
|
-
}
|
|
205
|
-
// compat for jest-image-snapshot https://github.com/vitest-dev/vitest/issues/7322
|
|
206
|
-
// `valueOf` and `Snapshot.added` setter allows
|
|
207
|
-
// snapshotState.added = snapshotState.added + 1
|
|
208
|
-
// to function as
|
|
209
|
-
// snapshotState.added.total_ = snapshotState.added.total() + 1
|
|
210
|
-
_total;
|
|
211
|
-
valueOf() {
|
|
212
|
-
return this._total = this.total();
|
|
213
|
-
}
|
|
214
|
-
increment(key) {
|
|
215
|
-
if (typeof this._total !== "undefined") this._total++;
|
|
216
|
-
this.set(key, this.get(key) + 1);
|
|
217
|
-
}
|
|
218
|
-
total() {
|
|
219
|
-
if (typeof this._total !== "undefined") return this._total;
|
|
220
|
-
let total = 0;
|
|
221
|
-
for (const x of this.values()) total += x;
|
|
222
|
-
return total;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
226
|
-
function memo(fn) {
|
|
227
|
-
const cache = /* @__PURE__ */ new Map();
|
|
228
|
-
return (arg) => {
|
|
229
|
-
if (!cache.has(arg)) cache.set(arg, fn(arg));
|
|
230
|
-
return cache.get(arg);
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
async function saveInlineSnapshots(environment, snapshots) {
|
|
235
|
-
const MagicString = (await import('magic-string')).default;
|
|
236
|
-
const files = new Set(snapshots.map((i) => i.file));
|
|
237
|
-
await Promise.all(Array.from(files).map(async (file) => {
|
|
238
|
-
const snaps = snapshots.filter((i) => i.file === file);
|
|
239
|
-
const code = await environment.readSnapshotFile(file);
|
|
240
|
-
if (code == null) throw new Error(`cannot read ${file} when saving inline snapshot`);
|
|
241
|
-
const s = new MagicString(code);
|
|
242
|
-
for (const snap of snaps) replaceInlineSnap(code, s, positionToOffset(code, snap.line, snap.column), snap.snapshot, snap.assertionName);
|
|
243
|
-
const transformed = s.toString();
|
|
244
|
-
if (transformed !== code) await environment.saveSnapshotFile(file, transformed);
|
|
245
|
-
}));
|
|
246
|
-
}
|
|
247
|
-
const defaultStartObjectRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*\{/;
|
|
248
|
-
function escapeRegExp(s) {
|
|
249
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
250
|
-
}
|
|
251
|
-
const buildStartObjectRegex = memo((assertionName) => {
|
|
252
|
-
const replaced = defaultStartObjectRegex.source.replace("toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot", escapeRegExp(assertionName));
|
|
253
|
-
return new RegExp(replaced);
|
|
254
|
-
});
|
|
255
|
-
function replaceObjectSnap(code, s, index, newSnap, assertionName) {
|
|
256
|
-
let _code = code.slice(index);
|
|
257
|
-
const startMatch = (assertionName ? buildStartObjectRegex(assertionName) : defaultStartObjectRegex).exec(_code);
|
|
258
|
-
if (!startMatch) return false;
|
|
259
|
-
_code = _code.slice(startMatch.index);
|
|
260
|
-
let callEnd = getCallLastIndex(_code);
|
|
261
|
-
if (callEnd === null) return false;
|
|
262
|
-
callEnd += index + startMatch.index;
|
|
263
|
-
const shapeEnd = getObjectShapeEndIndex(code, index + startMatch.index + startMatch[0].length);
|
|
264
|
-
const snap = `, ${prepareSnapString(newSnap, code, index)}`;
|
|
265
|
-
if (shapeEnd === callEnd)
|
|
266
|
-
// toMatchInlineSnapshot({ foo: expect.any(String) })
|
|
267
|
-
s.appendLeft(callEnd, snap);
|
|
268
|
-
else
|
|
269
|
-
// toMatchInlineSnapshot({ foo: expect.any(String) }, ``)
|
|
270
|
-
s.overwrite(shapeEnd, callEnd, snap);
|
|
271
|
-
return true;
|
|
272
|
-
}
|
|
273
|
-
function getObjectShapeEndIndex(code, index) {
|
|
274
|
-
let startBraces = 1;
|
|
275
|
-
let endBraces = 0;
|
|
276
|
-
while (startBraces !== endBraces && index < code.length) {
|
|
277
|
-
const s = code[index++];
|
|
278
|
-
if (s === "{") startBraces++;
|
|
279
|
-
else if (s === "}") endBraces++;
|
|
280
|
-
}
|
|
281
|
-
return index;
|
|
282
|
-
}
|
|
283
|
-
function prepareSnapString(snap, source, index) {
|
|
284
|
-
const lineNumber = offsetToLineNumber(source, index);
|
|
285
|
-
const indent = source.split(lineSplitRE)[lineNumber - 1].match(/^\s*/)[0] || "";
|
|
286
|
-
const indentNext = indent.includes(" ") ? `${indent}\t` : `${indent} `;
|
|
287
|
-
const lines = snap.trim().replace(/\\/g, "\\\\").split(/\n/g);
|
|
288
|
-
const isOneline = lines.length <= 1;
|
|
289
|
-
const quote = "`";
|
|
290
|
-
if (isOneline) return `${quote}${lines.join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}${quote}`;
|
|
291
|
-
return `${quote}\n${lines.map((i) => i ? indentNext + i : "").join("\n").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")}\n${indent}${quote}`;
|
|
292
|
-
}
|
|
293
|
-
const defaultMethodNames = ["toMatchInlineSnapshot", "toThrowErrorMatchingInlineSnapshot"];
|
|
294
|
-
// on webkit, the line number is at the end of the method, not at the start
|
|
295
|
-
function getCodeStartingAtIndex(code, index, methodNames) {
|
|
296
|
-
for (const name of methodNames) {
|
|
297
|
-
const adjusted = index - name.length;
|
|
298
|
-
if (adjusted >= 0 && code.slice(adjusted, index) === name) return {
|
|
299
|
-
code: code.slice(adjusted),
|
|
300
|
-
index: adjusted
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
return {
|
|
304
|
-
code: code.slice(index),
|
|
305
|
-
index
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
const defaultStartRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*[\w$]*(['"`)])/;
|
|
309
|
-
const buildStartRegex = memo((assertionName) => {
|
|
310
|
-
const replaced = defaultStartRegex.source.replace("toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot", escapeRegExp(assertionName));
|
|
311
|
-
return new RegExp(replaced);
|
|
312
|
-
});
|
|
313
|
-
function replaceInlineSnap(code, s, currentIndex, newSnap, assertionName) {
|
|
314
|
-
const { code: codeStartingAtIndex, index } = getCodeStartingAtIndex(code, currentIndex, assertionName ? [assertionName] : defaultMethodNames);
|
|
315
|
-
const startMatch = (assertionName ? buildStartRegex(assertionName) : defaultStartRegex).exec(codeStartingAtIndex);
|
|
316
|
-
const firstKeywordMatch = (assertionName ? new RegExp(escapeRegExp(assertionName)) : /toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot/).exec(codeStartingAtIndex);
|
|
317
|
-
if (!startMatch || startMatch.index !== firstKeywordMatch?.index) return replaceObjectSnap(code, s, index, newSnap, assertionName);
|
|
318
|
-
const quote = startMatch[1];
|
|
319
|
-
const startIndex = index + startMatch.index + startMatch[0].length;
|
|
320
|
-
const snapString = prepareSnapString(newSnap, code, index);
|
|
321
|
-
if (quote === ")") {
|
|
322
|
-
s.appendRight(startIndex - 1, snapString);
|
|
323
|
-
return true;
|
|
324
|
-
}
|
|
325
|
-
const endMatch = new RegExp(`(?:^|[^\\\\])${quote}`).exec(code.slice(startIndex));
|
|
326
|
-
if (!endMatch) return false;
|
|
327
|
-
const endIndex = startIndex + endMatch.index + endMatch[0].length;
|
|
328
|
-
s.overwrite(startIndex - 1, endIndex, snapString);
|
|
329
|
-
return true;
|
|
330
|
-
}
|
|
331
|
-
const INDENTATION_REGEX = /^([^\S\n]*)\S/m;
|
|
332
|
-
function stripSnapshotIndentation(inlineSnapshot) {
|
|
333
|
-
// Find indentation if exists.
|
|
334
|
-
const match = inlineSnapshot.match(INDENTATION_REGEX);
|
|
335
|
-
if (!match || !match[1])
|
|
336
|
-
// No indentation.
|
|
337
|
-
return inlineSnapshot;
|
|
338
|
-
const indentation = match[1];
|
|
339
|
-
const lines = inlineSnapshot.split(/\n/g);
|
|
340
|
-
if (lines.length <= 2)
|
|
341
|
-
// Must be at least 3 lines.
|
|
342
|
-
return inlineSnapshot;
|
|
343
|
-
if (lines[0].trim() !== "" || lines.at(-1)?.trim() !== "")
|
|
344
|
-
// If not blank first and last lines, abort.
|
|
345
|
-
return inlineSnapshot;
|
|
346
|
-
for (let i = 1; i < lines.length - 1; i++) if (lines[i] !== "") {
|
|
347
|
-
if (lines[i].indexOf(indentation) !== 0)
|
|
348
|
-
// All lines except first and last should either be blank or have the same
|
|
349
|
-
// indent as the first line (or more). If this isn't the case we don't
|
|
350
|
-
// want to touch the snapshot at all.
|
|
351
|
-
return inlineSnapshot;
|
|
352
|
-
lines[i] = lines[i].substring(indentation.length);
|
|
353
|
-
}
|
|
354
|
-
// Last line is a special case because it won't have the same indent as others
|
|
355
|
-
// but may still have been given some indent to line up.
|
|
356
|
-
lines[lines.length - 1] = "";
|
|
357
|
-
// Return inline snapshot, now at indent 0.
|
|
358
|
-
inlineSnapshot = lines.join("\n");
|
|
359
|
-
return inlineSnapshot;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
async function saveRawSnapshots(environment, snapshots) {
|
|
363
|
-
await Promise.all(snapshots.map(async (snap) => {
|
|
364
|
-
if (!snap.readonly) await environment.saveSnapshotFile(snap.file, snap.snapshot);
|
|
365
|
-
}));
|
|
366
|
-
}
|
|
367
|
-
|
|
368
18
|
function isSameStackPosition(x, y) {
|
|
369
19
|
return x.file === y.file && x.column === y.column && x.line === y.line;
|
|
370
20
|
}
|
|
@@ -608,7 +258,8 @@ class SnapshotState {
|
|
|
608
258
|
count: opts.count,
|
|
609
259
|
expected: opts.expectedDisplay,
|
|
610
260
|
key: opts.key,
|
|
611
|
-
pass: false
|
|
261
|
+
pass: false,
|
|
262
|
+
update: this._createUpdate(opts)
|
|
612
263
|
};
|
|
613
264
|
} else {
|
|
614
265
|
this.matched.increment(opts.testId);
|
|
@@ -621,6 +272,29 @@ class SnapshotState {
|
|
|
621
272
|
};
|
|
622
273
|
}
|
|
623
274
|
}
|
|
275
|
+
_createUpdate(opts) {
|
|
276
|
+
if (opts.stack) return {
|
|
277
|
+
type: "inline",
|
|
278
|
+
file: opts.stack.file,
|
|
279
|
+
line: opts.stack.line,
|
|
280
|
+
column: opts.stack.column,
|
|
281
|
+
snapshot: opts.addValue,
|
|
282
|
+
testId: opts.testId,
|
|
283
|
+
assertionName: opts.assertionName
|
|
284
|
+
};
|
|
285
|
+
if (opts.rawSnapshot) return {
|
|
286
|
+
type: "raw",
|
|
287
|
+
file: opts.rawSnapshot.file,
|
|
288
|
+
readonly: opts.rawSnapshot.readonly,
|
|
289
|
+
snapshot: opts.addValue
|
|
290
|
+
};
|
|
291
|
+
return {
|
|
292
|
+
type: "file",
|
|
293
|
+
file: this.snapshotPath,
|
|
294
|
+
key: opts.key,
|
|
295
|
+
snapshot: opts.addValue
|
|
296
|
+
};
|
|
297
|
+
}
|
|
624
298
|
async save() {
|
|
625
299
|
const hasExternalSnapshots = Object.keys(this._snapshotData).length;
|
|
626
300
|
const hasInlineSnapshots = this._inlineSnapshots.length;
|
|
@@ -864,7 +538,7 @@ class SnapshotClient {
|
|
|
864
538
|
}
|
|
865
539
|
received = deepMergeSnapshot(received, properties);
|
|
866
540
|
}
|
|
867
|
-
const { actual, expected, key, pass } = snapshotState.match({
|
|
541
|
+
const { actual, expected, key, pass, update } = snapshotState.match({
|
|
868
542
|
testId,
|
|
869
543
|
testName,
|
|
870
544
|
received,
|
|
@@ -878,7 +552,8 @@ class SnapshotClient {
|
|
|
878
552
|
pass,
|
|
879
553
|
message: () => `Snapshot \`${key || "unknown"}\` mismatched`,
|
|
880
554
|
actual: rawSnapshot ? actual : actual?.trim(),
|
|
881
|
-
expected: rawSnapshot ? expected : expected?.trim()
|
|
555
|
+
expected: rawSnapshot ? expected : expected?.trim(),
|
|
556
|
+
meta: createMatchMeta(key, update)
|
|
882
557
|
};
|
|
883
558
|
}
|
|
884
559
|
assert(options) {
|
|
@@ -889,7 +564,7 @@ class SnapshotClient {
|
|
|
889
564
|
}
|
|
890
565
|
}
|
|
891
566
|
matchDomain(options) {
|
|
892
|
-
const { received, filepath, name, testId = name, message, adapter, isInline = false, inlineSnapshot, error } = options;
|
|
567
|
+
const { received, filepath, name, testId = name, message, adapter, isInline = false, inlineSnapshot, error, assertionName } = options;
|
|
893
568
|
if (!filepath) throw new Error("Snapshot cannot be used outside of test");
|
|
894
569
|
const captured = adapter.capture(received);
|
|
895
570
|
const rendered = adapter.render(captured);
|
|
@@ -903,24 +578,25 @@ class SnapshotClient {
|
|
|
903
578
|
});
|
|
904
579
|
expectedSnapshot.markAsChecked();
|
|
905
580
|
const matchResult = expectedSnapshot.data !== void 0 ? adapter.match(captured, adapter.parseExpected(expectedSnapshot.data)) : void 0;
|
|
906
|
-
const { actual, expected, key, pass } = snapshotState.processDomainSnapshot({
|
|
581
|
+
const { actual, expected, key, pass, update } = snapshotState.processDomainSnapshot({
|
|
907
582
|
testId,
|
|
908
583
|
received: rendered,
|
|
909
584
|
expectedSnapshot,
|
|
910
585
|
matchResult,
|
|
911
586
|
isInline,
|
|
912
587
|
error,
|
|
913
|
-
assertionName
|
|
588
|
+
assertionName
|
|
914
589
|
});
|
|
915
590
|
return {
|
|
916
591
|
pass,
|
|
917
592
|
message: () => `Snapshot \`${key}\` mismatched`,
|
|
918
593
|
actual: actual?.trim(),
|
|
919
|
-
expected: expected?.trim()
|
|
594
|
+
expected: expected?.trim(),
|
|
595
|
+
meta: createMatchMeta(key, update)
|
|
920
596
|
};
|
|
921
597
|
}
|
|
922
598
|
async pollMatchDomain(options) {
|
|
923
|
-
const { poll, filepath, name, testId = name, message, adapter, isInline = false, inlineSnapshot, error, timeout = 1e3, interval = 50 } = options;
|
|
599
|
+
const { poll, filepath, name, testId = name, message, adapter, isInline = false, inlineSnapshot, error, timeout = 1e3, interval = 50, assertionName } = options;
|
|
924
600
|
if (!filepath) throw new Error("Snapshot cannot be used outside of test");
|
|
925
601
|
const snapshotState = this.getSnapshotState(filepath);
|
|
926
602
|
const testName = [name, ...message ? [message] : []].join(" > ");
|
|
@@ -956,20 +632,21 @@ class SnapshotClient {
|
|
|
956
632
|
// Silently hiding the error and creating snapshot full scratch isn't good either.
|
|
957
633
|
// Users can fix or purge the broken snapshot manually and that decision affects how domain snapshot gets updated.
|
|
958
634
|
const matchResult = expectedSnapshot.data !== void 0 ? adapter.match(stableResult.captured, adapter.parseExpected(expectedSnapshot.data)) : void 0;
|
|
959
|
-
const { actual, expected, key, pass } = snapshotState.processDomainSnapshot({
|
|
635
|
+
const { actual, expected, key, pass, update } = snapshotState.processDomainSnapshot({
|
|
960
636
|
testId,
|
|
961
637
|
received: stableResult.rendered,
|
|
962
638
|
expectedSnapshot,
|
|
963
639
|
matchResult,
|
|
964
640
|
isInline,
|
|
965
641
|
error,
|
|
966
|
-
assertionName
|
|
642
|
+
assertionName
|
|
967
643
|
});
|
|
968
644
|
return {
|
|
969
645
|
pass,
|
|
970
646
|
message: () => `Snapshot \`${key}\` mismatched`,
|
|
971
647
|
actual: actual?.trim(),
|
|
972
|
-
expected: expected?.trim()
|
|
648
|
+
expected: expected?.trim(),
|
|
649
|
+
meta: createMatchMeta(key, update)
|
|
973
650
|
};
|
|
974
651
|
}
|
|
975
652
|
async assertRaw(options) {
|
|
@@ -1045,6 +722,13 @@ function raceWith$1(promise, other) {
|
|
|
1045
722
|
value
|
|
1046
723
|
}))]);
|
|
1047
724
|
}
|
|
725
|
+
function createMatchMeta(key, update) {
|
|
726
|
+
return update && {
|
|
727
|
+
type: "snapshot",
|
|
728
|
+
key,
|
|
729
|
+
update
|
|
730
|
+
};
|
|
731
|
+
}
|
|
1048
732
|
|
|
1049
733
|
const ChaiStyleAssertions = (chai, utils) => {
|
|
1050
734
|
function defProperty(name, delegateTo) {
|
|
@@ -1410,6 +1094,12 @@ const IteratorSymbol = Symbol.iterator;
|
|
|
1410
1094
|
function hasIterator(object) {
|
|
1411
1095
|
return !!(object != null && object[IteratorSymbol]);
|
|
1412
1096
|
}
|
|
1097
|
+
function isTypedArray(value) {
|
|
1098
|
+
return ArrayBuffer.isView(value);
|
|
1099
|
+
}
|
|
1100
|
+
function getNonIndexEntries(typedArray) {
|
|
1101
|
+
return Object.keys(typedArray).slice(typedArray.length).map((key) => [key, Reflect.get(typedArray, key)]);
|
|
1102
|
+
}
|
|
1413
1103
|
function iterableEquality(a, b, customTesters = [], aStack = [], bStack = []) {
|
|
1414
1104
|
if (typeof a !== "object" || typeof b !== "object" || Array.isArray(a) || Array.isArray(b) || !hasIterator(a) || !hasIterator(b)) return;
|
|
1415
1105
|
if (a.constructor !== b.constructor) return false;
|
|
@@ -1463,6 +1153,14 @@ function iterableEquality(a, b, customTesters = [], aStack = [], bStack = []) {
|
|
|
1463
1153
|
return allFound;
|
|
1464
1154
|
}
|
|
1465
1155
|
}
|
|
1156
|
+
if (isTypedArray(a) && isTypedArray(b)) {
|
|
1157
|
+
if (a.length !== b.length) return false;
|
|
1158
|
+
for (let i = 0; i < a.length; i++) if (!Object.is(a[i], b[i]) && !equals(a[i], b[i], filteredCustomTesters)) return false;
|
|
1159
|
+
if (!equals(getNonIndexEntries(a), getNonIndexEntries(b), filteredCustomTesters)) return false;
|
|
1160
|
+
aStack.pop();
|
|
1161
|
+
bStack.pop();
|
|
1162
|
+
return true;
|
|
1163
|
+
}
|
|
1466
1164
|
const bIterator = b[IteratorSymbol]();
|
|
1467
1165
|
for (const aValue of a) {
|
|
1468
1166
|
const nextB = bIterator.next();
|
|
@@ -1951,7 +1649,7 @@ function wrapAssertion(utils, name, fn) {
|
|
|
1951
1649
|
return function(...args) {
|
|
1952
1650
|
// private
|
|
1953
1651
|
if (name !== "withTest") utils.flag(this, "_name", name);
|
|
1954
|
-
if (!utils.flag(this, "soft"))
|
|
1652
|
+
if (!(utils.flag(this, "soft") && !utils.flag(this, "promise")))
|
|
1955
1653
|
// avoid WebKit's proper tail call to preserve stacktrace offset for inline snapshot
|
|
1956
1654
|
// https://webkit.org/blog/6240/ecmascript-6-proper-tail-calls-in-webkit
|
|
1957
1655
|
try {
|
|
@@ -2708,6 +2406,92 @@ const benchMatchers = {
|
|
|
2708
2406
|
}
|
|
2709
2407
|
};
|
|
2710
2408
|
|
|
2409
|
+
const attempts = /* @__PURE__ */ new WeakMap();
|
|
2410
|
+
function startTraceAttempt(test, options) {
|
|
2411
|
+
attempts.set(test, {
|
|
2412
|
+
...options,
|
|
2413
|
+
startTime: performance.now(),
|
|
2414
|
+
entries: []
|
|
2415
|
+
});
|
|
2416
|
+
}
|
|
2417
|
+
function getTraceAttempt(test) {
|
|
2418
|
+
return attempts.get(test);
|
|
2419
|
+
}
|
|
2420
|
+
function createTraceRangeId() {
|
|
2421
|
+
return Math.random().toString(36).slice(2);
|
|
2422
|
+
}
|
|
2423
|
+
function recordTraceEntry(attempt, entry, source) {
|
|
2424
|
+
attempt.entries.push({
|
|
2425
|
+
entry: {
|
|
2426
|
+
...entry,
|
|
2427
|
+
startTime: performance.now() - attempt.startTime
|
|
2428
|
+
},
|
|
2429
|
+
source
|
|
2430
|
+
});
|
|
2431
|
+
}
|
|
2432
|
+
function startPromiseTraceRange(name, source) {
|
|
2433
|
+
const test = getCurrentTest();
|
|
2434
|
+
// the current test is a guess when several tests run concurrently
|
|
2435
|
+
const attempt = test && getRunningTests().size === 1 ? attempts.get(test) : void 0;
|
|
2436
|
+
if (!attempt) return (promise) => promise;
|
|
2437
|
+
const id = createTraceRangeId();
|
|
2438
|
+
recordTraceEntry(attempt, {
|
|
2439
|
+
name,
|
|
2440
|
+
kind: "expect",
|
|
2441
|
+
range: {
|
|
2442
|
+
id,
|
|
2443
|
+
phase: "start"
|
|
2444
|
+
}
|
|
2445
|
+
}, source);
|
|
2446
|
+
const end = (status) => recordTraceEntry(attempt, {
|
|
2447
|
+
name,
|
|
2448
|
+
kind: "expect",
|
|
2449
|
+
range: {
|
|
2450
|
+
id,
|
|
2451
|
+
phase: "end"
|
|
2452
|
+
},
|
|
2453
|
+
status
|
|
2454
|
+
}, source);
|
|
2455
|
+
return (promise) => {
|
|
2456
|
+
promise.then(() => end("pass"), () => end("fail"));
|
|
2457
|
+
return promise;
|
|
2458
|
+
};
|
|
2459
|
+
}
|
|
2460
|
+
async function finishTraceAttempt(test) {
|
|
2461
|
+
const attempt = attempts.get(test);
|
|
2462
|
+
attempts.delete(test);
|
|
2463
|
+
// record only failed attempts
|
|
2464
|
+
if (!attempt || test.result?.state !== "fail" || !attempt.entries.length) return;
|
|
2465
|
+
// locations are resolved in the main process, like error stacks
|
|
2466
|
+
const entries = attempt.entries.map(({ entry, source }) => ({
|
|
2467
|
+
...entry,
|
|
2468
|
+
stack: source.stack
|
|
2469
|
+
}));
|
|
2470
|
+
const data = {
|
|
2471
|
+
retry: attempt.retry,
|
|
2472
|
+
repeats: attempt.repeats,
|
|
2473
|
+
entries
|
|
2474
|
+
};
|
|
2475
|
+
await recordArtifact(test, {
|
|
2476
|
+
type: "internal:browserTrace",
|
|
2477
|
+
data
|
|
2478
|
+
});
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2481
|
+
/**
|
|
2482
|
+
* Copies the stack trace from one error to another.
|
|
2483
|
+
*
|
|
2484
|
+
* If the source has no stack trace, the target is left unchanged.
|
|
2485
|
+
*
|
|
2486
|
+
* @param target - The error to copy the stack trace to.
|
|
2487
|
+
* @param source - The error to copy the stack trace from.
|
|
2488
|
+
* @returns The target error with the updated stack trace.
|
|
2489
|
+
*/
|
|
2490
|
+
function copyStackTrace(target, source) {
|
|
2491
|
+
if (source.stack !== void 0) target.stack = source.stack.replace(source.message, target.message);
|
|
2492
|
+
return target;
|
|
2493
|
+
}
|
|
2494
|
+
|
|
2711
2495
|
var fakeTimersSrc = {};
|
|
2712
2496
|
|
|
2713
2497
|
var global;
|
|
@@ -3643,19 +3427,6 @@ function requireFakeTimersSrc () {
|
|
|
3643
3427
|
hasRequiredFakeTimersSrc = 1;
|
|
3644
3428
|
|
|
3645
3429
|
const globalObject = requireLib().global;
|
|
3646
|
-
let timersModule, timersPromisesModule;
|
|
3647
|
-
if (typeof __vitest_required__ !== 'undefined') {
|
|
3648
|
-
try {
|
|
3649
|
-
timersModule = __vitest_required__.timers;
|
|
3650
|
-
} catch {
|
|
3651
|
-
// ignored
|
|
3652
|
-
}
|
|
3653
|
-
try {
|
|
3654
|
-
timersPromisesModule = __vitest_required__.timersPromises;
|
|
3655
|
-
} catch {
|
|
3656
|
-
// ignored
|
|
3657
|
-
}
|
|
3658
|
-
}
|
|
3659
3430
|
|
|
3660
3431
|
/**
|
|
3661
3432
|
* @typedef {"nextAsync" | "manual" | "interval"} TickMode
|
|
@@ -4179,7 +3950,8 @@ function requireFakeTimersSrc () {
|
|
|
4179
3950
|
isPresent.hrtime && typeof _global.process.hrtime.bigint === "function";
|
|
4180
3951
|
isPresent.nextTick =
|
|
4181
3952
|
_global.process && typeof _global.process.nextTick === "function";
|
|
4182
|
-
const utilPromisify =
|
|
3953
|
+
const utilPromisify =
|
|
3954
|
+
_global.process && _global.__vitest_required__?.util.promisify;
|
|
4183
3955
|
isPresent.performance =
|
|
4184
3956
|
_global.performance && typeof _global.performance.now === "function";
|
|
4185
3957
|
const hasPerformancePrototype =
|
|
@@ -6219,6 +5991,7 @@ function requireFakeTimersSrc () {
|
|
|
6219
5991
|
clock.uninstall = function () {
|
|
6220
5992
|
uninstalled = true;
|
|
6221
5993
|
clock.setTickMode({ mode: "manual" });
|
|
5994
|
+
const { timersModule, timersPromisesModule } = clock;
|
|
6222
5995
|
|
|
6223
5996
|
if (clock.methods) {
|
|
6224
5997
|
const installedHrTime = "_hrtime";
|
|
@@ -6392,6 +6165,16 @@ function requireFakeTimersSrc () {
|
|
|
6392
6165
|
const clock = createClock(config.now, config.loopLimit);
|
|
6393
6166
|
clock.shouldClearNativeTimers = config.shouldClearNativeTimers;
|
|
6394
6167
|
|
|
6168
|
+
// Vitest injects Node builtins because this file is bundled without require.
|
|
6169
|
+
const vitestRequired =
|
|
6170
|
+
config.fakeNodeBuiltins && _global.__vitest_required__;
|
|
6171
|
+
const timersModule = vitestRequired?.timers;
|
|
6172
|
+
const timersPromisesModule = vitestRequired?.timersPromises;
|
|
6173
|
+
const syncBuiltinESMExports = vitestRequired?.syncBuiltinESMExports;
|
|
6174
|
+
// Keep the modules on the clock so uninstall can restore their methods.
|
|
6175
|
+
clock.timersModule = timersModule;
|
|
6176
|
+
clock.timersPromisesModule = timersPromisesModule;
|
|
6177
|
+
|
|
6395
6178
|
clock.abortListenerMap = new Map();
|
|
6396
6179
|
|
|
6397
6180
|
if (hasToFake) {
|
|
@@ -6733,6 +6516,21 @@ function requireFakeTimersSrc () {
|
|
|
6733
6516
|
}
|
|
6734
6517
|
}
|
|
6735
6518
|
|
|
6519
|
+
// Keep ESM named exports in sync with the patched CommonJS modules.
|
|
6520
|
+
if (
|
|
6521
|
+
syncBuiltinESMExports &&
|
|
6522
|
+
(clock.timersModuleMethods?.length ||
|
|
6523
|
+
clock.timersPromisesModuleMethods?.length)
|
|
6524
|
+
) {
|
|
6525
|
+
const uninstall = clock.uninstall;
|
|
6526
|
+
clock.uninstall = () => {
|
|
6527
|
+
const result = uninstall();
|
|
6528
|
+
syncBuiltinESMExports();
|
|
6529
|
+
return result;
|
|
6530
|
+
};
|
|
6531
|
+
syncBuiltinESMExports();
|
|
6532
|
+
}
|
|
6533
|
+
|
|
6736
6534
|
return clock;
|
|
6737
6535
|
}
|
|
6738
6536
|
|
|
@@ -6872,7 +6670,8 @@ class FakeTimers {
|
|
|
6872
6670
|
}
|
|
6873
6671
|
}
|
|
6874
6672
|
setSystemTime(now) {
|
|
6875
|
-
const
|
|
6673
|
+
const normalized = normalizeSystemTime(now);
|
|
6674
|
+
const date = typeof normalized === "undefined" || normalized instanceof Date ? normalized : new Date(normalized);
|
|
6876
6675
|
if (this._fakingTime) this._clock.setSystemTime(date);
|
|
6877
6676
|
else {
|
|
6878
6677
|
const newFakingDate = date ?? new Date(this.getRealSystemTime());
|
|
@@ -6921,6 +6720,10 @@ class FakeTimers {
|
|
|
6921
6720
|
return this._fakingTime;
|
|
6922
6721
|
}
|
|
6923
6722
|
}
|
|
6723
|
+
// Like fake-timers, read epochMilliseconds from Instant or ZonedDateTime without requiring built-in Temporal types.
|
|
6724
|
+
function normalizeSystemTime(time) {
|
|
6725
|
+
return time && typeof time === "object" && "epochMilliseconds" in time ? time.epochMilliseconds : time;
|
|
6726
|
+
}
|
|
6924
6727
|
|
|
6925
6728
|
const whenSymbol = Symbol.for("$$vitest:when");
|
|
6926
6729
|
/**
|
|
@@ -7151,15 +6954,27 @@ function validateOptions(options) {
|
|
|
7151
6954
|
if (typeof options?.times === "number" && options.times <= 0) throw new RangeError("vi.when: `times` option must be greater than 0");
|
|
7152
6955
|
}
|
|
7153
6956
|
|
|
7154
|
-
function
|
|
7155
|
-
if (
|
|
7156
|
-
|
|
6957
|
+
function prefixMessage(error, message) {
|
|
6958
|
+
if (message && error instanceof Error) {
|
|
6959
|
+
const original = error.message;
|
|
6960
|
+
try {
|
|
6961
|
+
error.message = `${message}: ${original}`;
|
|
6962
|
+
} catch {
|
|
6963
|
+
// message can be read-only, e.g. DOMException
|
|
6964
|
+
return error;
|
|
6965
|
+
}
|
|
6966
|
+
if (error.stack !== void 0) error.stack = error.stack.replace(original, error.message);
|
|
6967
|
+
}
|
|
6968
|
+
return error;
|
|
6969
|
+
}
|
|
6970
|
+
function getTraceName(name, message) {
|
|
6971
|
+
return message ? `${message} (${name})` : `${name}()`;
|
|
7157
6972
|
}
|
|
7158
6973
|
function waitFor(callback, options = {}) {
|
|
7159
6974
|
const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers();
|
|
7160
|
-
const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
|
|
6975
|
+
const { interval = 50, timeout = 1e3, message } = typeof options === "number" ? { timeout: options } : options;
|
|
7161
6976
|
const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
|
|
7162
|
-
return new Promise((resolve, reject) => {
|
|
6977
|
+
return startPromiseTraceRange(getTraceName("vi.waitFor", message), STACK_TRACE_ERROR)(new Promise((resolve, reject) => {
|
|
7163
6978
|
let lastError;
|
|
7164
6979
|
let promiseStatus = "idle";
|
|
7165
6980
|
let timeoutId;
|
|
@@ -7172,8 +6987,8 @@ function waitFor(callback, options = {}) {
|
|
|
7172
6987
|
const handleTimeout = () => {
|
|
7173
6988
|
if (intervalId) clearInterval(intervalId);
|
|
7174
6989
|
let error = lastError;
|
|
7175
|
-
if (!error) error = copyStackTrace
|
|
7176
|
-
reject(error);
|
|
6990
|
+
if (!error) error = copyStackTrace(/* @__PURE__ */ new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
|
|
6991
|
+
reject(prefixMessage(error, message));
|
|
7177
6992
|
};
|
|
7178
6993
|
const checkCallback = () => {
|
|
7179
6994
|
if (vi.isFakeTimers()) vi.advanceTimersByTime(interval);
|
|
@@ -7201,20 +7016,20 @@ function waitFor(callback, options = {}) {
|
|
|
7201
7016
|
if (checkCallback() === true) return;
|
|
7202
7017
|
timeoutId = setTimeout(handleTimeout, timeout);
|
|
7203
7018
|
intervalId = setInterval(checkCallback, interval);
|
|
7204
|
-
});
|
|
7019
|
+
}));
|
|
7205
7020
|
}
|
|
7206
7021
|
function waitUntil(callback, options = {}) {
|
|
7207
7022
|
const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers();
|
|
7208
|
-
const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
|
|
7023
|
+
const { interval = 50, timeout = 1e3, message } = typeof options === "number" ? { timeout: options } : options;
|
|
7209
7024
|
const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
|
|
7210
|
-
return new Promise((resolve, reject) => {
|
|
7025
|
+
return startPromiseTraceRange(getTraceName("vi.waitUntil", message), STACK_TRACE_ERROR)(new Promise((resolve, reject) => {
|
|
7211
7026
|
let promiseStatus = "idle";
|
|
7212
7027
|
let timeoutId;
|
|
7213
7028
|
let intervalId;
|
|
7214
7029
|
const onReject = (error) => {
|
|
7215
7030
|
if (intervalId) clearInterval(intervalId);
|
|
7216
|
-
if (!error) error = copyStackTrace
|
|
7217
|
-
reject(error);
|
|
7031
|
+
if (!error) error = copyStackTrace(/* @__PURE__ */ new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
|
|
7032
|
+
reject(prefixMessage(error, message));
|
|
7218
7033
|
};
|
|
7219
7034
|
const onResolve = (result) => {
|
|
7220
7035
|
if (!result) return;
|
|
@@ -7246,7 +7061,7 @@ function waitUntil(callback, options = {}) {
|
|
|
7246
7061
|
if (checkCallback() === true) return;
|
|
7247
7062
|
timeoutId = setTimeout(onReject, timeout);
|
|
7248
7063
|
intervalId = setInterval(checkCallback, interval);
|
|
7249
|
-
});
|
|
7064
|
+
}));
|
|
7250
7065
|
}
|
|
7251
7066
|
|
|
7252
7067
|
function createVitest() {
|
|
@@ -7361,7 +7176,7 @@ function createVitest() {
|
|
|
7361
7176
|
try {
|
|
7362
7177
|
return await result;
|
|
7363
7178
|
} catch (error) {
|
|
7364
|
-
if (error instanceof Error && !error.stack?.includes("__VITEST_HELPER__")) copyStackTrace
|
|
7179
|
+
if (error instanceof Error && !error.stack?.includes("__VITEST_HELPER__")) copyStackTrace(error, stackTraceError);
|
|
7365
7180
|
throw error;
|
|
7366
7181
|
}
|
|
7367
7182
|
})();
|
|
@@ -7495,10 +7310,6 @@ function getImporter(name) {
|
|
|
7495
7310
|
});
|
|
7496
7311
|
return parseSingleStack(stackArray[importerStackIndex + 1])?.file || "";
|
|
7497
7312
|
}
|
|
7498
|
-
function copyStackTrace$1(target, source) {
|
|
7499
|
-
if (source.stack !== void 0) target.stack = source.stack.replace(source.message, target.message);
|
|
7500
|
-
return target;
|
|
7501
|
-
}
|
|
7502
7313
|
function waitNextTick() {
|
|
7503
7314
|
const { setTimeout } = getSafeTimers();
|
|
7504
7315
|
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
@@ -7528,15 +7339,20 @@ const unsupported = [
|
|
|
7528
7339
|
"toThrowError"
|
|
7529
7340
|
];
|
|
7530
7341
|
/**
|
|
7531
|
-
* Attaches a `cause` property to the error if missing, copies the stack trace from the source, and throws.
|
|
7342
|
+
* Attaches a `cause` property to the error if missing, prefixes the custom message, copies the stack trace from the source, and throws.
|
|
7532
7343
|
*
|
|
7533
7344
|
* @param error - The error to throw
|
|
7534
7345
|
* @param source - Error to copy the stack trace from
|
|
7346
|
+
* @param message - Custom message passed to `expect.poll`
|
|
7535
7347
|
*
|
|
7536
7348
|
* @throws Always throws the provided error with an amended stack trace
|
|
7537
7349
|
*/
|
|
7538
|
-
function throwWithCause(error, source) {
|
|
7350
|
+
function throwWithCause(error, source, message) {
|
|
7539
7351
|
error.cause ??= /* @__PURE__ */ new Error("Matcher did not succeed in time.");
|
|
7352
|
+
// matcher errors already start with the custom message
|
|
7353
|
+
if (message && typeof error.message === "string" && !error.message.startsWith(`${message}: `)) try {
|
|
7354
|
+
error.message = `${message}: ${error.message}`;
|
|
7355
|
+
} catch {}
|
|
7540
7356
|
throw copyStackTrace(error, source);
|
|
7541
7357
|
}
|
|
7542
7358
|
function createExpectPoll(expect) {
|
|
@@ -7552,6 +7368,7 @@ function createExpectPoll(expect) {
|
|
|
7552
7368
|
chai.util.flag(assertion, "_poll.interval", interval);
|
|
7553
7369
|
const test = chai.util.flag(assertion, "vitest-test");
|
|
7554
7370
|
if (!test) throw new Error("expect.poll() must be called inside a test");
|
|
7371
|
+
setTraceHandlers(assertion, test);
|
|
7555
7372
|
const proxy = new Proxy(assertion, { get(target, key, receiver) {
|
|
7556
7373
|
const assertionFunction = Reflect.get(target, key, receiver);
|
|
7557
7374
|
if (typeof assertionFunction !== "function") return assertionFunction instanceof chai.Assertion ? proxy : assertionFunction;
|
|
@@ -7595,7 +7412,7 @@ function createExpectPoll(expect) {
|
|
|
7595
7412
|
assertion,
|
|
7596
7413
|
status: "fail"
|
|
7597
7414
|
});
|
|
7598
|
-
throwWithCause(err, STACK_TRACE_ERROR);
|
|
7415
|
+
throwWithCause(err, STACK_TRACE_ERROR, message);
|
|
7599
7416
|
}
|
|
7600
7417
|
const { setTimeout, clearTimeout } = getSafeTimers();
|
|
7601
7418
|
let timerId;
|
|
@@ -7643,7 +7460,7 @@ function createExpectPoll(expect) {
|
|
|
7643
7460
|
assertion,
|
|
7644
7461
|
status: "fail"
|
|
7645
7462
|
});
|
|
7646
|
-
throwWithCause(lastError, STACK_TRACE_ERROR);
|
|
7463
|
+
throwWithCause(lastError, STACK_TRACE_ERROR, message);
|
|
7647
7464
|
}
|
|
7648
7465
|
};
|
|
7649
7466
|
let awaited = false;
|
|
@@ -7652,7 +7469,8 @@ function createExpectPoll(expect) {
|
|
|
7652
7469
|
if (!awaited) {
|
|
7653
7470
|
const negated = chai.util.flag(assertion, "negate") ? "not." : "";
|
|
7654
7471
|
const assertionString = `expect.${chai.util.flag(assertion, "_poll.element") ? "element(locator)" : "poll(assertion)"}.${negated}${String(key)}()`;
|
|
7655
|
-
|
|
7472
|
+
const error = /* @__PURE__ */ new Error(`${assertionString} was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:\n\nawait ${assertionString}\n`);
|
|
7473
|
+
throw copyStackTrace(error, STACK_TRACE_ERROR);
|
|
7656
7474
|
}
|
|
7657
7475
|
});
|
|
7658
7476
|
let resultPromise;
|
|
@@ -7681,9 +7499,41 @@ function createExpectPoll(expect) {
|
|
|
7681
7499
|
return proxy;
|
|
7682
7500
|
};
|
|
7683
7501
|
}
|
|
7684
|
-
function
|
|
7685
|
-
|
|
7686
|
-
return
|
|
7502
|
+
function setTraceHandlers(assertion, test) {
|
|
7503
|
+
const attempt = getTraceAttempt(test);
|
|
7504
|
+
if (!attempt) return;
|
|
7505
|
+
const rangeId = createTraceRangeId();
|
|
7506
|
+
// TODO: compute the name once in `__VITEST_POLL_CHAIN__` and pass it to the hooks,
|
|
7507
|
+
// so this and `getTraceName` in packages/browser/src/client/tester/expect-element.ts can share it
|
|
7508
|
+
const getName = (assertion) => {
|
|
7509
|
+
const negated = chai.util.flag(assertion, "negate") ? "not." : "";
|
|
7510
|
+
const message = chai.util.flag(assertion, "message");
|
|
7511
|
+
const name = `expect.poll().${negated}${chai.util.flag(assertion, "_name")}`;
|
|
7512
|
+
return message ? `${message} (${name})` : `${name}()`;
|
|
7513
|
+
};
|
|
7514
|
+
const onStart = ({ assertion }) => {
|
|
7515
|
+
recordTraceEntry(attempt, {
|
|
7516
|
+
name: getName(assertion),
|
|
7517
|
+
kind: "expect",
|
|
7518
|
+
range: {
|
|
7519
|
+
id: rangeId,
|
|
7520
|
+
phase: "start"
|
|
7521
|
+
}
|
|
7522
|
+
}, chai.util.flag(assertion, "error"));
|
|
7523
|
+
};
|
|
7524
|
+
const onSettled = ({ assertion, status }) => {
|
|
7525
|
+
recordTraceEntry(attempt, {
|
|
7526
|
+
name: getName(assertion),
|
|
7527
|
+
kind: "expect",
|
|
7528
|
+
range: {
|
|
7529
|
+
id: rangeId,
|
|
7530
|
+
phase: "end"
|
|
7531
|
+
},
|
|
7532
|
+
status
|
|
7533
|
+
}, chai.util.flag(assertion, "error"));
|
|
7534
|
+
};
|
|
7535
|
+
chai.util.flag(assertion, "_poll.onStart", onStart);
|
|
7536
|
+
chai.util.flag(assertion, "_poll.onSettled", onSettled);
|
|
7687
7537
|
}
|
|
7688
7538
|
function raceWith(promise, other) {
|
|
7689
7539
|
const left = promise.then((value) => ({
|
|
@@ -7766,7 +7616,9 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
7766
7616
|
filepath,
|
|
7767
7617
|
hint
|
|
7768
7618
|
}).then((result) => assertMatchResult(result, chai.util.flag(this, "message")));
|
|
7769
|
-
|
|
7619
|
+
// `.resolves/rejects` handle `expect.soft` through `recordAsyncExpect`
|
|
7620
|
+
const isSoft = utils.flag(this, "soft") && !utils.flag(this, "promise");
|
|
7621
|
+
return recordAsyncExpect(getTest(this), assertPromise, createAssertionMessage(utils, this, true), /* @__PURE__ */ new Error("resolves"), isSoft);
|
|
7770
7622
|
});
|
|
7771
7623
|
utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", wrapAssertion(utils, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT_OFFSET_3__(propertiesOrInlineSnapshot, inlineSnapshotOrHint, hint) {
|
|
7772
7624
|
return assertMatchResult(toMatchSnapshotImpl({
|
|
@@ -7882,6 +7734,7 @@ async function toMatchFileSnapshotImpl(options) {
|
|
|
7882
7734
|
const snapshotState = getSnapshotClient().getSnapshotState(testNames.filepath);
|
|
7883
7735
|
const rawSnapshotFile = await snapshotState.environment.resolveRawPath(testNames.filepath, options.filepath);
|
|
7884
7736
|
const rawSnapshotContent = await snapshotState.environment.readSnapshotFile(rawSnapshotFile);
|
|
7737
|
+
const assertionName = getAssertionName(assertion);
|
|
7885
7738
|
return getSnapshotClient().match({
|
|
7886
7739
|
received: options.received,
|
|
7887
7740
|
message: options.hint,
|
|
@@ -7889,6 +7742,7 @@ async function toMatchFileSnapshotImpl(options) {
|
|
|
7889
7742
|
file: rawSnapshotFile,
|
|
7890
7743
|
content: rawSnapshotContent ?? void 0
|
|
7891
7744
|
},
|
|
7745
|
+
assertionName,
|
|
7892
7746
|
...testNames
|
|
7893
7747
|
});
|
|
7894
7748
|
}
|
|
@@ -7898,7 +7752,8 @@ function assertMatchResult(result, customMessage) {
|
|
|
7898
7752
|
throw Object.assign(new Error(errorMessage), {
|
|
7899
7753
|
actual: result.actual,
|
|
7900
7754
|
expected: result.expected,
|
|
7901
|
-
diffOptions: { expand: getWorkerState().config.snapshotOptions.expand }
|
|
7755
|
+
diffOptions: { expand: getWorkerState().config.snapshotOptions.expand },
|
|
7756
|
+
__vitest_error_context__: { meta: result.meta }
|
|
7902
7757
|
});
|
|
7903
7758
|
}
|
|
7904
7759
|
}
|
|
@@ -8518,7 +8373,8 @@ class TestRunner {
|
|
|
8518
8373
|
if (suite.mode !== "skip" && "filepath" in suite) await this.snapshotClient.setup(suite.file.filepath, this.workerState.config.snapshotOptions);
|
|
8519
8374
|
this.workerState.current = suite;
|
|
8520
8375
|
}
|
|
8521
|
-
onBeforeTryTask(test,
|
|
8376
|
+
onBeforeTryTask(test, options) {
|
|
8377
|
+
if (this.config.experimental.traceTimeline && test.type === "test") startTraceAttempt(test, options);
|
|
8522
8378
|
clearModuleMocks(this.config);
|
|
8523
8379
|
this.snapshotClient.clearTest(test.file.filepath, test.id);
|
|
8524
8380
|
setState({
|
|
@@ -8531,6 +8387,9 @@ class TestRunner {
|
|
|
8531
8387
|
snapshotState: this.snapshotClient.getSnapshotState(test.file.filepath)
|
|
8532
8388
|
}, globalThis[GLOBAL_EXPECT]);
|
|
8533
8389
|
}
|
|
8390
|
+
async onAfterRetryTask(test, _options) {
|
|
8391
|
+
if (this.config.experimental.traceTimeline) await finishTraceAttempt(test);
|
|
8392
|
+
}
|
|
8534
8393
|
onAfterTryTask(test) {
|
|
8535
8394
|
this.benchInstances.get(test)?.[kFinalize]();
|
|
8536
8395
|
const { assertionCalls, expectedAssertionsNumber, expectedAssertionsNumberErrorGen, isExpectingAssertions, isExpectingAssertionsError } = test.context._local ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
|
|
@@ -8610,33 +8469,33 @@ function clearModuleMocks(config) {
|
|
|
8610
8469
|
const assertType = function assertType() {};
|
|
8611
8470
|
|
|
8612
8471
|
var index = /*#__PURE__*/Object.freeze({
|
|
8613
|
-
|
|
8614
|
-
|
|
8615
|
-
|
|
8616
|
-
|
|
8617
|
-
|
|
8618
|
-
|
|
8619
|
-
|
|
8620
|
-
|
|
8621
|
-
|
|
8622
|
-
|
|
8623
|
-
|
|
8624
|
-
|
|
8625
|
-
|
|
8626
|
-
|
|
8627
|
-
|
|
8628
|
-
|
|
8629
|
-
|
|
8630
|
-
|
|
8631
|
-
|
|
8632
|
-
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
|
|
8472
|
+
__proto__: null,
|
|
8473
|
+
EvaluatedModules: VitestEvaluatedModules,
|
|
8474
|
+
Snapshots: Snapshots,
|
|
8475
|
+
TestRunner: TestRunner,
|
|
8476
|
+
afterAll: afterAll,
|
|
8477
|
+
afterEach: afterEach,
|
|
8478
|
+
aroundAll: aroundAll,
|
|
8479
|
+
aroundEach: aroundEach,
|
|
8480
|
+
assert: assert,
|
|
8481
|
+
assertType: assertType,
|
|
8482
|
+
beforeAll: beforeAll,
|
|
8483
|
+
beforeEach: beforeEach,
|
|
8484
|
+
chai: chai,
|
|
8485
|
+
createExpect: createExpect,
|
|
8486
|
+
describe: describe,
|
|
8487
|
+
expect: globalExpect,
|
|
8488
|
+
expectTypeOf: expectTypeOf,
|
|
8489
|
+
inject: inject,
|
|
8490
|
+
it: it,
|
|
8491
|
+
onTestFailed: onTestFailed,
|
|
8492
|
+
onTestFinished: onTestFinished,
|
|
8493
|
+
recordArtifact: recordArtifact,
|
|
8494
|
+
should: should,
|
|
8495
|
+
suite: suite,
|
|
8496
|
+
test: test,
|
|
8497
|
+
vi: vi,
|
|
8498
|
+
vitest: vitest
|
|
8640
8499
|
});
|
|
8641
8500
|
|
|
8642
8501
|
export { Snapshots as S, TestRunner as T, assert as a, assertType as b, createExpect as c, inject as d, vitest as e, globalExpect as g, index as i, should as s, vi as v };
|