vitest 4.0.17 → 4.1.0-beta.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 +36 -0
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +2 -2
- package/dist/chunks/acorn.B2iPLyUM.js +5958 -0
- package/dist/chunks/{base.XJJQZiKB.js → base.DiopZV8F.js} +49 -14
- package/dist/chunks/{benchmark.B3N2zMcH.js → benchmark.BoqSLF53.js} +1 -1
- package/dist/chunks/{browser.d.ChKACdzH.d.ts → browser.d.BE4kbYok.d.ts} +4 -1
- package/dist/chunks/{cac.jRCLJDDc.js → cac.C4jjt2RX.js} +816 -14
- package/dist/chunks/{cli-api.Cx2DW4Bc.js → cli-api.ChbI1JU9.js} +412 -166
- package/dist/chunks/{config.d.Cy95HiCx.d.ts → config.d.Cr1Ep39N.d.ts} +13 -11
- package/dist/chunks/{console.Cf-YriPC.js → console.CNlG1KsP.js} +3 -2
- package/dist/chunks/{constants.D_Q9UYh-.js → constants.B63TT-Bl.js} +1 -1
- package/dist/chunks/coverage.tyqbzn4W.js +1001 -0
- package/dist/chunks/{creator.DAmOKTvJ.js → creator.yyCHuw5R.js} +33 -2
- package/dist/chunks/{global.d.B15mdLcR.d.ts → global.d.JeWMqlOm.d.ts} +1 -1
- package/dist/chunks/{globals.DOayXfHP.js → globals.C6Ecf1TO.js} +11 -10
- package/dist/chunks/{index.M8mOzt4Y.js → index.B-iBE_Gx.js} +21 -5
- package/dist/chunks/{coverage.AVPTjMgw.js → index.BCY_7LL2.js} +5 -959
- package/dist/chunks/{index.6Qv1eEA6.js → index.CAN630q3.js} +20 -8
- package/dist/chunks/{index.C5r1PdPD.js → index.CFulQRmC.js} +1 -1
- package/dist/chunks/{index.Z5E_ObnR.js → index.CouFDptX.js} +4 -2
- package/dist/chunks/{init-forks.BC6ZwHQN.js → init-forks.BnCXPazU.js} +1 -1
- package/dist/chunks/{init-threads.CxSxLC0N.js → init-threads.Cyh2PqXi.js} +1 -1
- package/dist/chunks/{init.C9kljSTm.js → init.B95Mm0Iz.js} +65 -12
- package/dist/chunks/native.mV0-490A.js +148 -0
- package/dist/chunks/nativeModuleMocker.D_q5sFv6.js +206 -0
- package/dist/chunks/nativeModuleRunner.BIakptoF.js +36 -0
- package/dist/chunks/{node.Ce0vMQM7.js → node.CrSEwhm4.js} +1 -1
- package/dist/chunks/{plugin.d.CtqpEehP.d.ts → plugin.d.C9o5bttz.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CWXNI2jG.d.ts → reporters.d.7faYdkxy.d.ts} +146 -49
- package/dist/chunks/rpc.DcRWTy5G.js +148 -0
- package/dist/chunks/{rpc.d.RH3apGEf.d.ts → rpc.d.CM7x9-sm.d.ts} +1 -0
- package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.cvFp-ao9.js} +2 -2
- package/dist/chunks/{startModuleRunner.DEj0jb3e.js → startVitestModuleRunner.BK-u7y4N.js} +182 -391
- package/dist/chunks/{vi.2VT5v0um.js → test.G82XYNFk.js} +505 -119
- package/dist/chunks/{utils.DvEY5TfP.js → utils.DT4VyRyl.js} +5 -1
- package/dist/chunks/{vm.CMjifoPa.js → vm.BdLtzhnj.js} +15 -11
- package/dist/chunks/{worker.d.Dyxm8DEL.d.ts → worker.d.CPzI2ZzJ.d.ts} +2 -2
- package/dist/cli.js +4 -3
- package/dist/config.d.ts +11 -11
- package/dist/config.js +1 -1
- package/dist/coverage.d.ts +10 -8
- package/dist/coverage.js +7 -4
- package/dist/environments.js +2 -0
- package/dist/index.d.ts +30 -23
- package/dist/index.js +9 -8
- package/dist/module-evaluator.d.ts +10 -1
- package/dist/module-evaluator.js +1 -5
- package/dist/node.d.ts +13 -12
- package/dist/node.js +27 -25
- package/dist/nodejs-worker-loader.js +41 -0
- package/dist/reporters.d.ts +8 -8
- package/dist/reporters.js +4 -2
- package/dist/runners.d.ts +24 -4
- package/dist/runners.js +6 -6
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.js +35 -0
- package/dist/snapshot.js +4 -2
- package/dist/suite.js +4 -2
- package/dist/worker.d.ts +8 -7
- package/dist/worker.js +25 -20
- package/dist/workers/forks.js +21 -16
- package/dist/workers/runVmTests.js +11 -13
- package/dist/workers/threads.js +21 -16
- package/dist/workers/vmForks.js +14 -11
- package/dist/workers/vmThreads.js +14 -11
- package/package.json +28 -29
- package/suppress-warnings.cjs +1 -0
- package/dist/chunks/date.Bq6ZW5rf.js +0 -73
- package/dist/chunks/rpc.BoxB0q7B.js +0 -76
- package/dist/chunks/test.B8ej_ZHS.js +0 -254
- package/dist/mocker.d.ts +0 -1
- package/dist/mocker.js +0 -1
- package/dist/module-runner.js +0 -17
|
@@ -1,37 +1,40 @@
|
|
|
1
|
-
import { w as workerInit } from '../chunks/init-threads.
|
|
2
|
-
import { r as runVmTests } from '../chunks/vm.
|
|
1
|
+
import { w as workerInit } from '../chunks/init-threads.Cyh2PqXi.js';
|
|
2
|
+
import { s as setupVmWorker, r as runVmTests } from '../chunks/vm.BdLtzhnj.js';
|
|
3
3
|
import 'node:worker_threads';
|
|
4
|
-
import '../chunks/init.
|
|
4
|
+
import '../chunks/init.B95Mm0Iz.js';
|
|
5
5
|
import 'node:fs';
|
|
6
6
|
import 'node:module';
|
|
7
7
|
import 'node:url';
|
|
8
8
|
import 'pathe';
|
|
9
9
|
import 'vite/module-runner';
|
|
10
|
-
import '../chunks/
|
|
10
|
+
import '../chunks/startVitestModuleRunner.BK-u7y4N.js';
|
|
11
11
|
import '@vitest/utils/helpers';
|
|
12
12
|
import '../chunks/modules.BJuCwlRJ.js';
|
|
13
|
+
import '../chunks/utils.DT4VyRyl.js';
|
|
14
|
+
import '@vitest/utils/timers';
|
|
13
15
|
import '../path.js';
|
|
14
16
|
import 'node:path';
|
|
15
|
-
import '@vitest/utils/serialize';
|
|
16
17
|
import '../module-evaluator.js';
|
|
17
18
|
import 'node:vm';
|
|
18
19
|
import '../chunks/traces.CCmnQaNT.js';
|
|
19
20
|
import '@vitest/mocker';
|
|
21
|
+
import '@vitest/mocker/redirect';
|
|
20
22
|
import '../chunks/index.CyBMJtT7.js';
|
|
21
23
|
import 'node:console';
|
|
24
|
+
import '@vitest/utils/serialize';
|
|
22
25
|
import '@vitest/utils/error';
|
|
23
|
-
import '../chunks/rpc.
|
|
24
|
-
import '@vitest/utils/timers';
|
|
26
|
+
import '../chunks/rpc.DcRWTy5G.js';
|
|
25
27
|
import '../chunks/index.Chj8NDwU.js';
|
|
26
|
-
import '../chunks/utils.DvEY5TfP.js';
|
|
27
28
|
import '@vitest/utils/source-map';
|
|
28
29
|
import '../chunks/inspector.CvyFGlXm.js';
|
|
29
30
|
import '../chunks/evaluatedModules.Dg1zASAC.js';
|
|
30
|
-
import '../chunks/console.
|
|
31
|
+
import '../chunks/console.CNlG1KsP.js';
|
|
31
32
|
import 'node:stream';
|
|
32
33
|
import 'tinyrainbow';
|
|
33
|
-
import '../chunks/date.Bq6ZW5rf.js';
|
|
34
34
|
import '@vitest/utils/resolver';
|
|
35
35
|
import '@vitest/utils/constants';
|
|
36
36
|
|
|
37
|
-
workerInit({
|
|
37
|
+
workerInit({
|
|
38
|
+
runTests: runVmTests,
|
|
39
|
+
setup: setupVmWorker
|
|
40
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.1.0-beta.2",
|
|
5
5
|
"description": "Next generation testing framework powered by Vite",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"#module-evaluator": {
|
|
27
27
|
"types": "./dist/module-evaluator.d.ts",
|
|
28
28
|
"default": "./dist/module-evaluator.js"
|
|
29
|
-
}
|
|
29
|
+
},
|
|
30
|
+
"#nodejs-worker-loader": "./dist/nodejs-worker-loader.js"
|
|
30
31
|
},
|
|
31
32
|
"exports": {
|
|
32
33
|
".": {
|
|
@@ -68,10 +69,6 @@
|
|
|
68
69
|
"types": "./dist/browser.d.ts",
|
|
69
70
|
"default": "./dist/browser.js"
|
|
70
71
|
},
|
|
71
|
-
"./internal/module-runner": {
|
|
72
|
-
"types": "./dist/module-runner.d.ts",
|
|
73
|
-
"default": "./dist/module-runner.js"
|
|
74
|
-
},
|
|
75
72
|
"./runners": {
|
|
76
73
|
"types": "./dist/runners.d.ts",
|
|
77
74
|
"default": "./dist/runners.js"
|
|
@@ -101,9 +98,9 @@
|
|
|
101
98
|
"types": "./dist/snapshot.d.ts",
|
|
102
99
|
"default": "./dist/snapshot.js"
|
|
103
100
|
},
|
|
104
|
-
"./
|
|
105
|
-
"types": "./dist/
|
|
106
|
-
"default": "./dist/
|
|
101
|
+
"./runtime": {
|
|
102
|
+
"types": "./dist/runtime.d.ts",
|
|
103
|
+
"default": "./dist/runtime.js"
|
|
107
104
|
},
|
|
108
105
|
"./worker": {
|
|
109
106
|
"types": "./worker.d.ts",
|
|
@@ -134,10 +131,10 @@
|
|
|
134
131
|
"@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0",
|
|
135
132
|
"happy-dom": "*",
|
|
136
133
|
"jsdom": "*",
|
|
137
|
-
"@vitest/browser-playwright": "4.0.
|
|
138
|
-
"@vitest/browser-
|
|
139
|
-
"@vitest/
|
|
140
|
-
"@vitest/
|
|
134
|
+
"@vitest/browser-playwright": "4.1.0-beta.2",
|
|
135
|
+
"@vitest/browser-webdriverio": "4.1.0-beta.2",
|
|
136
|
+
"@vitest/ui": "4.1.0-beta.2",
|
|
137
|
+
"@vitest/browser-preview": "4.1.0-beta.2"
|
|
141
138
|
},
|
|
142
139
|
"peerDependenciesMeta": {
|
|
143
140
|
"@edge-runtime/vm": {
|
|
@@ -169,8 +166,8 @@
|
|
|
169
166
|
}
|
|
170
167
|
},
|
|
171
168
|
"dependencies": {
|
|
172
|
-
"es-module-lexer": "^
|
|
173
|
-
"expect-type": "^1.
|
|
169
|
+
"es-module-lexer": "^2.0.0",
|
|
170
|
+
"expect-type": "^1.3.0",
|
|
174
171
|
"magic-string": "^0.30.21",
|
|
175
172
|
"obug": "^2.1.1",
|
|
176
173
|
"pathe": "^2.0.3",
|
|
@@ -182,40 +179,42 @@
|
|
|
182
179
|
"tinyrainbow": "^3.0.3",
|
|
183
180
|
"vite": "^6.0.0 || ^7.0.0",
|
|
184
181
|
"why-is-node-running": "^2.3.0",
|
|
185
|
-
"@vitest/
|
|
186
|
-
"@vitest/
|
|
187
|
-
"@vitest/
|
|
188
|
-
"@vitest/
|
|
189
|
-
"@vitest/
|
|
190
|
-
"@vitest/
|
|
191
|
-
"@vitest/
|
|
182
|
+
"@vitest/mocker": "4.1.0-beta.2",
|
|
183
|
+
"@vitest/runner": "4.1.0-beta.2",
|
|
184
|
+
"@vitest/snapshot": "4.1.0-beta.2",
|
|
185
|
+
"@vitest/spy": "4.1.0-beta.2",
|
|
186
|
+
"@vitest/utils": "4.1.0-beta.2",
|
|
187
|
+
"@vitest/pretty-format": "4.1.0-beta.2",
|
|
188
|
+
"@vitest/expect": "4.1.0-beta.2"
|
|
192
189
|
},
|
|
193
190
|
"devDependencies": {
|
|
194
191
|
"@antfu/install-pkg": "^1.1.0",
|
|
192
|
+
"@bomb.sh/tab": "^0.0.9",
|
|
195
193
|
"@edge-runtime/vm": "^5.0.0",
|
|
196
194
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
197
195
|
"@opentelemetry/api": "^1.9.0",
|
|
198
|
-
"@sinonjs/fake-timers": "
|
|
196
|
+
"@sinonjs/fake-timers": "15.0.0",
|
|
199
197
|
"@types/estree": "^1.0.8",
|
|
200
198
|
"@types/istanbul-lib-coverage": "^2.0.6",
|
|
201
199
|
"@types/istanbul-reports": "^3.0.4",
|
|
202
200
|
"@types/jsdom": "^27.0.0",
|
|
203
|
-
"@types/node": "^24.10.
|
|
201
|
+
"@types/node": "^24.10.7",
|
|
204
202
|
"@types/picomatch": "^4.0.2",
|
|
205
203
|
"@types/prompts": "^2.4.9",
|
|
206
|
-
"@types/sinonjs__fake-timers": "^
|
|
204
|
+
"@types/sinonjs__fake-timers": "^15.0.0",
|
|
205
|
+
"acorn": "8.11.3",
|
|
207
206
|
"acorn-walk": "^8.3.4",
|
|
208
207
|
"birpc": "^4.0.0",
|
|
209
208
|
"cac": "^6.7.14",
|
|
210
209
|
"empathic": "^2.0.0",
|
|
211
|
-
"flatted": "
|
|
212
|
-
"happy-dom": "^20.0
|
|
213
|
-
"jsdom": "^27.
|
|
210
|
+
"flatted": "3.3.3",
|
|
211
|
+
"happy-dom": "^20.1.0",
|
|
212
|
+
"jsdom": "^27.4.0",
|
|
214
213
|
"local-pkg": "^1.1.2",
|
|
215
214
|
"mime": "^4.1.0",
|
|
216
215
|
"prompts": "^2.4.2",
|
|
217
216
|
"strip-literal": "^3.1.0",
|
|
218
|
-
"ws": "^8.
|
|
217
|
+
"ws": "^8.19.0"
|
|
219
218
|
},
|
|
220
219
|
"scripts": {
|
|
221
220
|
"build": "premove dist && rollup -c",
|
package/suppress-warnings.cjs
CHANGED
|
@@ -7,6 +7,7 @@ const ignoreWarnings = new Set([
|
|
|
7
7
|
'Custom ESM Loaders is an experimental feature and might change at any time',
|
|
8
8
|
'VM Modules is an experimental feature and might change at any time',
|
|
9
9
|
'VM Modules is an experimental feature. This feature could change at any time',
|
|
10
|
+
'stripTypeScriptTypes is an experimental feature and might change at any time',
|
|
10
11
|
])
|
|
11
12
|
|
|
12
13
|
const { emit } = process
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/* Ported from https://github.com/boblauer/MockDate/blob/master/src/mockdate.ts */
|
|
2
|
-
/*
|
|
3
|
-
The MIT License (MIT)
|
|
4
|
-
|
|
5
|
-
Copyright (c) 2014 Bob Lauer
|
|
6
|
-
|
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
in the Software without restriction, including without limitation the rights
|
|
10
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
furnished to do so, subject to the following conditions:
|
|
13
|
-
|
|
14
|
-
The above copyright notice and this permission notice shall be included in all
|
|
15
|
-
copies or substantial portions of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
const RealDate = Date;
|
|
26
|
-
let now = null;
|
|
27
|
-
class MockDate extends RealDate {
|
|
28
|
-
constructor(y, m, d, h, M, s, ms) {
|
|
29
|
-
super();
|
|
30
|
-
let date;
|
|
31
|
-
switch (arguments.length) {
|
|
32
|
-
case 0:
|
|
33
|
-
if (now !== null) date = new RealDate(now.valueOf());
|
|
34
|
-
else date = new RealDate();
|
|
35
|
-
break;
|
|
36
|
-
case 1:
|
|
37
|
-
date = new RealDate(y);
|
|
38
|
-
break;
|
|
39
|
-
default:
|
|
40
|
-
d = typeof d === "undefined" ? 1 : d;
|
|
41
|
-
h = h || 0;
|
|
42
|
-
M = M || 0;
|
|
43
|
-
s = s || 0;
|
|
44
|
-
ms = ms || 0;
|
|
45
|
-
date = new RealDate(y, m, d, h, M, s, ms);
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
Object.setPrototypeOf(date, MockDate.prototype);
|
|
49
|
-
return date;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
MockDate.UTC = RealDate.UTC;
|
|
53
|
-
MockDate.now = function() {
|
|
54
|
-
return new MockDate().valueOf();
|
|
55
|
-
};
|
|
56
|
-
MockDate.parse = function(dateString) {
|
|
57
|
-
return RealDate.parse(dateString);
|
|
58
|
-
};
|
|
59
|
-
MockDate.toString = function() {
|
|
60
|
-
return RealDate.toString();
|
|
61
|
-
};
|
|
62
|
-
function mockDate(date) {
|
|
63
|
-
const dateObj = new RealDate(date.valueOf());
|
|
64
|
-
if (Number.isNaN(dateObj.getTime())) throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
|
|
65
|
-
// @ts-expect-error global
|
|
66
|
-
globalThis.Date = MockDate;
|
|
67
|
-
now = dateObj.valueOf();
|
|
68
|
-
}
|
|
69
|
-
function resetDate() {
|
|
70
|
-
globalThis.Date = RealDate;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export { RealDate as R, mockDate as m, resetDate as r };
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { getSafeTimers } from '@vitest/utils/timers';
|
|
2
|
-
import { c as createBirpc } from './index.Chj8NDwU.js';
|
|
3
|
-
import { g as getWorkerState } from './utils.DvEY5TfP.js';
|
|
4
|
-
|
|
5
|
-
const { get } = Reflect;
|
|
6
|
-
function withSafeTimers(fn) {
|
|
7
|
-
const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers();
|
|
8
|
-
const currentSetTimeout = globalThis.setTimeout;
|
|
9
|
-
const currentClearTimeout = globalThis.clearTimeout;
|
|
10
|
-
const currentSetImmediate = globalThis.setImmediate;
|
|
11
|
-
const currentClearImmediate = globalThis.clearImmediate;
|
|
12
|
-
const currentNextTick = globalThis.process?.nextTick;
|
|
13
|
-
try {
|
|
14
|
-
globalThis.setTimeout = setTimeout;
|
|
15
|
-
globalThis.clearTimeout = clearTimeout;
|
|
16
|
-
if (setImmediate) globalThis.setImmediate = setImmediate;
|
|
17
|
-
if (clearImmediate) globalThis.clearImmediate = clearImmediate;
|
|
18
|
-
if (globalThis.process && nextTick) globalThis.process.nextTick = nextTick;
|
|
19
|
-
return fn();
|
|
20
|
-
} finally {
|
|
21
|
-
globalThis.setTimeout = currentSetTimeout;
|
|
22
|
-
globalThis.clearTimeout = currentClearTimeout;
|
|
23
|
-
globalThis.setImmediate = currentSetImmediate;
|
|
24
|
-
globalThis.clearImmediate = currentClearImmediate;
|
|
25
|
-
if (globalThis.process && nextTick) nextTick(() => {
|
|
26
|
-
globalThis.process.nextTick = currentNextTick;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const promises = /* @__PURE__ */ new Set();
|
|
31
|
-
async function rpcDone() {
|
|
32
|
-
if (!promises.size) return;
|
|
33
|
-
const awaitable = Array.from(promises);
|
|
34
|
-
return Promise.all(awaitable);
|
|
35
|
-
}
|
|
36
|
-
const onCancelCallbacks = [];
|
|
37
|
-
function onCancel(callback) {
|
|
38
|
-
onCancelCallbacks.push(callback);
|
|
39
|
-
}
|
|
40
|
-
function createRuntimeRpc(options) {
|
|
41
|
-
return createSafeRpc(createBirpc({ async onCancel(reason) {
|
|
42
|
-
await Promise.all(onCancelCallbacks.map((fn) => fn(reason)));
|
|
43
|
-
} }, {
|
|
44
|
-
eventNames: [
|
|
45
|
-
"onUserConsoleLog",
|
|
46
|
-
"onCollected",
|
|
47
|
-
"onCancel"
|
|
48
|
-
],
|
|
49
|
-
timeout: -1,
|
|
50
|
-
...options
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
function createSafeRpc(rpc) {
|
|
54
|
-
return new Proxy(rpc, { get(target, p, handler) {
|
|
55
|
-
// keep $rejectPendingCalls as sync function
|
|
56
|
-
if (p === "$rejectPendingCalls") return rpc.$rejectPendingCalls;
|
|
57
|
-
const sendCall = get(target, p, handler);
|
|
58
|
-
const safeSendCall = (...args) => withSafeTimers(async () => {
|
|
59
|
-
const result = sendCall(...args);
|
|
60
|
-
promises.add(result);
|
|
61
|
-
try {
|
|
62
|
-
return await result;
|
|
63
|
-
} finally {
|
|
64
|
-
promises.delete(result);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
safeSendCall.asEvent = sendCall.asEvent;
|
|
68
|
-
return safeSendCall;
|
|
69
|
-
} });
|
|
70
|
-
}
|
|
71
|
-
function rpc() {
|
|
72
|
-
const { rpc } = getWorkerState();
|
|
73
|
-
return rpc;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export { rpcDone as a, createRuntimeRpc as c, onCancel as o, rpc as r };
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import { updateTask } from '@vitest/runner';
|
|
2
|
-
import { createDefer } from '@vitest/utils/helpers';
|
|
3
|
-
import { getSafeTimers } from '@vitest/utils/timers';
|
|
4
|
-
import { a as getBenchOptions, g as getBenchFn } from './benchmark.B3N2zMcH.js';
|
|
5
|
-
import { g as getWorkerState } from './utils.DvEY5TfP.js';
|
|
6
|
-
import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
|
|
7
|
-
import { getTests, getNames, getTestName } from '@vitest/runner/utils';
|
|
8
|
-
import { processError } from '@vitest/utils/error';
|
|
9
|
-
import { normalize } from 'pathe';
|
|
10
|
-
import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.2VT5v0um.js';
|
|
11
|
-
import { r as rpc } from './rpc.BoxB0q7B.js';
|
|
12
|
-
|
|
13
|
-
function createBenchmarkResult(name) {
|
|
14
|
-
return {
|
|
15
|
-
name,
|
|
16
|
-
rank: 0,
|
|
17
|
-
rme: 0,
|
|
18
|
-
samples: []
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
const benchmarkTasks = /* @__PURE__ */ new WeakMap();
|
|
22
|
-
async function runBenchmarkSuite(suite, runner) {
|
|
23
|
-
const { Task, Bench } = await runner.importTinybench();
|
|
24
|
-
const start = performance.now();
|
|
25
|
-
const benchmarkGroup = [];
|
|
26
|
-
const benchmarkSuiteGroup = [];
|
|
27
|
-
for (const task of suite.tasks) {
|
|
28
|
-
if (task.mode !== "run" && task.mode !== "queued") continue;
|
|
29
|
-
if (task.meta?.benchmark) benchmarkGroup.push(task);
|
|
30
|
-
else if (task.type === "suite") benchmarkSuiteGroup.push(task);
|
|
31
|
-
}
|
|
32
|
-
// run sub suites sequentially
|
|
33
|
-
for (const subSuite of benchmarkSuiteGroup) await runBenchmarkSuite(subSuite, runner);
|
|
34
|
-
if (benchmarkGroup.length) {
|
|
35
|
-
const defer = createDefer();
|
|
36
|
-
suite.result = {
|
|
37
|
-
state: "run",
|
|
38
|
-
startTime: start,
|
|
39
|
-
benchmark: createBenchmarkResult(suite.name)
|
|
40
|
-
};
|
|
41
|
-
updateTask$1("suite-prepare", suite);
|
|
42
|
-
const addBenchTaskListener = (task, benchmark) => {
|
|
43
|
-
task.addEventListener("complete", (e) => {
|
|
44
|
-
const taskRes = e.task.result;
|
|
45
|
-
const result = benchmark.result.benchmark;
|
|
46
|
-
benchmark.result.state = "pass";
|
|
47
|
-
Object.assign(result, taskRes);
|
|
48
|
-
// compute extra stats and free raw samples as early as possible
|
|
49
|
-
const samples = result.samples;
|
|
50
|
-
result.sampleCount = samples.length;
|
|
51
|
-
result.median = samples.length % 2 ? samples[Math.floor(samples.length / 2)] : (samples[samples.length / 2] + samples[samples.length / 2 - 1]) / 2;
|
|
52
|
-
if (!runner.config.benchmark?.includeSamples) result.samples.length = 0;
|
|
53
|
-
updateTask$1("test-finished", benchmark);
|
|
54
|
-
}, { once: true });
|
|
55
|
-
task.addEventListener("error", (e) => {
|
|
56
|
-
const task = e.task;
|
|
57
|
-
defer.reject(benchmark ? task.result.error : e);
|
|
58
|
-
}, { once: true });
|
|
59
|
-
};
|
|
60
|
-
benchmarkGroup.forEach((benchmark) => {
|
|
61
|
-
const benchmarkInstance = new Bench(getBenchOptions(benchmark));
|
|
62
|
-
const benchmarkFn = getBenchFn(benchmark);
|
|
63
|
-
benchmark.result = {
|
|
64
|
-
state: "run",
|
|
65
|
-
startTime: start,
|
|
66
|
-
benchmark: createBenchmarkResult(benchmark.name)
|
|
67
|
-
};
|
|
68
|
-
const task = new Task(benchmarkInstance, benchmark.name, benchmarkFn);
|
|
69
|
-
benchmarkTasks.set(benchmark, task);
|
|
70
|
-
addBenchTaskListener(task, benchmark);
|
|
71
|
-
});
|
|
72
|
-
const { setTimeout } = getSafeTimers();
|
|
73
|
-
const tasks = [];
|
|
74
|
-
for (const benchmark of benchmarkGroup) {
|
|
75
|
-
const task = benchmarkTasks.get(benchmark);
|
|
76
|
-
updateTask$1("test-prepare", benchmark);
|
|
77
|
-
await task.warmup();
|
|
78
|
-
tasks.push([await new Promise((resolve) => setTimeout(async () => {
|
|
79
|
-
resolve(await task.run());
|
|
80
|
-
})), benchmark]);
|
|
81
|
-
}
|
|
82
|
-
suite.result.duration = performance.now() - start;
|
|
83
|
-
suite.result.state = "pass";
|
|
84
|
-
updateTask$1("suite-finished", suite);
|
|
85
|
-
defer.resolve(null);
|
|
86
|
-
await defer;
|
|
87
|
-
}
|
|
88
|
-
function updateTask$1(event, task) {
|
|
89
|
-
updateTask(event, task, runner);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
class NodeBenchmarkRunner {
|
|
93
|
-
moduleRunner;
|
|
94
|
-
constructor(config) {
|
|
95
|
-
this.config = config;
|
|
96
|
-
}
|
|
97
|
-
async importTinybench() {
|
|
98
|
-
return await import('tinybench');
|
|
99
|
-
}
|
|
100
|
-
importFile(filepath, source) {
|
|
101
|
-
if (source === "setup") {
|
|
102
|
-
const moduleNode = getWorkerState().evaluatedModules.getModuleById(filepath);
|
|
103
|
-
if (moduleNode) getWorkerState().evaluatedModules.invalidateModule(moduleNode);
|
|
104
|
-
}
|
|
105
|
-
return this.moduleRunner.import(filepath);
|
|
106
|
-
}
|
|
107
|
-
async runSuite(suite) {
|
|
108
|
-
await runBenchmarkSuite(suite, this);
|
|
109
|
-
}
|
|
110
|
-
async runTask() {
|
|
111
|
-
throw new Error("`test()` and `it()` is only available in test mode.");
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// worker context is shared between all tests
|
|
116
|
-
const workerContext = Object.create(null);
|
|
117
|
-
class VitestTestRunner {
|
|
118
|
-
snapshotClient = getSnapshotClient();
|
|
119
|
-
workerState = getWorkerState();
|
|
120
|
-
moduleRunner;
|
|
121
|
-
cancelRun = false;
|
|
122
|
-
assertionsErrors = /* @__PURE__ */ new WeakMap();
|
|
123
|
-
pool = this.workerState.ctx.pool;
|
|
124
|
-
_otel;
|
|
125
|
-
viteEnvironment;
|
|
126
|
-
constructor(config) {
|
|
127
|
-
this.config = config;
|
|
128
|
-
const environment = this.workerState.environment;
|
|
129
|
-
this.viteEnvironment = environment.viteEnvironment || environment.name;
|
|
130
|
-
}
|
|
131
|
-
importFile(filepath, source) {
|
|
132
|
-
if (source === "setup") {
|
|
133
|
-
const moduleNode = this.workerState.evaluatedModules.getModuleById(filepath);
|
|
134
|
-
if (moduleNode) this.workerState.evaluatedModules.invalidateModule(moduleNode);
|
|
135
|
-
}
|
|
136
|
-
return this._otel.$(`vitest.module.import_${source === "setup" ? "setup" : "spec"}`, { attributes: { "code.file.path": filepath } }, () => this.moduleRunner.import(filepath));
|
|
137
|
-
}
|
|
138
|
-
onCollectStart(file) {
|
|
139
|
-
this.workerState.current = file;
|
|
140
|
-
}
|
|
141
|
-
onCleanupWorkerContext(listener) {
|
|
142
|
-
this.workerState.onCleanup(listener);
|
|
143
|
-
}
|
|
144
|
-
onAfterRunFiles() {
|
|
145
|
-
this.snapshotClient.clear();
|
|
146
|
-
this.workerState.current = void 0;
|
|
147
|
-
}
|
|
148
|
-
getWorkerContext() {
|
|
149
|
-
return workerContext;
|
|
150
|
-
}
|
|
151
|
-
async onAfterRunSuite(suite) {
|
|
152
|
-
if (this.config.logHeapUsage && typeof process !== "undefined") suite.result.heap = process.memoryUsage().heapUsed;
|
|
153
|
-
if (suite.mode !== "skip" && "filepath" in suite) {
|
|
154
|
-
// mark snapshots in skipped tests as not obsolete
|
|
155
|
-
for (const test of getTests(suite)) if (test.mode === "skip") {
|
|
156
|
-
const name = getNames(test).slice(1).join(" > ");
|
|
157
|
-
this.snapshotClient.skipTest(suite.file.filepath, name);
|
|
158
|
-
}
|
|
159
|
-
const result = await this.snapshotClient.finish(suite.file.filepath);
|
|
160
|
-
if (this.workerState.config.snapshotOptions.updateSnapshot === "none" && result.unchecked) {
|
|
161
|
-
let message = `Obsolete snapshots found when no snapshot update is expected.\n`;
|
|
162
|
-
for (const key of result.uncheckedKeys) message += `· ${key}\n`;
|
|
163
|
-
suite.result.errors ??= [];
|
|
164
|
-
suite.result.errors.push(processError(new Error(message)));
|
|
165
|
-
suite.result.state = "fail";
|
|
166
|
-
}
|
|
167
|
-
await rpc().snapshotSaved(result);
|
|
168
|
-
}
|
|
169
|
-
this.workerState.current = suite.suite || suite.file;
|
|
170
|
-
}
|
|
171
|
-
onAfterRunTask(test) {
|
|
172
|
-
if (this.config.logHeapUsage && typeof process !== "undefined") test.result.heap = process.memoryUsage().heapUsed;
|
|
173
|
-
this.workerState.current = test.suite || test.file;
|
|
174
|
-
}
|
|
175
|
-
cancel(_reason) {
|
|
176
|
-
this.cancelRun = true;
|
|
177
|
-
}
|
|
178
|
-
injectValue(key) {
|
|
179
|
-
// inject has a very limiting type controlled by ProvidedContext
|
|
180
|
-
// some tests override it which causes the build to fail
|
|
181
|
-
return inject(key);
|
|
182
|
-
}
|
|
183
|
-
async onBeforeRunTask(test) {
|
|
184
|
-
if (this.cancelRun) test.mode = "skip";
|
|
185
|
-
if (test.mode !== "run" && test.mode !== "queued") return;
|
|
186
|
-
this.workerState.current = test;
|
|
187
|
-
}
|
|
188
|
-
async onBeforeRunSuite(suite) {
|
|
189
|
-
if (this.cancelRun) suite.mode = "skip";
|
|
190
|
-
// initialize snapshot state before running file suite
|
|
191
|
-
if (suite.mode !== "skip" && "filepath" in suite) await this.snapshotClient.setup(suite.file.filepath, this.workerState.config.snapshotOptions);
|
|
192
|
-
this.workerState.current = suite;
|
|
193
|
-
}
|
|
194
|
-
onBeforeTryTask(test) {
|
|
195
|
-
clearModuleMocks(this.config);
|
|
196
|
-
this.snapshotClient.clearTest(test.file.filepath, test.id);
|
|
197
|
-
setState({
|
|
198
|
-
assertionCalls: 0,
|
|
199
|
-
isExpectingAssertions: false,
|
|
200
|
-
isExpectingAssertionsError: null,
|
|
201
|
-
expectedAssertionsNumber: null,
|
|
202
|
-
expectedAssertionsNumberErrorGen: null,
|
|
203
|
-
currentTestName: getTestName(test),
|
|
204
|
-
snapshotState: this.snapshotClient.getSnapshotState(test.file.filepath)
|
|
205
|
-
}, globalThis[GLOBAL_EXPECT]);
|
|
206
|
-
}
|
|
207
|
-
onAfterTryTask(test) {
|
|
208
|
-
const { assertionCalls, expectedAssertionsNumber, expectedAssertionsNumberErrorGen, isExpectingAssertions, isExpectingAssertionsError } = test.context._local ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
|
|
209
|
-
if (expectedAssertionsNumber !== null && assertionCalls !== expectedAssertionsNumber) throw expectedAssertionsNumberErrorGen();
|
|
210
|
-
if (isExpectingAssertions === true && assertionCalls === 0) throw isExpectingAssertionsError;
|
|
211
|
-
if (this.config.expect.requireAssertions && assertionCalls === 0) throw this.assertionsErrors.get(test);
|
|
212
|
-
}
|
|
213
|
-
extendTaskContext(context) {
|
|
214
|
-
// create error during the test initialization so we have a nice stack trace
|
|
215
|
-
if (this.config.expect.requireAssertions) this.assertionsErrors.set(context.task, /* @__PURE__ */ new Error("expected any number of assertion, but got none"));
|
|
216
|
-
let _expect;
|
|
217
|
-
Object.defineProperty(context, "expect", { get() {
|
|
218
|
-
if (!_expect) _expect = createExpect(context.task);
|
|
219
|
-
return _expect;
|
|
220
|
-
} });
|
|
221
|
-
Object.defineProperty(context, "_local", { get() {
|
|
222
|
-
return _expect != null;
|
|
223
|
-
} });
|
|
224
|
-
return context;
|
|
225
|
-
}
|
|
226
|
-
getImportDurations() {
|
|
227
|
-
const importDurations = {};
|
|
228
|
-
const entries = this.workerState.moduleExecutionInfo?.entries() || [];
|
|
229
|
-
for (const [filepath, { duration, selfTime, external, importer }] of entries) importDurations[normalize(filepath)] = {
|
|
230
|
-
selfTime,
|
|
231
|
-
totalTime: duration,
|
|
232
|
-
external,
|
|
233
|
-
importer
|
|
234
|
-
};
|
|
235
|
-
return importDurations;
|
|
236
|
-
}
|
|
237
|
-
trace = (name, attributes, cb) => {
|
|
238
|
-
const options = typeof attributes === "object" ? { attributes } : {};
|
|
239
|
-
return this._otel.$(`vitest.test.runner.${name}`, options, cb || attributes);
|
|
240
|
-
};
|
|
241
|
-
__setTraces(traces) {
|
|
242
|
-
this._otel = traces;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
function clearModuleMocks(config) {
|
|
246
|
-
const { clearMocks, mockReset, restoreMocks, unstubEnvs, unstubGlobals } = config;
|
|
247
|
-
if (restoreMocks) vi.restoreAllMocks();
|
|
248
|
-
if (mockReset) vi.resetAllMocks();
|
|
249
|
-
if (clearMocks) vi.clearAllMocks();
|
|
250
|
-
if (unstubEnvs) vi.unstubAllEnvs();
|
|
251
|
-
if (unstubGlobals) vi.unstubAllGlobals();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export { NodeBenchmarkRunner as N, VitestTestRunner as V };
|
package/dist/mocker.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@vitest/mocker';
|
package/dist/mocker.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@vitest/mocker';
|
package/dist/module-runner.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export { VitestModuleEvaluator } from './module-evaluator.js';
|
|
2
|
-
export { a as VITEST_VM_CONTEXT_SYMBOL, V as VitestModuleRunner, s as startVitestModuleRunner } from './chunks/startModuleRunner.DEj0jb3e.js';
|
|
3
|
-
export { g as getWorkerState } from './chunks/utils.DvEY5TfP.js';
|
|
4
|
-
import 'node:module';
|
|
5
|
-
import 'node:url';
|
|
6
|
-
import 'node:vm';
|
|
7
|
-
import 'pathe';
|
|
8
|
-
import 'vite/module-runner';
|
|
9
|
-
import './chunks/traces.CCmnQaNT.js';
|
|
10
|
-
import 'node:fs';
|
|
11
|
-
import '@vitest/utils/helpers';
|
|
12
|
-
import './chunks/modules.BJuCwlRJ.js';
|
|
13
|
-
import './path.js';
|
|
14
|
-
import 'node:path';
|
|
15
|
-
import '@vitest/utils/serialize';
|
|
16
|
-
import '@vitest/mocker';
|
|
17
|
-
import '@vitest/utils/timers';
|