vitest 5.1.0-beta.1 → 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/dist/browser.d.ts +6 -5
- package/dist/browser.js +6 -6
- package/dist/chunks/{base.PJyN9N0u.js → base.Cof-UHJf.js} +14 -19
- package/dist/chunks/{browser.d.D7a15z82.d.ts → browser.d.C7tWgUvw.d.ts} +3 -3
- package/dist/chunks/{cac.Ccf5Je_F.js → cac.BYbt0aJp.js} +22 -20
- package/dist/chunks/{cli-api.DE22LIzq.js → cli-api.COfZo8lK.js} +714 -73
- package/dist/chunks/{config.d.BgktgHfG.d.ts → config.d.B3YV4t0O.d.ts} +37 -2
- package/dist/chunks/{console.DrMPSuFo.js → console.CQZ877Hi.js} +2 -2
- 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.BQ3onxbh.js → creator.DHWmytIK.js} +10 -10
- package/dist/chunks/{doctor.CPlMs7-y.js → doctor.B-oPbwps.js} +2 -2
- package/dist/chunks/{environment.d.CbTLsZSj.d.ts → environment.d.BFQtFKdZ.d.ts} +1 -1
- package/dist/chunks/{globals.TipXUFcZ.js → globals.ZKtKSkEf.js} +6 -5
- package/dist/chunks/{index.BFXLpwll.js → index.Bi0NXYPf.js} +58 -32
- package/dist/chunks/{index.BXttT2gP.js → index.CZzC1gGg.js} +265 -425
- package/dist/chunks/{index.D14IAvnE.js → index.Di8au7q4.js} +68 -62
- package/dist/chunks/{index.B03wg4V0.js → index.w_oBZ9N8.js} +5 -5
- package/dist/chunks/{init-forks.BL1E3__4.js → init-forks.BaDXQSD8.js} +1 -1
- package/dist/chunks/{init-threads.CYXAGzKQ.js → init-threads.ZX_Vov0z.js} +1 -1
- package/dist/chunks/{init.DVorxUyL.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.3uBcOd84.js → nativeModuleMocker.Dh5azSB4.js} +3 -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.olEn8IL9.d.ts → plugin.d.LRFSN46m.d.ts} +90 -19
- package/dist/chunks/rawSnapshot.DqSiqIEx.js +356 -0
- package/dist/chunks/{resolver.CtCcxIy1.js → resolver.BzpmeQeT.js} +1 -1
- package/dist/chunks/{rpc.BV0XpJ5q.js → rpc.Uhkwr2NM.js} +2 -2
- package/dist/chunks/{rpc.d.DGFP7vWr.d.ts → rpc.d.3FOhdFx8.d.ts} +1 -1
- package/dist/chunks/{run.BfrMbGVD.js → run.CjdgFZiW.js} +7 -4
- package/dist/chunks/{setup-common.llxJkJaD.js → setup-common.CqAQCXzx.js} +2 -2
- package/dist/chunks/{source-map.BjWcsIL9.js → source-map.DakdQc29.js} +11 -13
- package/dist/chunks/{source-map.d.C5A_Tr6V.d.ts → source-map.d.BkG8YK_3.d.ts} +1 -1
- package/dist/chunks/{task-utils.d.BUh7ylUT.d.ts → task-utils.d.D-gFPNFi.d.ts} +1 -1
- package/dist/chunks/{utils.DSfl_w8V.js → utils.BBk_icFG.js} +6 -3
- package/dist/chunks/{vm.Cwj01UFE.js → vm.b4MbCAJQ.js} +15 -13
- package/dist/chunks/{worker.d.gsA26mmR.d.ts → worker.d.CyJRpyfZ.d.ts} +3 -3
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +8 -8
- package/dist/index.d.ts +17 -12
- package/dist/index.js +6 -5
- package/dist/module-evaluator.d.ts +2 -2
- package/dist/node.d.ts +10 -10
- package/dist/node.js +15 -13
- package/dist/runtime.d.ts +4 -4
- package/dist/runtime.js +4 -4
- package/dist/task-utils.js +7 -3
- 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 +13 -10
- package/dist/workers/threads.js +15 -14
- package/dist/workers/vmForks.js +10 -10
- package/dist/workers/vmThreads.js +10 -10
- package/package.json +15 -15
|
@@ -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;
|
|
@@ -7170,15 +6954,27 @@ function validateOptions(options) {
|
|
|
7170
6954
|
if (typeof options?.times === "number" && options.times <= 0) throw new RangeError("vi.when: `times` option must be greater than 0");
|
|
7171
6955
|
}
|
|
7172
6956
|
|
|
7173
|
-
function
|
|
7174
|
-
if (
|
|
7175
|
-
|
|
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}()`;
|
|
7176
6972
|
}
|
|
7177
6973
|
function waitFor(callback, options = {}) {
|
|
7178
6974
|
const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers();
|
|
7179
|
-
const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
|
|
6975
|
+
const { interval = 50, timeout = 1e3, message } = typeof options === "number" ? { timeout: options } : options;
|
|
7180
6976
|
const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
|
|
7181
|
-
return new Promise((resolve, reject) => {
|
|
6977
|
+
return startPromiseTraceRange(getTraceName("vi.waitFor", message), STACK_TRACE_ERROR)(new Promise((resolve, reject) => {
|
|
7182
6978
|
let lastError;
|
|
7183
6979
|
let promiseStatus = "idle";
|
|
7184
6980
|
let timeoutId;
|
|
@@ -7191,8 +6987,8 @@ function waitFor(callback, options = {}) {
|
|
|
7191
6987
|
const handleTimeout = () => {
|
|
7192
6988
|
if (intervalId) clearInterval(intervalId);
|
|
7193
6989
|
let error = lastError;
|
|
7194
|
-
if (!error) error = copyStackTrace
|
|
7195
|
-
reject(error);
|
|
6990
|
+
if (!error) error = copyStackTrace(/* @__PURE__ */ new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
|
|
6991
|
+
reject(prefixMessage(error, message));
|
|
7196
6992
|
};
|
|
7197
6993
|
const checkCallback = () => {
|
|
7198
6994
|
if (vi.isFakeTimers()) vi.advanceTimersByTime(interval);
|
|
@@ -7220,20 +7016,20 @@ function waitFor(callback, options = {}) {
|
|
|
7220
7016
|
if (checkCallback() === true) return;
|
|
7221
7017
|
timeoutId = setTimeout(handleTimeout, timeout);
|
|
7222
7018
|
intervalId = setInterval(checkCallback, interval);
|
|
7223
|
-
});
|
|
7019
|
+
}));
|
|
7224
7020
|
}
|
|
7225
7021
|
function waitUntil(callback, options = {}) {
|
|
7226
7022
|
const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers();
|
|
7227
|
-
const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
|
|
7023
|
+
const { interval = 50, timeout = 1e3, message } = typeof options === "number" ? { timeout: options } : options;
|
|
7228
7024
|
const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
|
|
7229
|
-
return new Promise((resolve, reject) => {
|
|
7025
|
+
return startPromiseTraceRange(getTraceName("vi.waitUntil", message), STACK_TRACE_ERROR)(new Promise((resolve, reject) => {
|
|
7230
7026
|
let promiseStatus = "idle";
|
|
7231
7027
|
let timeoutId;
|
|
7232
7028
|
let intervalId;
|
|
7233
7029
|
const onReject = (error) => {
|
|
7234
7030
|
if (intervalId) clearInterval(intervalId);
|
|
7235
|
-
if (!error) error = copyStackTrace
|
|
7236
|
-
reject(error);
|
|
7031
|
+
if (!error) error = copyStackTrace(/* @__PURE__ */ new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
|
|
7032
|
+
reject(prefixMessage(error, message));
|
|
7237
7033
|
};
|
|
7238
7034
|
const onResolve = (result) => {
|
|
7239
7035
|
if (!result) return;
|
|
@@ -7265,7 +7061,7 @@ function waitUntil(callback, options = {}) {
|
|
|
7265
7061
|
if (checkCallback() === true) return;
|
|
7266
7062
|
timeoutId = setTimeout(onReject, timeout);
|
|
7267
7063
|
intervalId = setInterval(checkCallback, interval);
|
|
7268
|
-
});
|
|
7064
|
+
}));
|
|
7269
7065
|
}
|
|
7270
7066
|
|
|
7271
7067
|
function createVitest() {
|
|
@@ -7380,7 +7176,7 @@ function createVitest() {
|
|
|
7380
7176
|
try {
|
|
7381
7177
|
return await result;
|
|
7382
7178
|
} catch (error) {
|
|
7383
|
-
if (error instanceof Error && !error.stack?.includes("__VITEST_HELPER__")) copyStackTrace
|
|
7179
|
+
if (error instanceof Error && !error.stack?.includes("__VITEST_HELPER__")) copyStackTrace(error, stackTraceError);
|
|
7384
7180
|
throw error;
|
|
7385
7181
|
}
|
|
7386
7182
|
})();
|
|
@@ -7514,10 +7310,6 @@ function getImporter(name) {
|
|
|
7514
7310
|
});
|
|
7515
7311
|
return parseSingleStack(stackArray[importerStackIndex + 1])?.file || "";
|
|
7516
7312
|
}
|
|
7517
|
-
function copyStackTrace$1(target, source) {
|
|
7518
|
-
if (source.stack !== void 0) target.stack = source.stack.replace(source.message, target.message);
|
|
7519
|
-
return target;
|
|
7520
|
-
}
|
|
7521
7313
|
function waitNextTick() {
|
|
7522
7314
|
const { setTimeout } = getSafeTimers();
|
|
7523
7315
|
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
@@ -7547,15 +7339,20 @@ const unsupported = [
|
|
|
7547
7339
|
"toThrowError"
|
|
7548
7340
|
];
|
|
7549
7341
|
/**
|
|
7550
|
-
* 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.
|
|
7551
7343
|
*
|
|
7552
7344
|
* @param error - The error to throw
|
|
7553
7345
|
* @param source - Error to copy the stack trace from
|
|
7346
|
+
* @param message - Custom message passed to `expect.poll`
|
|
7554
7347
|
*
|
|
7555
7348
|
* @throws Always throws the provided error with an amended stack trace
|
|
7556
7349
|
*/
|
|
7557
|
-
function throwWithCause(error, source) {
|
|
7350
|
+
function throwWithCause(error, source, message) {
|
|
7558
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 {}
|
|
7559
7356
|
throw copyStackTrace(error, source);
|
|
7560
7357
|
}
|
|
7561
7358
|
function createExpectPoll(expect) {
|
|
@@ -7571,6 +7368,7 @@ function createExpectPoll(expect) {
|
|
|
7571
7368
|
chai.util.flag(assertion, "_poll.interval", interval);
|
|
7572
7369
|
const test = chai.util.flag(assertion, "vitest-test");
|
|
7573
7370
|
if (!test) throw new Error("expect.poll() must be called inside a test");
|
|
7371
|
+
setTraceHandlers(assertion, test);
|
|
7574
7372
|
const proxy = new Proxy(assertion, { get(target, key, receiver) {
|
|
7575
7373
|
const assertionFunction = Reflect.get(target, key, receiver);
|
|
7576
7374
|
if (typeof assertionFunction !== "function") return assertionFunction instanceof chai.Assertion ? proxy : assertionFunction;
|
|
@@ -7614,7 +7412,7 @@ function createExpectPoll(expect) {
|
|
|
7614
7412
|
assertion,
|
|
7615
7413
|
status: "fail"
|
|
7616
7414
|
});
|
|
7617
|
-
throwWithCause(err, STACK_TRACE_ERROR);
|
|
7415
|
+
throwWithCause(err, STACK_TRACE_ERROR, message);
|
|
7618
7416
|
}
|
|
7619
7417
|
const { setTimeout, clearTimeout } = getSafeTimers();
|
|
7620
7418
|
let timerId;
|
|
@@ -7662,7 +7460,7 @@ function createExpectPoll(expect) {
|
|
|
7662
7460
|
assertion,
|
|
7663
7461
|
status: "fail"
|
|
7664
7462
|
});
|
|
7665
|
-
throwWithCause(lastError, STACK_TRACE_ERROR);
|
|
7463
|
+
throwWithCause(lastError, STACK_TRACE_ERROR, message);
|
|
7666
7464
|
}
|
|
7667
7465
|
};
|
|
7668
7466
|
let awaited = false;
|
|
@@ -7671,7 +7469,8 @@ function createExpectPoll(expect) {
|
|
|
7671
7469
|
if (!awaited) {
|
|
7672
7470
|
const negated = chai.util.flag(assertion, "negate") ? "not." : "";
|
|
7673
7471
|
const assertionString = `expect.${chai.util.flag(assertion, "_poll.element") ? "element(locator)" : "poll(assertion)"}.${negated}${String(key)}()`;
|
|
7674
|
-
|
|
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);
|
|
7675
7474
|
}
|
|
7676
7475
|
});
|
|
7677
7476
|
let resultPromise;
|
|
@@ -7700,9 +7499,41 @@ function createExpectPoll(expect) {
|
|
|
7700
7499
|
return proxy;
|
|
7701
7500
|
};
|
|
7702
7501
|
}
|
|
7703
|
-
function
|
|
7704
|
-
|
|
7705
|
-
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);
|
|
7706
7537
|
}
|
|
7707
7538
|
function raceWith(promise, other) {
|
|
7708
7539
|
const left = promise.then((value) => ({
|
|
@@ -7785,7 +7616,9 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
7785
7616
|
filepath,
|
|
7786
7617
|
hint
|
|
7787
7618
|
}).then((result) => assertMatchResult(result, chai.util.flag(this, "message")));
|
|
7788
|
-
|
|
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);
|
|
7789
7622
|
});
|
|
7790
7623
|
utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", wrapAssertion(utils, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT_OFFSET_3__(propertiesOrInlineSnapshot, inlineSnapshotOrHint, hint) {
|
|
7791
7624
|
return assertMatchResult(toMatchSnapshotImpl({
|
|
@@ -7901,6 +7734,7 @@ async function toMatchFileSnapshotImpl(options) {
|
|
|
7901
7734
|
const snapshotState = getSnapshotClient().getSnapshotState(testNames.filepath);
|
|
7902
7735
|
const rawSnapshotFile = await snapshotState.environment.resolveRawPath(testNames.filepath, options.filepath);
|
|
7903
7736
|
const rawSnapshotContent = await snapshotState.environment.readSnapshotFile(rawSnapshotFile);
|
|
7737
|
+
const assertionName = getAssertionName(assertion);
|
|
7904
7738
|
return getSnapshotClient().match({
|
|
7905
7739
|
received: options.received,
|
|
7906
7740
|
message: options.hint,
|
|
@@ -7908,6 +7742,7 @@ async function toMatchFileSnapshotImpl(options) {
|
|
|
7908
7742
|
file: rawSnapshotFile,
|
|
7909
7743
|
content: rawSnapshotContent ?? void 0
|
|
7910
7744
|
},
|
|
7745
|
+
assertionName,
|
|
7911
7746
|
...testNames
|
|
7912
7747
|
});
|
|
7913
7748
|
}
|
|
@@ -7917,7 +7752,8 @@ function assertMatchResult(result, customMessage) {
|
|
|
7917
7752
|
throw Object.assign(new Error(errorMessage), {
|
|
7918
7753
|
actual: result.actual,
|
|
7919
7754
|
expected: result.expected,
|
|
7920
|
-
diffOptions: { expand: getWorkerState().config.snapshotOptions.expand }
|
|
7755
|
+
diffOptions: { expand: getWorkerState().config.snapshotOptions.expand },
|
|
7756
|
+
__vitest_error_context__: { meta: result.meta }
|
|
7921
7757
|
});
|
|
7922
7758
|
}
|
|
7923
7759
|
}
|
|
@@ -8537,7 +8373,8 @@ class TestRunner {
|
|
|
8537
8373
|
if (suite.mode !== "skip" && "filepath" in suite) await this.snapshotClient.setup(suite.file.filepath, this.workerState.config.snapshotOptions);
|
|
8538
8374
|
this.workerState.current = suite;
|
|
8539
8375
|
}
|
|
8540
|
-
onBeforeTryTask(test,
|
|
8376
|
+
onBeforeTryTask(test, options) {
|
|
8377
|
+
if (this.config.experimental.traceTimeline && test.type === "test") startTraceAttempt(test, options);
|
|
8541
8378
|
clearModuleMocks(this.config);
|
|
8542
8379
|
this.snapshotClient.clearTest(test.file.filepath, test.id);
|
|
8543
8380
|
setState({
|
|
@@ -8550,6 +8387,9 @@ class TestRunner {
|
|
|
8550
8387
|
snapshotState: this.snapshotClient.getSnapshotState(test.file.filepath)
|
|
8551
8388
|
}, globalThis[GLOBAL_EXPECT]);
|
|
8552
8389
|
}
|
|
8390
|
+
async onAfterRetryTask(test, _options) {
|
|
8391
|
+
if (this.config.experimental.traceTimeline) await finishTraceAttempt(test);
|
|
8392
|
+
}
|
|
8553
8393
|
onAfterTryTask(test) {
|
|
8554
8394
|
this.benchInstances.get(test)?.[kFinalize]();
|
|
8555
8395
|
const { assertionCalls, expectedAssertionsNumber, expectedAssertionsNumberErrorGen, isExpectingAssertions, isExpectingAssertionsError } = test.context._local ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
|
|
@@ -8629,33 +8469,33 @@ function clearModuleMocks(config) {
|
|
|
8629
8469
|
const assertType = function assertType() {};
|
|
8630
8470
|
|
|
8631
8471
|
var index = /*#__PURE__*/Object.freeze({
|
|
8632
|
-
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
|
|
8640
|
-
|
|
8641
|
-
|
|
8642
|
-
|
|
8643
|
-
|
|
8644
|
-
|
|
8645
|
-
|
|
8646
|
-
|
|
8647
|
-
|
|
8648
|
-
|
|
8649
|
-
|
|
8650
|
-
|
|
8651
|
-
|
|
8652
|
-
|
|
8653
|
-
|
|
8654
|
-
|
|
8655
|
-
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
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
|
|
8659
8499
|
});
|
|
8660
8500
|
|
|
8661
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 };
|