vitest 0.0.114 → 0.0.118
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 +32 -33
- package/dist/cli.js +1111 -34
- package/dist/{constants-9c7f06df.js → constants-56bfb5ab.js} +1 -1
- package/dist/{diff-3cfdad26.js → diff-d87307c6.js} +1 -1
- package/dist/entry.js +85 -22
- package/dist/{global-12653c72.js → global-fc93e939.js} +4 -4
- package/dist/{index-36694964.js → index-62869b66.js} +182 -144
- package/dist/{index-61c8686f.js → index-648e7ab2.js} +62 -62
- package/dist/index-6e709f57.js +781 -0
- package/dist/{index-ea5153a0.js → index-80671389.js} +29 -21
- package/dist/{index-ebf35a56.js → index-be3cc31e.js} +1 -1
- package/dist/{index-9f4b9905.js → index-ce49e384.js} +33 -800
- package/dist/{index-7889832e.js → index-e909c175.js} +25 -16
- package/dist/index.d.ts +99 -23
- package/dist/index.js +3 -3
- package/dist/node.d.ts +86 -19
- package/dist/node.js +8 -7
- package/dist/rpc-8c7cc374.js +5 -0
- package/dist/setup-b87afd31.js +4318 -0
- package/dist/utils.js +1 -1
- package/dist/{vi-67e478ef.js → vi-85b65e90.js} +30 -17
- package/dist/worker.js +8 -7
- package/package.json +7 -7
- package/vitest.mjs +1 -20
- package/dist/middleware-85ff8fbf.js +0 -81
- package/dist/rpc-85fe6402.js +0 -10
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fileURLToPath } from 'url';
|
|
2
|
-
import {
|
|
2
|
+
import { k as resolve } from './index-80671389.js';
|
|
3
3
|
|
|
4
4
|
const distDir = resolve(fileURLToPath(import.meta.url), "../../dist");
|
|
5
5
|
const defaultInclude = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
|
package/dist/entry.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import fs, { promises } from 'fs';
|
|
2
|
-
import { f as equals, h as iterableEquality, j as subsetEquality, k as isA, J as JestChaiExpect,
|
|
2
|
+
import { f as equals, h as iterableEquality, j as subsetEquality, k as isA, J as JestChaiExpect, l as clearContext, m as defaultSuite, n as setHooks, o as getHooks, p as context, s as setState, q as getFn, b as getState, e as vi } from './vi-85b65e90.js';
|
|
3
3
|
import { Console } from 'console';
|
|
4
4
|
import { Writable } from 'stream';
|
|
5
5
|
import { importModule } from 'local-pkg';
|
|
6
6
|
import chai$1, { expect, util } from 'chai';
|
|
7
7
|
import { a as commonjsRequire, c as commonjsGlobal } from './_commonjsHelpers-c9e3b764.js';
|
|
8
|
-
import {
|
|
9
|
-
import { r as rpc
|
|
10
|
-
import { l as getOriginalPos, m as posToNumber, n as parseStack, u as unifiedDiff } from './diff-
|
|
8
|
+
import { q as index, s as slash, u as getNames, c as c$1, t as toArray, r as relative, v as partitionSuiteChildren, w as hasTests, h as hasFailed } from './index-80671389.js';
|
|
9
|
+
import { r as rpc } from './rpc-8c7cc374.js';
|
|
10
|
+
import { l as getOriginalPos, m as posToNumber, n as parseStack, u as unifiedDiff } from './diff-d87307c6.js';
|
|
11
11
|
import { performance } from 'perf_hooks';
|
|
12
|
+
import { createHash } from 'crypto';
|
|
12
13
|
import { format as format$1 } from 'util';
|
|
13
14
|
import './jest-mock-4a754991.js';
|
|
14
15
|
import 'tinyspy';
|
|
@@ -387,7 +388,7 @@ async function saveInlineSnapshots(snapshots) {
|
|
|
387
388
|
const MagicString = (await import('./magic-string.es-94000aea.js')).default;
|
|
388
389
|
const files = new Set(snapshots.map((i) => i.file));
|
|
389
390
|
await Promise.all(Array.from(files).map(async (file) => {
|
|
390
|
-
const map = await rpc(
|
|
391
|
+
const map = await rpc().getSourceMap(file);
|
|
391
392
|
const snaps = snapshots.filter((i) => i.file === file);
|
|
392
393
|
const code = await promises.readFile(file, "utf8");
|
|
393
394
|
const s = new MagicString(code);
|
|
@@ -402,12 +403,13 @@ async function saveInlineSnapshots(snapshots) {
|
|
|
402
403
|
}));
|
|
403
404
|
}
|
|
404
405
|
const startRegex = /toMatchInlineSnapshot\s*\(\s*(['"`\)])/m;
|
|
405
|
-
function replaceInlineSnap(code, s, index, newSnap) {
|
|
406
|
+
function replaceInlineSnap(code, s, index, newSnap, indent = "") {
|
|
406
407
|
const startMatch = startRegex.exec(code.slice(index));
|
|
407
408
|
if (!startMatch)
|
|
408
409
|
return false;
|
|
409
|
-
newSnap = newSnap.replace(/\\/g, "\\\\");
|
|
410
|
-
const
|
|
410
|
+
newSnap = newSnap.replace(/\\/g, "\\\\").split("\n").map((i) => (indent + i).trimEnd()).join("\n");
|
|
411
|
+
const isOneline = !newSnap.includes("\n");
|
|
412
|
+
const snapString = isOneline ? `'${newSnap.replace(/'/g, "\\'").trim()}'` : `\`${newSnap.replace(/`/g, "\\`").trimEnd()}\``;
|
|
411
413
|
const quote = startMatch[1];
|
|
412
414
|
const startIndex = index + startMatch.index + startMatch[0].length;
|
|
413
415
|
if (quote === ")") {
|
|
@@ -3103,7 +3105,7 @@ class SnapshotClient {
|
|
|
3103
3105
|
if (!this.testFile || !this.snapshotState)
|
|
3104
3106
|
return;
|
|
3105
3107
|
const result = await packSnapshotState(this.testFile, this.snapshotState);
|
|
3106
|
-
await rpc(
|
|
3108
|
+
await rpc().snapshotSaved(result);
|
|
3107
3109
|
this.testFile = "";
|
|
3108
3110
|
this.snapshotState = void 0;
|
|
3109
3111
|
}
|
|
@@ -3530,13 +3532,13 @@ async function setupGlobalEnv(config) {
|
|
|
3530
3532
|
setupConsoleLogSpy();
|
|
3531
3533
|
await setupChai();
|
|
3532
3534
|
if (config.global)
|
|
3533
|
-
(await import('./global-
|
|
3535
|
+
(await import('./global-fc93e939.js')).registerApiGlobally();
|
|
3534
3536
|
}
|
|
3535
3537
|
function setupConsoleLogSpy() {
|
|
3536
3538
|
const stdout = new Writable({
|
|
3537
3539
|
write(data, encoding, callback) {
|
|
3538
3540
|
var _a;
|
|
3539
|
-
|
|
3541
|
+
rpc().onUserLog({
|
|
3540
3542
|
type: "stdout",
|
|
3541
3543
|
content: String(data),
|
|
3542
3544
|
taskId: (_a = process.__vitest_worker__.current) == null ? void 0 : _a.id
|
|
@@ -3547,7 +3549,7 @@ function setupConsoleLogSpy() {
|
|
|
3547
3549
|
const stderr = new Writable({
|
|
3548
3550
|
write(data, encoding, callback) {
|
|
3549
3551
|
var _a;
|
|
3550
|
-
|
|
3552
|
+
rpc().onUserLog({
|
|
3551
3553
|
type: "stderr",
|
|
3552
3554
|
content: String(data),
|
|
3553
3555
|
taskId: (_a = process.__vitest_worker__.current) == null ? void 0 : _a.id
|
|
@@ -3578,7 +3580,7 @@ async function runSetupFiles(config) {
|
|
|
3578
3580
|
}));
|
|
3579
3581
|
}
|
|
3580
3582
|
|
|
3581
|
-
function serializeError(val) {
|
|
3583
|
+
function serializeError(val, seen = /* @__PURE__ */ new WeakSet()) {
|
|
3582
3584
|
if (!val || typeof val === "string")
|
|
3583
3585
|
return val;
|
|
3584
3586
|
if (typeof val === "function")
|
|
@@ -3591,9 +3593,18 @@ function serializeError(val) {
|
|
|
3591
3593
|
return val.tagName;
|
|
3592
3594
|
if (typeof val.asymmetricMatch === "function")
|
|
3593
3595
|
return `${val.toString()} ${format$1(val.sample)}`;
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3596
|
+
if (seen.has(val))
|
|
3597
|
+
return val;
|
|
3598
|
+
seen.add(val);
|
|
3599
|
+
if (Array.isArray(val)) {
|
|
3600
|
+
val = val.map((e) => {
|
|
3601
|
+
return serializeError(e, seen);
|
|
3602
|
+
});
|
|
3603
|
+
} else {
|
|
3604
|
+
Object.keys(val).forEach((key) => {
|
|
3605
|
+
val[key] = serializeError(val[key], seen);
|
|
3606
|
+
});
|
|
3607
|
+
}
|
|
3597
3608
|
return val;
|
|
3598
3609
|
}
|
|
3599
3610
|
function processError(err) {
|
|
@@ -3610,12 +3621,16 @@ function processError(err) {
|
|
|
3610
3621
|
return serializeError(err);
|
|
3611
3622
|
}
|
|
3612
3623
|
|
|
3624
|
+
function hash(str, length = 10) {
|
|
3625
|
+
return createHash("md5").update(str).digest("hex").slice(0, length);
|
|
3626
|
+
}
|
|
3613
3627
|
async function collectTests(paths, config) {
|
|
3614
3628
|
const files = [];
|
|
3615
3629
|
for (const filepath of paths) {
|
|
3630
|
+
const path = relative(config.root, filepath);
|
|
3616
3631
|
const file = {
|
|
3617
|
-
id:
|
|
3618
|
-
name:
|
|
3632
|
+
id: hash(path),
|
|
3633
|
+
name: path,
|
|
3619
3634
|
type: "suite",
|
|
3620
3635
|
mode: "run",
|
|
3621
3636
|
computeMode: "serial",
|
|
@@ -3647,12 +3662,43 @@ async function collectTests(paths, config) {
|
|
|
3647
3662
|
};
|
|
3648
3663
|
process.stdout.write("\0");
|
|
3649
3664
|
}
|
|
3665
|
+
calculateHash(file);
|
|
3650
3666
|
files.push(file);
|
|
3651
3667
|
}
|
|
3652
|
-
|
|
3653
|
-
interpretOnlyMode(tasks);
|
|
3668
|
+
interpretTaskModes(files, config.testNamePattern);
|
|
3654
3669
|
return files;
|
|
3655
3670
|
}
|
|
3671
|
+
function interpretTaskModes(tasks, namePattern) {
|
|
3672
|
+
if (tasks.some((t) => t.mode === "only")) {
|
|
3673
|
+
tasks.forEach((t) => {
|
|
3674
|
+
if (t.mode === "run")
|
|
3675
|
+
t.mode = "skip";
|
|
3676
|
+
else if (t.mode === "only")
|
|
3677
|
+
t.mode = "run";
|
|
3678
|
+
});
|
|
3679
|
+
}
|
|
3680
|
+
tasks.forEach((t) => {
|
|
3681
|
+
if (t.type === "test") {
|
|
3682
|
+
if (namePattern && !t.name.match(namePattern))
|
|
3683
|
+
t.mode = "skip";
|
|
3684
|
+
} else if (t.type === "suite") {
|
|
3685
|
+
if (t.mode === "skip")
|
|
3686
|
+
t.tasks.forEach((c) => c.mode === "run" && (c.mode = "skip"));
|
|
3687
|
+
interpretTaskModes(t.tasks, namePattern);
|
|
3688
|
+
if (t.mode === "run") {
|
|
3689
|
+
if (t.tasks.every((i) => i.mode !== "run"))
|
|
3690
|
+
t.mode = "skip";
|
|
3691
|
+
}
|
|
3692
|
+
}
|
|
3693
|
+
});
|
|
3694
|
+
}
|
|
3695
|
+
function calculateHash(parent) {
|
|
3696
|
+
parent.tasks.forEach((t, idx) => {
|
|
3697
|
+
t.id = `${parent.id}_${idx}`;
|
|
3698
|
+
if (t.type === "suite")
|
|
3699
|
+
calculateHash(t);
|
|
3700
|
+
});
|
|
3701
|
+
}
|
|
3656
3702
|
|
|
3657
3703
|
async function callSuiteHook(suite, name, args) {
|
|
3658
3704
|
if (name === "beforeEach" && suite.suite)
|
|
@@ -3661,8 +3707,24 @@ async function callSuiteHook(suite, name, args) {
|
|
|
3661
3707
|
if (name === "afterEach" && suite.suite)
|
|
3662
3708
|
await callSuiteHook(suite.suite, name, args);
|
|
3663
3709
|
}
|
|
3710
|
+
const packs = [];
|
|
3711
|
+
let updateTimer;
|
|
3712
|
+
let previousUpdate;
|
|
3664
3713
|
function updateTask(task) {
|
|
3665
|
-
|
|
3714
|
+
packs.push([task.id, task.result]);
|
|
3715
|
+
clearTimeout(updateTimer);
|
|
3716
|
+
updateTimer = setTimeout(() => {
|
|
3717
|
+
previousUpdate = sendTasksUpdate();
|
|
3718
|
+
}, 10);
|
|
3719
|
+
}
|
|
3720
|
+
async function sendTasksUpdate() {
|
|
3721
|
+
clearTimeout(updateTimer);
|
|
3722
|
+
await previousUpdate;
|
|
3723
|
+
if (packs.length) {
|
|
3724
|
+
const p = rpc().onTaskUpdate(packs);
|
|
3725
|
+
packs.length = 0;
|
|
3726
|
+
return p;
|
|
3727
|
+
}
|
|
3666
3728
|
}
|
|
3667
3729
|
async function runTest(test) {
|
|
3668
3730
|
if (test.mode !== "run")
|
|
@@ -3761,9 +3823,10 @@ async function runSuites(suites) {
|
|
|
3761
3823
|
}
|
|
3762
3824
|
async function startTests(paths, config) {
|
|
3763
3825
|
const files = await collectTests(paths, config);
|
|
3764
|
-
|
|
3826
|
+
rpc().onCollected(files);
|
|
3765
3827
|
await runSuites(files);
|
|
3766
3828
|
await getSnapshotClient().saveSnap();
|
|
3829
|
+
await sendTasksUpdate();
|
|
3767
3830
|
}
|
|
3768
3831
|
function clearModuleMocks() {
|
|
3769
3832
|
const { clearMocks, mockReset, restoreMocks } = process.__vitest_worker__.config;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { g as globalApis } from './constants-
|
|
2
|
-
import { i as index } from './index-
|
|
1
|
+
import { g as globalApis } from './constants-56bfb5ab.js';
|
|
2
|
+
import { i as index } from './index-be3cc31e.js';
|
|
3
3
|
import 'url';
|
|
4
|
-
import './index-
|
|
4
|
+
import './index-80671389.js';
|
|
5
5
|
import 'tty';
|
|
6
6
|
import 'local-pkg';
|
|
7
7
|
import 'path';
|
|
8
|
-
import './vi-
|
|
8
|
+
import './vi-85b65e90.js';
|
|
9
9
|
import './_commonjsHelpers-c9e3b764.js';
|
|
10
10
|
import './jest-mock-4a754991.js';
|
|
11
11
|
import 'chai';
|