@voidzero-dev/vite-plus-test 0.1.9 → 0.1.10
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 +181 -1
- package/dist/@vitest/browser/client/.vite/manifest.json +6 -6
- package/dist/@vitest/browser/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-Di71CKDo.js +63 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.ico +0 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.svg +49 -4
- package/dist/@vitest/browser/client/__vitest__/index.html +2 -2
- package/dist/@vitest/browser/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
- package/dist/@vitest/browser/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
- package/dist/@vitest/browser/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
- package/dist/@vitest/browser/client/favicon.svg +49 -4
- package/dist/@vitest/browser/client/orchestrator.html +2 -2
- package/dist/@vitest/browser/client/tester/tester.html +2 -2
- package/dist/@vitest/browser/client.js +20 -13
- package/dist/@vitest/browser/context.d.ts +160 -10
- package/dist/@vitest/browser/context.js +108 -22
- package/dist/@vitest/browser/expect-element.js +23 -28
- package/dist/@vitest/browser/index-5Pe7X7sp.js +7 -0
- package/dist/@vitest/browser/index.d.ts +20 -2
- package/dist/@vitest/browser/index.js +5706 -159
- package/dist/@vitest/browser/locators.d.ts +14 -3
- package/dist/@vitest/browser/locators.js +1 -1
- package/dist/@vitest/browser-playwright/index.d.ts +22 -5
- package/dist/@vitest/browser-playwright/index.js +169 -61
- package/dist/@vitest/browser-preview/index.d.ts +14 -1
- package/dist/@vitest/browser-preview/locators.js +31 -18
- package/dist/@vitest/browser-webdriverio/index.d.ts +17 -3
- package/dist/@vitest/browser-webdriverio/index.js +22 -2
- package/dist/@vitest/browser-webdriverio/locators.js +84 -7
- package/dist/@vitest/expect/index.d.ts +172 -54
- package/dist/@vitest/expect/index.js +124 -67
- package/dist/@vitest/mocker/auto-register.js +1 -0
- package/dist/@vitest/mocker/automock.d.ts +1 -0
- package/dist/@vitest/mocker/automock.js +5 -0
- package/dist/@vitest/mocker/browser.d.ts +4 -4
- package/dist/@vitest/mocker/browser.js +1 -0
- package/dist/@vitest/mocker/chunk-automock.js +182 -14
- package/dist/@vitest/mocker/chunk-helpers.js +44 -0
- package/dist/@vitest/mocker/chunk-hoistMocks.js +659 -0
- package/dist/@vitest/mocker/chunk-mocker.js +41 -30
- package/dist/@vitest/mocker/chunk-registry.js +21 -7
- package/dist/@vitest/mocker/chunk-utils.js +18 -7
- package/dist/@vitest/mocker/hoistMocks.d-w2ILr1dG.d.ts +739 -0
- package/dist/@vitest/mocker/{index.d-C-sLYZi-.d.ts → index.d-B41z0AuW.d.ts} +1 -1
- package/dist/@vitest/mocker/index.d.ts +2 -2
- package/dist/@vitest/mocker/index.js +18 -3
- package/dist/@vitest/mocker/{mocker.d-TnKRhz7N.d.ts → mocker.d-QEntlm6J.d.ts} +10 -5
- package/dist/@vitest/mocker/node.d.ts +5 -734
- package/dist/@vitest/mocker/node.js +29 -587
- package/dist/@vitest/mocker/redirect.js +4 -4
- package/dist/@vitest/mocker/register.d.ts +3 -3
- package/dist/@vitest/mocker/register.js +1 -0
- package/dist/@vitest/mocker/transforms.d.ts +6 -0
- package/dist/@vitest/mocker/transforms.js +8 -0
- package/dist/@vitest/mocker/{types.d-B8CCKmHt.d.ts → types.d-BjI5eAwu.d.ts} +23 -7
- package/dist/@vitest/pretty-format/index.d.ts +11 -1
- package/dist/@vitest/pretty-format/index.js +33 -4
- package/dist/@vitest/runner/chunk-tasks.js +305 -37
- package/dist/@vitest/runner/index.d.ts +5 -6
- package/dist/@vitest/runner/index.js +1146 -455
- package/dist/@vitest/runner/{tasks.d-C7UxawJ9.d.ts → tasks.d-D2GKpdwQ.d.ts} +726 -55
- package/dist/@vitest/runner/types.d.ts +2 -182
- package/dist/@vitest/runner/utils.d.ts +16 -8
- package/dist/@vitest/runner/utils.js +1 -1
- package/dist/@vitest/snapshot/{environment.d-DHdQ1Csl.d.ts → environment.d-DOJxxZV9.d.ts} +2 -7
- package/dist/@vitest/snapshot/environment.d.ts +2 -1
- package/dist/@vitest/snapshot/environment.js +1 -1
- package/dist/@vitest/snapshot/index.d.ts +4 -3
- package/dist/@vitest/snapshot/index.js +21 -550
- package/dist/@vitest/snapshot/manager.d.ts +3 -2
- package/dist/@vitest/snapshot/manager.js +1 -1
- package/dist/@vitest/snapshot/{rawSnapshot.d-lFsMJFUd.d.ts → rawSnapshot.d-U2kJUxDr.d.ts} +1 -1
- package/dist/@vitest/spy/index.d.ts +34 -4
- package/dist/@vitest/spy/index.js +69 -19
- package/dist/@vitest/utils/diff.js +11 -9
- package/dist/@vitest/utils/display.d.ts +2 -1
- package/dist/@vitest/utils/display.js +38 -5
- package/dist/@vitest/utils/error.d.ts +2 -1
- package/dist/@vitest/utils/error.js +1 -2
- package/dist/@vitest/utils/helpers.d.ts +4 -1
- package/dist/@vitest/utils/helpers.js +43 -1
- package/dist/@vitest/utils/resolver.js +1 -2
- package/dist/@vitest/utils/serialize.js +6 -6
- package/dist/@vitest/utils/source-map/node.d.ts +6 -0
- package/dist/@vitest/utils/source-map/node.js +23 -0
- package/dist/@vitest/utils/source-map.js +15 -5
- package/dist/browser.d.ts +3 -2
- package/dist/browser.js +2 -2
- package/dist/chunks/acorn.B2iPLyUM.js +5958 -0
- package/dist/chunks/{base.CJ0Y4ePK.js → base.DM0-RqVb.js} +54 -16
- package/dist/chunks/{benchmark.B3N2zMcH.js → benchmark.D0SlKNbZ.js} +1 -1
- package/dist/chunks/{browser.d.ChKACdzH.d.ts → browser.d.X3SXoOCV.d.ts} +4 -1
- package/dist/chunks/{cac.DVeoLl0M.js → cac.CWGDZnXT.js} +979 -20
- package/dist/chunks/{cli-api.B7PN_QUv.js → cli-api.DuT9iuvY.js} +8764 -7898
- package/dist/chunks/{config.d.Cy95HiCx.d.ts → config.d.EJLVE3es.d.ts} +30 -15
- package/dist/chunks/{console.Cf-YriPC.js → console.3WNpx0tS.js} +3 -2
- package/dist/chunks/{constants.D_Q9UYh-.js → constants.CPYnjOGj.js} +4 -2
- package/dist/chunks/coverage.Bri33R1t.js +1050 -0
- package/dist/chunks/{creator.DAmOKTvJ.js → creator.DgVhQm5q.js} +35 -4
- package/dist/chunks/{defaults.BOqNVLsY.js → defaults.CdU2lD-q.js} +4 -3
- package/dist/chunks/{global.d.B15mdLcR.d.ts → global.d.x-ILCfAE.d.ts} +1 -2
- package/dist/chunks/{globals.DOayXfHP.js → globals.BXNGLnTL.js} +11 -10
- package/dist/chunks/{coverage.AVPTjMgw.js → index.BCY_7LL2.js} +5 -959
- package/dist/chunks/{index.C5r1PdPD.js → index.CEzQDJGb.js} +1 -1
- package/dist/chunks/{index.D3XRDfWc.js → index.CMESou6r.js} +26 -1
- package/dist/chunks/{index.6Qv1eEA6.js → index.DGNSnENe.js} +95 -9
- package/dist/chunks/{index.M8mOzt4Y.js → index.DXMFO5MJ.js} +3279 -2914
- package/dist/chunks/{index.Z5E_ObnR.js → index.DlDSLQD3.js} +7 -3
- package/dist/chunks/{index.CyBMJtT7.js → index.EY6TCHpo.js} +10 -8
- package/dist/chunks/{index.D4KonVSU.js → index.og1WyBLx.js} +18 -3
- package/dist/chunks/{init-forks._y3TW739.js → init-forks.DeArv0jT.js} +1 -1
- package/dist/chunks/{init-threads.DBO2kn-p.js → init-threads.-2OUl4Nn.js} +1 -1
- package/dist/chunks/{init.B6MLFIaN.js → init.DICorXCo.js} +52 -13
- package/dist/chunks/native.DPzPHdi5.js +148 -0
- package/dist/chunks/nativeModuleMocker.DndvSdL6.js +206 -0
- package/dist/chunks/nativeModuleRunner.BIakptoF.js +36 -0
- package/dist/chunks/{node.Ce0vMQM7.js → node.COQbm6gK.js} +1 -1
- package/dist/chunks/{plugin.d.CtqpEehP.d.ts → plugin.d.BuW-flqo.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CWXNI2jG.d.ts → reporters.d.DVUYHHhe.d.ts} +328 -79
- package/dist/chunks/rpc.MzXet3jl.js +144 -0
- package/dist/chunks/{rpc.d.RH3apGEf.d.ts → rpc.d.BFMWpdph.d.ts} +10 -2
- package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.B41N_kPE.js} +3 -3
- package/dist/chunks/{startModuleRunner.DEj0jb3e.js → startVitestModuleRunner.C3ZR-4J3.js} +265 -405
- package/dist/chunks/{suite.d.BJWk38HB.d.ts → suite.d.udJtyAgw.d.ts} +1 -1
- package/dist/chunks/{vi.2VT5v0um.js → test.CTcmp4Su.js} +538 -181
- package/dist/chunks/{utils.DvEY5TfP.js → utils.BX5Fg8C4.js} +8 -1
- package/dist/chunks/{vm.D3epNOPZ.js → vm.Dh2rTtmP.js} +48 -8
- package/dist/chunks/{worker.d.Dyxm8DEL.d.ts → worker.d.B84sVRy0.d.ts} +2 -2
- package/dist/cli.js +6 -5
- package/dist/client/.vite/manifest.json +6 -6
- package/dist/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
- package/dist/client/__vitest__/assets/index-Di71CKDo.js +63 -0
- package/dist/client/__vitest__/favicon.ico +0 -0
- package/dist/client/__vitest__/favicon.svg +49 -4
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
- package/dist/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
- package/dist/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
- package/dist/client/favicon.svg +49 -4
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/tester/tester.html +2 -2
- package/dist/client.js +20 -13
- package/dist/config.cjs +3 -2
- package/dist/config.d.ts +13 -12
- package/dist/config.js +2 -2
- package/dist/context.js +108 -22
- package/dist/coverage.d.ts +12 -8
- package/dist/coverage.js +8 -5
- package/dist/environments.js +3 -1
- package/dist/expect-element.js +23 -23
- package/dist/index-5Pe7X7sp.js +7 -0
- package/dist/index.d.ts +66 -27
- package/dist/index.js +10 -9
- package/dist/locators.d.ts +14 -3
- package/dist/locators.js +1 -1
- package/dist/module-evaluator.d.ts +11 -1
- package/dist/module-evaluator.js +43 -26
- package/dist/node.d.ts +28 -14
- package/dist/node.js +42 -40
- package/dist/nodejs-worker-loader.js +41 -0
- package/dist/plugins/mocker-transforms.mjs +2 -0
- package/dist/plugins/utils-source-map-node.mjs +2 -0
- package/dist/reporters.d.ts +8 -8
- package/dist/reporters.js +7 -5
- package/dist/runners.d.ts +24 -5
- 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.d.ts +1 -1
- package/dist/suite.js +4 -2
- package/dist/vendor/blazediff_core.d.mts +1 -0
- package/dist/vendor/blazediff_core.mjs +117 -0
- package/dist/vendor/chai.mjs +4 -249
- package/dist/vendor/convert-source-map.d.mts +1 -0
- package/dist/vendor/convert-source-map.mjs +150 -0
- package/dist/vendor/expect-type.d.mts +14 -7
- package/dist/vendor/expect-type.mjs +5 -5
- package/dist/vendor/std-env.d.mts +131 -40
- package/dist/vendor/std-env.mjs +114 -117
- package/dist/worker.d.ts +6 -6
- package/dist/worker.js +27 -21
- package/dist/workers/forks.js +23 -17
- package/dist/workers/runVmTests.js +18 -16
- package/dist/workers/threads.js +23 -17
- package/dist/workers/vmForks.js +15 -12
- package/dist/workers/vmThreads.js +15 -12
- package/globals.d.ts +2 -0
- package/package.json +35 -26
- package/suppress-warnings.cjs +1 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +0 -57
- package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
- package/dist/@vitest/browser/index-D6m36C6U.js +0 -11
- package/dist/@vitest/utils/chunk-_commonjsHelpers.js +0 -5
- package/dist/@vitest/utils/highlight.d.ts +0 -9
- package/dist/@vitest/utils/highlight.js +0 -538
- 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/client/__vitest__/assets/index-BUCFJtth.js +0 -57
- package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
- package/dist/index-D6m36C6U.js +0 -6
- package/dist/mocker.d.ts +0 -1
- package/dist/mocker.js +0 -1
- package/dist/module-runner.js +0 -17
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { b as bench } from './benchmark.
|
|
1
|
+
import { v as vi, N as NodeBenchmarkRunner, T as TestRunner, a as assert, c as createExpect, g as globalExpect, i as inject, s as should, b as vitest } from './test.CTcmp4Su.js';
|
|
2
|
+
import { b as bench } from './benchmark.D0SlKNbZ.js';
|
|
3
3
|
import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
|
|
4
4
|
import { expectTypeOf } from '../vendor/expect-type.mjs';
|
|
5
|
-
import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, recordArtifact, suite, test } from '../@vitest/runner/index.js';
|
|
5
|
+
import { afterAll, afterEach, aroundAll, aroundEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, recordArtifact, suite, test } from '../@vitest/runner/index.js';
|
|
6
6
|
import { chai } from '../@vitest/expect/index.js';
|
|
7
7
|
|
|
8
8
|
const assertType = function assertType() {};
|
|
9
9
|
|
|
10
10
|
var index = /*#__PURE__*/Object.freeze({
|
|
11
11
|
__proto__: null,
|
|
12
|
+
BenchmarkRunner: NodeBenchmarkRunner,
|
|
12
13
|
EvaluatedModules: VitestEvaluatedModules,
|
|
14
|
+
TestRunner: TestRunner,
|
|
13
15
|
afterAll: afterAll,
|
|
14
16
|
afterEach: afterEach,
|
|
17
|
+
aroundAll: aroundAll,
|
|
18
|
+
aroundEach: aroundEach,
|
|
15
19
|
assert: assert,
|
|
16
20
|
assertType: assertType,
|
|
17
21
|
beforeAll: beforeAll,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { URL } from 'node:url';
|
|
1
|
+
import { URL as URL$1 } from 'node:url';
|
|
2
2
|
import { Console } from 'node:console';
|
|
3
3
|
|
|
4
4
|
// SEE https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/interfaces.js
|
|
@@ -537,7 +537,7 @@ var jsdom = {
|
|
|
537
537
|
}
|
|
538
538
|
};
|
|
539
539
|
function createCompatRequest(utils) {
|
|
540
|
-
|
|
540
|
+
class Request extends NodeRequest_ {
|
|
541
541
|
constructor(...args) {
|
|
542
542
|
const [input, init] = args;
|
|
543
543
|
if (init?.body != null) {
|
|
@@ -550,21 +550,23 @@ function createCompatRequest(utils) {
|
|
|
550
550
|
static [Symbol.hasInstance](instance) {
|
|
551
551
|
return instance instanceof NodeRequest_;
|
|
552
552
|
}
|
|
553
|
-
}
|
|
553
|
+
}
|
|
554
|
+
return Request;
|
|
554
555
|
}
|
|
555
556
|
function createJSDOMCompatURL(utils) {
|
|
556
|
-
|
|
557
|
+
class URL extends URL$1 {
|
|
557
558
|
static createObjectURL(blob) {
|
|
558
559
|
if (blob instanceof utils.window.Blob) {
|
|
559
560
|
const compatBlob = utils.makeCompatBlob(blob);
|
|
560
|
-
return URL.createObjectURL(compatBlob);
|
|
561
|
+
return URL$1.createObjectURL(compatBlob);
|
|
561
562
|
}
|
|
562
|
-
return URL.createObjectURL(blob);
|
|
563
|
+
return URL$1.createObjectURL(blob);
|
|
563
564
|
}
|
|
564
565
|
static [Symbol.hasInstance](instance) {
|
|
565
|
-
return instance instanceof URL;
|
|
566
|
+
return instance instanceof URL$1;
|
|
566
567
|
}
|
|
567
|
-
}
|
|
568
|
+
}
|
|
569
|
+
return URL;
|
|
568
570
|
}
|
|
569
571
|
function createCompatUtils(window) {
|
|
570
572
|
// this returns a hidden Symbol(impl)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isAbsolute, resolve, dirname, join } from 'node:path';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import 'node:module';
|
|
4
4
|
import 'node:url';
|
|
@@ -6,6 +6,21 @@ import { g as getDefaultExportFromCjs } from './_commonjsHelpers.D26ty3Ew.js';
|
|
|
6
6
|
import require$$0 from 'readline';
|
|
7
7
|
import require$$0$1 from 'events';
|
|
8
8
|
|
|
9
|
+
function _mergeNamespaces(n, m) {
|
|
10
|
+
m.forEach(function (e) {
|
|
11
|
+
e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default' && !(k in n)) {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
9
24
|
/**
|
|
10
25
|
* Resolve an absolute path from {@link root}, but only
|
|
11
26
|
* if {@link input} isn't already absolute.
|
|
@@ -6335,9 +6350,9 @@ function requirePrompts () {
|
|
|
6335
6350
|
var promptsExports = requirePrompts();
|
|
6336
6351
|
var prompt = /*@__PURE__*/getDefaultExportFromCjs(promptsExports);
|
|
6337
6352
|
|
|
6338
|
-
var index = /*#__PURE__*/
|
|
6353
|
+
var index = /*#__PURE__*/_mergeNamespaces({
|
|
6339
6354
|
__proto__: null,
|
|
6340
6355
|
default: prompt
|
|
6341
|
-
});
|
|
6356
|
+
}, [promptsExports]);
|
|
6342
6357
|
|
|
6343
6358
|
export { any as a, index as i, prompt as p };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isMainThread, parentPort } from 'node:worker_threads';
|
|
2
|
-
import { i as init } from './init.
|
|
2
|
+
import { i as init } from './init.DICorXCo.js';
|
|
3
3
|
|
|
4
4
|
if (isMainThread || !parentPort) throw new Error("Expected worker to be run in node:worker_threads");
|
|
5
5
|
function workerInit(options) {
|
|
@@ -2,15 +2,17 @@ import { readFileSync } from 'node:fs';
|
|
|
2
2
|
import { isBuiltin } from 'node:module';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
import { resolve } from '../vendor/pathe.mjs';
|
|
5
|
-
import { ModuleRunner } from '@voidzero-dev/vite-plus-core/module-runner';
|
|
6
|
-
import { b as VitestTransport } from './
|
|
7
|
-
import { e as environments } from './index.
|
|
5
|
+
import { ModuleRunner, EvaluatedModules } from '@voidzero-dev/vite-plus-core/module-runner';
|
|
6
|
+
import { b as VitestTransport } from './startVitestModuleRunner.C3ZR-4J3.js';
|
|
7
|
+
import { e as environments } from './index.EY6TCHpo.js';
|
|
8
|
+
import { serializeValue } from '../@vitest/utils/serialize.js';
|
|
8
9
|
import { serializeError } from '../@vitest/utils/error.js';
|
|
9
10
|
import { T as Traces } from './traces.CCmnQaNT.js';
|
|
10
|
-
import { o as onCancel, a as rpcDone, c as createRuntimeRpc } from './rpc.
|
|
11
|
+
import { o as onCancel, a as rpcDone, c as createRuntimeRpc } from './rpc.MzXet3jl.js';
|
|
11
12
|
import { createStackString, parseStacktrace } from '../@vitest/utils/source-map.js';
|
|
12
13
|
import { s as setupInspect } from './inspector.CvyFGlXm.js';
|
|
13
14
|
import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
|
|
15
|
+
import { E as EnvironmentTeardownError } from './utils.BX5Fg8C4.js';
|
|
14
16
|
|
|
15
17
|
function isBuiltinEnvironment(env) {
|
|
16
18
|
return env in environments;
|
|
@@ -40,17 +42,17 @@ function createEnvironmentLoader(root, rpc) {
|
|
|
40
42
|
async resolveId(id, importer) {
|
|
41
43
|
return rpc.resolve(id, importer, "__vitest__");
|
|
42
44
|
}
|
|
43
|
-
})
|
|
45
|
+
}, new EvaluatedModules(), /* @__PURE__ */ new WeakMap())
|
|
44
46
|
});
|
|
45
47
|
_loaders.set(root, moduleRunner);
|
|
46
48
|
}
|
|
47
49
|
return _loaders.get(root);
|
|
48
50
|
}
|
|
49
|
-
async function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
async function loadNativeEnvironment(name, root, traces) {
|
|
52
|
+
const packageId = name[0] === "." || name[0] === "/" ? pathToFileURL(resolve(root, name)).toString() : import.meta.resolve(`vitest-environment-${name}`, pathToFileURL(root).toString());
|
|
53
|
+
return resolveEnvironmentFromModule(name, packageId, await traces.$("vitest.runtime.environment.import", () => import(packageId)));
|
|
54
|
+
}
|
|
55
|
+
function resolveEnvironmentFromModule(name, packageId, pkg) {
|
|
54
56
|
if (!pkg || !pkg.default || typeof pkg.default !== "object") throw new TypeError(`Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "setup" or/and "setupVM" method.`);
|
|
55
57
|
const environment = pkg.default;
|
|
56
58
|
if (environment.transformMode != null && environment.transformMode !== "web" && environment.transformMode !== "ssr") throw new TypeError(`Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "transformMode" method equal to "ssr" or "web", received "${environment.transformMode}".`);
|
|
@@ -59,8 +61,15 @@ async function loadEnvironment(name, root, rpc, traces) {
|
|
|
59
61
|
// keep for backwards compat
|
|
60
62
|
environment.viteEnvironment ??= environment.transformMode === "ssr" ? "ssr" : "client";
|
|
61
63
|
}
|
|
64
|
+
return environment;
|
|
65
|
+
}
|
|
66
|
+
async function loadEnvironment(name, root, rpc, traces, viteModuleRunner) {
|
|
67
|
+
if (isBuiltinEnvironment(name)) return { environment: environments[name] };
|
|
68
|
+
if (!viteModuleRunner) return { environment: await loadNativeEnvironment(name, root, traces) };
|
|
69
|
+
const loader = createEnvironmentLoader(root, rpc);
|
|
70
|
+
const packageId = name[0] === "." || name[0] === "/" ? resolve(root, name) : (await traces.$("vitest.runtime.environment.resolve", () => rpc.resolve(`vitest-environment-${name}`, void 0, "__vitest__")))?.id ?? resolve(root, name);
|
|
62
71
|
return {
|
|
63
|
-
environment,
|
|
72
|
+
environment: resolveEnvironmentFromModule(name, packageId, await traces.$("vitest.runtime.environment.import", () => loader.import(packageId))),
|
|
64
73
|
loader
|
|
65
74
|
};
|
|
66
75
|
}
|
|
@@ -80,6 +89,36 @@ function emitModuleRunner(moduleRunner) {
|
|
|
80
89
|
moduleRunnerListeners.forEach((l) => l(moduleRunner));
|
|
81
90
|
}
|
|
82
91
|
|
|
92
|
+
// Store globals in case tests overwrite them
|
|
93
|
+
const processListeners = process.listeners.bind(process);
|
|
94
|
+
const processOn = process.on.bind(process);
|
|
95
|
+
const processOff = process.off.bind(process);
|
|
96
|
+
const dispose = [];
|
|
97
|
+
function listenForErrors(state) {
|
|
98
|
+
dispose.forEach((fn) => fn());
|
|
99
|
+
dispose.length = 0;
|
|
100
|
+
function catchError(err, type, event) {
|
|
101
|
+
const worker = state();
|
|
102
|
+
// if there is another listener, assume that it's handled by user code
|
|
103
|
+
// one is Vitest's own listener
|
|
104
|
+
if (processListeners(event).length > 1) return;
|
|
105
|
+
const error = serializeValue(err);
|
|
106
|
+
if (typeof error === "object" && error != null) {
|
|
107
|
+
error.VITEST_TEST_NAME = worker.current?.type === "test" ? worker.current.name : void 0;
|
|
108
|
+
if (worker.filepath) error.VITEST_TEST_PATH = worker.filepath;
|
|
109
|
+
}
|
|
110
|
+
state().rpc.onUnhandledError(error, type);
|
|
111
|
+
}
|
|
112
|
+
const uncaughtException = (e) => catchError(e, "Uncaught Exception", "uncaughtException");
|
|
113
|
+
const unhandledRejection = (e) => catchError(e, "Unhandled Rejection", "unhandledRejection");
|
|
114
|
+
processOn("uncaughtException", uncaughtException);
|
|
115
|
+
processOn("unhandledRejection", unhandledRejection);
|
|
116
|
+
dispose.push(() => {
|
|
117
|
+
processOff("uncaughtException", uncaughtException);
|
|
118
|
+
processOff("unhandledRejection", unhandledRejection);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
83
122
|
const resolvingModules = /* @__PURE__ */ new Set();
|
|
84
123
|
async function execute(method, ctx, worker, traces) {
|
|
85
124
|
const prepareStart = performance.now();
|
|
@@ -90,7 +129,7 @@ async function execute(method, ctx, worker, traces) {
|
|
|
90
129
|
// do not close the RPC channel so that we can get the error messages sent to the main thread
|
|
91
130
|
cleanups.push(async () => {
|
|
92
131
|
await Promise.all(rpc.$rejectPendingCalls(({ method, reject }) => {
|
|
93
|
-
reject(
|
|
132
|
+
reject(new EnvironmentTeardownError(`[vitest-worker]: Closing rpc while "${method}" was pending`));
|
|
94
133
|
}));
|
|
95
134
|
});
|
|
96
135
|
const state = {
|
|
@@ -331,4 +370,4 @@ function getFilesWithLocations(files) {
|
|
|
331
370
|
});
|
|
332
371
|
}
|
|
333
372
|
|
|
334
|
-
export { emitModuleRunner as e, init as i, loadEnvironment as l };
|
|
373
|
+
export { listenForErrors as a, emitModuleRunner as e, init as i, loadEnvironment as l };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import module$1, { isBuiltin } from 'node:module';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { MessageChannel } from 'node:worker_threads';
|
|
4
|
+
import { initSyntaxLexers, hoistMocks } from '../@vitest/mocker/transforms.js';
|
|
5
|
+
import { cleanUrl } from '../@vitest/utils/helpers.js';
|
|
6
|
+
import { p as parse } from './acorn.B2iPLyUM.js';
|
|
7
|
+
import MagicString from '../vendor/magic-string.mjs';
|
|
8
|
+
import { resolve } from '../vendor/pathe.mjs';
|
|
9
|
+
import c from '../vendor/tinyrainbow.mjs';
|
|
10
|
+
import { distDir } from '../path.js';
|
|
11
|
+
import { t as toBuiltin } from './modules.BJuCwlRJ.js';
|
|
12
|
+
import 'node:path';
|
|
13
|
+
|
|
14
|
+
const NOW_LENGTH = Date.now().toString().length;
|
|
15
|
+
const REGEXP_VITEST = new RegExp(`%3Fvitest=\\d{${NOW_LENGTH}}`);
|
|
16
|
+
const REGEXP_MOCK_ACTUAL = /\?mock=actual/;
|
|
17
|
+
async function setupNodeLoaderHooks(worker) {
|
|
18
|
+
if (module$1.setSourceMapsSupport) module$1.setSourceMapsSupport(true);
|
|
19
|
+
else if (process.setSourceMapsEnabled) process.setSourceMapsEnabled(true);
|
|
20
|
+
if (worker.config.experimental.nodeLoader !== false) await initSyntaxLexers();
|
|
21
|
+
if (typeof module$1.registerHooks === "function") module$1.registerHooks({
|
|
22
|
+
resolve(specifier, context, nextResolve) {
|
|
23
|
+
if (specifier.includes("mock=actual")) {
|
|
24
|
+
// url is already resolved by `importActual`
|
|
25
|
+
const moduleId = specifier.replace(REGEXP_MOCK_ACTUAL, "");
|
|
26
|
+
const builtin = isBuiltin(moduleId);
|
|
27
|
+
return {
|
|
28
|
+
url: builtin ? toBuiltin(moduleId) : moduleId,
|
|
29
|
+
format: builtin ? "builtin" : void 0,
|
|
30
|
+
shortCircuit: true
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const isVitest = specifier.includes("%3Fvitest=");
|
|
34
|
+
const result = nextResolve(isVitest ? specifier.replace(REGEXP_VITEST, "") : specifier, context);
|
|
35
|
+
// avoid tracking /node_modules/ module graph for performance reasons
|
|
36
|
+
if (context.parentURL && result.url && !result.url.includes("/node_modules/")) worker.rpc.ensureModuleGraphEntry(result.url, context.parentURL).catch(() => {
|
|
37
|
+
// ignore errors
|
|
38
|
+
});
|
|
39
|
+
// this is require for in-source tests to be invalidated if
|
|
40
|
+
// one of the files already imported it in --maxWorkers=1 --no-isolate
|
|
41
|
+
if (isVitest) result.url = `${result.url}?vitest=${Date.now()}`;
|
|
42
|
+
if (worker.config.experimental.nodeLoader === false || !context.parentURL || result.url.includes(distDir) || context.parentURL?.toString().includes(distDir)) return result;
|
|
43
|
+
const mockedResult = getNativeMocker()?.resolveMockedModule(result.url, context.parentURL);
|
|
44
|
+
if (mockedResult != null) return mockedResult;
|
|
45
|
+
return result;
|
|
46
|
+
},
|
|
47
|
+
load: worker.config.experimental.nodeLoader === false ? void 0 : createLoadHook()
|
|
48
|
+
});
|
|
49
|
+
else if (module$1.register) {
|
|
50
|
+
if (worker.config.experimental.nodeLoader !== false) console.warn(`${c.bgYellow(" WARNING ")} "module.registerHooks" is not supported in Node.js ${process.version}. This means that some features like module mocking or in-source testing are not supported. Upgrade your Node.js version to at least 22.15 or disable "experimental.nodeLoader" flag manually.\n`);
|
|
51
|
+
const { port1, port2 } = new MessageChannel();
|
|
52
|
+
port1.unref();
|
|
53
|
+
port2.unref();
|
|
54
|
+
port1.on("message", (data) => {
|
|
55
|
+
if (!data || typeof data !== "object") return;
|
|
56
|
+
switch (data.event) {
|
|
57
|
+
case "register-module-graph-entry": {
|
|
58
|
+
const { url, parentURL } = data;
|
|
59
|
+
worker.rpc.ensureModuleGraphEntry(url, parentURL);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
default: console.error("Unknown message event:", data.event);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
/** Registers {@link file://./../nodejsWorkerLoader.ts} */
|
|
66
|
+
module$1.register("#nodejs-worker-loader", {
|
|
67
|
+
parentURL: import.meta.url,
|
|
68
|
+
data: { port: port2 },
|
|
69
|
+
transferList: [port2]
|
|
70
|
+
});
|
|
71
|
+
} else if (!process.versions.deno && !process.versions.bun) console.warn("\"module.registerHooks\" and \"module.register\" are not supported. Some Vitest features may not work. Please, use Node.js 18.19.0 or higher.");
|
|
72
|
+
}
|
|
73
|
+
function replaceInSourceMarker(url, source, ms) {
|
|
74
|
+
const re = /import\.meta\.vitest/g;
|
|
75
|
+
let match;
|
|
76
|
+
let overridden = false;
|
|
77
|
+
// eslint-disable-next-line no-cond-assign
|
|
78
|
+
while (match = re.exec(source)) {
|
|
79
|
+
const { index, "0": code } = match;
|
|
80
|
+
overridden = true;
|
|
81
|
+
// should it support process.vitest for CJS modules?
|
|
82
|
+
ms().overwrite(index, index + code.length, "IMPORT_META_TEST()");
|
|
83
|
+
}
|
|
84
|
+
if (overridden) {
|
|
85
|
+
const filename = resolve(fileURLToPath(url));
|
|
86
|
+
// appending instead of prepending because functions are hoisted and we don't change the offset
|
|
87
|
+
ms().append(`;\nfunction IMPORT_META_TEST() { return typeof __vitest_worker__ !== 'undefined' && __vitest_worker__.filepath === "${filename.replace(/"/g, "\\\"")}" ? __vitest_index__ : undefined; }`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const ignoreFormats = new Set([
|
|
91
|
+
"addon",
|
|
92
|
+
"builtin",
|
|
93
|
+
"wasm"
|
|
94
|
+
]);
|
|
95
|
+
function createLoadHook(_worker) {
|
|
96
|
+
return (url, context, nextLoad) => {
|
|
97
|
+
const result = url.includes("mock=") && isBuiltin(cleanUrl(url)) ? { format: "commonjs" } : nextLoad(url, context);
|
|
98
|
+
if (result.format && ignoreFormats.has(result.format) || url.includes(distDir)) return result;
|
|
99
|
+
const mocker = getNativeMocker();
|
|
100
|
+
mocker?.checkCircularManualMock(url);
|
|
101
|
+
if (url.includes("mock=automock") || url.includes("mock=autospy")) {
|
|
102
|
+
const automockedResult = mocker?.loadAutomock(url, result);
|
|
103
|
+
if (automockedResult != null) return automockedResult;
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
if (url.includes("mock=manual")) {
|
|
107
|
+
const mockedResult = mocker?.loadManualMock(url, result);
|
|
108
|
+
if (mockedResult != null) return mockedResult;
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
// ignore non-vitest modules for performance reasons,
|
|
112
|
+
// vi.hoisted and vi.mock won't work outside of test files or setup files
|
|
113
|
+
if (!result.source || !url.includes("vitest=")) return result;
|
|
114
|
+
const filename = url.startsWith("file://") ? fileURLToPath(url) : url;
|
|
115
|
+
const source = result.source.toString();
|
|
116
|
+
const transformedCode = result.format?.includes("typescript") ? module$1.stripTypeScriptTypes(source) : source;
|
|
117
|
+
let _ms;
|
|
118
|
+
const ms = () => _ms || (_ms = new MagicString(source));
|
|
119
|
+
if (source.includes("import.meta.vitest")) replaceInSourceMarker(url, source, ms);
|
|
120
|
+
hoistMocks(transformedCode, filename, (code) => parse(code, {
|
|
121
|
+
ecmaVersion: "latest",
|
|
122
|
+
sourceType: result.format === "module" || result.format === "module-typescript" || result.format === "typescript" ? "module" : "script"
|
|
123
|
+
}), {
|
|
124
|
+
magicString: ms,
|
|
125
|
+
globalThisAccessor: "\"__vitest_mocker__\""
|
|
126
|
+
});
|
|
127
|
+
let code;
|
|
128
|
+
if (_ms) code = `${_ms.toString()}\n//# sourceMappingURL=${genSourceMapUrl(_ms.generateMap({
|
|
129
|
+
hires: "boundary",
|
|
130
|
+
source: filename
|
|
131
|
+
}))}`;
|
|
132
|
+
else code = source;
|
|
133
|
+
return {
|
|
134
|
+
format: result.format,
|
|
135
|
+
shortCircuit: true,
|
|
136
|
+
source: code
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function genSourceMapUrl(map) {
|
|
141
|
+
if (typeof map !== "string") map = JSON.stringify(map);
|
|
142
|
+
return `data:application/json;base64,${Buffer.from(map).toString("base64")}`;
|
|
143
|
+
}
|
|
144
|
+
function getNativeMocker() {
|
|
145
|
+
return typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : void 0;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export { setupNodeLoaderHooks };
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import module$1, { isBuiltin } from 'node:module';
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
3
|
+
import { automockModule, createManualModuleSource, collectModuleExports } from '../@vitest/mocker/transforms.js';
|
|
4
|
+
import { cleanUrl, createDefer } from '../@vitest/utils/helpers.js';
|
|
5
|
+
import { p as parse } from './acorn.B2iPLyUM.js';
|
|
6
|
+
import { isAbsolute } from '../vendor/pathe.mjs';
|
|
7
|
+
import { t as toBuiltin } from './modules.BJuCwlRJ.js';
|
|
8
|
+
import { B as BareModuleMocker, n as normalizeModuleId } from './startVitestModuleRunner.C3ZR-4J3.js';
|
|
9
|
+
import 'node:fs';
|
|
10
|
+
import './utils.BX5Fg8C4.js';
|
|
11
|
+
import '../@vitest/utils/timers.js';
|
|
12
|
+
import '../path.js';
|
|
13
|
+
import 'node:path';
|
|
14
|
+
import '../module-evaluator.js';
|
|
15
|
+
import 'node:vm';
|
|
16
|
+
import '@voidzero-dev/vite-plus-core/module-runner';
|
|
17
|
+
import './traces.CCmnQaNT.js';
|
|
18
|
+
import '../@vitest/mocker/index.js';
|
|
19
|
+
import '../@vitest/mocker/redirect.js';
|
|
20
|
+
|
|
21
|
+
class NativeModuleMocker extends BareModuleMocker {
|
|
22
|
+
wrapDynamicImport(moduleFactory) {
|
|
23
|
+
if (typeof moduleFactory === "function") return new Promise((resolve, reject) => {
|
|
24
|
+
this.resolveMocks().finally(() => {
|
|
25
|
+
moduleFactory().then(resolve, reject);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
return moduleFactory;
|
|
29
|
+
}
|
|
30
|
+
resolveMockedModule(url, parentURL) {
|
|
31
|
+
// don't mock modules inside of packages because there is
|
|
32
|
+
// a high chance that it uses `require` which is not mockable
|
|
33
|
+
// because we use top-level await in "manual" mocks.
|
|
34
|
+
// for the sake of consistency we don't support mocking anything at all
|
|
35
|
+
if (parentURL.includes("/node_modules/")) return;
|
|
36
|
+
const moduleId = normalizeModuleId(url.startsWith("file://") ? fileURLToPath(url) : url);
|
|
37
|
+
const mockedModule = this.getDependencyMock(moduleId);
|
|
38
|
+
if (!mockedModule) return;
|
|
39
|
+
if (mockedModule.type === "redirect") return {
|
|
40
|
+
url: pathToFileURL(mockedModule.redirect).toString(),
|
|
41
|
+
shortCircuit: true
|
|
42
|
+
};
|
|
43
|
+
if (mockedModule.type === "automock" || mockedModule.type === "autospy") return {
|
|
44
|
+
url: injectQuery(url, parentURL, `mock=${mockedModule.type}`),
|
|
45
|
+
shortCircuit: true
|
|
46
|
+
};
|
|
47
|
+
if (mockedModule.type === "manual") return {
|
|
48
|
+
url: injectQuery(url, parentURL, "mock=manual"),
|
|
49
|
+
shortCircuit: true
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
loadAutomock(url, result) {
|
|
53
|
+
const moduleId = cleanUrl(normalizeModuleId(url.startsWith("file://") ? fileURLToPath(url) : url));
|
|
54
|
+
let source;
|
|
55
|
+
if (isBuiltin(moduleId)) {
|
|
56
|
+
const builtinModule = getBuiltinModule(moduleId);
|
|
57
|
+
const exports$1 = Object.keys(builtinModule);
|
|
58
|
+
source = `
|
|
59
|
+
import * as builtinModule from '${toBuiltin(moduleId)}?mock=actual'
|
|
60
|
+
|
|
61
|
+
${exports$1.map((key, index) => {
|
|
62
|
+
return `
|
|
63
|
+
const __${index} = builtinModule["${key}"]
|
|
64
|
+
export { __${index} as "${key}" }
|
|
65
|
+
`;
|
|
66
|
+
}).join("")}`;
|
|
67
|
+
} else source = result.source?.toString();
|
|
68
|
+
if (source == null) return;
|
|
69
|
+
const mockType = url.includes("mock=automock") ? "automock" : "autospy";
|
|
70
|
+
const transformedCode = transformCode(source, result.format || "module", moduleId);
|
|
71
|
+
try {
|
|
72
|
+
const ms = automockModule(transformedCode, mockType, (code) => parse(code, {
|
|
73
|
+
sourceType: "module",
|
|
74
|
+
ecmaVersion: "latest"
|
|
75
|
+
}), { id: moduleId });
|
|
76
|
+
return {
|
|
77
|
+
format: "module",
|
|
78
|
+
source: `${ms.toString()}\n//# sourceMappingURL=${genSourceMapUrl(ms.generateMap({
|
|
79
|
+
hires: "boundary",
|
|
80
|
+
source: moduleId
|
|
81
|
+
}))}`,
|
|
82
|
+
shortCircuit: true
|
|
83
|
+
};
|
|
84
|
+
} catch (cause) {
|
|
85
|
+
throw new Error(`Cannot automock '${url}' because it failed to parse.`, { cause });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
loadManualMock(url, result) {
|
|
89
|
+
const moduleId = cleanUrl(normalizeModuleId(url.startsWith("file://") ? fileURLToPath(url) : url));
|
|
90
|
+
// should not be possible
|
|
91
|
+
if (this.getDependencyMock(moduleId)?.type !== "manual") {
|
|
92
|
+
console.warn(`Vitest detected unregistered manual mock ${moduleId}. This is a bug in Vitest. Please, open a new issue with reproduction.`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (isBuiltin(moduleId)) {
|
|
96
|
+
const builtinModule = getBuiltinModule(toBuiltin(moduleId));
|
|
97
|
+
return {
|
|
98
|
+
format: "module",
|
|
99
|
+
source: createManualModuleSource(moduleId, Object.keys(builtinModule)),
|
|
100
|
+
shortCircuit: true
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (!result.source) return;
|
|
104
|
+
const transformedCode = transformCode(result.source.toString(), result.format || "module", moduleId);
|
|
105
|
+
if (transformedCode == null) return;
|
|
106
|
+
const format = result.format?.startsWith("module") ? "module" : "commonjs";
|
|
107
|
+
try {
|
|
108
|
+
return {
|
|
109
|
+
format: "module",
|
|
110
|
+
source: createManualModuleSource(moduleId, collectModuleExports(moduleId, transformedCode, format)),
|
|
111
|
+
shortCircuit: true
|
|
112
|
+
};
|
|
113
|
+
} catch (cause) {
|
|
114
|
+
throw new Error(`Failed to mock '${url}'. See the cause for more information.`, { cause });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
processedModules = /* @__PURE__ */ new Map();
|
|
118
|
+
checkCircularManualMock(url) {
|
|
119
|
+
const id = cleanUrl(normalizeModuleId(url.startsWith("file://") ? fileURLToPath(url) : url));
|
|
120
|
+
this.processedModules.set(id, (this.processedModules.get(id) ?? 0) + 1);
|
|
121
|
+
// the module is mocked and requested a second time, let's resolve
|
|
122
|
+
// the factory function that will redefine the exports later
|
|
123
|
+
if (this.originalModulePromises.has(id)) {
|
|
124
|
+
const factoryPromise = this.factoryPromises.get(id);
|
|
125
|
+
this.originalModulePromises.get(id)?.resolve({ __factoryPromise: factoryPromise });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
originalModulePromises = /* @__PURE__ */ new Map();
|
|
129
|
+
factoryPromises = /* @__PURE__ */ new Map();
|
|
130
|
+
// potential performance improvement:
|
|
131
|
+
// store by URL, not ids, no need to call url.*to* methods and normalizeModuleId
|
|
132
|
+
getFactoryModule(id) {
|
|
133
|
+
const mock = this.getMockerRegistry().getById(id);
|
|
134
|
+
if (!mock || mock.type !== "manual") throw new Error(`Mock ${id} wasn't registered. This is probably a Vitest error. Please, open a new issue with reproduction.`);
|
|
135
|
+
const mockResult = mock.resolve();
|
|
136
|
+
if (mockResult instanceof Promise) {
|
|
137
|
+
// to avoid circular dependency, we resolve this function as {__factoryPromise} in `checkCircularManualMock`
|
|
138
|
+
// when it's requested the second time. then the exports are exposed as `undefined`,
|
|
139
|
+
// but later redefined when the promise is actually resolved
|
|
140
|
+
const promise = createDefer();
|
|
141
|
+
promise.finally(() => {
|
|
142
|
+
this.originalModulePromises.delete(id);
|
|
143
|
+
});
|
|
144
|
+
mockResult.then(promise.resolve, promise.reject).finally(() => {
|
|
145
|
+
this.factoryPromises.delete(id);
|
|
146
|
+
});
|
|
147
|
+
this.factoryPromises.set(id, mockResult);
|
|
148
|
+
this.originalModulePromises.set(id, promise);
|
|
149
|
+
// Node.js on windows processes all the files first, and then runs them
|
|
150
|
+
// unlike Node.js logic on Mac and Unix where it also runs the code while evaluating
|
|
151
|
+
// So on Linux/Mac this `if` won't be hit because `checkCircularManualMock` will resolve it
|
|
152
|
+
// And on Windows, the `checkCircularManualMock` will never have `originalModulePromises`
|
|
153
|
+
// because `getFactoryModule` is not called until the evaluation phase
|
|
154
|
+
// But if we track how many times the module was transformed,
|
|
155
|
+
// we can deduce when to return `__factoryPromise` to support circular modules
|
|
156
|
+
if ((this.processedModules.get(id) ?? 0) > 1) {
|
|
157
|
+
this.processedModules.set(id, (this.processedModules.get(id) ?? 1) - 1);
|
|
158
|
+
promise.resolve({ __factoryPromise: mockResult });
|
|
159
|
+
}
|
|
160
|
+
return promise;
|
|
161
|
+
}
|
|
162
|
+
return mockResult;
|
|
163
|
+
}
|
|
164
|
+
importActual(rawId, importer) {
|
|
165
|
+
const resolvedId = import.meta.resolve(rawId, pathToFileURL(importer).toString());
|
|
166
|
+
const url = new URL(resolvedId);
|
|
167
|
+
url.searchParams.set("mock", "actual");
|
|
168
|
+
return import(url.toString());
|
|
169
|
+
}
|
|
170
|
+
importMock(rawId, importer) {
|
|
171
|
+
const resolvedId = import.meta.resolve(rawId, pathToFileURL(importer).toString());
|
|
172
|
+
// file is already mocked
|
|
173
|
+
if (resolvedId.includes("mock=")) return import(resolvedId);
|
|
174
|
+
const filename = fileURLToPath(resolvedId);
|
|
175
|
+
const external = !isAbsolute(filename) || this.isModuleDirectory(resolvedId) ? normalizeModuleId(rawId) : null;
|
|
176
|
+
// file is not mocked, automock or redirect it
|
|
177
|
+
const redirect = this.findMockRedirect(filename, external);
|
|
178
|
+
if (redirect) return import(pathToFileURL(redirect).toString());
|
|
179
|
+
const url = new URL(resolvedId);
|
|
180
|
+
url.searchParams.set("mock", "automock");
|
|
181
|
+
return import(url.toString());
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const replacePercentageRE = /%/g;
|
|
185
|
+
function injectQuery(url, importer, queryToInject) {
|
|
186
|
+
const { search, hash } = new URL(url.replace(replacePercentageRE, "%25"), importer);
|
|
187
|
+
return `${cleanUrl(url)}?${queryToInject}${search ? `&${search.slice(1)}` : ""}${hash ?? ""}`;
|
|
188
|
+
}
|
|
189
|
+
let __require;
|
|
190
|
+
function getBuiltinModule(moduleId) {
|
|
191
|
+
__require ??= module$1.createRequire(import.meta.url);
|
|
192
|
+
return __require(`${moduleId}?mock=actual`);
|
|
193
|
+
}
|
|
194
|
+
function genSourceMapUrl(map) {
|
|
195
|
+
if (typeof map !== "string") map = JSON.stringify(map);
|
|
196
|
+
return `data:application/json;base64,${Buffer.from(map).toString("base64")}`;
|
|
197
|
+
}
|
|
198
|
+
function transformCode(code, format, filename) {
|
|
199
|
+
if (format.includes("typescript")) {
|
|
200
|
+
if (!module$1.stripTypeScriptTypes) throw new Error(`Cannot parse '${filename}' because "module.stripTypeScriptTypes" is not supported. Module mocking requires Node.js 22.15 or higher. This is NOT a bug of Vitest.`);
|
|
201
|
+
return module$1.stripTypeScriptTypes(code);
|
|
202
|
+
}
|
|
203
|
+
return code;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export { NativeModuleMocker };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { pathToFileURL } from 'node:url';
|
|
2
|
+
import { r as resolveModule } from './index.BCY_7LL2.js';
|
|
3
|
+
import { resolve } from '../vendor/pathe.mjs';
|
|
4
|
+
import { ModuleRunner } from '@voidzero-dev/vite-plus-core/module-runner';
|
|
5
|
+
|
|
6
|
+
class NativeModuleRunner extends ModuleRunner {
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
mocker;
|
|
11
|
+
constructor(root, mocker) {
|
|
12
|
+
super({
|
|
13
|
+
hmr: false,
|
|
14
|
+
sourcemapInterceptor: false,
|
|
15
|
+
transport: { invoke() {
|
|
16
|
+
throw new Error("Unexpected `invoke`");
|
|
17
|
+
} }
|
|
18
|
+
});
|
|
19
|
+
this.root = root;
|
|
20
|
+
this.mocker = mocker;
|
|
21
|
+
if (mocker) Object.defineProperty(globalThis, "__vitest_mocker__", {
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: mocker
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async import(moduleId) {
|
|
28
|
+
const path = resolveModule(moduleId, { paths: [this.root] }) ?? resolve(this.root, moduleId);
|
|
29
|
+
// resolveModule doesn't keep the query params, so we need to add them back
|
|
30
|
+
let queryParams = "";
|
|
31
|
+
if (moduleId.includes("?") && !path.includes("?")) queryParams = moduleId.slice(moduleId.indexOf("?"));
|
|
32
|
+
return import(pathToFileURL(path + queryParams).toString());
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { NativeModuleRunner as N };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NodeSnapshotEnvironment } from '../@vitest/snapshot/environment.js';
|
|
2
|
-
import { g as getWorkerState } from './utils.
|
|
2
|
+
import { g as getWorkerState } from './utils.BX5Fg8C4.js';
|
|
3
3
|
import '../@vitest/utils/timers.js';
|
|
4
4
|
|
|
5
5
|
class VitestNodeSnapshotEnvironment extends NodeSnapshotEnvironment {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DevEnvironment } from '@voidzero-dev/vite-plus-core';
|
|
2
|
-
import { V as Vitest, T as TestProject,
|
|
2
|
+
import { V as Vitest, T as TestProject, a as TestProjectConfiguration } from './reporters.d.DVUYHHhe.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Generate a unique cache identifier.
|