vitest 3.2.0-beta.1 → 3.2.0-beta.3
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 +0 -232
- package/dist/browser.d.ts +5 -3
- package/dist/browser.js +3 -4
- package/dist/chunks/{base.SfTiRNZf.js → base.D4119yLM.js} +4 -3
- package/dist/chunks/{benchmark.BoF7jW0Q.js → benchmark.Cf_PACH1.js} +1 -1
- package/dist/chunks/{cac.TfX2-DVH.js → cac.DWaWHIIE.js} +21 -16
- package/dist/chunks/{cli-api.2970Nj9J.js → cli-api.CnmEXkxs.js} +292 -59
- package/dist/chunks/{config.d.UqE-KR0o.d.ts → config.d.D2ROskhv.d.ts} +2 -0
- package/dist/chunks/{console.K1NMVOSc.js → console.Cwr-MFPV.js} +3 -2
- package/dist/chunks/{constants.BZZyIeIE.js → constants.DnKduX2e.js} +1 -0
- package/dist/chunks/{coverage.z0LVMxgb.js → coverage.C73DaDgS.js} +241 -4226
- package/dist/chunks/{creator.CuL7xDWI.js → creator.C8WKy2eW.js} +26 -44
- package/dist/chunks/{date.CDOsz-HY.js → date.ByMsSlOr.js} +25 -0
- package/dist/chunks/{defaults.DSxsTG0h.js → defaults.DpVH7vbg.js} +1 -0
- package/dist/chunks/{environment.d.D8YDy2v5.d.ts → environment.d.cL3nLXbE.d.ts} +1 -0
- package/dist/chunks/{execute.BpmIjFTD.js → execute.B3q-2LPV.js} +28 -5
- package/dist/chunks/{global.d.BCOHQEpR.d.ts → global.d.BNLIi6yo.d.ts} +13 -11
- package/dist/chunks/{globals.Cg4NtV4P.js → globals.CI21aWXF.js} +7 -7
- package/dist/chunks/{index.DFXFpH3w.js → index.2jgTs_Q5.js} +19 -1
- package/dist/chunks/{index.CUacZlWG.js → index.Bter3jj9.js} +954 -954
- package/dist/chunks/{index.DbWBPwtH.js → index.CbT4iuwc.js} +7 -4
- package/dist/chunks/index.D3XRDfWc.js +213 -0
- package/dist/chunks/{index.BPc7M5ni.js → index.DNgLEKsQ.js} +5 -15
- package/dist/chunks/index.JOzufsrU.js +276 -0
- package/dist/chunks/{index.DBIGubLC.js → index.X0nbfr6-.js} +7 -7
- package/dist/chunks/{inspector.DbDkSkFn.js → inspector.BFsh5KO0.js} +3 -0
- package/dist/chunks/{node.3xsWotC9.js → node.Be-ntJnD.js} +1 -1
- package/dist/chunks/{reporters.d.DGm4k1Wx.d.ts → reporters.d.Bt4IGtsa.d.ts} +41 -6
- package/dist/chunks/{rpc.D9_013TY.js → rpc.BKExFSRG.js} +2 -1
- package/dist/chunks/{runBaseTests.CguliJB5.js → runBaseTests.B_M1TTsK.js} +19 -11
- package/dist/chunks/{setup-common.BP6KrF_Z.js → setup-common.CF-O-dZX.js} +2 -3
- package/dist/chunks/typechecker.BgzF-6iO.js +954 -0
- package/dist/chunks/{utils.CgTj3MsC.js → utils.BlI4TC7Y.js} +1 -0
- package/dist/chunks/{utils.BfxieIyZ.js → utils.DPCq3gzW.js} +3 -0
- package/dist/chunks/{vi.BFR5YIgu.js → vi.pkoYCV6A.js} +25 -2
- package/dist/chunks/{vite.d.DjP_ALCZ.d.ts → vite.d.B-Kx3KCF.d.ts} +3 -1
- package/dist/chunks/{vm.CuLHT1BG.js → vm.DPYem2so.js} +72 -4
- package/dist/chunks/{worker.d.CoCI7hzP.d.ts → worker.d.BKbBp2ga.d.ts} +2 -2
- package/dist/chunks/{worker.d.D5Xdi-Zr.d.ts → worker.d.Bl1O4kuf.d.ts} +1 -1
- package/dist/cli.js +21 -2
- package/dist/config.cjs +2 -0
- package/dist/config.d.ts +7 -6
- package/dist/config.js +2 -2
- package/dist/coverage.d.ts +4 -4
- package/dist/coverage.js +7 -10
- package/dist/environments.d.ts +6 -2
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +9 -3
- package/dist/execute.js +1 -1
- package/dist/index.d.ts +25 -35
- package/dist/index.js +5 -6
- package/dist/node.d.ts +18 -10
- package/dist/node.js +22 -22
- package/dist/reporters.d.ts +4 -4
- package/dist/reporters.js +14 -14
- package/dist/runners.d.ts +1 -1
- package/dist/runners.js +13 -5
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +9 -5
- package/dist/workers/forks.js +6 -4
- package/dist/workers/runVmTests.js +14 -10
- package/dist/workers/threads.js +4 -4
- package/dist/workers/vmForks.js +6 -6
- package/dist/workers/vmThreads.js +6 -6
- package/dist/workers.d.ts +4 -4
- package/dist/workers.js +10 -10
- package/package.json +22 -26
- package/dist/chunks/index.Bw6JxgX8.js +0 -143
- package/dist/chunks/run-once.Dimr7O9f.js +0 -47
- package/dist/chunks/typechecker.DYQbn8uK.js +0 -956
- package/dist/chunks/utils.8gfOgtry.js +0 -207
- package/dist/utils.d.ts +0 -3
- package/dist/utils.js +0 -2
|
@@ -2,6 +2,7 @@ import { getSafeTimers } from '@vitest/utils';
|
|
|
2
2
|
|
|
3
3
|
const NAME_WORKER_STATE = "__vitest_worker__";
|
|
4
4
|
function getWorkerState() {
|
|
5
|
+
// @ts-expect-error untyped global
|
|
5
6
|
const workerState = globalThis[NAME_WORKER_STATE];
|
|
6
7
|
if (!workerState) {
|
|
7
8
|
const errorMsg = "Vitest failed to access its internal state." + "\n\nOne of the following is possible:" + "\n- \"vitest\" is imported directly without running \"vitest\" command" + "\n- \"vitest\" is imported inside \"globalSetup\" (to fix this, use \"setupFiles\" instead, because \"globalSetup\" runs in a different context)" + "\n- \"vitest\" is imported inside Vite / Vitest config file" + "\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { parseRegexp } from '@vitest/utils';
|
|
2
2
|
|
|
3
3
|
const REGEXP_WRAP_PREFIX = "$$vitest:";
|
|
4
|
+
// Store global APIs in case process is overwritten by tests
|
|
4
5
|
const processSend = process.send?.bind(process);
|
|
5
6
|
const processOn = process.on?.bind(process);
|
|
6
7
|
const processOff = process.off?.bind(process);
|
|
@@ -32,6 +33,7 @@ function createForksRpcOptions(nodeV8) {
|
|
|
32
33
|
},
|
|
33
34
|
on(fn) {
|
|
34
35
|
const handler = (message, ...extras) => {
|
|
36
|
+
// Do not react on Tinypool's internal messaging
|
|
35
37
|
if (message?.__tinypool_worker_message__) {
|
|
36
38
|
return;
|
|
37
39
|
}
|
|
@@ -55,6 +57,7 @@ function unwrapSerializableConfig(config) {
|
|
|
55
57
|
if (config.defines && Array.isArray(config.defines.keys) && config.defines.original) {
|
|
56
58
|
const { keys, original } = config.defines;
|
|
57
59
|
const defines = {};
|
|
60
|
+
// Apply all keys from the original. Entries which had undefined value are missing from original now
|
|
58
61
|
for (const key of keys) {
|
|
59
62
|
defines[key] = original[key];
|
|
60
63
|
}
|
|
@@ -2,15 +2,16 @@ import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, J
|
|
|
2
2
|
import { getCurrentTest } from '@vitest/runner';
|
|
3
3
|
import { getNames, getTestName } from '@vitest/runner/utils';
|
|
4
4
|
import * as chai$1 from 'chai';
|
|
5
|
-
import { g as getWorkerState, a as getCurrentEnvironment, i as isChildProcess, w as waitForImportsToResolve, r as resetModules } from './utils.
|
|
5
|
+
import { g as getWorkerState, a as getCurrentEnvironment, i as isChildProcess, w as waitForImportsToResolve, r as resetModules } from './utils.BlI4TC7Y.js';
|
|
6
6
|
import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
|
|
7
7
|
import { g as getDefaultExportFromCjs, c as commonjsGlobal } from './_commonjsHelpers.BFTU3MAI.js';
|
|
8
8
|
import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest/snapshot';
|
|
9
9
|
import '@vitest/utils/error';
|
|
10
10
|
import { fn, spyOn, mocks, isMockFunction } from '@vitest/spy';
|
|
11
11
|
import { parseSingleStack } from '@vitest/utils/source-map';
|
|
12
|
-
import { R as RealDate, r as resetDate, m as mockDate } from './date.
|
|
12
|
+
import { R as RealDate, r as resetDate, m as mockDate } from './date.ByMsSlOr.js';
|
|
13
13
|
|
|
14
|
+
// these matchers are not supported because they don't make sense with poll
|
|
14
15
|
const unsupported = [
|
|
15
16
|
"matchSnapshot",
|
|
16
17
|
"toMatchSnapshot",
|
|
@@ -28,6 +29,7 @@ function createExpectPoll(expect) {
|
|
|
28
29
|
const state = getWorkerState();
|
|
29
30
|
const defaults = state.config.expect?.poll ?? {};
|
|
30
31
|
const { interval = defaults.interval ?? 50, timeout = defaults.timeout ?? 1e3, message } = options;
|
|
32
|
+
// @ts-expect-error private poll access
|
|
31
33
|
const assertion = expect(null, message).withContext({ poll: true });
|
|
32
34
|
fn = fn.bind(assertion);
|
|
33
35
|
const test = chai$1.util.flag(assertion, "vitest-test");
|
|
@@ -89,6 +91,8 @@ function createExpectPoll(expect) {
|
|
|
89
91
|
}
|
|
90
92
|
});
|
|
91
93
|
let resultPromise;
|
|
94
|
+
// only .then is enough to check awaited, but we type this as `Promise<void>` in global types
|
|
95
|
+
// so let's follow it
|
|
92
96
|
return {
|
|
93
97
|
then(onFulfilled, onRejected) {
|
|
94
98
|
awaited = true;
|
|
@@ -222,7 +226,9 @@ function createAssertionMessage(util, assertion, hasArgs) {
|
|
|
222
226
|
}
|
|
223
227
|
function recordAsyncExpect(_test, promise, assertion, error) {
|
|
224
228
|
const test = _test;
|
|
229
|
+
// record promise for test, that resolves before test ends
|
|
225
230
|
if (test && promise instanceof Promise) {
|
|
231
|
+
// if promise is explicitly awaited, remove it from the list
|
|
226
232
|
promise = promise.finally(() => {
|
|
227
233
|
if (!test.promises) {
|
|
228
234
|
return;
|
|
@@ -232,6 +238,7 @@ function recordAsyncExpect(_test, promise, assertion, error) {
|
|
|
232
238
|
test.promises.splice(index, 1);
|
|
233
239
|
}
|
|
234
240
|
});
|
|
241
|
+
// record promise
|
|
235
242
|
if (!test.promises) {
|
|
236
243
|
test.promises = [];
|
|
237
244
|
}
|
|
@@ -281,6 +288,7 @@ function getError(expected, promise) {
|
|
|
281
288
|
if (!promise) {
|
|
282
289
|
throw new Error(`expected must be a function, received ${typeof expected}`);
|
|
283
290
|
}
|
|
291
|
+
// when "promised", it receives thrown error
|
|
284
292
|
return expected;
|
|
285
293
|
}
|
|
286
294
|
try {
|
|
@@ -442,6 +450,7 @@ function createExpect(test) {
|
|
|
442
450
|
const assert = chai$1.expect(value, message);
|
|
443
451
|
const _test = test || getCurrentTest();
|
|
444
452
|
if (_test) {
|
|
453
|
+
// @ts-expect-error internal
|
|
445
454
|
return assert.withTest(_test);
|
|
446
455
|
} else {
|
|
447
456
|
return assert;
|
|
@@ -451,6 +460,7 @@ function createExpect(test) {
|
|
|
451
460
|
Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
|
|
452
461
|
expect.getState = () => getState(expect);
|
|
453
462
|
expect.setState = (state) => setState(state, expect);
|
|
463
|
+
// @ts-expect-error global is not typed
|
|
454
464
|
const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
|
|
455
465
|
setState({
|
|
456
466
|
...globalState,
|
|
@@ -465,9 +475,11 @@ function createExpect(test) {
|
|
|
465
475
|
},
|
|
466
476
|
currentTestName: test ? getTestName(test) : globalState.currentTestName
|
|
467
477
|
}, expect);
|
|
478
|
+
// @ts-expect-error untyped
|
|
468
479
|
expect.extend = (matchers) => chai$1.expect.extend(expect, matchers);
|
|
469
480
|
expect.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters);
|
|
470
481
|
expect.soft = (...args) => {
|
|
482
|
+
// @ts-expect-error private soft access
|
|
471
483
|
return expect(...args).withContext({ soft: true });
|
|
472
484
|
};
|
|
473
485
|
expect.poll = createExpectPoll(expect);
|
|
@@ -3611,6 +3623,12 @@ var fakeTimersSrcExports = requireFakeTimersSrc();
|
|
|
3611
3623
|
class FakeTimers {
|
|
3612
3624
|
_global;
|
|
3613
3625
|
_clock;
|
|
3626
|
+
// | _fakingTime | _fakingDate |
|
|
3627
|
+
// +-------------+-------------+
|
|
3628
|
+
// | false | falsy | initial
|
|
3629
|
+
// | false | truthy | vi.setSystemTime called first (for mocking only Date without fake timers)
|
|
3630
|
+
// | true | falsy | vi.useFakeTimers called first
|
|
3631
|
+
// | true | truthy | unreachable
|
|
3614
3632
|
_fakingTime;
|
|
3615
3633
|
_fakingDate;
|
|
3616
3634
|
_fakeTimers;
|
|
@@ -3655,6 +3673,7 @@ class FakeTimers {
|
|
|
3655
3673
|
if (this._checkFakeTimers()) {
|
|
3656
3674
|
for (let i = steps; i > 0; i--) {
|
|
3657
3675
|
this._clock.next();
|
|
3676
|
+
// Fire all timers at this point: https://github.com/sinonjs/fake-timers/issues/250
|
|
3658
3677
|
this._clock.tick(0);
|
|
3659
3678
|
if (this._clock.countTimers() === 0) {
|
|
3660
3679
|
break;
|
|
@@ -3666,6 +3685,7 @@ class FakeTimers {
|
|
|
3666
3685
|
if (this._checkFakeTimers()) {
|
|
3667
3686
|
for (let i = steps; i > 0; i--) {
|
|
3668
3687
|
await this._clock.nextAsync();
|
|
3688
|
+
// Fire all timers at this point: https://github.com/sinonjs/fake-timers/issues/250
|
|
3669
3689
|
this._clock.tick(0);
|
|
3670
3690
|
if (this._clock.countTimers() === 0) {
|
|
3671
3691
|
break;
|
|
@@ -3690,6 +3710,7 @@ class FakeTimers {
|
|
|
3690
3710
|
}
|
|
3691
3711
|
runAllTicks() {
|
|
3692
3712
|
if (this._checkFakeTimers()) {
|
|
3713
|
+
// @ts-expect-error method not exposed
|
|
3693
3714
|
this._clock.runMicrotasks();
|
|
3694
3715
|
}
|
|
3695
3716
|
}
|
|
@@ -4124,6 +4145,7 @@ function createVitest() {
|
|
|
4124
4145
|
const vitest = createVitest();
|
|
4125
4146
|
const vi = vitest;
|
|
4126
4147
|
function _mocker() {
|
|
4148
|
+
// @ts-expect-error injected by vite-nide
|
|
4127
4149
|
return typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : new Proxy({}, { get(_, name) {
|
|
4128
4150
|
throw new Error("Vitest mocker was not initialized in this environment. " + `vi.${String(name)}() is forbidden.`);
|
|
4129
4151
|
} });
|
|
@@ -4131,6 +4153,7 @@ function _mocker() {
|
|
|
4131
4153
|
function getImporter(name) {
|
|
4132
4154
|
const stackTrace = createSimpleStackTrace({ stackTraceLimit: 5 });
|
|
4133
4155
|
const stackArray = stackTrace.split("\n");
|
|
4156
|
+
// if there is no message in a stack trace, use the item - 1
|
|
4134
4157
|
const importerStackIndex = stackArray.findIndex((stack) => {
|
|
4135
4158
|
return stack.includes(` at Object.${name}`) || stack.includes(`${name}@`);
|
|
4136
4159
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HookHandler } from 'vite';
|
|
2
|
-
import { V as Vitest, T as TestProject, b as TestProjectConfiguration, I as InlineConfig } from './reporters.d.
|
|
2
|
+
import { V as Vitest, T as TestProject, b as TestProjectConfiguration, I as InlineConfig } from './reporters.d.Bt4IGtsa.js';
|
|
3
3
|
|
|
4
4
|
interface VitestPluginContext {
|
|
5
5
|
vitest: Vitest;
|
|
@@ -7,6 +7,8 @@ interface VitestPluginContext {
|
|
|
7
7
|
injectTestProjects: (config: TestProjectConfiguration | TestProjectConfiguration[]) => Promise<TestProject[]>;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/* eslint-disable unused-imports/no-unused-vars */
|
|
11
|
+
|
|
10
12
|
type VitestInlineConfig = InlineConfig;
|
|
11
13
|
declare module "vite" {
|
|
12
14
|
interface UserConfig {
|
|
@@ -2,14 +2,14 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
|
2
2
|
import vm, { isContext } from 'node:vm';
|
|
3
3
|
import { dirname, basename, extname, normalize, join, resolve } from 'pathe';
|
|
4
4
|
import { distDir } from '../path.js';
|
|
5
|
-
import { createCustomConsole } from './console.
|
|
6
|
-
import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute.
|
|
5
|
+
import { createCustomConsole } from './console.Cwr-MFPV.js';
|
|
6
|
+
import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute.B3q-2LPV.js';
|
|
7
7
|
import fs from 'node:fs';
|
|
8
8
|
import { dirname as dirname$1 } from 'node:path';
|
|
9
9
|
import { isPrimitive, isNodeBuiltin, toArray, getCachedData, setCacheData, isBareImport } from 'vite-node/utils';
|
|
10
10
|
import { createRequire, Module } from 'node:module';
|
|
11
11
|
import { CSS_LANGS_RE, KNOWN_ASSET_RE } from 'vite-node/constants';
|
|
12
|
-
import { p as provideWorkerState } from './utils.
|
|
12
|
+
import { p as provideWorkerState } from './utils.BlI4TC7Y.js';
|
|
13
13
|
|
|
14
14
|
function interopCommonJsModule(interopDefault, mod) {
|
|
15
15
|
if (isPrimitive(mod) || Array.isArray(mod) || mod instanceof Promise) {
|
|
@@ -58,6 +58,7 @@ class CommonjsExecutor {
|
|
|
58
58
|
this.fs = options.fileMap;
|
|
59
59
|
this.interopDefault = options.interopDefault;
|
|
60
60
|
const primitives = vm.runInContext("({ Object, Array, Error })", this.context);
|
|
61
|
+
// eslint-disable-next-line ts/no-this-alias
|
|
61
62
|
const executor = this;
|
|
62
63
|
this.Module = class Module$1 {
|
|
63
64
|
exports;
|
|
@@ -71,6 +72,7 @@ class CommonjsExecutor {
|
|
|
71
72
|
paths = [];
|
|
72
73
|
constructor(id = "", parent) {
|
|
73
74
|
this.exports = primitives.Object.create(Object.prototype);
|
|
75
|
+
// in our case the path should always be resolved already
|
|
74
76
|
this.path = dirname(id);
|
|
75
77
|
this.id = id;
|
|
76
78
|
this.filename = id;
|
|
@@ -89,12 +91,16 @@ class CommonjsExecutor {
|
|
|
89
91
|
static register = () => {
|
|
90
92
|
throw new Error(`[vitest] "register" is not available when running in Vitest.`);
|
|
91
93
|
};
|
|
94
|
+
static registerHooks = () => {
|
|
95
|
+
throw new Error(`[vitest] "registerHooks" is not available when running in Vitest.`);
|
|
96
|
+
};
|
|
92
97
|
_compile(code, filename) {
|
|
93
98
|
const cjsModule = Module$1.wrap(code);
|
|
94
99
|
const script = new vm.Script(cjsModule, {
|
|
95
100
|
filename,
|
|
96
101
|
importModuleDynamically: options.importModuleDynamically
|
|
97
102
|
});
|
|
103
|
+
// @ts-expect-error mark script with current identifier
|
|
98
104
|
script.identifier = filename;
|
|
99
105
|
const fn = script.runInContext(executor.context);
|
|
100
106
|
const __dirname = dirname(filename);
|
|
@@ -106,6 +112,7 @@ class CommonjsExecutor {
|
|
|
106
112
|
this.loaded = true;
|
|
107
113
|
}
|
|
108
114
|
}
|
|
115
|
+
// exposed for external use, Node.js does the opposite
|
|
109
116
|
static _load = (request, parent, _isMain) => {
|
|
110
117
|
const require = Module$1.createRequire(parent?.filename ?? request);
|
|
111
118
|
return require(request);
|
|
@@ -126,11 +133,17 @@ class CommonjsExecutor {
|
|
|
126
133
|
static runMain = () => {
|
|
127
134
|
throw new primitives.Error("[vitest] \"runMain\" is not implemented.");
|
|
128
135
|
};
|
|
136
|
+
// @ts-expect-error not typed
|
|
129
137
|
static _resolveFilename = Module._resolveFilename;
|
|
138
|
+
// @ts-expect-error not typed
|
|
130
139
|
static _findPath = Module._findPath;
|
|
140
|
+
// @ts-expect-error not typed
|
|
131
141
|
static _initPaths = Module._initPaths;
|
|
142
|
+
// @ts-expect-error not typed
|
|
132
143
|
static _preloadModules = Module._preloadModules;
|
|
144
|
+
// @ts-expect-error not typed
|
|
133
145
|
static _resolveLookupPaths = Module._resolveLookupPaths;
|
|
146
|
+
// @ts-expect-error not typed
|
|
134
147
|
static globalPaths = Module.globalPaths;
|
|
135
148
|
static isBuiltin = Module.isBuiltin;
|
|
136
149
|
static constants = Module.constants;
|
|
@@ -189,6 +202,7 @@ class CommonjsExecutor {
|
|
|
189
202
|
}
|
|
190
203
|
});
|
|
191
204
|
}
|
|
205
|
+
// very naive implementation for Node.js require
|
|
192
206
|
loadCommonJSModule(module, filename) {
|
|
193
207
|
const cached = this.requireCache.get(filename);
|
|
194
208
|
if (cached) {
|
|
@@ -204,6 +218,7 @@ class CommonjsExecutor {
|
|
|
204
218
|
let currentExtension;
|
|
205
219
|
let index;
|
|
206
220
|
let startIndex = 0;
|
|
221
|
+
// eslint-disable-next-line no-cond-assign
|
|
207
222
|
while ((index = name.indexOf(".", startIndex)) !== -1) {
|
|
208
223
|
startIndex = index + 1;
|
|
209
224
|
if (index === 0) {
|
|
@@ -239,6 +254,7 @@ class CommonjsExecutor {
|
|
|
239
254
|
return this.moduleCache.get(identifier);
|
|
240
255
|
}
|
|
241
256
|
const exports = this.require(path);
|
|
257
|
+
// TODO: technically module should be parsed to find static exports, implement for strict mode in #2854
|
|
242
258
|
const { keys, moduleExports, defaultExport } = interopCommonJsModule(this.interopDefault, exports);
|
|
243
259
|
const module = new SyntheticModule([...keys, "default"], function() {
|
|
244
260
|
for (const key of keys) {
|
|
@@ -252,6 +268,42 @@ class CommonjsExecutor {
|
|
|
252
268
|
this.moduleCache.set(identifier, module);
|
|
253
269
|
return module;
|
|
254
270
|
}
|
|
271
|
+
// TODO: use this in strict mode, when available in #2854
|
|
272
|
+
// private _getNamedCjsExports(path: string): Set<string> {
|
|
273
|
+
// const cachedNamedExports = this.cjsNamedExportsMap.get(path)
|
|
274
|
+
// if (cachedNamedExports) {
|
|
275
|
+
// return cachedNamedExports
|
|
276
|
+
// }
|
|
277
|
+
// if (extname(path) === '.node') {
|
|
278
|
+
// const moduleExports = this.require(path)
|
|
279
|
+
// const namedExports = new Set(Object.keys(moduleExports))
|
|
280
|
+
// this.cjsNamedExportsMap.set(path, namedExports)
|
|
281
|
+
// return namedExports
|
|
282
|
+
// }
|
|
283
|
+
// const code = this.fs.readFile(path)
|
|
284
|
+
// const { exports, reexports } = parseCjs(code, path)
|
|
285
|
+
// const namedExports = new Set(exports)
|
|
286
|
+
// this.cjsNamedExportsMap.set(path, namedExports)
|
|
287
|
+
// for (const reexport of reexports) {
|
|
288
|
+
// if (isNodeBuiltin(reexport)) {
|
|
289
|
+
// const exports = this.require(reexport)
|
|
290
|
+
// if (exports !== null && typeof exports === 'object') {
|
|
291
|
+
// for (const e of Object.keys(exports)) {
|
|
292
|
+
// namedExports.add(e)
|
|
293
|
+
// }
|
|
294
|
+
// }
|
|
295
|
+
// }
|
|
296
|
+
// else {
|
|
297
|
+
// const require = this.createRequire(path)
|
|
298
|
+
// const resolved = require.resolve(reexport)
|
|
299
|
+
// const exports = this._getNamedCjsExports(resolved)
|
|
300
|
+
// for (const e of exports) {
|
|
301
|
+
// namedExports.add(e)
|
|
302
|
+
// }
|
|
303
|
+
// }
|
|
304
|
+
// }
|
|
305
|
+
// return namedExports
|
|
306
|
+
// }
|
|
255
307
|
require(identifier) {
|
|
256
308
|
const ext = extname(identifier);
|
|
257
309
|
if (ext === ".node" || isNodeBuiltin(identifier)) {
|
|
@@ -273,6 +325,7 @@ class CommonjsExecutor {
|
|
|
273
325
|
return module.exports;
|
|
274
326
|
}
|
|
275
327
|
this.builtinCache[normalized] = _require.cache[normalized];
|
|
328
|
+
// TODO: should we wrap module to rethrow context errors?
|
|
276
329
|
return moduleExports;
|
|
277
330
|
}
|
|
278
331
|
}
|
|
@@ -308,6 +361,7 @@ class EsmExecutor {
|
|
|
308
361
|
}
|
|
309
362
|
async loadEsModule(fileURL, getCode) {
|
|
310
363
|
const code = await getCode();
|
|
364
|
+
// TODO: should not be allowed in strict mode, implement in #2854
|
|
311
365
|
if (fileURL.endsWith(".json")) {
|
|
312
366
|
const m = new SyntheticModule(["default"], function() {
|
|
313
367
|
const result = JSON.parse(code);
|
|
@@ -345,13 +399,14 @@ class EsmExecutor {
|
|
|
345
399
|
return m;
|
|
346
400
|
}
|
|
347
401
|
async createNetworkModule(fileUrl) {
|
|
402
|
+
// https://nodejs.org/api/esm.html#https-and-http-imports
|
|
348
403
|
if (fileUrl.startsWith("http:")) {
|
|
349
404
|
const url = new URL(fileUrl);
|
|
350
405
|
if (url.hostname !== "localhost" && url.hostname !== "::1" && (IPnumber(url.hostname) & IPmask(8)) !== this.#httpIp) {
|
|
351
406
|
throw new Error(
|
|
352
407
|
// we don't know the importer, so it's undefined (the same happens in --pool=threads)
|
|
353
408
|
`import of '${fileUrl}' by undefined is not supported: ` + "http can only be used to load local resources (use https instead)."
|
|
354
|
-
);
|
|
409
|
+
);
|
|
355
410
|
}
|
|
356
411
|
}
|
|
357
412
|
return this.createEsModule(fileUrl, () => fetch(fileUrl).then((r) => r.text()));
|
|
@@ -496,6 +551,7 @@ class ViteExecutor {
|
|
|
496
551
|
return result.code;
|
|
497
552
|
}
|
|
498
553
|
} catch (cause) {
|
|
554
|
+
// rethrow vite error if it cannot load the module because it's not resolved
|
|
499
555
|
if (typeof cause === "object" && cause.code === "ERR_LOAD_URL" || typeof cause?.message === "string" && cause.message.includes("Failed to load url")) {
|
|
500
556
|
const error = new Error(`Cannot find module '${fileUrl}'`, { cause });
|
|
501
557
|
error.code = "ERR_MODULE_NOT_FOUND";
|
|
@@ -548,7 +604,9 @@ class ViteExecutor {
|
|
|
548
604
|
}
|
|
549
605
|
|
|
550
606
|
const { existsSync, statSync } = fs;
|
|
607
|
+
// always defined when we use vm pool
|
|
551
608
|
const nativeResolve = import.meta.resolve;
|
|
609
|
+
// TODO: improve Node.js strict mode support in #2854
|
|
552
610
|
class ExternalModulesExecutor {
|
|
553
611
|
cjs;
|
|
554
612
|
esm;
|
|
@@ -587,6 +645,7 @@ class ExternalModulesExecutor {
|
|
|
587
645
|
createRequire(identifier) {
|
|
588
646
|
return this.cjs.createRequire(identifier);
|
|
589
647
|
}
|
|
648
|
+
// dynamic import can be used in both ESM and CJS, so we have it in the executor
|
|
590
649
|
importModuleDynamically = async (specifier, referencer) => {
|
|
591
650
|
const module = await this.resolveModule(specifier, referencer.identifier);
|
|
592
651
|
return await this.esm.evaluateModule(module);
|
|
@@ -605,6 +664,7 @@ class ExternalModulesExecutor {
|
|
|
605
664
|
return id;
|
|
606
665
|
}
|
|
607
666
|
}
|
|
667
|
+
// import.meta.resolve can be asynchronous in older +18 Node versions
|
|
608
668
|
return nativeResolve(specifier, parent);
|
|
609
669
|
}
|
|
610
670
|
findNearestPackageData(basedir) {
|
|
@@ -667,6 +727,8 @@ class ExternalModulesExecutor {
|
|
|
667
727
|
} else if (extension === ".cjs") {
|
|
668
728
|
type = "commonjs";
|
|
669
729
|
} else if (extension === ".wasm") {
|
|
730
|
+
// still experimental on NodeJS --experimental-wasm-modules
|
|
731
|
+
// cf. ESM_FILE_FORMAT(url) in https://nodejs.org/docs/latest-v20.x/api/esm.html#resolution-algorithm
|
|
670
732
|
type = "wasm";
|
|
671
733
|
} else {
|
|
672
734
|
const pkgData = this.findNearestPackageData(normalize(pathUrl));
|
|
@@ -680,6 +742,8 @@ class ExternalModulesExecutor {
|
|
|
680
742
|
}
|
|
681
743
|
createModule(identifier) {
|
|
682
744
|
const { type, url, path } = this.getModuleInformation(identifier);
|
|
745
|
+
// create ERR_MODULE_NOT_FOUND on our own since latest NodeJS's import.meta.resolve doesn't throw on non-existing namespace or path
|
|
746
|
+
// https://github.com/nodejs/node/pull/49038
|
|
683
747
|
if ((type === "module" || type === "commonjs" || type === "wasm") && !existsSync(path)) {
|
|
684
748
|
const error = new Error(`Cannot find ${isBareImport(path) ? "package" : "module"} '${path}'`);
|
|
685
749
|
error.code = "ERR_MODULE_NOT_FOUND";
|
|
@@ -767,9 +831,13 @@ async function runVmTests(method, state) {
|
|
|
767
831
|
throw new TypeError(`Environment ${environment.name} doesn't provide a valid context. It should be created by "vm.createContext" method.`);
|
|
768
832
|
}
|
|
769
833
|
provideWorkerState(context, state);
|
|
834
|
+
// this is unfortunately needed for our own dependencies
|
|
835
|
+
// we need to find a way to not rely on this by default
|
|
836
|
+
// because browser doesn't provide these globals
|
|
770
837
|
context.process = process;
|
|
771
838
|
context.global = context;
|
|
772
839
|
context.console = state.config.disableConsoleIntercept ? console : createCustomConsole(state);
|
|
840
|
+
// TODO: don't hardcode setImmediate in fake timers defaults
|
|
773
841
|
context.setImmediate = setImmediate;
|
|
774
842
|
context.clearImmediate = clearImmediate;
|
|
775
843
|
const stubs = getDefaultRequestStubs(context);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { File, TaskResultPack, TaskEventPack, CancelReason, FileSpecification, Task } from '@vitest/runner';
|
|
2
2
|
import { ViteNodeResolveId, ModuleCacheMap, ModuleExecutionInfo } from 'vite-node';
|
|
3
|
-
import { a as SerializedConfig } from './config.d.
|
|
4
|
-
import { T as TransformMode, U as UserConsoleLog, A as AfterSuiteRunMeta, E as Environment } from './environment.d.
|
|
3
|
+
import { a as SerializedConfig } from './config.d.D2ROskhv.js';
|
|
4
|
+
import { T as TransformMode, U as UserConsoleLog, A as AfterSuiteRunMeta, E as Environment } from './environment.d.cL3nLXbE.js';
|
|
5
5
|
import { SnapshotResult } from '@vitest/snapshot';
|
|
6
6
|
|
|
7
7
|
type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never;
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
1
|
-
import { c as createCLI } from './chunks/cac.
|
|
1
|
+
import { c as createCLI } from './chunks/cac.DWaWHIIE.js';
|
|
2
2
|
import '@vitest/utils';
|
|
3
3
|
import 'events';
|
|
4
4
|
import 'pathe';
|
|
5
5
|
import 'tinyrainbow';
|
|
6
|
-
import './chunks/constants.
|
|
6
|
+
import './chunks/constants.DnKduX2e.js';
|
|
7
|
+
import './chunks/index.Bter3jj9.js';
|
|
8
|
+
import 'node:perf_hooks';
|
|
9
|
+
import '@vitest/runner/utils';
|
|
10
|
+
import '@vitest/utils/source-map';
|
|
11
|
+
import './chunks/env.Dq0hM4Xv.js';
|
|
12
|
+
import 'std-env';
|
|
13
|
+
import './chunks/typechecker.BgzF-6iO.js';
|
|
14
|
+
import 'node:os';
|
|
15
|
+
import 'tinyexec';
|
|
16
|
+
import './path.js';
|
|
17
|
+
import 'node:path';
|
|
18
|
+
import 'node:url';
|
|
19
|
+
import 'vite';
|
|
20
|
+
import 'node:util';
|
|
21
|
+
import 'node:fs';
|
|
22
|
+
import 'node:fs/promises';
|
|
23
|
+
import 'node:console';
|
|
24
|
+
import 'node:stream';
|
|
25
|
+
import 'node:module';
|
|
7
26
|
|
|
8
27
|
createCLI().parse();
|
package/dist/config.cjs
CHANGED
|
@@ -4,6 +4,7 @@ var os = require('node:os');
|
|
|
4
4
|
var stdEnv = require('std-env');
|
|
5
5
|
var vite = require('vite');
|
|
6
6
|
|
|
7
|
+
// if changed, update also jsdocs and docs
|
|
7
8
|
const defaultBrowserPort = 63315;
|
|
8
9
|
const extraInlineDeps = [
|
|
9
10
|
/^(?!.*node_modules).*\.mjs$/,
|
|
@@ -43,6 +44,7 @@ const defaultCoverageExcludes = [
|
|
|
43
44
|
"**/vitest.{workspace,projects}.[jt]s?(on)",
|
|
44
45
|
"**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}"
|
|
45
46
|
];
|
|
47
|
+
// These are the generic defaults for coverage. Providers may also set some provider specific defaults.
|
|
46
48
|
const coverageConfigDefaults = {
|
|
47
49
|
provider: "v8",
|
|
48
50
|
enabled: false,
|
package/dist/config.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { UserConfig as UserConfig$1, ConfigEnv } from 'vite';
|
|
2
2
|
export { ConfigEnv, Plugin, UserConfig as ViteUserConfig, mergeConfig } from 'vite';
|
|
3
|
-
import { c as CoverageV8Options, R as ResolvedCoverageOptions, U as UserWorkspaceConfig, d as UserProjectConfigFn, e as UserProjectConfigExport, b as TestProjectConfiguration } from './chunks/reporters.d.
|
|
4
|
-
export { f as TestProjectInlineConfiguration, g as WatcherTriggerPattern, W as WorkspaceProjectConfiguration } from './chunks/reporters.d.
|
|
5
|
-
import './chunks/vite.d.
|
|
6
|
-
import { F as FakeTimerInstallOpts } from './chunks/config.d.
|
|
3
|
+
import { c as CoverageV8Options, R as ResolvedCoverageOptions, U as UserWorkspaceConfig, d as UserProjectConfigFn, e as UserProjectConfigExport, b as TestProjectConfiguration } from './chunks/reporters.d.Bt4IGtsa.js';
|
|
4
|
+
export { f as TestProjectInlineConfiguration, g as WatcherTriggerPattern, W as WorkspaceProjectConfiguration } from './chunks/reporters.d.Bt4IGtsa.js';
|
|
5
|
+
import './chunks/vite.d.B-Kx3KCF.js';
|
|
6
|
+
import { F as FakeTimerInstallOpts } from './chunks/config.d.D2ROskhv.js';
|
|
7
7
|
import '@vitest/runner';
|
|
8
|
-
import './chunks/environment.d.
|
|
8
|
+
import './chunks/environment.d.cL3nLXbE.js';
|
|
9
9
|
import 'vitest/optional-types.js';
|
|
10
10
|
import '@vitest/utils';
|
|
11
11
|
import 'node:stream';
|
|
12
12
|
import 'node:console';
|
|
13
13
|
import '@vitest/mocker';
|
|
14
14
|
import '@vitest/utils/source-map';
|
|
15
|
-
import './chunks/worker.d.
|
|
15
|
+
import './chunks/worker.d.BKbBp2ga.js';
|
|
16
16
|
import 'vite-node';
|
|
17
17
|
import '@vitest/snapshot';
|
|
18
18
|
import '@vitest/pretty-format';
|
|
@@ -32,6 +32,7 @@ declare const extraInlineDeps: RegExp[];
|
|
|
32
32
|
|
|
33
33
|
declare const defaultInclude: string[];
|
|
34
34
|
declare const defaultExclude: string[];
|
|
35
|
+
// These are the generic defaults for coverage. Providers may also set some provider specific defaults.
|
|
35
36
|
declare const coverageConfigDefaults: ResolvedCoverageOptions;
|
|
36
37
|
declare const configDefaults: Readonly<{
|
|
37
38
|
allowOnly: boolean
|
package/dist/config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { d as defaultBrowserPort, e as extraInlineDeps } from './chunks/constants.
|
|
2
|
-
export { c as configDefaults, a as coverageConfigDefaults, d as defaultExclude, b as defaultInclude } from './chunks/defaults.
|
|
1
|
+
export { d as defaultBrowserPort, e as extraInlineDeps } from './chunks/constants.DnKduX2e.js';
|
|
2
|
+
export { c as configDefaults, a as coverageConfigDefaults, d as defaultExclude, b as defaultInclude } from './chunks/defaults.DpVH7vbg.js';
|
|
3
3
|
export { mergeConfig } from 'vite';
|
|
4
4
|
import 'node:os';
|
|
5
5
|
import './chunks/env.Dq0hM4Xv.js';
|
package/dist/coverage.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { R as ResolvedCoverageOptions, V as Vitest, C as CoverageMap, a as ReportContext } from './chunks/reporters.d.
|
|
1
|
+
import { R as ResolvedCoverageOptions, V as Vitest, C as CoverageMap, a as ReportContext } from './chunks/reporters.d.Bt4IGtsa.js';
|
|
2
2
|
import { TransformResult } from 'vite';
|
|
3
|
-
import { A as AfterSuiteRunMeta } from './chunks/environment.d.
|
|
3
|
+
import { A as AfterSuiteRunMeta } from './chunks/environment.d.cL3nLXbE.js';
|
|
4
4
|
import '@vitest/runner';
|
|
5
5
|
import '@vitest/utils';
|
|
6
6
|
import 'node:stream';
|
|
7
7
|
import 'node:console';
|
|
8
8
|
import '@vitest/mocker';
|
|
9
9
|
import '@vitest/utils/source-map';
|
|
10
|
-
import './chunks/worker.d.
|
|
10
|
+
import './chunks/worker.d.BKbBp2ga.js';
|
|
11
11
|
import 'vite-node';
|
|
12
|
-
import './chunks/config.d.
|
|
12
|
+
import './chunks/config.d.D2ROskhv.js';
|
|
13
13
|
import '@vitest/pretty-format';
|
|
14
14
|
import '@vitest/snapshot';
|
|
15
15
|
import '@vitest/snapshot/environment';
|
package/dist/coverage.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
export { B as BaseCoverageProvider } from './chunks/coverage.
|
|
1
|
+
export { B as BaseCoverageProvider } from './chunks/coverage.C73DaDgS.js';
|
|
2
2
|
import 'node:fs';
|
|
3
|
-
import './chunks/_commonjsHelpers.BFTU3MAI.js';
|
|
4
|
-
import 'util';
|
|
5
|
-
import 'path';
|
|
6
3
|
import 'pathe';
|
|
4
|
+
import 'picomatch';
|
|
7
5
|
import 'tinyrainbow';
|
|
8
|
-
import './chunks/defaults.
|
|
6
|
+
import './chunks/defaults.DpVH7vbg.js';
|
|
9
7
|
import 'node:os';
|
|
10
8
|
import './chunks/env.Dq0hM4Xv.js';
|
|
11
9
|
import 'std-env';
|
|
@@ -19,19 +17,18 @@ import 'node:url';
|
|
|
19
17
|
import 'node:assert';
|
|
20
18
|
import 'node:v8';
|
|
21
19
|
import 'node:util';
|
|
22
|
-
import './chunks/constants.BZZyIeIE.js';
|
|
23
|
-
import 'node:tty';
|
|
24
20
|
import 'vite';
|
|
21
|
+
import './chunks/constants.DnKduX2e.js';
|
|
22
|
+
import 'node:tty';
|
|
25
23
|
import 'node:events';
|
|
26
24
|
import './chunks/index.CJ0plNrh.js';
|
|
27
25
|
import 'tinypool';
|
|
28
|
-
import './chunks/typechecker.
|
|
26
|
+
import './chunks/typechecker.BgzF-6iO.js';
|
|
29
27
|
import 'node:perf_hooks';
|
|
30
28
|
import '@vitest/utils/source-map';
|
|
31
29
|
import 'tinyexec';
|
|
30
|
+
import './path.js';
|
|
32
31
|
import '@vitest/runner/utils';
|
|
33
|
-
import 'fs';
|
|
34
32
|
import 'node:worker_threads';
|
|
35
|
-
import './path.js';
|
|
36
33
|
import 'vite-node/utils';
|
|
37
34
|
import './chunks/coverage.0iPg4Wrz.js';
|
package/dist/environments.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as Environment } from './chunks/environment.d.
|
|
2
|
-
export { a as EnvironmentReturn, V as VmEnvironmentReturn } from './chunks/environment.d.
|
|
1
|
+
import { E as Environment } from './chunks/environment.d.cL3nLXbE.js';
|
|
2
|
+
export { a as EnvironmentReturn, V as VmEnvironmentReturn } from './chunks/environment.d.cL3nLXbE.js';
|
|
3
3
|
import 'vitest/optional-types.js';
|
|
4
4
|
|
|
5
5
|
declare const environments: {
|
|
@@ -10,6 +10,10 @@ declare const environments: {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
interface PopulateOptions {
|
|
13
|
+
// we bind functions such as addEventListener and others
|
|
14
|
+
// because they rely on `this` in happy-dom, and in jsdom it
|
|
15
|
+
// has a priority for getting implementation from symbols
|
|
16
|
+
// (global doesn't have these symbols, but window - does)
|
|
13
17
|
bindFunctions?: boolean;
|
|
14
18
|
additionalKeys?: string[];
|
|
15
19
|
}
|
package/dist/environments.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { e as builtinEnvironments, p as populateGlobal } from './chunks/index.
|
|
1
|
+
export { e as builtinEnvironments, p as populateGlobal } from './chunks/index.2jgTs_Q5.js';
|
|
2
2
|
import 'node:console';
|