vitest 2.0.0-beta.10 → 2.0.0-beta.12
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 +1 -1
- package/dist/browser.js +3 -3
- package/dist/chunks/browser-creator.Bw94IHrL.js +673 -0
- package/dist/chunks/{environments-node.39w4gmlF.js → environments-node.XE5FbRPQ.js} +1 -1
- package/dist/chunks/{integrations-globals.C6Ah-pUW.js → integrations-globals.DSNOaUHv.js} +10 -10
- 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.Cukyr5-I.js → runtime-runBaseTests.BDt9gQFB.js} +41 -33
- package/dist/cli.js +3 -3
- package/dist/config.cjs +45 -21
- package/dist/config.d.ts +1 -1
- package/dist/config.js +45 -22
- package/dist/coverage.d.ts +5 -4
- package/dist/coverage.js +100 -37
- package/dist/environments.d.ts +1 -1
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +1 -1
- package/dist/execute.js +2 -2
- package/dist/index.d.ts +37 -11
- package/dist/index.js +10 -10
- package/dist/node.d.ts +20 -7
- package/dist/node.js +29 -20
- package/dist/path.js +4 -1
- package/dist/{reporters-CYVC6LOl.d.ts → reporters-Cd1vkLMZ.d.ts} +134 -182
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +8 -8
- package/dist/runners.d.ts +1 -1
- package/dist/runners.js +99 -61
- package/dist/snapshot.js +2 -2
- package/dist/{suite-Dpu9EC_k.d.ts → suite-BS2CV79a.d.ts} +1 -1
- package/dist/suite.d.ts +2 -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.Dln9yllP.js → base.Cy97mmVC.js} +4 -3
- package/dist/vendor/{benchmark.BNLebNi5.js → benchmark.B6pblCp2.js} +13 -14
- package/dist/vendor/{cac.CtYFkoSJ.js → cac.DRNUX42m.js} +82 -38
- package/dist/vendor/{cli-api.CUtJc4r3.js → cli-api.Bu-PSdzx.js} +5908 -13271
- package/dist/vendor/{constants.TCjCaw2D.js → constants.BWsVtsAj.js} +5 -22
- 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.T3gg2ZK6.js} +174 -60
- package/dist/vendor/{index.B5SKBLvV.js → index.B7pSlOSa.js} +18 -10
- package/dist/vendor/{index._7XLd8Kd.js → index.BJmtb_7W.js} +3 -2
- package/dist/vendor/{index.CThipSqB.js → index.BMmMjLIQ.js} +2540 -2540
- package/dist/vendor/{index.kpsSqFiz.js → index.D4nqnQWz.js} +69 -73
- package/dist/vendor/index.D6GZqexG.js +6575 -0
- package/dist/vendor/{index.D3hs2WiI.js → index.Hqvcg1pf.js} +3 -3
- package/dist/vendor/{index.BOMEjpjj.js → index.ZtQtNPP2.js} +962 -471
- package/dist/vendor/{rpc.DRDE9Pu1.js → rpc.BGx7q_k2.js} +30 -19
- package/dist/vendor/{run-once.DLomgGUH.js → run-once.Db8Hgq9X.js} +2 -1
- package/dist/vendor/{setup-common.DAu7t7mY.js → setup-common.CWnv_2-5.js} +30 -15
- package/dist/vendor/{tasks.WC7M-K-v.js → tasks.DhVtQBtW.js} +3 -1
- package/dist/vendor/{utils.YuQ3LT2a.js → utils.DSO2UK15.js} +40 -25
- package/dist/vendor/{utils.CUjzkRH7.js → utils.DkxLWvS1.js} +12 -5
- package/dist/vendor/{vi.hATFzZbX.js → vi.DXACdGTu.js} +267 -138
- package/dist/vendor/{vm.Ow-X2mkS.js → vm.D9wVR14y.js} +152 -87
- package/dist/worker.js +31 -15
- package/dist/workers/forks.js +4 -4
- package/dist/workers/runVmTests.js +15 -14
- package/dist/workers/threads.js +4 -4
- package/dist/workers/vmForks.js +7 -7
- package/dist/workers/vmThreads.js +7 -7
- package/dist/workers.d.ts +2 -2
- package/dist/workers.js +10 -10
- package/package.json +11 -11
- package/suppress-warnings.cjs +1 -4
- 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,25 +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 = () => {
|
|
3279
|
-
if (intervalId)
|
|
3349
|
+
if (intervalId) {
|
|
3280
3350
|
clearInterval(intervalId);
|
|
3351
|
+
}
|
|
3281
3352
|
let error = lastError;
|
|
3282
|
-
if (!error)
|
|
3283
|
-
error = copyStackTrace(
|
|
3353
|
+
if (!error) {
|
|
3354
|
+
error = copyStackTrace(
|
|
3355
|
+
new Error("Timed out in waitFor!"),
|
|
3356
|
+
STACK_TRACE_ERROR
|
|
3357
|
+
);
|
|
3358
|
+
}
|
|
3284
3359
|
reject(error);
|
|
3285
3360
|
};
|
|
3286
3361
|
const checkCallback = () => {
|
|
3287
|
-
if (vi.isFakeTimers())
|
|
3362
|
+
if (vi.isFakeTimers()) {
|
|
3288
3363
|
vi.advanceTimersByTime(interval);
|
|
3289
|
-
|
|
3364
|
+
}
|
|
3365
|
+
if (promiseStatus === "pending") {
|
|
3290
3366
|
return;
|
|
3367
|
+
}
|
|
3291
3368
|
try {
|
|
3292
3369
|
const result = callback();
|
|
3293
3370
|
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
@@ -3311,8 +3388,9 @@ function waitFor(callback, options = {}) {
|
|
|
3311
3388
|
lastError = error;
|
|
3312
3389
|
}
|
|
3313
3390
|
};
|
|
3314
|
-
if (checkCallback() === true)
|
|
3391
|
+
if (checkCallback() === true) {
|
|
3315
3392
|
return;
|
|
3393
|
+
}
|
|
3316
3394
|
timeoutId = setTimeout(handleTimeout, timeout);
|
|
3317
3395
|
intervalId = setInterval(checkCallback, interval);
|
|
3318
3396
|
});
|
|
@@ -3326,27 +3404,37 @@ function waitUntil(callback, options = {}) {
|
|
|
3326
3404
|
let timeoutId;
|
|
3327
3405
|
let intervalId;
|
|
3328
3406
|
const onReject = (error) => {
|
|
3329
|
-
if (intervalId)
|
|
3407
|
+
if (intervalId) {
|
|
3330
3408
|
clearInterval(intervalId);
|
|
3331
|
-
|
|
3332
|
-
|
|
3409
|
+
}
|
|
3410
|
+
if (!error) {
|
|
3411
|
+
error = copyStackTrace(
|
|
3412
|
+
new Error("Timed out in waitUntil!"),
|
|
3413
|
+
STACK_TRACE_ERROR
|
|
3414
|
+
);
|
|
3415
|
+
}
|
|
3333
3416
|
reject(error);
|
|
3334
3417
|
};
|
|
3335
3418
|
const onResolve = (result) => {
|
|
3336
|
-
if (!result)
|
|
3419
|
+
if (!result) {
|
|
3337
3420
|
return;
|
|
3338
|
-
|
|
3421
|
+
}
|
|
3422
|
+
if (timeoutId) {
|
|
3339
3423
|
clearTimeout(timeoutId);
|
|
3340
|
-
|
|
3424
|
+
}
|
|
3425
|
+
if (intervalId) {
|
|
3341
3426
|
clearInterval(intervalId);
|
|
3427
|
+
}
|
|
3342
3428
|
resolve(result);
|
|
3343
3429
|
return true;
|
|
3344
3430
|
};
|
|
3345
3431
|
const checkCallback = () => {
|
|
3346
|
-
if (vi.isFakeTimers())
|
|
3432
|
+
if (vi.isFakeTimers()) {
|
|
3347
3433
|
vi.advanceTimersByTime(interval);
|
|
3348
|
-
|
|
3434
|
+
}
|
|
3435
|
+
if (promiseStatus === "pending") {
|
|
3349
3436
|
return;
|
|
3437
|
+
}
|
|
3350
3438
|
try {
|
|
3351
3439
|
const result = callback();
|
|
3352
3440
|
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
@@ -3369,23 +3457,29 @@ function waitUntil(callback, options = {}) {
|
|
|
3369
3457
|
onReject(error);
|
|
3370
3458
|
}
|
|
3371
3459
|
};
|
|
3372
|
-
if (checkCallback() === true)
|
|
3460
|
+
if (checkCallback() === true) {
|
|
3373
3461
|
return;
|
|
3462
|
+
}
|
|
3374
3463
|
timeoutId = setTimeout(onReject, timeout);
|
|
3375
3464
|
intervalId = setInterval(checkCallback, interval);
|
|
3376
3465
|
});
|
|
3377
3466
|
}
|
|
3378
3467
|
|
|
3379
3468
|
function createVitest() {
|
|
3380
|
-
const _mocker = typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : new Proxy({}, {
|
|
3381
|
-
get(_, name) {
|
|
3382
|
-
throw new Error(
|
|
3383
|
-
`Vitest mocker was not initialized in this environment. vi.${String(name)}() is forbidden.`
|
|
3384
|
-
);
|
|
3385
|
-
}
|
|
3386
|
-
});
|
|
3387
3469
|
let _mockedDate = null;
|
|
3388
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
|
+
}
|
|
3389
3483
|
const workerState = getWorkerState();
|
|
3390
3484
|
let _timers;
|
|
3391
3485
|
const timers = () => _timers || (_timers = new FakeTimers({
|
|
@@ -3414,10 +3508,11 @@ function createVitest() {
|
|
|
3414
3508
|
);
|
|
3415
3509
|
}
|
|
3416
3510
|
}
|
|
3417
|
-
if (config)
|
|
3511
|
+
if (config) {
|
|
3418
3512
|
timers().configure({ ...workerState.config.fakeTimers, ...config });
|
|
3419
|
-
else
|
|
3513
|
+
} else {
|
|
3420
3514
|
timers().configure(workerState.config.fakeTimers);
|
|
3515
|
+
}
|
|
3421
3516
|
timers().useFakeTimers();
|
|
3422
3517
|
return utils;
|
|
3423
3518
|
},
|
|
@@ -3494,46 +3589,70 @@ function createVitest() {
|
|
|
3494
3589
|
return factory();
|
|
3495
3590
|
},
|
|
3496
3591
|
mock(path, factory) {
|
|
3497
|
-
if (typeof path !== "string")
|
|
3498
|
-
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
|
+
}
|
|
3499
3597
|
const importer = getImporter("mock");
|
|
3500
|
-
_mocker.queueMock(
|
|
3598
|
+
_mocker().queueMock(
|
|
3501
3599
|
path,
|
|
3502
3600
|
importer,
|
|
3503
|
-
factory ? () => factory(
|
|
3601
|
+
factory ? () => factory(
|
|
3602
|
+
() => _mocker().importActual(
|
|
3603
|
+
path,
|
|
3604
|
+
importer,
|
|
3605
|
+
_mocker().getMockContext().callstack
|
|
3606
|
+
)
|
|
3607
|
+
) : void 0,
|
|
3504
3608
|
true
|
|
3505
3609
|
);
|
|
3506
3610
|
},
|
|
3507
3611
|
unmock(path) {
|
|
3508
|
-
if (typeof path !== "string")
|
|
3509
|
-
throw new
|
|
3510
|
-
|
|
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"));
|
|
3511
3618
|
},
|
|
3512
3619
|
doMock(path, factory) {
|
|
3513
|
-
if (typeof path !== "string")
|
|
3514
|
-
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
|
+
}
|
|
3515
3625
|
const importer = getImporter("doMock");
|
|
3516
|
-
_mocker.queueMock(
|
|
3626
|
+
_mocker().queueMock(
|
|
3517
3627
|
path,
|
|
3518
3628
|
importer,
|
|
3519
|
-
factory ? () => factory(
|
|
3629
|
+
factory ? () => factory(
|
|
3630
|
+
() => _mocker().importActual(
|
|
3631
|
+
path,
|
|
3632
|
+
importer,
|
|
3633
|
+
_mocker().getMockContext().callstack
|
|
3634
|
+
)
|
|
3635
|
+
) : void 0,
|
|
3520
3636
|
false
|
|
3521
3637
|
);
|
|
3522
3638
|
},
|
|
3523
3639
|
doUnmock(path) {
|
|
3524
|
-
if (typeof path !== "string")
|
|
3525
|
-
throw new
|
|
3526
|
-
|
|
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"));
|
|
3527
3646
|
},
|
|
3528
3647
|
async importActual(path) {
|
|
3529
|
-
return _mocker.importActual(
|
|
3648
|
+
return _mocker().importActual(
|
|
3530
3649
|
path,
|
|
3531
3650
|
getImporter("importActual"),
|
|
3532
|
-
_mocker.getMockContext().callstack
|
|
3651
|
+
_mocker().getMockContext().callstack
|
|
3533
3652
|
);
|
|
3534
3653
|
},
|
|
3535
3654
|
async importMock(path) {
|
|
3536
|
-
return _mocker.importMock(path, getImporter("importMock"));
|
|
3655
|
+
return _mocker().importMock(path, getImporter("importMock"));
|
|
3537
3656
|
},
|
|
3538
3657
|
// this is typed in the interface so it's not necessary to type it here
|
|
3539
3658
|
mocked(item, _options = {}) {
|
|
@@ -3555,8 +3674,12 @@ function createVitest() {
|
|
|
3555
3674
|
return utils;
|
|
3556
3675
|
},
|
|
3557
3676
|
stubGlobal(name, value) {
|
|
3558
|
-
if (!_stubsGlobal.has(name))
|
|
3559
|
-
_stubsGlobal.set(
|
|
3677
|
+
if (!_stubsGlobal.has(name)) {
|
|
3678
|
+
_stubsGlobal.set(
|
|
3679
|
+
name,
|
|
3680
|
+
Object.getOwnPropertyDescriptor(globalThis, name)
|
|
3681
|
+
);
|
|
3682
|
+
}
|
|
3560
3683
|
Object.defineProperty(globalThis, name, {
|
|
3561
3684
|
value,
|
|
3562
3685
|
writable: true,
|
|
@@ -3566,30 +3689,34 @@ function createVitest() {
|
|
|
3566
3689
|
return utils;
|
|
3567
3690
|
},
|
|
3568
3691
|
stubEnv(name, value) {
|
|
3569
|
-
if (!_stubsEnv.has(name))
|
|
3692
|
+
if (!_stubsEnv.has(name)) {
|
|
3570
3693
|
_stubsEnv.set(name, process.env[name]);
|
|
3571
|
-
|
|
3694
|
+
}
|
|
3695
|
+
if (_envBooleans.includes(name)) {
|
|
3572
3696
|
process.env[name] = value ? "1" : "";
|
|
3573
|
-
else
|
|
3697
|
+
} else {
|
|
3574
3698
|
process.env[name] = String(value);
|
|
3699
|
+
}
|
|
3575
3700
|
return utils;
|
|
3576
3701
|
},
|
|
3577
3702
|
unstubAllGlobals() {
|
|
3578
3703
|
_stubsGlobal.forEach((original, name) => {
|
|
3579
|
-
if (!original)
|
|
3704
|
+
if (!original) {
|
|
3580
3705
|
Reflect.deleteProperty(globalThis, name);
|
|
3581
|
-
else
|
|
3706
|
+
} else {
|
|
3582
3707
|
Object.defineProperty(globalThis, name, original);
|
|
3708
|
+
}
|
|
3583
3709
|
});
|
|
3584
3710
|
_stubsGlobal.clear();
|
|
3585
3711
|
return utils;
|
|
3586
3712
|
},
|
|
3587
3713
|
unstubAllEnvs() {
|
|
3588
3714
|
_stubsEnv.forEach((original, name) => {
|
|
3589
|
-
if (original === void 0)
|
|
3715
|
+
if (original === void 0) {
|
|
3590
3716
|
delete process.env[name];
|
|
3591
|
-
else
|
|
3717
|
+
} else {
|
|
3592
3718
|
process.env[name] = original;
|
|
3719
|
+
}
|
|
3593
3720
|
});
|
|
3594
3721
|
_stubsEnv.clear();
|
|
3595
3722
|
return utils;
|
|
@@ -3602,13 +3729,15 @@ function createVitest() {
|
|
|
3602
3729
|
return waitForImportsToResolve();
|
|
3603
3730
|
},
|
|
3604
3731
|
setConfig(config) {
|
|
3605
|
-
if (!_config)
|
|
3732
|
+
if (!_config) {
|
|
3606
3733
|
_config = { ...workerState.config };
|
|
3734
|
+
}
|
|
3607
3735
|
Object.assign(workerState.config, config);
|
|
3608
3736
|
},
|
|
3609
3737
|
resetConfig() {
|
|
3610
|
-
if (_config)
|
|
3738
|
+
if (_config) {
|
|
3611
3739
|
Object.assign(workerState.config, _config);
|
|
3740
|
+
}
|
|
3612
3741
|
}
|
|
3613
3742
|
};
|
|
3614
3743
|
return utils;
|