vitest 2.0.0-beta.9 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -22
- package/dist/browser.d.ts +24 -7
- package/dist/browser.js +5 -19
- package/dist/chunks/browser-creator.DSqYDthP.js +673 -0
- package/dist/chunks/{environments-node.39w4gmlF.js → environments-node.XE5FbRPQ.js} +1 -1
- package/dist/chunks/{integrations-globals.BK0Cn4q1.js → integrations-globals.CzYWb38r.js} +10 -9
- package/dist/chunks/{node-git.CCI8evVZ.js → node-git.ZtkbKc8u.js} +14 -15
- package/dist/chunks/{runtime-console.DiVMr5d4.js → runtime-console.O41g23Zj.js} +26 -11
- package/dist/chunks/{runtime-runBaseTests.C-Bkopka.js → runtime-runBaseTests.DX3h28Mp.js} +47 -34
- package/dist/cli.js +3 -3
- package/dist/config.cjs +48 -23
- package/dist/config.d.ts +2 -1
- package/dist/config.js +48 -24
- package/dist/coverage.d.ts +6 -4
- package/dist/coverage.js +102 -38
- package/dist/environments.d.ts +2 -1
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +4 -3
- package/dist/execute.js +2 -2
- package/dist/index.d.ts +1437 -7
- package/dist/index.js +10 -9
- package/dist/node.d.ts +34 -7
- package/dist/node.js +31 -20
- package/dist/path.js +4 -1
- package/dist/{reporters-DaDey3o0.d.ts → reporters-BU_vXAUX.d.ts} +216 -206
- package/dist/reporters.d.ts +2 -1
- package/dist/reporters.js +8 -8
- package/dist/runners.d.ts +3 -1
- package/dist/runners.js +100 -61
- package/dist/snapshot.js +2 -2
- package/dist/{suite-BHSUxUib.d.ts → suite-BRl_IYuM.d.ts} +1 -1
- package/dist/suite.d.ts +3 -2
- package/dist/suite.js +3 -3
- package/dist/utils.d.ts +1 -5
- package/dist/utils.js +1 -6
- package/dist/vendor/{base._gnK9Slw.js → base.CTYV4Gnz.js} +24 -17
- package/dist/vendor/{base.D4XK-wRp.js → base.CdA1i5tB.js} +6 -4
- package/dist/vendor/{benchmark.BNLebNi5.js → benchmark.B6pblCp2.js} +13 -14
- package/dist/vendor/{cac.DCg3FnEs.js → cac.BQc6bsef.js} +142 -47
- package/dist/vendor/{cli-api.LMvYagQ5.js → cli-api.BGRtK_Kj.js} +4189 -9537
- package/dist/vendor/{constants.TCjCaw2D.js → constants.CsnA4eRy.js} +5 -23
- package/dist/vendor/{coverage.ChSqD-qS.js → coverage.BhYSDdTT.js} +27 -11
- package/dist/vendor/{date.BKM1wewY.js → date.W2xKR2qe.js} +5 -3
- package/dist/vendor/env.2ltrQNq0.js +8 -0
- package/dist/vendor/{execute.BHj6OMh4.js → execute.Dx503nGn.js} +186 -64
- package/dist/vendor/{index.TBU3GqRP.js → index.3x3MdmUV.js} +1075 -526
- package/dist/vendor/{index._7XLd8Kd.js → index.BJmtb_7W.js} +3 -2
- package/dist/vendor/{index.DP-km6lF.js → index.BMmMjLIQ.js} +64 -51
- package/dist/vendor/{index.DHRpy7zp.js → index.CROIsoiT.js} +18 -10
- package/dist/vendor/{index.DeR1hhfY.js → index.D4nqnQWz.js} +71 -74
- package/dist/vendor/index.D6GZqexG.js +6575 -0
- package/dist/vendor/{index.DwR86H5i.js → index.Hqvcg1pf.js} +4 -27
- package/dist/vendor/{rpc.DRDE9Pu1.js → rpc.BGx7q_k2.js} +30 -19
- package/dist/vendor/run-once.Db8Hgq9X.js +28 -0
- package/dist/vendor/{setup-common.BhJvzjns.js → setup-common.yHaxjRhz.js} +30 -15
- package/dist/vendor/spy.Cf_4R5Oe.js +22 -0
- package/dist/vendor/{tasks.WC7M-K-v.js → tasks.DhVtQBtW.js} +3 -1
- package/dist/vendor/{utils.YuQ3LT2a.js → utils.BVMrsl6E.js} +55 -30
- package/dist/vendor/{utils.CUjzkRH7.js → utils.DkxLWvS1.js} +12 -5
- package/dist/vendor/{vi.C6AfDXK6.js → vi.DXACdGTu.js} +269 -136
- package/dist/vendor/{vm.Ow-X2mkS.js → vm.BrDS6p7h.js} +157 -90
- package/dist/worker.js +41 -18
- package/dist/workers/forks.js +12 -6
- package/dist/workers/runVmTests.js +22 -16
- package/dist/workers/threads.js +8 -5
- package/dist/workers/vmForks.js +15 -9
- package/dist/workers/vmThreads.js +11 -8
- package/dist/workers.d.ts +8 -5
- package/dist/workers.js +11 -11
- package/package.json +22 -21
- package/suppress-warnings.cjs +2 -4
- package/dist/index-B0dCycbN.d.ts +0 -1571
- package/dist/vendor/env.bmJgw1qP.js +0 -7
|
@@ -5,14 +5,14 @@ import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest
|
|
|
5
5
|
import { getNames } from '@vitest/runner/utils';
|
|
6
6
|
import '@vitest/utils/error';
|
|
7
7
|
import { getCurrentTest } from '@vitest/runner';
|
|
8
|
-
import { g as getTestName } from './tasks.
|
|
8
|
+
import { g as getTestName } from './tasks.DhVtQBtW.js';
|
|
9
9
|
import { g as getWorkerState, a as getCurrentEnvironment } from './global.7bFbnyXl.js';
|
|
10
10
|
import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
|
|
11
11
|
import 'pathe';
|
|
12
|
-
import './env.
|
|
12
|
+
import './env.2ltrQNq0.js';
|
|
13
13
|
import { parseSingleStack } from '@vitest/utils/source-map';
|
|
14
|
-
import { i as isChildProcess } from './base.
|
|
15
|
-
import { R as RealDate, r as resetDate, m as mockDate } from './date.
|
|
14
|
+
import { i as isChildProcess } from './base.CTYV4Gnz.js';
|
|
15
|
+
import { R as RealDate, r as resetDate, m as mockDate } from './date.W2xKR2qe.js';
|
|
16
16
|
import { spyOn, fn, isMockFunction, mocks } from '@vitest/spy';
|
|
17
17
|
|
|
18
18
|
function resetModules(modules, resetMocks = false) {
|
|
@@ -28,8 +28,9 @@ function resetModules(modules, resetMocks = false) {
|
|
|
28
28
|
...!resetMocks ? [/^mock:/] : []
|
|
29
29
|
];
|
|
30
30
|
modules.forEach((mod, path) => {
|
|
31
|
-
if (skipPaths.some((re) => re.test(path)))
|
|
31
|
+
if (skipPaths.some((re) => re.test(path))) {
|
|
32
32
|
return;
|
|
33
|
+
}
|
|
33
34
|
modules.invalidateModule(mod);
|
|
34
35
|
});
|
|
35
36
|
}
|
|
@@ -43,13 +44,16 @@ async function waitForImportsToResolve() {
|
|
|
43
44
|
const promises = [];
|
|
44
45
|
let resolvingCount = 0;
|
|
45
46
|
for (const mod of state.moduleCache.values()) {
|
|
46
|
-
if (mod.promise && !mod.evaluated)
|
|
47
|
+
if (mod.promise && !mod.evaluated) {
|
|
47
48
|
promises.push(mod.promise);
|
|
48
|
-
|
|
49
|
+
}
|
|
50
|
+
if (mod.resolving) {
|
|
49
51
|
resolvingCount++;
|
|
52
|
+
}
|
|
50
53
|
}
|
|
51
|
-
if (!promises.length && !resolvingCount)
|
|
54
|
+
if (!promises.length && !resolvingCount) {
|
|
52
55
|
return;
|
|
56
|
+
}
|
|
53
57
|
await Promise.allSettled(promises);
|
|
54
58
|
await waitForImportsToResolve();
|
|
55
59
|
}
|
|
@@ -148,11 +152,13 @@ function recordAsyncExpect(test, promise) {
|
|
|
148
152
|
if (test && promise instanceof Promise) {
|
|
149
153
|
promise = promise.finally(() => {
|
|
150
154
|
const index = test.promises.indexOf(promise);
|
|
151
|
-
if (index !== -1)
|
|
155
|
+
if (index !== -1) {
|
|
152
156
|
test.promises.splice(index, 1);
|
|
157
|
+
}
|
|
153
158
|
});
|
|
154
|
-
if (!test.promises)
|
|
159
|
+
if (!test.promises) {
|
|
155
160
|
test.promises = [];
|
|
161
|
+
}
|
|
156
162
|
test.promises.push(promise);
|
|
157
163
|
}
|
|
158
164
|
return promise;
|
|
@@ -171,8 +177,11 @@ function getSnapshotClient() {
|
|
|
171
177
|
}
|
|
172
178
|
function getError(expected, promise) {
|
|
173
179
|
if (typeof expected !== "function") {
|
|
174
|
-
if (!promise)
|
|
175
|
-
throw new Error(
|
|
180
|
+
if (!promise) {
|
|
181
|
+
throw new Error(
|
|
182
|
+
`expected must be a function, received ${typeof expected}`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
176
185
|
return expected;
|
|
177
186
|
}
|
|
178
187
|
try {
|
|
@@ -184,8 +193,9 @@ function getError(expected, promise) {
|
|
|
184
193
|
}
|
|
185
194
|
const SnapshotPlugin = (chai, utils) => {
|
|
186
195
|
const getTestNames = (test) => {
|
|
187
|
-
if (!test)
|
|
196
|
+
if (!test) {
|
|
188
197
|
return {};
|
|
198
|
+
}
|
|
189
199
|
return {
|
|
190
200
|
filepath: test.file.filepath,
|
|
191
201
|
name: getNames(test).slice(1).join(" > ")
|
|
@@ -197,8 +207,9 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
197
207
|
key,
|
|
198
208
|
function(properties, message) {
|
|
199
209
|
const isNot = utils.flag(this, "negate");
|
|
200
|
-
if (isNot)
|
|
210
|
+
if (isNot) {
|
|
201
211
|
throw new Error(`${key} cannot be used with "not"`);
|
|
212
|
+
}
|
|
202
213
|
const expected = utils.flag(this, "object");
|
|
203
214
|
const test = utils.flag(this, "vitest-test");
|
|
204
215
|
if (typeof properties === "string" && typeof message === "undefined") {
|
|
@@ -222,8 +233,9 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
222
233
|
"toMatchFileSnapshot",
|
|
223
234
|
function(file, message) {
|
|
224
235
|
const isNot = utils.flag(this, "negate");
|
|
225
|
-
if (isNot)
|
|
236
|
+
if (isNot) {
|
|
226
237
|
throw new Error('toMatchFileSnapshot cannot be used with "not"');
|
|
238
|
+
}
|
|
227
239
|
const expected = utils.flag(this, "object");
|
|
228
240
|
const test = utils.flag(this, "vitest-test");
|
|
229
241
|
const errorMessage = utils.flag(this, "message");
|
|
@@ -246,12 +258,16 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
246
258
|
function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
|
|
247
259
|
var _a;
|
|
248
260
|
const isNot = utils.flag(this, "negate");
|
|
249
|
-
if (isNot)
|
|
261
|
+
if (isNot) {
|
|
250
262
|
throw new Error('toMatchInlineSnapshot cannot be used with "not"');
|
|
263
|
+
}
|
|
251
264
|
const test = utils.flag(this, "vitest-test");
|
|
252
265
|
const isInsideEach = test && (test.each || ((_a = test.suite) == null ? void 0 : _a.each));
|
|
253
|
-
if (isInsideEach)
|
|
254
|
-
throw new Error(
|
|
266
|
+
if (isInsideEach) {
|
|
267
|
+
throw new Error(
|
|
268
|
+
"InlineSnapshot cannot be used inside of test.each or describe.each"
|
|
269
|
+
);
|
|
270
|
+
}
|
|
255
271
|
const expected = utils.flag(this, "object");
|
|
256
272
|
const error = utils.flag(this, "error");
|
|
257
273
|
if (typeof properties === "string") {
|
|
@@ -259,8 +275,9 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
259
275
|
inlineSnapshot = properties;
|
|
260
276
|
properties = void 0;
|
|
261
277
|
}
|
|
262
|
-
if (inlineSnapshot)
|
|
278
|
+
if (inlineSnapshot) {
|
|
263
279
|
inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
|
|
280
|
+
}
|
|
264
281
|
const errorMessage = utils.flag(this, "message");
|
|
265
282
|
getSnapshotClient().assert({
|
|
266
283
|
received: expected,
|
|
@@ -279,8 +296,11 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
279
296
|
"toThrowErrorMatchingSnapshot",
|
|
280
297
|
function(message) {
|
|
281
298
|
const isNot = utils.flag(this, "negate");
|
|
282
|
-
if (isNot)
|
|
283
|
-
throw new Error(
|
|
299
|
+
if (isNot) {
|
|
300
|
+
throw new Error(
|
|
301
|
+
'toThrowErrorMatchingSnapshot cannot be used with "not"'
|
|
302
|
+
);
|
|
303
|
+
}
|
|
284
304
|
const expected = utils.flag(this, "object");
|
|
285
305
|
const test = utils.flag(this, "vitest-test");
|
|
286
306
|
const promise = utils.flag(this, "promise");
|
|
@@ -299,18 +319,25 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
299
319
|
function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
|
|
300
320
|
var _a;
|
|
301
321
|
const isNot = utils.flag(this, "negate");
|
|
302
|
-
if (isNot)
|
|
303
|
-
throw new Error(
|
|
322
|
+
if (isNot) {
|
|
323
|
+
throw new Error(
|
|
324
|
+
'toThrowErrorMatchingInlineSnapshot cannot be used with "not"'
|
|
325
|
+
);
|
|
326
|
+
}
|
|
304
327
|
const test = utils.flag(this, "vitest-test");
|
|
305
328
|
const isInsideEach = test && (test.each || ((_a = test.suite) == null ? void 0 : _a.each));
|
|
306
|
-
if (isInsideEach)
|
|
307
|
-
throw new Error(
|
|
329
|
+
if (isInsideEach) {
|
|
330
|
+
throw new Error(
|
|
331
|
+
"InlineSnapshot cannot be used inside of test.each or describe.each"
|
|
332
|
+
);
|
|
333
|
+
}
|
|
308
334
|
const expected = utils.flag(this, "object");
|
|
309
335
|
const error = utils.flag(this, "error");
|
|
310
336
|
const promise = utils.flag(this, "promise");
|
|
311
337
|
const errorMessage = utils.flag(this, "message");
|
|
312
|
-
if (inlineSnapshot)
|
|
338
|
+
if (inlineSnapshot) {
|
|
313
339
|
inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
|
|
340
|
+
}
|
|
314
341
|
getSnapshotClient().assert({
|
|
315
342
|
received: getError(expected, promise),
|
|
316
343
|
message,
|
|
@@ -322,11 +349,7 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
322
349
|
});
|
|
323
350
|
}
|
|
324
351
|
);
|
|
325
|
-
utils.addMethod(
|
|
326
|
-
chai.expect,
|
|
327
|
-
"addSnapshotSerializer",
|
|
328
|
-
addSerializer
|
|
329
|
-
);
|
|
352
|
+
utils.addMethod(chai.expect, "addSnapshotSerializer", addSerializer);
|
|
330
353
|
};
|
|
331
354
|
|
|
332
355
|
chai$1.use(JestExtend);
|
|
@@ -365,16 +388,23 @@ function createExpectPoll(expect) {
|
|
|
365
388
|
timeout = defaults.timeout ?? 1e3,
|
|
366
389
|
message
|
|
367
390
|
} = options;
|
|
368
|
-
const assertion = expect(null, message).withContext({
|
|
391
|
+
const assertion = expect(null, message).withContext({
|
|
392
|
+
poll: true
|
|
393
|
+
});
|
|
369
394
|
const proxy = new Proxy(assertion, {
|
|
370
395
|
get(target, key, receiver) {
|
|
371
|
-
const
|
|
372
|
-
if (typeof
|
|
373
|
-
return
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
396
|
+
const assertionFunction = Reflect.get(target, key, receiver);
|
|
397
|
+
if (typeof assertionFunction !== "function") {
|
|
398
|
+
return assertionFunction instanceof chai$1.Assertion ? proxy : assertionFunction;
|
|
399
|
+
}
|
|
400
|
+
if (key === "assert") {
|
|
401
|
+
return assertionFunction;
|
|
402
|
+
}
|
|
403
|
+
if (typeof key === "string" && unsupported.includes(key)) {
|
|
404
|
+
throw new SyntaxError(
|
|
405
|
+
`expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`
|
|
406
|
+
);
|
|
407
|
+
}
|
|
378
408
|
return function(...args) {
|
|
379
409
|
const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
|
|
380
410
|
return new Promise((resolve, reject) => {
|
|
@@ -383,12 +413,20 @@ function createExpectPoll(expect) {
|
|
|
383
413
|
const { setTimeout, clearTimeout } = getSafeTimers();
|
|
384
414
|
const timeoutId = setTimeout(() => {
|
|
385
415
|
clearTimeout(intervalId);
|
|
386
|
-
reject(
|
|
416
|
+
reject(
|
|
417
|
+
copyStackTrace$1(
|
|
418
|
+
new Error(`Matcher did not succeed in ${timeout}ms`, {
|
|
419
|
+
cause: lastError
|
|
420
|
+
}),
|
|
421
|
+
STACK_TRACE_ERROR
|
|
422
|
+
)
|
|
423
|
+
);
|
|
387
424
|
}, timeout);
|
|
388
425
|
const check = async () => {
|
|
389
426
|
try {
|
|
390
|
-
|
|
391
|
-
|
|
427
|
+
const obj = await fn();
|
|
428
|
+
chai$1.util.flag(assertion, "object", obj);
|
|
429
|
+
resolve(await assertionFunction.call(assertion, ...args));
|
|
392
430
|
clearTimeout(intervalId);
|
|
393
431
|
clearTimeout(timeoutId);
|
|
394
432
|
} catch (err) {
|
|
@@ -405,8 +443,9 @@ function createExpectPoll(expect) {
|
|
|
405
443
|
};
|
|
406
444
|
}
|
|
407
445
|
function copyStackTrace$1(target, source) {
|
|
408
|
-
if (source.stack !== void 0)
|
|
446
|
+
if (source.stack !== void 0) {
|
|
409
447
|
target.stack = source.stack.replace(source.message, target.message);
|
|
448
|
+
}
|
|
410
449
|
return target;
|
|
411
450
|
}
|
|
412
451
|
|
|
@@ -416,10 +455,11 @@ function createExpect(test) {
|
|
|
416
455
|
setState({ assertionCalls: assertionCalls + 1 }, expect);
|
|
417
456
|
const assert2 = chai$1.expect(value, message);
|
|
418
457
|
const _test = test || getCurrentTest();
|
|
419
|
-
if (_test)
|
|
458
|
+
if (_test) {
|
|
420
459
|
return assert2.withTest(_test);
|
|
421
|
-
else
|
|
460
|
+
} else {
|
|
422
461
|
return assert2;
|
|
462
|
+
}
|
|
423
463
|
};
|
|
424
464
|
Object.assign(expect, chai$1.expect);
|
|
425
465
|
Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
|
|
@@ -427,18 +467,21 @@ function createExpect(test) {
|
|
|
427
467
|
expect.setState = (state) => setState(state, expect);
|
|
428
468
|
const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
|
|
429
469
|
const testPath = getTestFile(test);
|
|
430
|
-
setState(
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
470
|
+
setState(
|
|
471
|
+
{
|
|
472
|
+
// this should also add "snapshotState" that is added conditionally
|
|
473
|
+
...globalState,
|
|
474
|
+
assertionCalls: 0,
|
|
475
|
+
isExpectingAssertions: false,
|
|
476
|
+
isExpectingAssertionsError: null,
|
|
477
|
+
expectedAssertionsNumber: null,
|
|
478
|
+
expectedAssertionsNumberErrorGen: null,
|
|
479
|
+
environment: getCurrentEnvironment(),
|
|
480
|
+
testPath,
|
|
481
|
+
currentTestName: test ? getTestName(test) : globalState.currentTestName
|
|
482
|
+
},
|
|
483
|
+
expect
|
|
484
|
+
);
|
|
442
485
|
expect.extend = (matchers) => chai$1.expect.extend(expect, matchers);
|
|
443
486
|
expect.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters);
|
|
444
487
|
expect.soft = (...args) => {
|
|
@@ -446,12 +489,17 @@ function createExpect(test) {
|
|
|
446
489
|
};
|
|
447
490
|
expect.poll = createExpectPoll(expect);
|
|
448
491
|
expect.unreachable = (message) => {
|
|
449
|
-
chai$1.assert.fail(
|
|
492
|
+
chai$1.assert.fail(
|
|
493
|
+
`expected${message ? ` "${message}" ` : " "}not to be reached`
|
|
494
|
+
);
|
|
450
495
|
};
|
|
451
496
|
function assertions(expected) {
|
|
452
|
-
const errorGen = () => new Error(
|
|
453
|
-
|
|
497
|
+
const errorGen = () => new Error(
|
|
498
|
+
`expected number of assertions to be ${expected}, but got ${expect.getState().assertionCalls}`
|
|
499
|
+
);
|
|
500
|
+
if (Error.captureStackTrace) {
|
|
454
501
|
Error.captureStackTrace(errorGen(), assertions);
|
|
502
|
+
}
|
|
455
503
|
expect.setState({
|
|
456
504
|
expectedAssertionsNumber: expected,
|
|
457
505
|
expectedAssertionsNumberErrorGen: errorGen
|
|
@@ -459,8 +507,9 @@ function createExpect(test) {
|
|
|
459
507
|
}
|
|
460
508
|
function hasAssertions() {
|
|
461
509
|
const error = new Error("expected any number of assertion, but got none");
|
|
462
|
-
if (Error.captureStackTrace)
|
|
510
|
+
if (Error.captureStackTrace) {
|
|
463
511
|
Error.captureStackTrace(error, hasAssertions);
|
|
512
|
+
}
|
|
464
513
|
expect.setState({
|
|
465
514
|
isExpectingAssertions: true,
|
|
466
515
|
isExpectingAssertionsError: error
|
|
@@ -471,8 +520,9 @@ function createExpect(test) {
|
|
|
471
520
|
return expect;
|
|
472
521
|
}
|
|
473
522
|
function getTestFile(test) {
|
|
474
|
-
if (test)
|
|
523
|
+
if (test) {
|
|
475
524
|
return test.file.filepath;
|
|
525
|
+
}
|
|
476
526
|
const state = getWorkerState();
|
|
477
527
|
return state.filepath;
|
|
478
528
|
}
|
|
@@ -3122,35 +3172,41 @@ class FakeTimers {
|
|
|
3122
3172
|
this._global = global;
|
|
3123
3173
|
}
|
|
3124
3174
|
clearAllTimers() {
|
|
3125
|
-
if (this._fakingTime)
|
|
3175
|
+
if (this._fakingTime) {
|
|
3126
3176
|
this._clock.reset();
|
|
3177
|
+
}
|
|
3127
3178
|
}
|
|
3128
3179
|
dispose() {
|
|
3129
3180
|
this.useRealTimers();
|
|
3130
3181
|
}
|
|
3131
3182
|
runAllTimers() {
|
|
3132
|
-
if (this._checkFakeTimers())
|
|
3183
|
+
if (this._checkFakeTimers()) {
|
|
3133
3184
|
this._clock.runAll();
|
|
3185
|
+
}
|
|
3134
3186
|
}
|
|
3135
3187
|
async runAllTimersAsync() {
|
|
3136
|
-
if (this._checkFakeTimers())
|
|
3188
|
+
if (this._checkFakeTimers()) {
|
|
3137
3189
|
await this._clock.runAllAsync();
|
|
3190
|
+
}
|
|
3138
3191
|
}
|
|
3139
3192
|
runOnlyPendingTimers() {
|
|
3140
|
-
if (this._checkFakeTimers())
|
|
3193
|
+
if (this._checkFakeTimers()) {
|
|
3141
3194
|
this._clock.runToLast();
|
|
3195
|
+
}
|
|
3142
3196
|
}
|
|
3143
3197
|
async runOnlyPendingTimersAsync() {
|
|
3144
|
-
if (this._checkFakeTimers())
|
|
3198
|
+
if (this._checkFakeTimers()) {
|
|
3145
3199
|
await this._clock.runToLastAsync();
|
|
3200
|
+
}
|
|
3146
3201
|
}
|
|
3147
3202
|
advanceTimersToNextTimer(steps = 1) {
|
|
3148
3203
|
if (this._checkFakeTimers()) {
|
|
3149
3204
|
for (let i = steps; i > 0; i--) {
|
|
3150
3205
|
this._clock.next();
|
|
3151
3206
|
this._clock.tick(0);
|
|
3152
|
-
if (this._clock.countTimers() === 0)
|
|
3207
|
+
if (this._clock.countTimers() === 0) {
|
|
3153
3208
|
break;
|
|
3209
|
+
}
|
|
3154
3210
|
}
|
|
3155
3211
|
}
|
|
3156
3212
|
}
|
|
@@ -3159,18 +3215,21 @@ class FakeTimers {
|
|
|
3159
3215
|
for (let i = steps; i > 0; i--) {
|
|
3160
3216
|
await this._clock.nextAsync();
|
|
3161
3217
|
this._clock.tick(0);
|
|
3162
|
-
if (this._clock.countTimers() === 0)
|
|
3218
|
+
if (this._clock.countTimers() === 0) {
|
|
3163
3219
|
break;
|
|
3220
|
+
}
|
|
3164
3221
|
}
|
|
3165
3222
|
}
|
|
3166
3223
|
}
|
|
3167
3224
|
advanceTimersByTime(msToRun) {
|
|
3168
|
-
if (this._checkFakeTimers())
|
|
3225
|
+
if (this._checkFakeTimers()) {
|
|
3169
3226
|
this._clock.tick(msToRun);
|
|
3227
|
+
}
|
|
3170
3228
|
}
|
|
3171
3229
|
async advanceTimersByTimeAsync(msToRun) {
|
|
3172
|
-
if (this._checkFakeTimers())
|
|
3230
|
+
if (this._checkFakeTimers()) {
|
|
3173
3231
|
await this._clock.tickAsync(msToRun);
|
|
3232
|
+
}
|
|
3174
3233
|
}
|
|
3175
3234
|
runAllTicks() {
|
|
3176
3235
|
if (this._checkFakeTimers()) {
|
|
@@ -3195,18 +3254,25 @@ class FakeTimers {
|
|
|
3195
3254
|
);
|
|
3196
3255
|
}
|
|
3197
3256
|
if (!this._fakingTime) {
|
|
3198
|
-
const toFake = Object.keys(this._fakeTimers.timers).filter(
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3257
|
+
const toFake = Object.keys(this._fakeTimers.timers).filter(
|
|
3258
|
+
(timer) => timer !== "nextTick"
|
|
3259
|
+
);
|
|
3260
|
+
if (((_b = (_a = this._userConfig) == null ? void 0 : _a.toFake) == null ? void 0 : _b.includes("nextTick")) && isChildProcess()) {
|
|
3261
|
+
throw new Error(
|
|
3262
|
+
"process.nextTick cannot be mocked inside child_process"
|
|
3263
|
+
);
|
|
3264
|
+
}
|
|
3265
|
+
const existingFakedMethods = (((_c = this._userConfig) == null ? void 0 : _c.toFake) || toFake).filter(
|
|
3266
|
+
(method) => {
|
|
3267
|
+
switch (method) {
|
|
3268
|
+
case "setImmediate":
|
|
3269
|
+
case "clearImmediate":
|
|
3270
|
+
return method in this._global && this._global[method];
|
|
3271
|
+
default:
|
|
3272
|
+
return true;
|
|
3273
|
+
}
|
|
3208
3274
|
}
|
|
3209
|
-
|
|
3275
|
+
);
|
|
3210
3276
|
this._clock = this._fakeTimers.install({
|
|
3211
3277
|
now: Date.now(),
|
|
3212
3278
|
...this._userConfig,
|
|
@@ -3234,8 +3300,9 @@ class FakeTimers {
|
|
|
3234
3300
|
return this._now();
|
|
3235
3301
|
}
|
|
3236
3302
|
getTimerCount() {
|
|
3237
|
-
if (this._checkFakeTimers())
|
|
3303
|
+
if (this._checkFakeTimers()) {
|
|
3238
3304
|
return this._clock.countTimers();
|
|
3305
|
+
}
|
|
3239
3306
|
return 0;
|
|
3240
3307
|
}
|
|
3241
3308
|
configure(config) {
|
|
@@ -3255,8 +3322,9 @@ class FakeTimers {
|
|
|
3255
3322
|
}
|
|
3256
3323
|
|
|
3257
3324
|
function copyStackTrace(target, source) {
|
|
3258
|
-
if (source.stack !== void 0)
|
|
3325
|
+
if (source.stack !== void 0) {
|
|
3259
3326
|
target.stack = source.stack.replace(source.message, target.message);
|
|
3327
|
+
}
|
|
3260
3328
|
return target;
|
|
3261
3329
|
}
|
|
3262
3330
|
function waitFor(callback, options = {}) {
|
|
@@ -3269,23 +3337,34 @@ function waitFor(callback, options = {}) {
|
|
|
3269
3337
|
let timeoutId;
|
|
3270
3338
|
let intervalId;
|
|
3271
3339
|
const onResolve = (result) => {
|
|
3272
|
-
if (timeoutId)
|
|
3340
|
+
if (timeoutId) {
|
|
3273
3341
|
clearTimeout(timeoutId);
|
|
3274
|
-
|
|
3342
|
+
}
|
|
3343
|
+
if (intervalId) {
|
|
3275
3344
|
clearInterval(intervalId);
|
|
3345
|
+
}
|
|
3276
3346
|
resolve(result);
|
|
3277
3347
|
};
|
|
3278
3348
|
const handleTimeout = () => {
|
|
3349
|
+
if (intervalId) {
|
|
3350
|
+
clearInterval(intervalId);
|
|
3351
|
+
}
|
|
3279
3352
|
let error = lastError;
|
|
3280
|
-
if (!error)
|
|
3281
|
-
error = copyStackTrace(
|
|
3353
|
+
if (!error) {
|
|
3354
|
+
error = copyStackTrace(
|
|
3355
|
+
new Error("Timed out in waitFor!"),
|
|
3356
|
+
STACK_TRACE_ERROR
|
|
3357
|
+
);
|
|
3358
|
+
}
|
|
3282
3359
|
reject(error);
|
|
3283
3360
|
};
|
|
3284
3361
|
const checkCallback = () => {
|
|
3285
|
-
if (vi.isFakeTimers())
|
|
3362
|
+
if (vi.isFakeTimers()) {
|
|
3286
3363
|
vi.advanceTimersByTime(interval);
|
|
3287
|
-
|
|
3364
|
+
}
|
|
3365
|
+
if (promiseStatus === "pending") {
|
|
3288
3366
|
return;
|
|
3367
|
+
}
|
|
3289
3368
|
try {
|
|
3290
3369
|
const result = callback();
|
|
3291
3370
|
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
@@ -3309,8 +3388,9 @@ function waitFor(callback, options = {}) {
|
|
|
3309
3388
|
lastError = error;
|
|
3310
3389
|
}
|
|
3311
3390
|
};
|
|
3312
|
-
if (checkCallback() === true)
|
|
3391
|
+
if (checkCallback() === true) {
|
|
3313
3392
|
return;
|
|
3393
|
+
}
|
|
3314
3394
|
timeoutId = setTimeout(handleTimeout, timeout);
|
|
3315
3395
|
intervalId = setInterval(checkCallback, interval);
|
|
3316
3396
|
});
|
|
@@ -3324,25 +3404,37 @@ function waitUntil(callback, options = {}) {
|
|
|
3324
3404
|
let timeoutId;
|
|
3325
3405
|
let intervalId;
|
|
3326
3406
|
const onReject = (error) => {
|
|
3327
|
-
if (
|
|
3328
|
-
|
|
3407
|
+
if (intervalId) {
|
|
3408
|
+
clearInterval(intervalId);
|
|
3409
|
+
}
|
|
3410
|
+
if (!error) {
|
|
3411
|
+
error = copyStackTrace(
|
|
3412
|
+
new Error("Timed out in waitUntil!"),
|
|
3413
|
+
STACK_TRACE_ERROR
|
|
3414
|
+
);
|
|
3415
|
+
}
|
|
3329
3416
|
reject(error);
|
|
3330
3417
|
};
|
|
3331
3418
|
const onResolve = (result) => {
|
|
3332
|
-
if (!result)
|
|
3419
|
+
if (!result) {
|
|
3333
3420
|
return;
|
|
3334
|
-
|
|
3421
|
+
}
|
|
3422
|
+
if (timeoutId) {
|
|
3335
3423
|
clearTimeout(timeoutId);
|
|
3336
|
-
|
|
3424
|
+
}
|
|
3425
|
+
if (intervalId) {
|
|
3337
3426
|
clearInterval(intervalId);
|
|
3427
|
+
}
|
|
3338
3428
|
resolve(result);
|
|
3339
3429
|
return true;
|
|
3340
3430
|
};
|
|
3341
3431
|
const checkCallback = () => {
|
|
3342
|
-
if (vi.isFakeTimers())
|
|
3432
|
+
if (vi.isFakeTimers()) {
|
|
3343
3433
|
vi.advanceTimersByTime(interval);
|
|
3344
|
-
|
|
3434
|
+
}
|
|
3435
|
+
if (promiseStatus === "pending") {
|
|
3345
3436
|
return;
|
|
3437
|
+
}
|
|
3346
3438
|
try {
|
|
3347
3439
|
const result = callback();
|
|
3348
3440
|
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
@@ -3365,23 +3457,29 @@ function waitUntil(callback, options = {}) {
|
|
|
3365
3457
|
onReject(error);
|
|
3366
3458
|
}
|
|
3367
3459
|
};
|
|
3368
|
-
if (checkCallback() === true)
|
|
3460
|
+
if (checkCallback() === true) {
|
|
3369
3461
|
return;
|
|
3462
|
+
}
|
|
3370
3463
|
timeoutId = setTimeout(onReject, timeout);
|
|
3371
3464
|
intervalId = setInterval(checkCallback, interval);
|
|
3372
3465
|
});
|
|
3373
3466
|
}
|
|
3374
3467
|
|
|
3375
3468
|
function createVitest() {
|
|
3376
|
-
const _mocker = typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : new Proxy({}, {
|
|
3377
|
-
get(_, name) {
|
|
3378
|
-
throw new Error(
|
|
3379
|
-
`Vitest mocker was not initialized in this environment. vi.${String(name)}() is forbidden.`
|
|
3380
|
-
);
|
|
3381
|
-
}
|
|
3382
|
-
});
|
|
3383
3469
|
let _mockedDate = null;
|
|
3384
3470
|
let _config = null;
|
|
3471
|
+
function _mocker() {
|
|
3472
|
+
return typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : new Proxy(
|
|
3473
|
+
{},
|
|
3474
|
+
{
|
|
3475
|
+
get(_, name) {
|
|
3476
|
+
throw new Error(
|
|
3477
|
+
`Vitest mocker was not initialized in this environment. vi.${String(name)}() is forbidden.`
|
|
3478
|
+
);
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3481
|
+
);
|
|
3482
|
+
}
|
|
3385
3483
|
const workerState = getWorkerState();
|
|
3386
3484
|
let _timers;
|
|
3387
3485
|
const timers = () => _timers || (_timers = new FakeTimers({
|
|
@@ -3410,10 +3508,11 @@ function createVitest() {
|
|
|
3410
3508
|
);
|
|
3411
3509
|
}
|
|
3412
3510
|
}
|
|
3413
|
-
if (config)
|
|
3511
|
+
if (config) {
|
|
3414
3512
|
timers().configure({ ...workerState.config.fakeTimers, ...config });
|
|
3415
|
-
else
|
|
3513
|
+
} else {
|
|
3416
3514
|
timers().configure(workerState.config.fakeTimers);
|
|
3515
|
+
}
|
|
3417
3516
|
timers().useFakeTimers();
|
|
3418
3517
|
return utils;
|
|
3419
3518
|
},
|
|
@@ -3490,46 +3589,70 @@ function createVitest() {
|
|
|
3490
3589
|
return factory();
|
|
3491
3590
|
},
|
|
3492
3591
|
mock(path, factory) {
|
|
3493
|
-
if (typeof path !== "string")
|
|
3494
|
-
throw new
|
|
3592
|
+
if (typeof path !== "string") {
|
|
3593
|
+
throw new TypeError(
|
|
3594
|
+
`vi.mock() expects a string path, but received a ${typeof path}`
|
|
3595
|
+
);
|
|
3596
|
+
}
|
|
3495
3597
|
const importer = getImporter("mock");
|
|
3496
|
-
_mocker.queueMock(
|
|
3598
|
+
_mocker().queueMock(
|
|
3497
3599
|
path,
|
|
3498
3600
|
importer,
|
|
3499
|
-
factory ? () => factory(
|
|
3601
|
+
factory ? () => factory(
|
|
3602
|
+
() => _mocker().importActual(
|
|
3603
|
+
path,
|
|
3604
|
+
importer,
|
|
3605
|
+
_mocker().getMockContext().callstack
|
|
3606
|
+
)
|
|
3607
|
+
) : void 0,
|
|
3500
3608
|
true
|
|
3501
3609
|
);
|
|
3502
3610
|
},
|
|
3503
3611
|
unmock(path) {
|
|
3504
|
-
if (typeof path !== "string")
|
|
3505
|
-
throw new
|
|
3506
|
-
|
|
3612
|
+
if (typeof path !== "string") {
|
|
3613
|
+
throw new TypeError(
|
|
3614
|
+
`vi.unmock() expects a string path, but received a ${typeof path}`
|
|
3615
|
+
);
|
|
3616
|
+
}
|
|
3617
|
+
_mocker().queueUnmock(path, getImporter("unmock"));
|
|
3507
3618
|
},
|
|
3508
3619
|
doMock(path, factory) {
|
|
3509
|
-
if (typeof path !== "string")
|
|
3510
|
-
throw new
|
|
3620
|
+
if (typeof path !== "string") {
|
|
3621
|
+
throw new TypeError(
|
|
3622
|
+
`vi.doMock() expects a string path, but received a ${typeof path}`
|
|
3623
|
+
);
|
|
3624
|
+
}
|
|
3511
3625
|
const importer = getImporter("doMock");
|
|
3512
|
-
_mocker.queueMock(
|
|
3626
|
+
_mocker().queueMock(
|
|
3513
3627
|
path,
|
|
3514
3628
|
importer,
|
|
3515
|
-
factory ? () => factory(
|
|
3629
|
+
factory ? () => factory(
|
|
3630
|
+
() => _mocker().importActual(
|
|
3631
|
+
path,
|
|
3632
|
+
importer,
|
|
3633
|
+
_mocker().getMockContext().callstack
|
|
3634
|
+
)
|
|
3635
|
+
) : void 0,
|
|
3516
3636
|
false
|
|
3517
3637
|
);
|
|
3518
3638
|
},
|
|
3519
3639
|
doUnmock(path) {
|
|
3520
|
-
if (typeof path !== "string")
|
|
3521
|
-
throw new
|
|
3522
|
-
|
|
3640
|
+
if (typeof path !== "string") {
|
|
3641
|
+
throw new TypeError(
|
|
3642
|
+
`vi.doUnmock() expects a string path, but received a ${typeof path}`
|
|
3643
|
+
);
|
|
3644
|
+
}
|
|
3645
|
+
_mocker().queueUnmock(path, getImporter("doUnmock"));
|
|
3523
3646
|
},
|
|
3524
3647
|
async importActual(path) {
|
|
3525
|
-
return _mocker.importActual(
|
|
3648
|
+
return _mocker().importActual(
|
|
3526
3649
|
path,
|
|
3527
3650
|
getImporter("importActual"),
|
|
3528
|
-
_mocker.getMockContext().callstack
|
|
3651
|
+
_mocker().getMockContext().callstack
|
|
3529
3652
|
);
|
|
3530
3653
|
},
|
|
3531
3654
|
async importMock(path) {
|
|
3532
|
-
return _mocker.importMock(path, getImporter("importMock"));
|
|
3655
|
+
return _mocker().importMock(path, getImporter("importMock"));
|
|
3533
3656
|
},
|
|
3534
3657
|
// this is typed in the interface so it's not necessary to type it here
|
|
3535
3658
|
mocked(item, _options = {}) {
|
|
@@ -3551,8 +3674,12 @@ function createVitest() {
|
|
|
3551
3674
|
return utils;
|
|
3552
3675
|
},
|
|
3553
3676
|
stubGlobal(name, value) {
|
|
3554
|
-
if (!_stubsGlobal.has(name))
|
|
3555
|
-
_stubsGlobal.set(
|
|
3677
|
+
if (!_stubsGlobal.has(name)) {
|
|
3678
|
+
_stubsGlobal.set(
|
|
3679
|
+
name,
|
|
3680
|
+
Object.getOwnPropertyDescriptor(globalThis, name)
|
|
3681
|
+
);
|
|
3682
|
+
}
|
|
3556
3683
|
Object.defineProperty(globalThis, name, {
|
|
3557
3684
|
value,
|
|
3558
3685
|
writable: true,
|
|
@@ -3562,30 +3689,34 @@ function createVitest() {
|
|
|
3562
3689
|
return utils;
|
|
3563
3690
|
},
|
|
3564
3691
|
stubEnv(name, value) {
|
|
3565
|
-
if (!_stubsEnv.has(name))
|
|
3692
|
+
if (!_stubsEnv.has(name)) {
|
|
3566
3693
|
_stubsEnv.set(name, process.env[name]);
|
|
3567
|
-
|
|
3694
|
+
}
|
|
3695
|
+
if (_envBooleans.includes(name)) {
|
|
3568
3696
|
process.env[name] = value ? "1" : "";
|
|
3569
|
-
else
|
|
3697
|
+
} else {
|
|
3570
3698
|
process.env[name] = String(value);
|
|
3699
|
+
}
|
|
3571
3700
|
return utils;
|
|
3572
3701
|
},
|
|
3573
3702
|
unstubAllGlobals() {
|
|
3574
3703
|
_stubsGlobal.forEach((original, name) => {
|
|
3575
|
-
if (!original)
|
|
3704
|
+
if (!original) {
|
|
3576
3705
|
Reflect.deleteProperty(globalThis, name);
|
|
3577
|
-
else
|
|
3706
|
+
} else {
|
|
3578
3707
|
Object.defineProperty(globalThis, name, original);
|
|
3708
|
+
}
|
|
3579
3709
|
});
|
|
3580
3710
|
_stubsGlobal.clear();
|
|
3581
3711
|
return utils;
|
|
3582
3712
|
},
|
|
3583
3713
|
unstubAllEnvs() {
|
|
3584
3714
|
_stubsEnv.forEach((original, name) => {
|
|
3585
|
-
if (original === void 0)
|
|
3715
|
+
if (original === void 0) {
|
|
3586
3716
|
delete process.env[name];
|
|
3587
|
-
else
|
|
3717
|
+
} else {
|
|
3588
3718
|
process.env[name] = original;
|
|
3719
|
+
}
|
|
3589
3720
|
});
|
|
3590
3721
|
_stubsEnv.clear();
|
|
3591
3722
|
return utils;
|
|
@@ -3598,13 +3729,15 @@ function createVitest() {
|
|
|
3598
3729
|
return waitForImportsToResolve();
|
|
3599
3730
|
},
|
|
3600
3731
|
setConfig(config) {
|
|
3601
|
-
if (!_config)
|
|
3732
|
+
if (!_config) {
|
|
3602
3733
|
_config = { ...workerState.config };
|
|
3734
|
+
}
|
|
3603
3735
|
Object.assign(workerState.config, config);
|
|
3604
3736
|
},
|
|
3605
3737
|
resetConfig() {
|
|
3606
|
-
if (_config)
|
|
3738
|
+
if (_config) {
|
|
3607
3739
|
Object.assign(workerState.config, _config);
|
|
3740
|
+
}
|
|
3608
3741
|
}
|
|
3609
3742
|
};
|
|
3610
3743
|
return utils;
|