vitest 0.22.1 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +29 -29
- package/dist/browser.d.ts +5 -4
- package/dist/browser.mjs +11 -9
- package/dist/{chunk-api-setup.377c28aa.mjs → chunk-api-setup.5fc06d1d.mjs} +90 -87
- package/dist/{chunk-constants.71e8a211.mjs → chunk-constants.6196597b.mjs} +0 -0
- package/dist/{chunk-integrations-coverage.d205bd87.mjs → chunk-env-node.ceb43f1c.mjs} +31 -179
- package/dist/{chunk-install-pkg.3aa3eae6.mjs → chunk-install-pkg.e081fc1b.mjs} +3 -3
- package/dist/chunk-integrations-coverage.99c020eb.mjs +166 -0
- package/dist/{chunk-integrations-globals.60af7da3.mjs → chunk-integrations-globals.ef598c23.mjs} +6 -7
- package/dist/{chunk-magic-string.efe26975.mjs → chunk-magic-string.56b2b543.mjs} +30 -10
- package/dist/{chunk-mock-date.304e29b1.mjs → chunk-mock-date.0d86eaa5.mjs} +26 -5
- package/dist/{chunk-node-git.9a7e3153.mjs → chunk-node-git.6f289b0a.mjs} +18 -12
- package/dist/{chunk-runtime-chain.be610650.mjs → chunk-runtime-chain.2af36ddf.mjs} +507 -173
- package/dist/{chunk-runtime-error.1104e45a.mjs → chunk-runtime-error.ed9b4f70.mjs} +206 -75
- package/dist/{chunk-runtime-hooks.5d7073db.mjs → chunk-runtime-hooks.75ce0575.mjs} +18 -12
- package/dist/{chunk-runtime-mocker.49d21aa6.mjs → chunk-runtime-mocker.fc76f21d.mjs} +17 -10
- package/dist/{chunk-runtime-rpc.57586b73.mjs → chunk-runtime-rpc.3fe371e9.mjs} +1 -2
- package/dist/{chunk-utils-source-map.bbf3ad19.mjs → chunk-utils-source-map.70ee97e1.mjs} +11 -5
- package/dist/{chunk-vite-node-client.cddda63d.mjs → chunk-vite-node-client.74ebe3d5.mjs} +55 -13
- package/dist/{chunk-vite-node-debug.536c4c5b.mjs → chunk-vite-node-debug.2d8a1dc3.mjs} +1 -1
- package/dist/{chunk-vite-node-externalize.c843f497.mjs → chunk-vite-node-externalize.41bf722e.mjs} +483 -197
- package/dist/{chunk-vite-node-utils.b432150c.mjs → chunk-vite-node-utils.68573626.mjs} +24 -40
- package/dist/cli-wrapper.mjs +21 -17
- package/dist/cli.mjs +23 -15
- package/dist/config.cjs +2 -2
- package/dist/config.d.ts +4 -3
- package/dist/config.mjs +2 -2
- package/dist/entry.mjs +19 -14
- package/dist/environments.d.ts +23 -0
- package/dist/environments.mjs +3 -0
- package/dist/{global-fe52f84b.d.ts → global-ea084c9f.d.ts} +135 -19
- package/dist/{index-ea17aa0c.d.ts → index-5f09f4d0.d.ts} +3 -2
- package/dist/index.d.ts +6 -5
- package/dist/index.mjs +6 -7
- package/dist/loader.mjs +3 -4
- package/dist/node.d.ts +5 -4
- package/dist/node.mjs +14 -12
- package/dist/suite.mjs +5 -6
- package/dist/vendor-index.0557b03a.mjs +147 -0
- package/dist/{vendor-index.9d9196cc.mjs → vendor-index.13e3bda3.mjs} +0 -0
- package/dist/{vendor-index.fbec8a81.mjs → vendor-index.4aeeb598.mjs} +2 -2
- package/dist/{vendor-index.2ae8040a.mjs → vendor-index.62ce5c33.mjs} +0 -0
- package/dist/{vendor-index.29636037.mjs → vendor-index.731a22f2.mjs} +0 -0
- package/dist/worker.mjs +17 -15
- package/package.json +17 -10
- 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.75ce0575.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.0d86eaa5.mjs';
|
|
5
|
+
import { f as clearCollectorContext, h as defaultSuite, j as setHooks, k as getHooks, l as collectorContext, m as getBenchmarkFactory, n as getFn, o as setState, G as GLOBAL_EXPECT, p as getState } from './chunk-runtime-chain.2af36ddf.mjs';
|
|
6
|
+
import { r as rpc } from './chunk-runtime-rpc.3fe371e9.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.70ee97e1.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.ef598c23.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);
|
|
@@ -410,13 +447,19 @@ function updateSuiteHookState(suite, name, state) {
|
|
|
410
447
|
async function callSuiteHook(suite, currentTask, name, args) {
|
|
411
448
|
const callbacks = [];
|
|
412
449
|
if (name === "beforeEach" && suite.suite) {
|
|
413
|
-
callbacks.push(
|
|
450
|
+
callbacks.push(
|
|
451
|
+
...await callSuiteHook(suite.suite, currentTask, name, args)
|
|
452
|
+
);
|
|
414
453
|
}
|
|
415
454
|
updateSuiteHookState(currentTask, name, "run");
|
|
416
|
-
callbacks.push(
|
|
455
|
+
callbacks.push(
|
|
456
|
+
...await Promise.all(getHooks(suite)[name].map((fn) => fn(...args)))
|
|
457
|
+
);
|
|
417
458
|
updateSuiteHookState(currentTask, name, "pass");
|
|
418
459
|
if (name === "afterEach" && suite.suite) {
|
|
419
|
-
callbacks.push(
|
|
460
|
+
callbacks.push(
|
|
461
|
+
...await callSuiteHook(suite.suite, currentTask, name, args)
|
|
462
|
+
);
|
|
420
463
|
}
|
|
421
464
|
return callbacks;
|
|
422
465
|
}
|
|
@@ -442,7 +485,7 @@ async function sendTasksUpdate() {
|
|
|
442
485
|
async function runTest(test) {
|
|
443
486
|
var _a, _b;
|
|
444
487
|
if (test.mode !== "run") {
|
|
445
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
488
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.2af36ddf.mjs').then(function (n) { return n.r; });
|
|
446
489
|
getSnapshotClient().skipTestSnapshots(test);
|
|
447
490
|
return;
|
|
448
491
|
}
|
|
@@ -458,46 +501,53 @@ async function runTest(test) {
|
|
|
458
501
|
updateTask(test);
|
|
459
502
|
clearModuleMocks();
|
|
460
503
|
if (isNode) {
|
|
461
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
504
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.2af36ddf.mjs').then(function (n) { return n.r; });
|
|
462
505
|
await getSnapshotClient().setTest(test);
|
|
463
506
|
}
|
|
464
507
|
const workerState = getWorkerState();
|
|
465
508
|
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
|
-
|
|
509
|
+
const retry = test.retry || 1;
|
|
510
|
+
for (let retryCount = 0; retryCount < retry; retryCount++) {
|
|
511
|
+
let beforeEachCleanups = [];
|
|
512
|
+
try {
|
|
513
|
+
beforeEachCleanups = await callSuiteHook(test.suite, test, "beforeEach", [test.context, test.suite]);
|
|
514
|
+
setState({
|
|
515
|
+
assertionCalls: 0,
|
|
516
|
+
isExpectingAssertions: false,
|
|
517
|
+
isExpectingAssertionsError: null,
|
|
518
|
+
expectedAssertionsNumber: null,
|
|
519
|
+
expectedAssertionsNumberErrorGen: null,
|
|
520
|
+
testPath: (_b = test.suite.file) == null ? void 0 : _b.filepath,
|
|
521
|
+
currentTestName: getFullName(test)
|
|
522
|
+
}, globalThis[GLOBAL_EXPECT]);
|
|
523
|
+
test.result.retryCount = retryCount;
|
|
524
|
+
await getFn(test)();
|
|
525
|
+
const {
|
|
526
|
+
assertionCalls,
|
|
527
|
+
expectedAssertionsNumber,
|
|
528
|
+
expectedAssertionsNumberErrorGen,
|
|
529
|
+
isExpectingAssertions,
|
|
530
|
+
isExpectingAssertionsError
|
|
531
|
+
} = test.context._local ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
|
|
532
|
+
if (expectedAssertionsNumber !== null && assertionCalls !== expectedAssertionsNumber)
|
|
533
|
+
throw expectedAssertionsNumberErrorGen();
|
|
534
|
+
if (isExpectingAssertions === true && assertionCalls === 0)
|
|
535
|
+
throw isExpectingAssertionsError;
|
|
536
|
+
test.result.state = "pass";
|
|
537
|
+
} catch (e) {
|
|
538
|
+
test.result.state = "fail";
|
|
539
|
+
test.result.error = processError(e);
|
|
540
|
+
}
|
|
541
|
+
try {
|
|
542
|
+
await callSuiteHook(test.suite, test, "afterEach", [test.context, test.suite]);
|
|
543
|
+
await Promise.all(beforeEachCleanups.map((i) => i == null ? void 0 : i()));
|
|
544
|
+
} catch (e) {
|
|
545
|
+
test.result.state = "fail";
|
|
546
|
+
test.result.error = processError(e);
|
|
547
|
+
}
|
|
548
|
+
if (test.result.state === "pass")
|
|
549
|
+
break;
|
|
550
|
+
updateTask(test);
|
|
501
551
|
}
|
|
502
552
|
if (test.fails) {
|
|
503
553
|
if (test.result.state === "pass") {
|
|
@@ -511,7 +561,7 @@ async function runTest(test) {
|
|
|
511
561
|
if (isBrowser && test.result.error)
|
|
512
562
|
console.error(test.result.error.message, test.result.error.stackStr);
|
|
513
563
|
if (isNode) {
|
|
514
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
564
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.2af36ddf.mjs').then(function (n) { return n.r; });
|
|
515
565
|
getSnapshotClient().clearTest();
|
|
516
566
|
}
|
|
517
567
|
test.result.duration = now() - start;
|
|
@@ -550,20 +600,24 @@ async function runSuite(suite) {
|
|
|
550
600
|
} else {
|
|
551
601
|
try {
|
|
552
602
|
const beforeAllCleanups = await callSuiteHook(suite, suite, "beforeAll", [suite]);
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
const
|
|
562
|
-
|
|
563
|
-
|
|
603
|
+
if (isRunningInBenchmark()) {
|
|
604
|
+
await runBenchmarkSuit(suite);
|
|
605
|
+
} else {
|
|
606
|
+
for (let tasksGroup of partitionSuiteChildren(suite)) {
|
|
607
|
+
if (tasksGroup[0].concurrent === true) {
|
|
608
|
+
const mutex = pLimit(workerState.config.maxConcurrency);
|
|
609
|
+
await Promise.all(tasksGroup.map((c) => mutex(() => runSuiteChild(c))));
|
|
610
|
+
} else {
|
|
611
|
+
const { sequence } = workerState.config;
|
|
612
|
+
if (sequence.shuffle || suite.shuffle) {
|
|
613
|
+
const suites = tasksGroup.filter((group) => group.type === "suite");
|
|
614
|
+
const tests = tasksGroup.filter((group) => group.type === "test");
|
|
615
|
+
const groups = shuffle([suites, tests], sequence.seed);
|
|
616
|
+
tasksGroup = groups.flatMap((group) => shuffle(group, sequence.seed));
|
|
617
|
+
}
|
|
618
|
+
for (const c of tasksGroup)
|
|
619
|
+
await runSuiteChild(c);
|
|
564
620
|
}
|
|
565
|
-
for (const c of tasksGroup)
|
|
566
|
-
await runSuiteChild(c);
|
|
567
621
|
}
|
|
568
622
|
}
|
|
569
623
|
await callSuiteHook(suite, suite, "afterAll", [suite]);
|
|
@@ -589,8 +643,85 @@ async function runSuite(suite) {
|
|
|
589
643
|
}
|
|
590
644
|
updateTask(suite);
|
|
591
645
|
}
|
|
646
|
+
function createBenchmarkResult(name) {
|
|
647
|
+
return {
|
|
648
|
+
name,
|
|
649
|
+
rank: 0,
|
|
650
|
+
rme: 0,
|
|
651
|
+
samples: []
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
async function runBenchmarkSuit(suite) {
|
|
655
|
+
const start = performance.now();
|
|
656
|
+
const benchmarkGroup = [];
|
|
657
|
+
const benchmarkSuiteGroup = [];
|
|
658
|
+
for (const task of suite.tasks) {
|
|
659
|
+
if (task.type === "benchmark")
|
|
660
|
+
benchmarkGroup.push(task);
|
|
661
|
+
else if (task.type === "suite")
|
|
662
|
+
benchmarkSuiteGroup.push(task);
|
|
663
|
+
}
|
|
664
|
+
if (benchmarkSuiteGroup.length)
|
|
665
|
+
await Promise.all(benchmarkSuiteGroup.map((subSuite) => runBenchmarkSuit(subSuite)));
|
|
666
|
+
if (benchmarkGroup.length) {
|
|
667
|
+
const benchmarkInstance = await getBenchmarkFactory(suite);
|
|
668
|
+
const defer = createDefer();
|
|
669
|
+
const benchmarkMap = {};
|
|
670
|
+
suite.result = {
|
|
671
|
+
state: "run",
|
|
672
|
+
startTime: start,
|
|
673
|
+
benchmark: createBenchmarkResult(suite.name)
|
|
674
|
+
};
|
|
675
|
+
updateTask(suite);
|
|
676
|
+
benchmarkGroup.forEach((benchmark, idx) => {
|
|
677
|
+
const benchmarkFn = getFn(benchmark);
|
|
678
|
+
benchmark.result = {
|
|
679
|
+
state: "run",
|
|
680
|
+
startTime: start,
|
|
681
|
+
benchmark: createBenchmarkResult(benchmark.name)
|
|
682
|
+
};
|
|
683
|
+
const id = idx.toString();
|
|
684
|
+
benchmarkMap[id] = benchmark;
|
|
685
|
+
benchmarkInstance.add(id, benchmarkFn);
|
|
686
|
+
updateTask(benchmark);
|
|
687
|
+
});
|
|
688
|
+
benchmarkInstance.addEventListener("cycle", (e) => {
|
|
689
|
+
const task = e.task;
|
|
690
|
+
const benchmark = benchmarkMap[task.name || ""];
|
|
691
|
+
if (benchmark) {
|
|
692
|
+
const taskRes = task.result;
|
|
693
|
+
const result = benchmark.result.benchmark;
|
|
694
|
+
Object.assign(result, taskRes);
|
|
695
|
+
updateTask(benchmark);
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
benchmarkInstance.addEventListener("complete", () => {
|
|
699
|
+
suite.result.duration = performance.now() - start;
|
|
700
|
+
suite.result.state = "pass";
|
|
701
|
+
benchmarkInstance.tasks.sort((a, b) => b.result.mean - a.result.mean).forEach((cycle, idx) => {
|
|
702
|
+
const benchmark = benchmarkMap[cycle.name || ""];
|
|
703
|
+
benchmark.result.state = "pass";
|
|
704
|
+
if (benchmark) {
|
|
705
|
+
const result = benchmark.result.benchmark;
|
|
706
|
+
result.rank = Number(idx) + 1;
|
|
707
|
+
updateTask(benchmark);
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
updateTask(suite);
|
|
711
|
+
defer.resolve(null);
|
|
712
|
+
});
|
|
713
|
+
benchmarkInstance.addEventListener("error", (e) => {
|
|
714
|
+
defer.reject(e);
|
|
715
|
+
});
|
|
716
|
+
benchmarkInstance.run();
|
|
717
|
+
await defer;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
592
720
|
async function runSuiteChild(c) {
|
|
593
|
-
|
|
721
|
+
if (c.type === "test")
|
|
722
|
+
return runTest(c);
|
|
723
|
+
else if (c.type === "suite")
|
|
724
|
+
return runSuite(c);
|
|
594
725
|
}
|
|
595
726
|
async function runSuites(suites) {
|
|
596
727
|
for (const suite of suites)
|
|
@@ -623,7 +754,7 @@ async function startTestsBrowser(paths, config) {
|
|
|
623
754
|
async function startTestsNode(paths, config) {
|
|
624
755
|
const files = await collectTests(paths, config);
|
|
625
756
|
rpc().onCollected(files);
|
|
626
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
757
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.2af36ddf.mjs').then(function (n) { return n.r; });
|
|
627
758
|
getSnapshotClient().clear();
|
|
628
759
|
await runFiles(files, config);
|
|
629
760
|
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.2af36ddf.mjs';
|
|
2
|
+
import { g as getWorkerState, R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-mock-date.0d86eaa5.mjs';
|
|
3
|
+
import { p as parseStacktrace } from './chunk-utils-source-map.70ee97e1.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.74ebe3d5.mjs';
|
|
2
2
|
import { normalizePath } from 'vite';
|
|
3
|
-
import {
|
|
3
|
+
import { g as getWorkerState, G as isWindows, H as mergeSlashes, s as slash, l as getType, I as getAllMockableProperties } from './chunk-mock-date.0d86eaa5.mjs';
|
|
4
4
|
import { existsSync, readdirSync } from 'fs';
|
|
5
|
-
import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.
|
|
6
|
-
import { d as dirname, j as join, b as basename, a as resolve, c as distDir } from './chunk-constants.
|
|
7
|
-
import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
|
|
5
|
+
import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.68573626.mjs';
|
|
6
|
+
import { d as dirname, j as join, b as basename, a as resolve, c as distDir } from './chunk-constants.6196597b.mjs';
|
|
8
7
|
|
|
9
8
|
class RefTracker {
|
|
10
9
|
constructor() {
|
|
@@ -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.0d86eaa5.mjs';
|
|
3
2
|
import { w as withSafeTimers } from './chunk-utils-timers.b48455ed.mjs';
|
|
4
3
|
|
|
5
4
|
const rpc = () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { s as slash,
|
|
2
|
-
import { p as picocolors } from './chunk-constants.
|
|
1
|
+
import { s as slash, j as notNullish } from './chunk-mock-date.0d86eaa5.mjs';
|
|
2
|
+
import { p as picocolors } from './chunk-constants.6196597b.mjs';
|
|
3
3
|
|
|
4
4
|
var build = {};
|
|
5
5
|
|
|
@@ -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 };
|