vitest 1.5.3 → 2.0.0-beta.1
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 +172 -0
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +4 -4
- package/dist/chunks/environments-node.39w4gmlF.js +19 -0
- package/dist/chunks/{install-pkg.LE8oaA1t.js → install-pkg.DNUmWFkO.js} +2 -2
- package/dist/chunks/integrations-globals.B5Jl0grA.js +31 -0
- package/dist/chunks/{runtime-console.EO5ha7qv.js → runtime-console.CUES-L8X.js} +9 -9
- package/dist/chunks/{runtime-runBaseTests.l6qXp5eU.js → runtime-runBaseTests._dXkRAZc.js} +21 -22
- package/dist/cli.js +3 -3
- package/dist/config.cjs +2 -3
- package/dist/config.d.ts +1 -1
- package/dist/config.js +2 -3
- package/dist/coverage.d.ts +1 -1
- package/dist/coverage.js +2 -2
- package/dist/environments.d.ts +1 -1
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +7 -4
- package/dist/execute.js +3 -3
- package/dist/index.d.ts +770 -21
- package/dist/index.js +12 -12
- package/dist/node.d.ts +2 -2
- package/dist/node.js +21 -22
- package/dist/{reporters-BXNXFKfg.d.ts → reporters-MGvT5U9f.d.ts} +128 -55
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +11 -12
- package/dist/runners.d.ts +1 -1
- package/dist/runners.js +17 -18
- package/dist/snapshot.d.ts +9 -0
- package/dist/snapshot.js +8 -0
- package/dist/{suite-KPWE530F.d.ts → suite-8WAe-urM.d.ts} +1 -1
- package/dist/suite.d.ts +2 -2
- package/dist/suite.js +4 -4
- package/dist/vendor/{base.oIzAvGLe.js → base.VFkIJ66g.js} +3 -3
- package/dist/vendor/{base.Xt0Omgh7.js → base._gnK9Slw.js} +8 -1
- package/dist/vendor/{benchmark.yGkUTKnC.js → benchmark.BNLebNi5.js} +1 -1
- package/dist/vendor/{cac.RDd_SGOd.js → cac.DzKZaJu2.js} +39 -17
- package/dist/vendor/{cli-api.AmIc1Dmz.js → cli-api.DTeni0Qq.js} +3201 -404
- package/dist/vendor/{execute.2_yoIC01.js → execute.CLLNVNnK.js} +8 -3
- package/dist/vendor/{index.Fm6OikHU.js → index.BfoZyXD1.js} +20 -21
- package/dist/vendor/{index.8bPxjt7g.js → index.BpSiYbpB.js} +5 -1
- package/dist/vendor/{index.X7lgIMc_.js → index.CRxYS9H3.js} +586 -230
- package/dist/vendor/{index.QVcwRDVW.js → index.CmILuxzC.js} +8 -6
- package/dist/vendor/{index.xL8XjTLv.js → index.DP-km6lF.js} +1 -1
- package/dist/vendor/{index.SMVOaj7F.js → index._7XLd8Kd.js} +2 -2
- package/dist/vendor/{rpc.joBhAkyK.js → rpc.DRDE9Pu1.js} +2 -2
- package/dist/vendor/{run-once.Olz_Zkd8.js → run-once.DLomgGUH.js} +1 -1
- package/dist/vendor/{setup-common.5nUd4r76.js → setup-common.XeoZAW8t.js} +2 -2
- package/dist/vendor/{tasks.IknbGB2n.js → tasks.WC7M-K-v.js} +4 -1
- package/dist/vendor/{utils.VYmeMh-u.js → utils.D5gGkwyH.js} +1 -1
- package/dist/vendor/{vi.Y_w82WR8.js → vi.ClD3hi7L.js} +23 -10
- package/dist/vendor/{vm.i4FO5N37.js → vm.Bi3bljci.js} +132 -54
- package/dist/worker.js +13 -7
- package/dist/workers/forks.js +6 -6
- package/dist/workers/runVmTests.js +22 -20
- package/dist/workers/threads.js +6 -6
- package/dist/workers/vmForks.js +9 -9
- package/dist/workers/vmThreads.js +9 -9
- package/dist/workers.d.ts +1 -1
- package/dist/workers.js +14 -14
- package/package.json +33 -29
- package/snapshot.d.ts +1 -0
- package/vitest.mjs +1 -1
- package/dist/chunks/integrations-globals.Hr6znn-f.js +0 -31
- package/dist/cli-wrapper.js +0 -119
- /package/dist/chunks/{node-git.Hw101KjS.js → node-git.CCI8evVZ.js} +0 -0
- /package/dist/vendor/{_commonjsHelpers.jjO7Zipk.js → _commonjsHelpers.BFTU3MAI.js} +0 -0
- /package/dist/vendor/{constants.5J7I254_.js → constants.5SOfHUj0.js} +0 -0
- /package/dist/vendor/{coverage.E7sG1b3r.js → coverage.ChSqD-qS.js} +0 -0
- /package/dist/vendor/{date.Ns1pGd_X.js → date.BKM1wewY.js} +0 -0
- /package/dist/vendor/{env.AtSIuHFg.js → env.bmJgw1qP.js} +0 -0
- /package/dist/vendor/{global.CkGT_TMy.js → global.7bFbnyXl.js} +0 -0
- /package/dist/vendor/{index.GVFv9dZ0.js → index.DeR1hhfY.js} +0 -0
- /package/dist/vendor/{inspector.IgLX3ur5.js → inspector.hPQncR7V.js} +0 -0
- /package/dist/vendor/{utils.0uYuCbzo.js → utils.CUjzkRH7.js} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
|
|
2
|
-
import { b as bench } from './benchmark.
|
|
3
|
-
import { i as isFirstRun, a as runOnce } from './run-once.
|
|
4
|
-
import { c as createExpect, a as globalExpect, v as vi, b as vitest } from './vi.
|
|
5
|
-
import { g as getWorkerState } from './global.
|
|
2
|
+
import { b as bench } from './benchmark.BNLebNi5.js';
|
|
3
|
+
import { i as isFirstRun, a as runOnce } from './run-once.DLomgGUH.js';
|
|
4
|
+
import { c as createExpect, a as globalExpect, v as vi, b as vitest } from './vi.ClD3hi7L.js';
|
|
5
|
+
import { g as getWorkerState } from './global.7bFbnyXl.js';
|
|
6
6
|
import * as chai from 'chai';
|
|
7
7
|
import { assert, should } from 'chai';
|
|
8
8
|
|
|
@@ -61,7 +61,7 @@ var dist = {};
|
|
|
61
61
|
'branded',
|
|
62
62
|
];
|
|
63
63
|
const obj = {
|
|
64
|
-
/* eslint-disable
|
|
64
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
65
65
|
toBeAny: fn,
|
|
66
66
|
toBeUnknown: fn,
|
|
67
67
|
toBeNever: fn,
|
|
@@ -80,9 +80,11 @@ var dist = {};
|
|
|
80
80
|
toEqualTypeOf: fn,
|
|
81
81
|
toBeCallableWith: fn,
|
|
82
82
|
toBeConstructibleWith: fn,
|
|
83
|
-
/* eslint-enable
|
|
83
|
+
/* eslint-enable @typescript-eslint/no-unsafe-assignment */
|
|
84
84
|
extract: exports.expectTypeOf,
|
|
85
85
|
exclude: exports.expectTypeOf,
|
|
86
|
+
pick: exports.expectTypeOf,
|
|
87
|
+
omit: exports.expectTypeOf,
|
|
86
88
|
toHaveProperty: exports.expectTypeOf,
|
|
87
89
|
parameter: exports.expectTypeOf,
|
|
88
90
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { relative } from 'pathe';
|
|
2
2
|
import '@vitest/runner/utils';
|
|
3
3
|
import '@vitest/utils';
|
|
4
|
-
import { g as getWorkerState } from './global.
|
|
5
|
-
import './env.
|
|
4
|
+
import { g as getWorkerState } from './global.7bFbnyXl.js';
|
|
5
|
+
import './env.bmJgw1qP.js';
|
|
6
6
|
|
|
7
7
|
function getRunMode() {
|
|
8
8
|
return getWorkerState().config.mode;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getSafeTimers } from '@vitest/utils';
|
|
2
|
-
import { c as createBirpc } from './index.
|
|
3
|
-
import { g as getWorkerState } from './global.
|
|
2
|
+
import { c as createBirpc } from './index.BpSiYbpB.js';
|
|
3
|
+
import { g as getWorkerState } from './global.7bFbnyXl.js';
|
|
4
4
|
|
|
5
5
|
const { get } = Reflect;
|
|
6
6
|
function withSafeTimers(fn) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { setSafeTimers } from '@vitest/utils';
|
|
2
2
|
import { addSerializer } from '@vitest/snapshot';
|
|
3
|
-
import { r as resetRunOnceCounter } from './run-once.
|
|
3
|
+
import { r as resetRunOnceCounter } from './run-once.DLomgGUH.js';
|
|
4
4
|
|
|
5
5
|
let globalSetup = false;
|
|
6
6
|
async function setupCommonEnv(config) {
|
|
@@ -12,7 +12,7 @@ async function setupCommonEnv(config) {
|
|
|
12
12
|
globalSetup = true;
|
|
13
13
|
setSafeTimers();
|
|
14
14
|
if (config.globals)
|
|
15
|
-
(await import('../chunks/integrations-globals.
|
|
15
|
+
(await import('../chunks/integrations-globals.B5Jl0grA.js')).registerApiGlobally();
|
|
16
16
|
}
|
|
17
17
|
function setupDefines(defines) {
|
|
18
18
|
for (const key in defines)
|
|
@@ -10,5 +10,8 @@ function hasFailedSnapshot(suite) {
|
|
|
10
10
|
function getFullName(task, separator = " > ") {
|
|
11
11
|
return getNames(task).join(separator);
|
|
12
12
|
}
|
|
13
|
+
function getTestName(task, separator = " > ") {
|
|
14
|
+
return getNames(task).slice(1).join(separator);
|
|
15
|
+
}
|
|
13
16
|
|
|
14
|
-
export { getFullName as g, hasFailedSnapshot as h };
|
|
17
|
+
export { getFullName as a, getTestName as g, hasFailedSnapshot as h };
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as chai$1 from 'chai';
|
|
2
|
-
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers.
|
|
2
|
+
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers.BFTU3MAI.js';
|
|
3
3
|
import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT as GLOBAL_EXPECT$1, ASYMMETRIC_MATCHERS_OBJECT as ASYMMETRIC_MATCHERS_OBJECT$1, getState, setState, addCustomEqualityTesters } from '@vitest/expect';
|
|
4
4
|
import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest/snapshot';
|
|
5
5
|
import { getNames } from '@vitest/runner/utils';
|
|
6
6
|
import '@vitest/utils/error';
|
|
7
7
|
import { getCurrentTest } from '@vitest/runner';
|
|
8
|
-
import { g as
|
|
9
|
-
import { g as getWorkerState, a as getCurrentEnvironment } from './global.
|
|
8
|
+
import { g as getTestName } from './tasks.WC7M-K-v.js';
|
|
9
|
+
import { g as getWorkerState, a as getCurrentEnvironment } from './global.7bFbnyXl.js';
|
|
10
10
|
import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
|
|
11
11
|
import { parseSingleStack } from '@vitest/utils/source-map';
|
|
12
|
-
import { i as isChildProcess } from './base.
|
|
13
|
-
import { R as RealDate, r as resetDate, m as mockDate } from './date.
|
|
12
|
+
import { i as isChildProcess } from './base._gnK9Slw.js';
|
|
13
|
+
import { R as RealDate, r as resetDate, m as mockDate } from './date.BKM1wewY.js';
|
|
14
14
|
import { spyOn, fn, isMockFunction, mocks } from '@vitest/spy';
|
|
15
15
|
|
|
16
16
|
function resetModules(modules, resetMocks = false) {
|
|
@@ -208,11 +208,10 @@ function getError(expected, promise) {
|
|
|
208
208
|
}
|
|
209
209
|
const SnapshotPlugin = (chai, utils) => {
|
|
210
210
|
const getTestNames = (test) => {
|
|
211
|
-
var _a;
|
|
212
211
|
if (!test)
|
|
213
212
|
return {};
|
|
214
213
|
return {
|
|
215
|
-
filepath:
|
|
214
|
+
filepath: test.file.filepath,
|
|
216
215
|
name: getNames(test).slice(1).join(" > ")
|
|
217
216
|
};
|
|
218
217
|
};
|
|
@@ -361,7 +360,6 @@ chai$1.use(SnapshotPlugin);
|
|
|
361
360
|
chai$1.use(JestAsymmetricMatchers);
|
|
362
361
|
|
|
363
362
|
function createExpect(test) {
|
|
364
|
-
var _a;
|
|
365
363
|
const expect = (value, message) => {
|
|
366
364
|
const { assertionCalls } = getState(expect);
|
|
367
365
|
setState({ assertionCalls: assertionCalls + 1, soft: false }, expect);
|
|
@@ -377,6 +375,7 @@ function createExpect(test) {
|
|
|
377
375
|
expect.getState = () => getState(expect);
|
|
378
376
|
expect.setState = (state) => setState(state, expect);
|
|
379
377
|
const globalState = getState(globalThis[GLOBAL_EXPECT$1]) || {};
|
|
378
|
+
const testPath = getTestFile(test);
|
|
380
379
|
setState({
|
|
381
380
|
// this should also add "snapshotState" that is added conditionally
|
|
382
381
|
...globalState,
|
|
@@ -386,8 +385,8 @@ function createExpect(test) {
|
|
|
386
385
|
expectedAssertionsNumber: null,
|
|
387
386
|
expectedAssertionsNumberErrorGen: null,
|
|
388
387
|
environment: getCurrentEnvironment(),
|
|
389
|
-
testPath
|
|
390
|
-
currentTestName: test ?
|
|
388
|
+
testPath,
|
|
389
|
+
currentTestName: test ? getTestName(test) : globalState.currentTestName
|
|
391
390
|
}, expect);
|
|
392
391
|
expect.extend = (matchers) => chai$1.expect.extend(expect, matchers);
|
|
393
392
|
expect.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters);
|
|
@@ -423,6 +422,12 @@ function createExpect(test) {
|
|
|
423
422
|
chai$1.util.addMethod(expect, "hasAssertions", hasAssertions);
|
|
424
423
|
return expect;
|
|
425
424
|
}
|
|
425
|
+
function getTestFile(test) {
|
|
426
|
+
if (test)
|
|
427
|
+
return test.file.filepath;
|
|
428
|
+
const state = getWorkerState();
|
|
429
|
+
return state.filepath;
|
|
430
|
+
}
|
|
426
431
|
const globalExpect = createExpect();
|
|
427
432
|
Object.defineProperty(globalThis, GLOBAL_EXPECT$1, {
|
|
428
433
|
value: globalExpect,
|
|
@@ -3434,6 +3439,8 @@ function createVitest() {
|
|
|
3434
3439
|
return factory();
|
|
3435
3440
|
},
|
|
3436
3441
|
mock(path, factory) {
|
|
3442
|
+
if (typeof path !== "string")
|
|
3443
|
+
throw new Error(`vi.mock() expects a string path, but received a ${typeof path}`);
|
|
3437
3444
|
const importer = getImporter();
|
|
3438
3445
|
_mocker.queueMock(
|
|
3439
3446
|
path,
|
|
@@ -3443,9 +3450,13 @@ function createVitest() {
|
|
|
3443
3450
|
);
|
|
3444
3451
|
},
|
|
3445
3452
|
unmock(path) {
|
|
3453
|
+
if (typeof path !== "string")
|
|
3454
|
+
throw new Error(`vi.unmock() expects a string path, but received a ${typeof path}`);
|
|
3446
3455
|
_mocker.queueUnmock(path, getImporter());
|
|
3447
3456
|
},
|
|
3448
3457
|
doMock(path, factory) {
|
|
3458
|
+
if (typeof path !== "string")
|
|
3459
|
+
throw new Error(`vi.doMock() expects a string path, but received a ${typeof path}`);
|
|
3449
3460
|
const importer = getImporter();
|
|
3450
3461
|
_mocker.queueMock(
|
|
3451
3462
|
path,
|
|
@@ -3455,6 +3466,8 @@ function createVitest() {
|
|
|
3455
3466
|
);
|
|
3456
3467
|
},
|
|
3457
3468
|
doUnmock(path) {
|
|
3469
|
+
if (typeof path !== "string")
|
|
3470
|
+
throw new Error(`vi.doUnmock() expects a string path, but received a ${typeof path}`);
|
|
3458
3471
|
_mocker.queueUnmock(path, getImporter());
|
|
3459
3472
|
},
|
|
3460
3473
|
async importActual(path) {
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import vm, { isContext } from 'node:vm';
|
|
2
2
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
3
3
|
import { dirname, basename, extname, normalize, join, resolve } from 'pathe';
|
|
4
|
-
import { createCustomConsole } from '../chunks/runtime-console.
|
|
5
|
-
import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute.
|
|
4
|
+
import { createCustomConsole } from '../chunks/runtime-console.CUES-L8X.js';
|
|
5
|
+
import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute.CLLNVNnK.js';
|
|
6
6
|
import { distDir } from '../path.js';
|
|
7
7
|
import { dirname as dirname$1 } from 'node:path';
|
|
8
|
-
import { statSync, existsSync, readFileSync } from 'node:fs';
|
|
8
|
+
import { statSync, existsSync, promises, readFileSync } from 'node:fs';
|
|
9
9
|
import { isNodeBuiltin, isPrimitive, toArray, getCachedData, setCacheData } 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
12
|
import '@vitest/runner/utils';
|
|
13
13
|
import '@vitest/utils';
|
|
14
|
-
import { p as provideWorkerState } from './global.
|
|
15
|
-
import './env.
|
|
14
|
+
import { p as provideWorkerState } from './global.7bFbnyXl.js';
|
|
15
|
+
import './env.bmJgw1qP.js';
|
|
16
16
|
|
|
17
17
|
const _require = createRequire(import.meta.url);
|
|
18
18
|
const requiresCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -244,15 +244,26 @@ function interopCommonJsModule(interopDefault, mod) {
|
|
|
244
244
|
const SyntheticModule$1 = vm.SyntheticModule;
|
|
245
245
|
const SourceTextModule = vm.SourceTextModule;
|
|
246
246
|
|
|
247
|
+
var __defProp$1 = Object.defineProperty;
|
|
248
|
+
var __typeError$1 = (msg) => {
|
|
249
|
+
throw TypeError(msg);
|
|
250
|
+
};
|
|
251
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
252
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
253
|
+
var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
|
|
254
|
+
var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
255
|
+
var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
256
|
+
var _httpIp;
|
|
247
257
|
const dataURIRegex = /^data:(?<mime>text\/javascript|application\/json|application\/wasm)(?:;(?<encoding>charset=utf-8|base64))?,(?<code>.*)$/;
|
|
248
258
|
class EsmExecutor {
|
|
249
259
|
constructor(executor, options) {
|
|
250
260
|
this.executor = executor;
|
|
261
|
+
__publicField$1(this, "moduleCache", /* @__PURE__ */ new Map());
|
|
262
|
+
__publicField$1(this, "esmLinkMap", /* @__PURE__ */ new WeakMap());
|
|
263
|
+
__publicField$1(this, "context");
|
|
264
|
+
__privateAdd$1(this, _httpIp, IPnumber("127.0.0.0"));
|
|
251
265
|
this.context = options.context;
|
|
252
266
|
}
|
|
253
|
-
moduleCache = /* @__PURE__ */ new Map();
|
|
254
|
-
esmLinkMap = /* @__PURE__ */ new WeakMap();
|
|
255
|
-
context;
|
|
256
267
|
async evaluateModule(m) {
|
|
257
268
|
if (m.status === "unlinked") {
|
|
258
269
|
this.esmLinkMap.set(
|
|
@@ -265,11 +276,17 @@ class EsmExecutor {
|
|
|
265
276
|
await m.evaluate();
|
|
266
277
|
return m;
|
|
267
278
|
}
|
|
268
|
-
async createEsModule(
|
|
269
|
-
const cached = this.moduleCache.get(
|
|
279
|
+
async createEsModule(fileURL, getCode) {
|
|
280
|
+
const cached = this.moduleCache.get(fileURL);
|
|
270
281
|
if (cached)
|
|
271
282
|
return cached;
|
|
272
|
-
|
|
283
|
+
const promise = this.loadEsModule(fileURL, getCode);
|
|
284
|
+
this.moduleCache.set(fileURL, promise);
|
|
285
|
+
return promise;
|
|
286
|
+
}
|
|
287
|
+
async loadEsModule(fileURL, getCode) {
|
|
288
|
+
const code = await getCode();
|
|
289
|
+
if (fileURL.endsWith(".json")) {
|
|
273
290
|
const m2 = new SyntheticModule$1(
|
|
274
291
|
["default"],
|
|
275
292
|
() => {
|
|
@@ -277,13 +294,13 @@ class EsmExecutor {
|
|
|
277
294
|
m2.setExport("default", result);
|
|
278
295
|
}
|
|
279
296
|
);
|
|
280
|
-
this.moduleCache.set(
|
|
297
|
+
this.moduleCache.set(fileURL, m2);
|
|
281
298
|
return m2;
|
|
282
299
|
}
|
|
283
300
|
const m = new SourceTextModule(
|
|
284
301
|
code,
|
|
285
302
|
{
|
|
286
|
-
identifier:
|
|
303
|
+
identifier: fileURL,
|
|
287
304
|
context: this.context,
|
|
288
305
|
importModuleDynamically: this.executor.importModuleDynamically,
|
|
289
306
|
initializeImportMeta: (meta, mod) => {
|
|
@@ -299,17 +316,29 @@ class EsmExecutor {
|
|
|
299
316
|
}
|
|
300
317
|
}
|
|
301
318
|
);
|
|
302
|
-
this.moduleCache.set(
|
|
319
|
+
this.moduleCache.set(fileURL, m);
|
|
303
320
|
return m;
|
|
304
321
|
}
|
|
305
|
-
async createWebAssemblyModule(fileUrl,
|
|
322
|
+
async createWebAssemblyModule(fileUrl, getCode) {
|
|
306
323
|
const cached = this.moduleCache.get(fileUrl);
|
|
307
324
|
if (cached)
|
|
308
325
|
return cached;
|
|
309
|
-
const m = this.loadWebAssemblyModule(
|
|
326
|
+
const m = this.loadWebAssemblyModule(getCode(), fileUrl);
|
|
310
327
|
this.moduleCache.set(fileUrl, m);
|
|
311
328
|
return m;
|
|
312
329
|
}
|
|
330
|
+
async createNetworkModule(fileUrl) {
|
|
331
|
+
if (fileUrl.startsWith("http:")) {
|
|
332
|
+
const url = new URL(fileUrl);
|
|
333
|
+
if (url.hostname !== "localhost" && url.hostname !== "::1" && (IPnumber(url.hostname) & IPmask(8)) !== __privateGet$1(this, _httpIp)) {
|
|
334
|
+
throw new Error(
|
|
335
|
+
// we don't know the importer, so it's undefined (the same happens in --pool=threads)
|
|
336
|
+
`import of '${fileUrl}' by undefined is not supported: http can only be used to load local resources (use https instead).`
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return this.createEsModule(fileUrl, () => fetch(fileUrl).then((r) => r.text()));
|
|
341
|
+
}
|
|
313
342
|
async loadWebAssemblyModule(source, identifier) {
|
|
314
343
|
const cached = this.moduleCache.get(identifier);
|
|
315
344
|
if (cached)
|
|
@@ -393,9 +422,19 @@ class EsmExecutor {
|
|
|
393
422
|
this.moduleCache.set(identifier, module);
|
|
394
423
|
return module;
|
|
395
424
|
}
|
|
396
|
-
return this.createEsModule(identifier, code);
|
|
425
|
+
return this.createEsModule(identifier, () => code);
|
|
397
426
|
}
|
|
398
427
|
}
|
|
428
|
+
_httpIp = new WeakMap();
|
|
429
|
+
function IPnumber(address) {
|
|
430
|
+
const ip = address.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/);
|
|
431
|
+
if (ip)
|
|
432
|
+
return (+ip[1] << 24) + (+ip[2] << 16) + (+ip[3] << 8) + +ip[4];
|
|
433
|
+
throw new Error(`Expected IP address, received ${address}`);
|
|
434
|
+
}
|
|
435
|
+
function IPmask(maskSize) {
|
|
436
|
+
return -1 << 32 - maskSize;
|
|
437
|
+
}
|
|
399
438
|
|
|
400
439
|
const CLIENT_ID = "/@vite/client";
|
|
401
440
|
const CLIENT_FILE = pathToFileURL(CLIENT_ID).href;
|
|
@@ -433,10 +472,12 @@ class ViteExecutor {
|
|
|
433
472
|
const cached = this.esm.resolveCachedModule(fileUrl);
|
|
434
473
|
if (cached)
|
|
435
474
|
return cached;
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
475
|
+
return this.esm.createEsModule(fileUrl, async () => {
|
|
476
|
+
const result = await this.options.transform(fileUrl, "web");
|
|
477
|
+
if (!result.code)
|
|
478
|
+
throw new Error(`[vitest] Failed to transform ${fileUrl}. Does the file exist?`);
|
|
479
|
+
return result.code;
|
|
480
|
+
});
|
|
440
481
|
}
|
|
441
482
|
createViteClientModule() {
|
|
442
483
|
const identifier = CLIENT_ID;
|
|
@@ -476,11 +517,40 @@ class ViteExecutor {
|
|
|
476
517
|
};
|
|
477
518
|
}
|
|
478
519
|
|
|
520
|
+
var __defProp = Object.defineProperty;
|
|
521
|
+
var __typeError = (msg) => {
|
|
522
|
+
throw TypeError(msg);
|
|
523
|
+
};
|
|
524
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
525
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
526
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
527
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
528
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
529
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
530
|
+
var _networkSupported;
|
|
479
531
|
const SyntheticModule = vm.SyntheticModule;
|
|
480
532
|
const nativeResolve = import.meta.resolve;
|
|
481
533
|
class ExternalModulesExecutor {
|
|
482
534
|
constructor(options) {
|
|
483
535
|
this.options = options;
|
|
536
|
+
__publicField(this, "cjs");
|
|
537
|
+
__publicField(this, "esm");
|
|
538
|
+
__publicField(this, "vite");
|
|
539
|
+
__publicField(this, "context");
|
|
540
|
+
__publicField(this, "fs");
|
|
541
|
+
__publicField(this, "resolvers", []);
|
|
542
|
+
__privateAdd(this, _networkSupported, null);
|
|
543
|
+
// dynamic import can be used in both ESM and CJS, so we have it in the executor
|
|
544
|
+
__publicField(this, "importModuleDynamically", async (specifier, referencer) => {
|
|
545
|
+
const module = await this.resolveModule(specifier, referencer.identifier);
|
|
546
|
+
return await this.esm.evaluateModule(module);
|
|
547
|
+
});
|
|
548
|
+
__publicField(this, "resolveModule", async (specifier, referencer) => {
|
|
549
|
+
let identifier = this.resolve(specifier, referencer);
|
|
550
|
+
if (identifier instanceof Promise)
|
|
551
|
+
identifier = await identifier;
|
|
552
|
+
return await this.createModule(identifier);
|
|
553
|
+
});
|
|
484
554
|
this.context = options.context;
|
|
485
555
|
this.fs = options.fileMap;
|
|
486
556
|
this.esm = new EsmExecutor(this, {
|
|
@@ -499,23 +569,17 @@ class ExternalModulesExecutor {
|
|
|
499
569
|
});
|
|
500
570
|
this.resolvers = [this.vite.resolve];
|
|
501
571
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
return this.
|
|
512
|
-
}
|
|
513
|
-
resolveModule = async (specifier, referencer) => {
|
|
514
|
-
let identifier = this.resolve(specifier, referencer);
|
|
515
|
-
if (identifier instanceof Promise)
|
|
516
|
-
identifier = await identifier;
|
|
517
|
-
return await this.createModule(identifier);
|
|
518
|
-
};
|
|
572
|
+
async import(identifier) {
|
|
573
|
+
const module = await this.createModule(identifier);
|
|
574
|
+
await this.esm.evaluateModule(module);
|
|
575
|
+
return module.namespace;
|
|
576
|
+
}
|
|
577
|
+
require(identifier) {
|
|
578
|
+
return this.cjs.require(identifier);
|
|
579
|
+
}
|
|
580
|
+
createRequire(identifier) {
|
|
581
|
+
return this.cjs.createRequire(identifier);
|
|
582
|
+
}
|
|
519
583
|
resolve(specifier, parent) {
|
|
520
584
|
for (const resolver of this.resolvers) {
|
|
521
585
|
const id = resolver(specifier, parent);
|
|
@@ -587,6 +651,8 @@ class ExternalModulesExecutor {
|
|
|
587
651
|
const extension = extname(identifier);
|
|
588
652
|
if (extension === ".node" || isNodeBuiltin(identifier))
|
|
589
653
|
return { type: "builtin", url: identifier, path: identifier };
|
|
654
|
+
if (this.isNetworkSupported && (identifier.startsWith("http:") || identifier.startsWith("https:")))
|
|
655
|
+
return { type: "network", url: identifier, path: identifier };
|
|
590
656
|
const isFileUrl = identifier.startsWith("file://");
|
|
591
657
|
const pathUrl = isFileUrl ? fileURLToPath(identifier.split("?")[0]) : identifier;
|
|
592
658
|
const fileUrl = isFileUrl ? identifier : pathToFileURL(pathUrl).toString();
|
|
@@ -614,7 +680,7 @@ class ExternalModulesExecutor {
|
|
|
614
680
|
}
|
|
615
681
|
switch (type) {
|
|
616
682
|
case "data":
|
|
617
|
-
return this.esm.createDataModule(identifier);
|
|
683
|
+
return await this.esm.createDataModule(identifier);
|
|
618
684
|
case "builtin": {
|
|
619
685
|
const exports = this.require(identifier);
|
|
620
686
|
return this.wrapCoreSynteticModule(identifier, exports);
|
|
@@ -622,38 +688,50 @@ class ExternalModulesExecutor {
|
|
|
622
688
|
case "vite":
|
|
623
689
|
return await this.vite.createViteModule(url);
|
|
624
690
|
case "wasm":
|
|
625
|
-
return await this.esm.createWebAssemblyModule(url, this.fs.readBuffer(path));
|
|
691
|
+
return await this.esm.createWebAssemblyModule(url, () => this.fs.readBuffer(path));
|
|
626
692
|
case "module":
|
|
627
|
-
return await this.esm.createEsModule(url, this.fs.
|
|
693
|
+
return await this.esm.createEsModule(url, () => this.fs.readFileAsync(path));
|
|
628
694
|
case "commonjs": {
|
|
629
695
|
const exports = this.require(path);
|
|
630
696
|
return this.wrapCommonJsSynteticModule(identifier, exports);
|
|
631
697
|
}
|
|
698
|
+
case "network":
|
|
699
|
+
return await this.esm.createNetworkModule(url);
|
|
632
700
|
default: {
|
|
633
701
|
const _deadend = type;
|
|
634
702
|
return _deadend;
|
|
635
703
|
}
|
|
636
704
|
}
|
|
637
705
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
706
|
+
get isNetworkSupported() {
|
|
707
|
+
var _a;
|
|
708
|
+
if (__privateGet(this, _networkSupported) == null) {
|
|
709
|
+
if (process.execArgv.includes("--experimental-network-imports"))
|
|
710
|
+
__privateSet(this, _networkSupported, true);
|
|
711
|
+
else if ((_a = process.env.NODE_OPTIONS) == null ? void 0 : _a.includes("--experimental-network-imports"))
|
|
712
|
+
__privateSet(this, _networkSupported, true);
|
|
713
|
+
else
|
|
714
|
+
__privateSet(this, _networkSupported, false);
|
|
715
|
+
}
|
|
716
|
+
return __privateGet(this, _networkSupported);
|
|
648
717
|
}
|
|
649
718
|
}
|
|
719
|
+
_networkSupported = new WeakMap();
|
|
650
720
|
|
|
651
721
|
class FileMap {
|
|
652
722
|
fsCache = /* @__PURE__ */ new Map();
|
|
653
723
|
fsBufferCache = /* @__PURE__ */ new Map();
|
|
724
|
+
async readFileAsync(path) {
|
|
725
|
+
const cached = this.fsCache.get(path);
|
|
726
|
+
if (cached != null)
|
|
727
|
+
return cached;
|
|
728
|
+
const source = await promises.readFile(path, "utf-8");
|
|
729
|
+
this.fsCache.set(path, source);
|
|
730
|
+
return source;
|
|
731
|
+
}
|
|
654
732
|
readFile(path) {
|
|
655
733
|
const cached = this.fsCache.get(path);
|
|
656
|
-
if (cached)
|
|
734
|
+
if (cached != null)
|
|
657
735
|
return cached;
|
|
658
736
|
const source = readFileSync(path, "utf-8");
|
|
659
737
|
this.fsCache.set(path, source);
|
|
@@ -661,7 +739,7 @@ class FileMap {
|
|
|
661
739
|
}
|
|
662
740
|
readBuffer(path) {
|
|
663
741
|
const cached = this.fsBufferCache.get(path);
|
|
664
|
-
if (cached)
|
|
742
|
+
if (cached != null)
|
|
665
743
|
return cached;
|
|
666
744
|
const buffer = readFileSync(path);
|
|
667
745
|
this.fsBufferCache.set(path, buffer);
|
|
@@ -693,7 +771,7 @@ async function runVmTests(state) {
|
|
|
693
771
|
provideWorkerState(context, state);
|
|
694
772
|
context.process = process;
|
|
695
773
|
context.global = context;
|
|
696
|
-
context.console = state.config.disableConsoleIntercept ? console : createCustomConsole();
|
|
774
|
+
context.console = state.config.disableConsoleIntercept ? console : createCustomConsole(state);
|
|
697
775
|
context.setImmediate = setImmediate;
|
|
698
776
|
context.clearImmediate = clearImmediate;
|
|
699
777
|
const stubs = getDefaultRequestStubs(context);
|
package/dist/worker.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { pathToFileURL } from 'node:url';
|
|
2
2
|
import { workerId } from 'tinypool';
|
|
3
3
|
import { ViteNodeRunner, ModuleCacheMap } from 'vite-node/client';
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
4
5
|
import { resolve, normalize } from 'pathe';
|
|
5
|
-
import { e as environments } from './vendor/index.
|
|
6
|
-
import { i as isChildProcess, s as setProcessTitle } from './vendor/base.
|
|
7
|
-
import { s as setupInspect } from './vendor/inspector.
|
|
8
|
-
import { c as createRuntimeRpc, a as rpcDone } from './vendor/rpc.
|
|
6
|
+
import { e as environments } from './vendor/index.DeR1hhfY.js';
|
|
7
|
+
import { i as isChildProcess, s as setProcessTitle } from './vendor/base._gnK9Slw.js';
|
|
8
|
+
import { s as setupInspect } from './vendor/inspector.hPQncR7V.js';
|
|
9
|
+
import { c as createRuntimeRpc, a as rpcDone } from './vendor/rpc.DRDE9Pu1.js';
|
|
9
10
|
import 'node:console';
|
|
10
11
|
import '@vitest/utils';
|
|
11
12
|
import 'node:module';
|
|
12
|
-
import './vendor/index.
|
|
13
|
-
import './vendor/global.
|
|
13
|
+
import './vendor/index.BpSiYbpB.js';
|
|
14
|
+
import './vendor/global.7bFbnyXl.js';
|
|
14
15
|
|
|
15
16
|
function isBuiltinEnvironment(env) {
|
|
16
17
|
return env in environments;
|
|
@@ -31,7 +32,12 @@ async function loadEnvironment(ctx, rpc) {
|
|
|
31
32
|
return environments[name];
|
|
32
33
|
const loader = await createEnvironmentLoader({
|
|
33
34
|
root: ctx.config.root,
|
|
34
|
-
fetchModule: (id) =>
|
|
35
|
+
fetchModule: async (id) => {
|
|
36
|
+
const result = await rpc.fetch(id, "ssr");
|
|
37
|
+
if (result.id)
|
|
38
|
+
return { code: readFileSync(result.id, "utf-8") };
|
|
39
|
+
return result;
|
|
40
|
+
},
|
|
35
41
|
resolveId: (id, importer) => rpc.resolveId(id, importer, "ssr")
|
|
36
42
|
});
|
|
37
43
|
const root = loader.root;
|
package/dist/workers/forks.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import v8 from 'node:v8';
|
|
2
|
-
import { c as createForksRpcOptions, u as unwrapSerializableConfig } from '../vendor/utils.
|
|
3
|
-
import { r as runBaseTests } from '../vendor/base.
|
|
2
|
+
import { c as createForksRpcOptions, u as unwrapSerializableConfig } from '../vendor/utils.CUjzkRH7.js';
|
|
3
|
+
import { r as runBaseTests } from '../vendor/base.VFkIJ66g.js';
|
|
4
4
|
import '@vitest/utils';
|
|
5
5
|
import 'vite-node/client';
|
|
6
|
-
import '../vendor/global.
|
|
7
|
-
import '../vendor/execute.
|
|
6
|
+
import '../vendor/global.7bFbnyXl.js';
|
|
7
|
+
import '../vendor/execute.CLLNVNnK.js';
|
|
8
8
|
import 'node:vm';
|
|
9
9
|
import 'node:url';
|
|
10
|
+
import 'node:fs';
|
|
10
11
|
import 'vite-node/utils';
|
|
11
12
|
import 'pathe';
|
|
12
13
|
import '@vitest/utils/error';
|
|
13
14
|
import '../path.js';
|
|
14
|
-
import '
|
|
15
|
-
import '../vendor/base.Xt0Omgh7.js';
|
|
15
|
+
import '../vendor/base._gnK9Slw.js';
|
|
16
16
|
|
|
17
17
|
class ForksBaseWorker {
|
|
18
18
|
getRpcOptions() {
|