vitest 0.0.113 → 0.0.117
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 +61 -33
- package/dist/cli.js +1112 -35
- package/dist/{constants-900abe4a.js → constants-080f26e8.js} +2 -2
- package/dist/{diff-9c43ab50.js → diff-80c47cfa.js} +1 -2
- package/dist/entry.js +68 -26
- package/dist/{global-75208c77.js → global-d95ee155.js} +8 -9
- package/dist/{index-09437c50.js → index-2b1f526f.js} +2 -2
- package/dist/{index-c3f2f9fe.js → index-33d800eb.js} +182 -111
- package/dist/{index-61c8686f.js → index-648e7ab2.js} +62 -62
- package/dist/index-6e709f57.js +781 -0
- package/dist/index-bf29f0e6.js +386 -0
- package/dist/{index-9f4b9905.js → index-ce49e384.js} +33 -800
- package/dist/index-e909c175.js +62 -0
- package/dist/index.d.ts +97 -35
- package/dist/index.js +6 -4
- package/dist/{jest-mock-a57b745c.js → jest-mock-4a754991.js} +1 -12
- package/dist/node.d.ts +87 -16
- package/dist/node.js +10 -9
- package/dist/rpc-8c7cc374.js +5 -0
- package/dist/setup-95b119ff.js +4318 -0
- package/dist/utils.js +2 -2
- package/dist/{vi-51946984.js → vi-39f06eb7.js} +30 -6
- package/dist/worker.js +25 -40
- package/package.json +7 -6
- package/vitest.mjs +1 -20
- package/dist/index-041e627e.js +0 -168
- package/dist/index-1488b423.js +0 -186
- package/dist/middleware-0ebc5238.js +0 -79
- package/dist/rpc-7de86f29.js +0 -10
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { fileURLToPath } from 'url';
|
|
2
|
-
import {
|
|
2
|
+
import { k as resolve } from './index-bf29f0e6.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}"];
|
|
6
|
-
const defaultExclude = ["**/node_modules/**", "**/dist/**", "**/.{idea,git,cache,output,temp}/**"];
|
|
6
|
+
const defaultExclude = ["**/node_modules/**", "**/dist/**", "**/cypress/**", "**/.{idea,git,cache,output,temp}/**"];
|
|
7
7
|
const defaultPort = 51204;
|
|
8
8
|
const API_PATH = "/__vitest_api__";
|
|
9
9
|
const configFiles = [
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { existsSync, promises } from 'fs';
|
|
2
|
-
import { r as relative } from './index-
|
|
3
|
-
import { d as notNullish, c } from './index-041e627e.js';
|
|
2
|
+
import { o as notNullish, c, r as relative } from './index-bf29f0e6.js';
|
|
4
3
|
|
|
5
4
|
function Diff() {}
|
|
6
5
|
Diff.prototype = {
|
package/dist/entry.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import fs, { promises } from 'fs';
|
|
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-
|
|
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-39f06eb7.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 {
|
|
11
|
-
import { l as getOriginalPos, m as posToNumber, n as parseStack, u as unifiedDiff } from './diff-9c43ab50.js';
|
|
8
|
+
import { q as index, s as slash, u as getNames, c as c$1, t as toArray, r as relative, v as interpretOnlyMode, w as partitionSuiteChildren, x as hasTests, h as hasFailed } from './index-bf29f0e6.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-80c47cfa.js';
|
|
12
11
|
import { performance } from 'perf_hooks';
|
|
13
|
-
import {
|
|
12
|
+
import { createHash } from 'crypto';
|
|
14
13
|
import { format as format$1 } from 'util';
|
|
15
|
-
import '
|
|
16
|
-
import 'tty';
|
|
14
|
+
import './jest-mock-4a754991.js';
|
|
17
15
|
import 'tinyspy';
|
|
16
|
+
import 'url';
|
|
17
|
+
import 'tty';
|
|
18
|
+
import 'path';
|
|
18
19
|
|
|
19
20
|
var node = {
|
|
20
21
|
name: "node",
|
|
@@ -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);
|
|
@@ -396,16 +397,19 @@ async function saveInlineSnapshots(snapshots) {
|
|
|
396
397
|
const index = posToNumber(code, pos);
|
|
397
398
|
replaceInlineSnap(code, s, index, snap.snapshot);
|
|
398
399
|
}
|
|
399
|
-
|
|
400
|
+
const transformed = s.toString();
|
|
401
|
+
if (transformed !== code)
|
|
402
|
+
await promises.writeFile(file, transformed, "utf-8");
|
|
400
403
|
}));
|
|
401
404
|
}
|
|
402
405
|
const startRegex = /toMatchInlineSnapshot\s*\(\s*(['"`\)])/m;
|
|
403
|
-
function replaceInlineSnap(code, s, index, newSnap) {
|
|
406
|
+
function replaceInlineSnap(code, s, index, newSnap, indent = "") {
|
|
404
407
|
const startMatch = startRegex.exec(code.slice(index));
|
|
405
408
|
if (!startMatch)
|
|
406
409
|
return false;
|
|
407
|
-
newSnap = newSnap.replace(/\\/g, "\\\\");
|
|
408
|
-
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()}\``;
|
|
409
413
|
const quote = startMatch[1];
|
|
410
414
|
const startIndex = index + startMatch.index + startMatch[0].length;
|
|
411
415
|
if (quote === ")") {
|
|
@@ -3101,7 +3105,7 @@ class SnapshotClient {
|
|
|
3101
3105
|
if (!this.testFile || !this.snapshotState)
|
|
3102
3106
|
return;
|
|
3103
3107
|
const result = await packSnapshotState(this.testFile, this.snapshotState);
|
|
3104
|
-
await rpc(
|
|
3108
|
+
await rpc().snapshotSaved(result);
|
|
3105
3109
|
this.testFile = "";
|
|
3106
3110
|
this.snapshotState = void 0;
|
|
3107
3111
|
}
|
|
@@ -3528,13 +3532,13 @@ async function setupGlobalEnv(config) {
|
|
|
3528
3532
|
setupConsoleLogSpy();
|
|
3529
3533
|
await setupChai();
|
|
3530
3534
|
if (config.global)
|
|
3531
|
-
(await import('./global-
|
|
3535
|
+
(await import('./global-d95ee155.js')).registerApiGlobally();
|
|
3532
3536
|
}
|
|
3533
3537
|
function setupConsoleLogSpy() {
|
|
3534
3538
|
const stdout = new Writable({
|
|
3535
3539
|
write(data, encoding, callback) {
|
|
3536
3540
|
var _a;
|
|
3537
|
-
|
|
3541
|
+
rpc().onUserLog({
|
|
3538
3542
|
type: "stdout",
|
|
3539
3543
|
content: String(data),
|
|
3540
3544
|
taskId: (_a = process.__vitest_worker__.current) == null ? void 0 : _a.id
|
|
@@ -3545,7 +3549,7 @@ function setupConsoleLogSpy() {
|
|
|
3545
3549
|
const stderr = new Writable({
|
|
3546
3550
|
write(data, encoding, callback) {
|
|
3547
3551
|
var _a;
|
|
3548
|
-
|
|
3552
|
+
rpc().onUserLog({
|
|
3549
3553
|
type: "stderr",
|
|
3550
3554
|
content: String(data),
|
|
3551
3555
|
taskId: (_a = process.__vitest_worker__.current) == null ? void 0 : _a.id
|
|
@@ -3576,22 +3580,31 @@ async function runSetupFiles(config) {
|
|
|
3576
3580
|
}));
|
|
3577
3581
|
}
|
|
3578
3582
|
|
|
3579
|
-
function serializeError(val) {
|
|
3583
|
+
function serializeError(val, seen = /* @__PURE__ */ new WeakSet()) {
|
|
3580
3584
|
if (!val || typeof val === "string")
|
|
3581
3585
|
return val;
|
|
3582
3586
|
if (typeof val === "function")
|
|
3583
3587
|
return `Function<${val.name}>`;
|
|
3584
3588
|
if (typeof val !== "object")
|
|
3585
3589
|
return val;
|
|
3586
|
-
if (val instanceof Promise || "then" in val)
|
|
3590
|
+
if (val instanceof Promise || "then" in val || val.constructor && val.constructor.prototype === "AsyncFunction")
|
|
3587
3591
|
return "Promise";
|
|
3588
3592
|
if (typeof Element !== "undefined" && val instanceof Element)
|
|
3589
3593
|
return val.tagName;
|
|
3590
3594
|
if (typeof val.asymmetricMatch === "function")
|
|
3591
3595
|
return `${val.toString()} ${format$1(val.sample)}`;
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
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
|
+
}
|
|
3595
3608
|
return val;
|
|
3596
3609
|
}
|
|
3597
3610
|
function processError(err) {
|
|
@@ -3608,12 +3621,16 @@ function processError(err) {
|
|
|
3608
3621
|
return serializeError(err);
|
|
3609
3622
|
}
|
|
3610
3623
|
|
|
3624
|
+
function hash(str, length = 10) {
|
|
3625
|
+
return createHash("md5").update(str).digest("hex").slice(0, length);
|
|
3626
|
+
}
|
|
3611
3627
|
async function collectTests(paths, config) {
|
|
3612
3628
|
const files = [];
|
|
3613
3629
|
for (const filepath of paths) {
|
|
3630
|
+
const path = relative(config.root, filepath);
|
|
3614
3631
|
const file = {
|
|
3615
|
-
id:
|
|
3616
|
-
name:
|
|
3632
|
+
id: hash(path),
|
|
3633
|
+
name: path,
|
|
3617
3634
|
type: "suite",
|
|
3618
3635
|
mode: "run",
|
|
3619
3636
|
computeMode: "serial",
|
|
@@ -3645,12 +3662,20 @@ async function collectTests(paths, config) {
|
|
|
3645
3662
|
};
|
|
3646
3663
|
process.stdout.write("\0");
|
|
3647
3664
|
}
|
|
3665
|
+
calculateHash(file);
|
|
3648
3666
|
files.push(file);
|
|
3649
3667
|
}
|
|
3650
3668
|
const tasks = files.reduce((tasks2, file) => tasks2.concat(file.tasks), []);
|
|
3651
3669
|
interpretOnlyMode(tasks);
|
|
3652
3670
|
return files;
|
|
3653
3671
|
}
|
|
3672
|
+
function calculateHash(parent) {
|
|
3673
|
+
parent.tasks.forEach((t, idx) => {
|
|
3674
|
+
t.id = `${parent.id}_${idx}`;
|
|
3675
|
+
if (t.type === "suite")
|
|
3676
|
+
calculateHash(t);
|
|
3677
|
+
});
|
|
3678
|
+
}
|
|
3654
3679
|
|
|
3655
3680
|
async function callSuiteHook(suite, name, args) {
|
|
3656
3681
|
if (name === "beforeEach" && suite.suite)
|
|
@@ -3659,8 +3684,24 @@ async function callSuiteHook(suite, name, args) {
|
|
|
3659
3684
|
if (name === "afterEach" && suite.suite)
|
|
3660
3685
|
await callSuiteHook(suite.suite, name, args);
|
|
3661
3686
|
}
|
|
3687
|
+
const packs = [];
|
|
3688
|
+
let updateTimer;
|
|
3689
|
+
let previousUpdate;
|
|
3662
3690
|
function updateTask(task) {
|
|
3663
|
-
|
|
3691
|
+
packs.push([task.id, task.result]);
|
|
3692
|
+
clearTimeout(updateTimer);
|
|
3693
|
+
updateTimer = setTimeout(() => {
|
|
3694
|
+
previousUpdate = sendTasksUpdate();
|
|
3695
|
+
}, 10);
|
|
3696
|
+
}
|
|
3697
|
+
async function sendTasksUpdate() {
|
|
3698
|
+
clearTimeout(updateTimer);
|
|
3699
|
+
await previousUpdate;
|
|
3700
|
+
if (packs.length) {
|
|
3701
|
+
const p = rpc().onTaskUpdate(packs);
|
|
3702
|
+
packs.length = 0;
|
|
3703
|
+
return p;
|
|
3704
|
+
}
|
|
3664
3705
|
}
|
|
3665
3706
|
async function runTest(test) {
|
|
3666
3707
|
if (test.mode !== "run")
|
|
@@ -3759,9 +3800,10 @@ async function runSuites(suites) {
|
|
|
3759
3800
|
}
|
|
3760
3801
|
async function startTests(paths, config) {
|
|
3761
3802
|
const files = await collectTests(paths, config);
|
|
3762
|
-
|
|
3803
|
+
rpc().onCollected(files);
|
|
3763
3804
|
await runSuites(files);
|
|
3764
3805
|
await getSnapshotClient().saveSnap();
|
|
3806
|
+
await sendTasksUpdate();
|
|
3765
3807
|
}
|
|
3766
3808
|
function clearModuleMocks() {
|
|
3767
3809
|
const { clearMocks, mockReset, restoreMocks } = process.__vitest_worker__.config;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { g as globalApis } from './constants-
|
|
2
|
-
import { i as index } from './index-
|
|
1
|
+
import { g as globalApis } from './constants-080f26e8.js';
|
|
2
|
+
import { i as index } from './index-2b1f526f.js';
|
|
3
3
|
import 'url';
|
|
4
|
-
import './index-
|
|
5
|
-
import 'path';
|
|
6
|
-
import './vi-51946984.js';
|
|
7
|
-
import './jest-mock-a57b745c.js';
|
|
8
|
-
import 'chai';
|
|
9
|
-
import 'tinyspy';
|
|
10
|
-
import './index-041e627e.js';
|
|
4
|
+
import './index-bf29f0e6.js';
|
|
11
5
|
import 'tty';
|
|
12
6
|
import 'local-pkg';
|
|
7
|
+
import 'path';
|
|
8
|
+
import './vi-39f06eb7.js';
|
|
13
9
|
import './_commonjsHelpers-c9e3b764.js';
|
|
10
|
+
import './jest-mock-4a754991.js';
|
|
11
|
+
import 'chai';
|
|
12
|
+
import 'tinyspy';
|
|
14
13
|
|
|
15
14
|
function registerApiGlobally() {
|
|
16
15
|
globalApis.forEach((api) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, b as getState, s as setState, c as suite, t as test, d as describe, i as it, v as vitest, e as vi } from './vi-
|
|
1
|
+
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, b as getState, s as setState, c as suite, t as test, d as describe, i as it, v as vitest, e as vi } from './vi-39f06eb7.js';
|
|
2
2
|
import chai, { assert, should } from 'chai';
|
|
3
|
-
import { s as spies, a as spyOn, f as fn } from './jest-mock-
|
|
3
|
+
import { s as spies, a as spyOn, f as fn } from './jest-mock-4a754991.js';
|
|
4
4
|
|
|
5
5
|
const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
6
6
|
const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|