vitest 0.22.1 → 0.23.2
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 +29 -29
- package/dist/browser.d.ts +5 -4
- package/dist/browser.mjs +10 -8
- package/dist/{chunk-api-setup.377c28aa.mjs → chunk-api-setup.11cfd513.mjs} +89 -86
- package/dist/{chunk-integrations-coverage.d205bd87.mjs → chunk-env-node.ceb43f1c.mjs} +31 -179
- package/dist/chunk-integrations-coverage.99c020eb.mjs +166 -0
- package/dist/{chunk-integrations-globals.60af7da3.mjs → chunk-integrations-globals.ad5b1b51.mjs} +5 -6
- package/dist/{chunk-magic-string.efe26975.mjs → chunk-magic-string.56b2b543.mjs} +30 -10
- package/dist/{chunk-mock-date.304e29b1.mjs → chunk-mock-date.2917be60.mjs} +25 -4
- package/dist/{chunk-node-git.9a7e3153.mjs → chunk-node-git.a44b4872.mjs} +14 -8
- package/dist/{chunk-runtime-chain.be610650.mjs → chunk-runtime-chain.7a7f3c3b.mjs} +494 -172
- package/dist/{chunk-runtime-error.1104e45a.mjs → chunk-runtime-error.2723946b.mjs} +219 -75
- package/dist/{chunk-runtime-hooks.5d7073db.mjs → chunk-runtime-hooks.1a0bc3fd.mjs} +18 -12
- package/dist/{chunk-runtime-mocker.49d21aa6.mjs → chunk-runtime-mocker.8d4a2494.mjs} +18 -11
- package/dist/{chunk-runtime-rpc.57586b73.mjs → chunk-runtime-rpc.00a890d2.mjs} +1 -2
- package/dist/{chunk-utils-source-map.bbf3ad19.mjs → chunk-utils-source-map.2be5aa48.mjs} +10 -4
- package/dist/{chunk-vite-node-client.cddda63d.mjs → chunk-vite-node-client.da0a17ff.mjs} +49 -12
- package/dist/{chunk-vite-node-externalize.c843f497.mjs → chunk-vite-node-externalize.f55c4577.mjs} +547 -218
- package/dist/{chunk-vite-node-utils.b432150c.mjs → chunk-vite-node-utils.473cd0b2.mjs} +39 -41
- package/dist/cli-wrapper.mjs +17 -13
- package/dist/cli.mjs +26 -14
- package/dist/config.cjs +2 -2
- package/dist/config.d.ts +4 -3
- package/dist/config.mjs +2 -2
- package/dist/entry.mjs +18 -13
- package/dist/environments.d.ts +23 -0
- package/dist/environments.mjs +3 -0
- package/dist/{global-fe52f84b.d.ts → global-d05ffb3f.d.ts} +140 -19
- package/dist/{index-ea17aa0c.d.ts → index-60e2a8e1.d.ts} +3 -2
- package/dist/index.d.ts +6 -5
- package/dist/index.mjs +5 -6
- package/dist/loader.mjs +5 -6
- package/dist/node.d.ts +5 -4
- package/dist/node.mjs +11 -9
- package/dist/suite.mjs +4 -5
- package/dist/vendor-index.0557b03a.mjs +147 -0
- package/dist/worker.mjs +16 -14
- package/package.json +20 -13
- package/dist/chunk-utils-global.fa20c2f6.mjs +0 -5
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { performance } from 'perf_hooks';
|
|
2
|
+
import { t as takeCoverageInsideWorker, p as pLimit } from './chunk-integrations-coverage.99c020eb.mjs';
|
|
3
|
+
import { r as resetRunOnceCounter, i as index, v as vi } from './chunk-runtime-hooks.1a0bc3fd.mjs';
|
|
4
|
+
import { k as deepClone, l as getType, o as isNode, g as getWorkerState, R as RealDate, t as toArray, p as relativePath, q as isBrowser, h as isRunningInBenchmark, u as partitionSuiteChildren, v as shuffle, w as hasTests, x as hasFailed, y as createDefer, e as getFullName } from './chunk-mock-date.2917be60.mjs';
|
|
5
|
+
import { f as clearCollectorContext, h as defaultSuite, j as setHooks, k as getHooks, l as collectorContext, m as getFn, n as setState, G as GLOBAL_EXPECT, o as getState } from './chunk-runtime-chain.7a7f3c3b.mjs';
|
|
6
|
+
import { r as rpc } from './chunk-runtime-rpc.00a890d2.mjs';
|
|
6
7
|
import util$1 from 'util';
|
|
7
8
|
import { util } from 'chai';
|
|
8
|
-
import { s as stringify } from './chunk-utils-source-map.
|
|
9
|
-
import {
|
|
9
|
+
import { s as stringify } from './chunk-utils-source-map.2be5aa48.mjs';
|
|
10
|
+
import { e as environments } from './chunk-env-node.ceb43f1c.mjs';
|
|
10
11
|
import { a as safeClearTimeout, s as safeSetTimeout } from './chunk-utils-timers.b48455ed.mjs';
|
|
11
12
|
|
|
12
13
|
const OBJECT_PROTO = Object.getPrototypeOf({});
|
|
14
|
+
function getUnserializableMessage(err) {
|
|
15
|
+
if (err instanceof Error)
|
|
16
|
+
return `<unserializable>: ${err.message}`;
|
|
17
|
+
if (typeof err === "string")
|
|
18
|
+
return `<unserializable>: ${err}`;
|
|
19
|
+
return "<unserializable>";
|
|
20
|
+
}
|
|
13
21
|
function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
|
|
14
22
|
if (!val || typeof val === "string")
|
|
15
23
|
return val;
|
|
@@ -17,7 +25,7 @@ function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
|
|
|
17
25
|
return `Function<${val.name}>`;
|
|
18
26
|
if (typeof val !== "object")
|
|
19
27
|
return val;
|
|
20
|
-
if (val instanceof Promise ||
|
|
28
|
+
if (val instanceof Promise || val.constructor && val.constructor.prototype === "AsyncFunction")
|
|
21
29
|
return "Promise";
|
|
22
30
|
if (typeof Element !== "undefined" && val instanceof Element)
|
|
23
31
|
return val.tagName;
|
|
@@ -29,7 +37,11 @@ function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
|
|
|
29
37
|
const clone = new Array(val.length);
|
|
30
38
|
seen.set(val, clone);
|
|
31
39
|
val.forEach((e, i) => {
|
|
32
|
-
|
|
40
|
+
try {
|
|
41
|
+
clone[i] = serializeError(e, seen);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
clone[i] = getUnserializableMessage(err);
|
|
44
|
+
}
|
|
33
45
|
});
|
|
34
46
|
return clone;
|
|
35
47
|
} else {
|
|
@@ -38,8 +50,14 @@ function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
|
|
|
38
50
|
let obj = val;
|
|
39
51
|
while (obj && obj !== OBJECT_PROTO) {
|
|
40
52
|
Object.getOwnPropertyNames(obj).forEach((key) => {
|
|
41
|
-
if (
|
|
53
|
+
if (key in clone)
|
|
54
|
+
return;
|
|
55
|
+
try {
|
|
42
56
|
clone[key] = serializeError(obj[key], seen);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
delete clone[key];
|
|
59
|
+
clone[key] = getUnserializableMessage(err);
|
|
60
|
+
}
|
|
43
61
|
});
|
|
44
62
|
obj = Object.getPrototypeOf(obj);
|
|
45
63
|
}
|
|
@@ -50,7 +68,7 @@ function normalizeErrorMessage(message) {
|
|
|
50
68
|
return message.replace(/__vite_ssr_import_\d+__\./g, "");
|
|
51
69
|
}
|
|
52
70
|
function processError(err) {
|
|
53
|
-
if (!err)
|
|
71
|
+
if (!err || typeof err !== "object")
|
|
54
72
|
return err;
|
|
55
73
|
if (err.stack)
|
|
56
74
|
err.stackStr = String(err.stack);
|
|
@@ -105,7 +123,12 @@ function replaceAsymmetricMatcher(actual, expected, actualReplaced = /* @__PURE_
|
|
|
105
123
|
if (actualValue.asymmetricMatch(expectedValue))
|
|
106
124
|
expected[key] = actualValue;
|
|
107
125
|
} else if (isReplaceable(actualValue, expectedValue)) {
|
|
108
|
-
const replaced = replaceAsymmetricMatcher(
|
|
126
|
+
const replaced = replaceAsymmetricMatcher(
|
|
127
|
+
actualValue,
|
|
128
|
+
expectedValue,
|
|
129
|
+
actualReplaced,
|
|
130
|
+
expectedReplaced
|
|
131
|
+
);
|
|
109
132
|
actual[key] = replaced.replacedActual;
|
|
110
133
|
expected[key] = replaced.replacedExpected;
|
|
111
134
|
}
|
|
@@ -131,7 +154,7 @@ async function setupGlobalEnv(config) {
|
|
|
131
154
|
if (isNode)
|
|
132
155
|
await setupConsoleLogSpy();
|
|
133
156
|
if (config.globals)
|
|
134
|
-
(await import('./chunk-integrations-globals.
|
|
157
|
+
(await import('./chunk-integrations-globals.ad5b1b51.mjs')).registerApiGlobally();
|
|
135
158
|
}
|
|
136
159
|
function setupDefines(defines) {
|
|
137
160
|
for (const key in defines)
|
|
@@ -243,8 +266,18 @@ async function setupConsoleLogSpy() {
|
|
|
243
266
|
groupIndentation: 2
|
|
244
267
|
});
|
|
245
268
|
}
|
|
269
|
+
async function loadEnvironment(name) {
|
|
270
|
+
const pkg = await import(`vitest-environment-${name}`);
|
|
271
|
+
if (!pkg || !pkg.default || typeof pkg.default !== "object" || typeof pkg.default.setup !== "function") {
|
|
272
|
+
throw new Error(
|
|
273
|
+
`Environment "${name}" is not a valid environment. Package "vitest-environment-${name}" should have default export with "setup" method.`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
return pkg.default;
|
|
277
|
+
}
|
|
246
278
|
async function withEnv(name, options, fn) {
|
|
247
|
-
const
|
|
279
|
+
const config = environments[name] || await loadEnvironment(name);
|
|
280
|
+
const env = await config.setup(globalThis, options);
|
|
248
281
|
try {
|
|
249
282
|
await fn();
|
|
250
283
|
} finally {
|
|
@@ -253,10 +286,12 @@ async function withEnv(name, options, fn) {
|
|
|
253
286
|
}
|
|
254
287
|
async function runSetupFiles(config) {
|
|
255
288
|
const files = toArray(config.setupFiles);
|
|
256
|
-
await Promise.all(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
289
|
+
await Promise.all(
|
|
290
|
+
files.map(async (fsPath) => {
|
|
291
|
+
getWorkerState().moduleCache.delete(fsPath);
|
|
292
|
+
await import(fsPath);
|
|
293
|
+
})
|
|
294
|
+
);
|
|
260
295
|
}
|
|
261
296
|
|
|
262
297
|
const now$1 = Date.now;
|
|
@@ -307,9 +342,11 @@ async function collectTests(paths, config) {
|
|
|
307
342
|
for (const c of [...defaultTasks.tasks, ...collectorContext.tasks]) {
|
|
308
343
|
if (c.type === "test") {
|
|
309
344
|
file.tasks.push(c);
|
|
345
|
+
} else if (c.type === "benchmark") {
|
|
346
|
+
file.tasks.push(c);
|
|
310
347
|
} else if (c.type === "suite") {
|
|
311
348
|
file.tasks.push(c);
|
|
312
|
-
} else {
|
|
349
|
+
} else if (c.type === "collector") {
|
|
313
350
|
const suite = await c.collect(file);
|
|
314
351
|
if (suite.name || suite.tasks.length)
|
|
315
352
|
file.tasks.push(suite);
|
|
@@ -394,6 +431,11 @@ function calculateHash(parent) {
|
|
|
394
431
|
});
|
|
395
432
|
}
|
|
396
433
|
|
|
434
|
+
async function importTinybench() {
|
|
435
|
+
if (!globalThis.EventTarget)
|
|
436
|
+
await import('./vendor-index.0557b03a.mjs').then(function (n) { return n.i; });
|
|
437
|
+
return await import('tinybench');
|
|
438
|
+
}
|
|
397
439
|
const now = Date.now;
|
|
398
440
|
function updateSuiteHookState(suite, name, state) {
|
|
399
441
|
var _a;
|
|
@@ -410,13 +452,19 @@ function updateSuiteHookState(suite, name, state) {
|
|
|
410
452
|
async function callSuiteHook(suite, currentTask, name, args) {
|
|
411
453
|
const callbacks = [];
|
|
412
454
|
if (name === "beforeEach" && suite.suite) {
|
|
413
|
-
callbacks.push(
|
|
455
|
+
callbacks.push(
|
|
456
|
+
...await callSuiteHook(suite.suite, currentTask, name, args)
|
|
457
|
+
);
|
|
414
458
|
}
|
|
415
459
|
updateSuiteHookState(currentTask, name, "run");
|
|
416
|
-
callbacks.push(
|
|
460
|
+
callbacks.push(
|
|
461
|
+
...await Promise.all(getHooks(suite)[name].map((fn) => fn(...args)))
|
|
462
|
+
);
|
|
417
463
|
updateSuiteHookState(currentTask, name, "pass");
|
|
418
464
|
if (name === "afterEach" && suite.suite) {
|
|
419
|
-
callbacks.push(
|
|
465
|
+
callbacks.push(
|
|
466
|
+
...await callSuiteHook(suite.suite, currentTask, name, args)
|
|
467
|
+
);
|
|
420
468
|
}
|
|
421
469
|
return callbacks;
|
|
422
470
|
}
|
|
@@ -442,7 +490,7 @@ async function sendTasksUpdate() {
|
|
|
442
490
|
async function runTest(test) {
|
|
443
491
|
var _a, _b;
|
|
444
492
|
if (test.mode !== "run") {
|
|
445
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
493
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.7a7f3c3b.mjs').then(function (n) { return n.q; });
|
|
446
494
|
getSnapshotClient().skipTestSnapshots(test);
|
|
447
495
|
return;
|
|
448
496
|
}
|
|
@@ -458,46 +506,53 @@ async function runTest(test) {
|
|
|
458
506
|
updateTask(test);
|
|
459
507
|
clearModuleMocks();
|
|
460
508
|
if (isNode) {
|
|
461
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
509
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.7a7f3c3b.mjs').then(function (n) { return n.q; });
|
|
462
510
|
await getSnapshotClient().setTest(test);
|
|
463
511
|
}
|
|
464
512
|
const workerState = getWorkerState();
|
|
465
513
|
workerState.current = test;
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
beforeEachCleanups =
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
514
|
+
const retry = test.retry || 1;
|
|
515
|
+
for (let retryCount = 0; retryCount < retry; retryCount++) {
|
|
516
|
+
let beforeEachCleanups = [];
|
|
517
|
+
try {
|
|
518
|
+
beforeEachCleanups = await callSuiteHook(test.suite, test, "beforeEach", [test.context, test.suite]);
|
|
519
|
+
setState({
|
|
520
|
+
assertionCalls: 0,
|
|
521
|
+
isExpectingAssertions: false,
|
|
522
|
+
isExpectingAssertionsError: null,
|
|
523
|
+
expectedAssertionsNumber: null,
|
|
524
|
+
expectedAssertionsNumberErrorGen: null,
|
|
525
|
+
testPath: (_b = test.suite.file) == null ? void 0 : _b.filepath,
|
|
526
|
+
currentTestName: getFullName(test)
|
|
527
|
+
}, globalThis[GLOBAL_EXPECT]);
|
|
528
|
+
test.result.retryCount = retryCount;
|
|
529
|
+
await getFn(test)();
|
|
530
|
+
const {
|
|
531
|
+
assertionCalls,
|
|
532
|
+
expectedAssertionsNumber,
|
|
533
|
+
expectedAssertionsNumberErrorGen,
|
|
534
|
+
isExpectingAssertions,
|
|
535
|
+
isExpectingAssertionsError
|
|
536
|
+
} = test.context._local ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
|
|
537
|
+
if (expectedAssertionsNumber !== null && assertionCalls !== expectedAssertionsNumber)
|
|
538
|
+
throw expectedAssertionsNumberErrorGen();
|
|
539
|
+
if (isExpectingAssertions === true && assertionCalls === 0)
|
|
540
|
+
throw isExpectingAssertionsError;
|
|
541
|
+
test.result.state = "pass";
|
|
542
|
+
} catch (e) {
|
|
543
|
+
test.result.state = "fail";
|
|
544
|
+
test.result.error = processError(e);
|
|
545
|
+
}
|
|
546
|
+
try {
|
|
547
|
+
await callSuiteHook(test.suite, test, "afterEach", [test.context, test.suite]);
|
|
548
|
+
await Promise.all(beforeEachCleanups.map((i) => i == null ? void 0 : i()));
|
|
549
|
+
} catch (e) {
|
|
550
|
+
test.result.state = "fail";
|
|
551
|
+
test.result.error = processError(e);
|
|
552
|
+
}
|
|
553
|
+
if (test.result.state === "pass")
|
|
554
|
+
break;
|
|
555
|
+
updateTask(test);
|
|
501
556
|
}
|
|
502
557
|
if (test.fails) {
|
|
503
558
|
if (test.result.state === "pass") {
|
|
@@ -511,7 +566,7 @@ async function runTest(test) {
|
|
|
511
566
|
if (isBrowser && test.result.error)
|
|
512
567
|
console.error(test.result.error.message, test.result.error.stackStr);
|
|
513
568
|
if (isNode) {
|
|
514
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
569
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.7a7f3c3b.mjs').then(function (n) { return n.q; });
|
|
515
570
|
getSnapshotClient().clearTest();
|
|
516
571
|
}
|
|
517
572
|
test.result.duration = now() - start;
|
|
@@ -550,20 +605,24 @@ async function runSuite(suite) {
|
|
|
550
605
|
} else {
|
|
551
606
|
try {
|
|
552
607
|
const beforeAllCleanups = await callSuiteHook(suite, suite, "beforeAll", [suite]);
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
const
|
|
562
|
-
|
|
563
|
-
|
|
608
|
+
if (isRunningInBenchmark()) {
|
|
609
|
+
await runBenchmarkSuit(suite);
|
|
610
|
+
} else {
|
|
611
|
+
for (let tasksGroup of partitionSuiteChildren(suite)) {
|
|
612
|
+
if (tasksGroup[0].concurrent === true) {
|
|
613
|
+
const mutex = pLimit(workerState.config.maxConcurrency);
|
|
614
|
+
await Promise.all(tasksGroup.map((c) => mutex(() => runSuiteChild(c))));
|
|
615
|
+
} else {
|
|
616
|
+
const { sequence } = workerState.config;
|
|
617
|
+
if (sequence.shuffle || suite.shuffle) {
|
|
618
|
+
const suites = tasksGroup.filter((group) => group.type === "suite");
|
|
619
|
+
const tests = tasksGroup.filter((group) => group.type === "test");
|
|
620
|
+
const groups = shuffle([suites, tests], sequence.seed);
|
|
621
|
+
tasksGroup = groups.flatMap((group) => shuffle(group, sequence.seed));
|
|
622
|
+
}
|
|
623
|
+
for (const c of tasksGroup)
|
|
624
|
+
await runSuiteChild(c);
|
|
564
625
|
}
|
|
565
|
-
for (const c of tasksGroup)
|
|
566
|
-
await runSuiteChild(c);
|
|
567
626
|
}
|
|
568
627
|
}
|
|
569
628
|
await callSuiteHook(suite, suite, "afterAll", [suite]);
|
|
@@ -589,8 +648,93 @@ async function runSuite(suite) {
|
|
|
589
648
|
}
|
|
590
649
|
updateTask(suite);
|
|
591
650
|
}
|
|
651
|
+
function createBenchmarkResult(name) {
|
|
652
|
+
return {
|
|
653
|
+
name,
|
|
654
|
+
rank: 0,
|
|
655
|
+
rme: 0,
|
|
656
|
+
samples: []
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
async function runBenchmarkSuit(suite) {
|
|
660
|
+
const { Task, Bench } = await importTinybench();
|
|
661
|
+
const start = performance.now();
|
|
662
|
+
const benchmarkGroup = [];
|
|
663
|
+
const benchmarkSuiteGroup = [];
|
|
664
|
+
for (const task of suite.tasks) {
|
|
665
|
+
if (task.type === "benchmark")
|
|
666
|
+
benchmarkGroup.push(task);
|
|
667
|
+
else if (task.type === "suite")
|
|
668
|
+
benchmarkSuiteGroup.push(task);
|
|
669
|
+
}
|
|
670
|
+
if (benchmarkSuiteGroup.length)
|
|
671
|
+
await Promise.all(benchmarkSuiteGroup.map((subSuite) => runBenchmarkSuit(subSuite)));
|
|
672
|
+
if (benchmarkGroup.length) {
|
|
673
|
+
const defer = createDefer();
|
|
674
|
+
const benchmarkMap = {};
|
|
675
|
+
suite.result = {
|
|
676
|
+
state: "run",
|
|
677
|
+
startTime: start,
|
|
678
|
+
benchmark: createBenchmarkResult(suite.name)
|
|
679
|
+
};
|
|
680
|
+
updateTask(suite);
|
|
681
|
+
benchmarkGroup.forEach((benchmark, idx) => {
|
|
682
|
+
const benchmarkInstance = new Bench(benchmark.options);
|
|
683
|
+
const benchmarkFn = getFn(benchmark);
|
|
684
|
+
benchmark.result = {
|
|
685
|
+
state: "run",
|
|
686
|
+
startTime: start,
|
|
687
|
+
benchmark: createBenchmarkResult(benchmark.name)
|
|
688
|
+
};
|
|
689
|
+
const id = idx.toString();
|
|
690
|
+
benchmarkMap[id] = benchmark;
|
|
691
|
+
const task = new Task(benchmarkInstance, id, benchmarkFn);
|
|
692
|
+
benchmark.task = task;
|
|
693
|
+
updateTask(benchmark);
|
|
694
|
+
});
|
|
695
|
+
benchmarkGroup.forEach((benchmark) => {
|
|
696
|
+
benchmark.task.addEventListener("complete", (e) => {
|
|
697
|
+
const task = e.task;
|
|
698
|
+
const _benchmark = benchmarkMap[task.name || ""];
|
|
699
|
+
if (_benchmark) {
|
|
700
|
+
const taskRes = task.result;
|
|
701
|
+
const result = _benchmark.result.benchmark;
|
|
702
|
+
Object.assign(result, taskRes);
|
|
703
|
+
updateTask(_benchmark);
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
benchmark.task.addEventListener("error", (e) => {
|
|
707
|
+
defer.reject(e);
|
|
708
|
+
});
|
|
709
|
+
});
|
|
710
|
+
Promise.all(benchmarkGroup.map(async (benchmark) => {
|
|
711
|
+
await benchmark.task.warmup();
|
|
712
|
+
return await new Promise((resolve) => safeSetTimeout(async () => {
|
|
713
|
+
resolve(await benchmark.task.run());
|
|
714
|
+
}));
|
|
715
|
+
})).then((tasks) => {
|
|
716
|
+
suite.result.duration = performance.now() - start;
|
|
717
|
+
suite.result.state = "pass";
|
|
718
|
+
tasks.sort((a, b) => a.result.mean - b.result.mean).forEach((cycle, idx) => {
|
|
719
|
+
const benchmark = benchmarkMap[cycle.name || ""];
|
|
720
|
+
benchmark.result.state = "pass";
|
|
721
|
+
if (benchmark) {
|
|
722
|
+
const result = benchmark.result.benchmark;
|
|
723
|
+
result.rank = Number(idx) + 1;
|
|
724
|
+
updateTask(benchmark);
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
updateTask(suite);
|
|
728
|
+
defer.resolve(null);
|
|
729
|
+
});
|
|
730
|
+
await defer;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
592
733
|
async function runSuiteChild(c) {
|
|
593
|
-
|
|
734
|
+
if (c.type === "test")
|
|
735
|
+
return runTest(c);
|
|
736
|
+
else if (c.type === "suite")
|
|
737
|
+
return runSuite(c);
|
|
594
738
|
}
|
|
595
739
|
async function runSuites(suites) {
|
|
596
740
|
for (const suite of suites)
|
|
@@ -623,7 +767,7 @@ async function startTestsBrowser(paths, config) {
|
|
|
623
767
|
async function startTestsNode(paths, config) {
|
|
624
768
|
const files = await collectTests(paths, config);
|
|
625
769
|
rpc().onCollected(files);
|
|
626
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
770
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.7a7f3c3b.mjs').then(function (n) { return n.q; });
|
|
627
771
|
getSnapshotClient().clear();
|
|
628
772
|
await runFiles(files, config);
|
|
629
773
|
const coverage = await takeCoverageInsideWorker(config.coverage);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, c as createExpect,
|
|
2
|
-
import { R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-mock-date.
|
|
3
|
-
import {
|
|
4
|
-
import { p as parseStacktrace } from './chunk-utils-source-map.bbf3ad19.mjs';
|
|
1
|
+
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, b as bench, c as createExpect, e as globalExpect } from './chunk-runtime-chain.7a7f3c3b.mjs';
|
|
2
|
+
import { g as getWorkerState, R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-mock-date.2917be60.mjs';
|
|
3
|
+
import { p as parseStacktrace } from './chunk-utils-source-map.2be5aa48.mjs';
|
|
5
4
|
import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
|
|
6
5
|
import util from 'util';
|
|
7
6
|
import { spyOn, fn, isMockFunction, spies } from './spy.mjs';
|
|
@@ -15,12 +14,14 @@ const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeo
|
|
|
15
14
|
const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
|
|
16
15
|
|
|
17
16
|
function withCallback(fn) {
|
|
18
|
-
return new Promise(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
return new Promise(
|
|
18
|
+
(resolve, reject) => fn((err) => {
|
|
19
|
+
if (err)
|
|
20
|
+
reject(err);
|
|
21
|
+
else
|
|
22
|
+
resolve();
|
|
23
|
+
})
|
|
24
|
+
);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
const filesCount = /* @__PURE__ */ new Map();
|
|
@@ -2608,7 +2609,9 @@ class FakeTimers {
|
|
|
2608
2609
|
}
|
|
2609
2610
|
useFakeTimers() {
|
|
2610
2611
|
if (this._fakingDate) {
|
|
2611
|
-
throw new Error(
|
|
2612
|
+
throw new Error(
|
|
2613
|
+
'"setSystemTime" was called already and date was mocked. Reset timers using `vi.useRealTimers()` if you want to use fake timers again.'
|
|
2614
|
+
);
|
|
2612
2615
|
}
|
|
2613
2616
|
if (!this._fakingTime) {
|
|
2614
2617
|
const toFake = Object.keys(this._fakeTimers.timers);
|
|
@@ -2648,7 +2651,9 @@ class FakeTimers {
|
|
|
2648
2651
|
}
|
|
2649
2652
|
_checkFakeTimers() {
|
|
2650
2653
|
if (!this._fakingTime) {
|
|
2651
|
-
throw new Error(
|
|
2654
|
+
throw new Error(
|
|
2655
|
+
'Timers are not mocked. Try calling "vi.useFakeTimers()" first.'
|
|
2656
|
+
);
|
|
2652
2657
|
}
|
|
2653
2658
|
return this._fakingTime;
|
|
2654
2659
|
}
|
|
@@ -2805,6 +2810,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
2805
2810
|
test: test,
|
|
2806
2811
|
describe: describe,
|
|
2807
2812
|
it: it,
|
|
2813
|
+
bench: bench,
|
|
2808
2814
|
runOnce: runOnce,
|
|
2809
2815
|
isFirstRun: isFirstRun,
|
|
2810
2816
|
beforeAll: beforeAll,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { V as ViteNodeRunner } from './chunk-vite-node-client.
|
|
1
|
+
import { V as ViteNodeRunner } from './chunk-vite-node-client.da0a17ff.mjs';
|
|
2
2
|
import { normalizePath } from 'vite';
|
|
3
|
-
import {
|
|
3
|
+
import { g as getWorkerState, G as mergeSlashes, s as slash, l as getType, H as getAllMockableProperties } from './chunk-mock-date.2917be60.mjs';
|
|
4
4
|
import { existsSync, readdirSync } from 'fs';
|
|
5
|
-
import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.
|
|
5
|
+
import { n as normalizeRequestId, p as pathFromRoot, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.473cd0b2.mjs';
|
|
6
6
|
import { d as dirname, j as join, b as basename, a as resolve, c as distDir } from './chunk-constants.71e8a211.mjs';
|
|
7
|
-
import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
|
|
8
7
|
|
|
9
8
|
class RefTracker {
|
|
10
9
|
constructor() {
|
|
@@ -102,12 +101,12 @@ const _VitestMocker = class {
|
|
|
102
101
|
return this.getMocks()[id];
|
|
103
102
|
}
|
|
104
103
|
normalizePath(path) {
|
|
105
|
-
return
|
|
104
|
+
return pathFromRoot(this.root, normalizeRequestId(path, this.base));
|
|
106
105
|
}
|
|
107
106
|
getFsPath(path, external) {
|
|
108
107
|
if (external)
|
|
109
108
|
return mergeSlashes(`/@fs/${path}`);
|
|
110
|
-
return normalizeRequestId(path
|
|
109
|
+
return normalizeRequestId(path, this.base);
|
|
111
110
|
}
|
|
112
111
|
resolveMockPath(mockPath, external) {
|
|
113
112
|
const path = normalizeRequestId(external || mockPath);
|
|
@@ -132,7 +131,9 @@ const _VitestMocker = class {
|
|
|
132
131
|
}
|
|
133
132
|
mockObject(object) {
|
|
134
133
|
if (!_VitestMocker.spyModule) {
|
|
135
|
-
throw new Error(
|
|
134
|
+
throw new Error(
|
|
135
|
+
"Error: Spy module is not defined. This is likely an internal bug in Vitest. Please report it to https://github.com/vitest-dev/vitest/issues"
|
|
136
|
+
);
|
|
136
137
|
}
|
|
137
138
|
const spyModule = _VitestMocker.spyModule;
|
|
138
139
|
const finalizers = new Array();
|
|
@@ -149,15 +150,18 @@ const _VitestMocker = class {
|
|
|
149
150
|
const containerType = getType(container);
|
|
150
151
|
const isModule = containerType === "Module" || !!container.__esModule;
|
|
151
152
|
for (const { key: property, descriptor } of getAllMockableProperties(container)) {
|
|
152
|
-
if (!isModule) {
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
if (!isModule && descriptor.get) {
|
|
154
|
+
try {
|
|
155
|
+
Object.defineProperty(newContainer, property, descriptor);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
}
|
|
158
|
+
continue;
|
|
155
159
|
}
|
|
156
160
|
if (isSpecialProp(property, containerType))
|
|
157
161
|
continue;
|
|
158
162
|
const value = container[property];
|
|
159
163
|
const refId = refs.getId(value);
|
|
160
|
-
if (refId) {
|
|
164
|
+
if (refId !== void 0) {
|
|
161
165
|
finalizers.push(() => define(newContainer, property, refs.getMockedValue(refId)));
|
|
162
166
|
continue;
|
|
163
167
|
}
|
|
@@ -193,6 +197,9 @@ const _VitestMocker = class {
|
|
|
193
197
|
const mock = this.mockMap.get(suitefile);
|
|
194
198
|
if (mock == null ? void 0 : mock[id])
|
|
195
199
|
delete mock[id];
|
|
200
|
+
const mockId = this.getMockPath(id);
|
|
201
|
+
if (this.moduleCache.get(mockId))
|
|
202
|
+
this.moduleCache.delete(mockId);
|
|
196
203
|
}
|
|
197
204
|
mockPath(path, external, factory) {
|
|
198
205
|
const suitefile = this.getSuiteFilepath();
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import './chunk-mock-date.
|
|
2
|
-
import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
|
|
1
|
+
import { g as getWorkerState } from './chunk-mock-date.2917be60.mjs';
|
|
3
2
|
import { w as withSafeTimers } from './chunk-utils-timers.b48455ed.mjs';
|
|
4
3
|
|
|
5
4
|
const rpc = () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { s as slash,
|
|
1
|
+
import { s as slash, j as notNullish } from './chunk-mock-date.2917be60.mjs';
|
|
2
2
|
import { p as picocolors } from './chunk-constants.71e8a211.mjs';
|
|
3
3
|
|
|
4
4
|
var build = {};
|
|
@@ -5725,7 +5725,9 @@ function numberToPos(source, offset) {
|
|
|
5725
5725
|
if (typeof offset !== "number")
|
|
5726
5726
|
return offset;
|
|
5727
5727
|
if (offset > source.length) {
|
|
5728
|
-
throw new Error(
|
|
5728
|
+
throw new Error(
|
|
5729
|
+
`offset is longer than source length! offset ${offset} > length ${source.length}`
|
|
5730
|
+
);
|
|
5729
5731
|
}
|
|
5730
5732
|
const lines = source.split(lineSplitRE);
|
|
5731
5733
|
let counted = 0;
|
|
@@ -7323,7 +7325,11 @@ function unifiedDiff(actual, expected, options = {}) {
|
|
|
7323
7325
|
const last = formatted.length - 1;
|
|
7324
7326
|
if (formatted[last].endsWith('"'))
|
|
7325
7327
|
formatted[last] = formatted[last].slice(0, formatted[last].length - 1);
|
|
7326
|
-
formatted.unshift(
|
|
7328
|
+
formatted.unshift(
|
|
7329
|
+
picocolors.exports.green(`- Expected - ${counts["-"]}`),
|
|
7330
|
+
picocolors.exports.red(`+ Received + ${counts["+"]}`),
|
|
7331
|
+
""
|
|
7332
|
+
);
|
|
7327
7333
|
}
|
|
7328
7334
|
}
|
|
7329
7335
|
return formatted.map((i) => indent + i).join("\n");
|
|
@@ -7436,4 +7442,4 @@ var matcherUtils = /*#__PURE__*/Object.freeze({
|
|
|
7436
7442
|
diff: diff
|
|
7437
7443
|
});
|
|
7438
7444
|
|
|
7439
|
-
export { plugins_1 as a, posToNumber as b, stripAnsi as c, cliTruncate as d, stringWidth as e, format_1 as f, getOriginalPos as g, ansiStyles as h,
|
|
7445
|
+
export { plugins_1 as a, posToNumber as b, stripAnsi as c, cliTruncate as d, stringWidth as e, format_1 as f, getOriginalPos as g, ansiStyles as h, interpretSourcePos as i, sliceAnsi as j, lineSplitRE as l, matcherUtils as m, numberToPos as n, parseStacktrace as p, stringify as s, unifiedDiff as u };
|