@voidzero-dev/vite-plus-test 0.0.0-0bfcc90f.20260209-0731
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 +691 -0
- package/browser/context.d.ts +4 -0
- package/browser/context.js +20 -0
- package/config.d.ts +3 -0
- package/coverage.d.ts +1 -0
- package/dist/@vitest/browser/client/.vite/manifest.json +24 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +57 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +1 -0
- package/dist/@vitest/browser/client/__vitest__/bg.png +0 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.ico +0 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.svg +5 -0
- package/dist/@vitest/browser/client/__vitest__/index.html +32 -0
- package/dist/@vitest/browser/client/__vitest_browser__/orchestrator-S_3e_uzt.js +345 -0
- package/dist/@vitest/browser/client/__vitest_browser__/tester-k74mgIRa.js +2171 -0
- package/dist/@vitest/browser/client/__vitest_browser__/utils-uxqdqUz8.js +223 -0
- package/dist/@vitest/browser/client/error-catcher.js +82 -0
- package/dist/@vitest/browser/client/esm-client-injector.js +67 -0
- package/dist/@vitest/browser/client/favicon.svg +5 -0
- package/dist/@vitest/browser/client/orchestrator.html +35 -0
- package/dist/@vitest/browser/client/tester/tester.html +13 -0
- package/dist/@vitest/browser/client.js +456 -0
- package/dist/@vitest/browser/context.d.ts +792 -0
- package/dist/@vitest/browser/context.js +541 -0
- package/dist/@vitest/browser/expect-element.js +32 -0
- package/dist/@vitest/browser/index-D6m36C6U.js +11 -0
- package/dist/@vitest/browser/index.d.ts +73 -0
- package/dist/@vitest/browser/index.js +3513 -0
- package/dist/@vitest/browser/jest-dom.d.ts +724 -0
- package/dist/@vitest/browser/locators.d.ts +354 -0
- package/dist/@vitest/browser/locators.js +1 -0
- package/dist/@vitest/browser/matchers.d.ts +29 -0
- package/dist/@vitest/browser/shared/screenshotMatcher/types.d.ts +22 -0
- package/dist/@vitest/browser/state.js +280 -0
- package/dist/@vitest/browser/types.d.ts +69 -0
- package/dist/@vitest/browser-playwright/context.d.ts +1 -0
- package/dist/@vitest/browser-playwright/index.d.ts +106 -0
- package/dist/@vitest/browser-playwright/index.js +1111 -0
- package/dist/@vitest/browser-playwright/locators.js +114 -0
- package/dist/@vitest/browser-preview/context.d.ts +1 -0
- package/dist/@vitest/browser-preview/index.d.ts +19 -0
- package/dist/@vitest/browser-preview/index.js +148 -0
- package/dist/@vitest/browser-preview/locators.js +79 -0
- package/dist/@vitest/browser-webdriverio/context.d.ts +1 -0
- package/dist/@vitest/browser-webdriverio/index.d.ts +63 -0
- package/dist/@vitest/browser-webdriverio/index.js +600 -0
- package/dist/@vitest/browser-webdriverio/locators.js +163 -0
- package/dist/@vitest/expect/index.d.ts +807 -0
- package/dist/@vitest/expect/index.js +1875 -0
- package/dist/@vitest/mocker/auto-register.d.ts +2 -0
- package/dist/@vitest/mocker/auto-register.js +9 -0
- package/dist/@vitest/mocker/automock.d.ts +12 -0
- package/dist/@vitest/mocker/automock.js +1 -0
- package/dist/@vitest/mocker/browser.d.ts +53 -0
- package/dist/@vitest/mocker/browser.js +91 -0
- package/dist/@vitest/mocker/chunk-automock.js +354 -0
- package/dist/@vitest/mocker/chunk-interceptor-native.js +15 -0
- package/dist/@vitest/mocker/chunk-mocker.js +521 -0
- package/dist/@vitest/mocker/chunk-pathe.M-eThtNZ.js +174 -0
- package/dist/@vitest/mocker/chunk-registry.js +185 -0
- package/dist/@vitest/mocker/chunk-utils.js +16 -0
- package/dist/@vitest/mocker/index.d-C-sLYZi-.d.ts +25 -0
- package/dist/@vitest/mocker/index.d.ts +2 -0
- package/dist/@vitest/mocker/index.js +185 -0
- package/dist/@vitest/mocker/mocker.d-TnKRhz7N.d.ts +81 -0
- package/dist/@vitest/mocker/node.d.ts +800 -0
- package/dist/@vitest/mocker/node.js +966 -0
- package/dist/@vitest/mocker/redirect.d.ts +3 -0
- package/dist/@vitest/mocker/redirect.js +79 -0
- package/dist/@vitest/mocker/register.d.ts +9 -0
- package/dist/@vitest/mocker/register.js +41 -0
- package/dist/@vitest/mocker/types.d-B8CCKmHt.d.ts +107 -0
- package/dist/@vitest/pretty-format/index.d.ts +124 -0
- package/dist/@vitest/pretty-format/index.js +1022 -0
- package/dist/@vitest/runner/chunk-tasks.js +340 -0
- package/dist/@vitest/runner/index.d.ts +180 -0
- package/dist/@vitest/runner/index.js +2114 -0
- package/dist/@vitest/runner/tasks.d-C7UxawJ9.d.ts +834 -0
- package/dist/@vitest/runner/types.d.ts +183 -0
- package/dist/@vitest/runner/types.js +1 -0
- package/dist/@vitest/runner/utils.d.ts +45 -0
- package/dist/@vitest/runner/utils.js +5 -0
- package/dist/@vitest/snapshot/environment.d-DHdQ1Csl.d.ts +22 -0
- package/dist/@vitest/snapshot/environment.d.ts +16 -0
- package/dist/@vitest/snapshot/environment.js +40 -0
- package/dist/@vitest/snapshot/index.d.ts +130 -0
- package/dist/@vitest/snapshot/index.js +1437 -0
- package/dist/@vitest/snapshot/manager.d.ts +18 -0
- package/dist/@vitest/snapshot/manager.js +73 -0
- package/dist/@vitest/snapshot/rawSnapshot.d-lFsMJFUd.d.ts +61 -0
- package/dist/@vitest/spy/index.d.ts +384 -0
- package/dist/@vitest/spy/index.js +433 -0
- package/dist/@vitest/utils/chunk-_commonjsHelpers.js +5 -0
- package/dist/@vitest/utils/chunk-pathe.M-eThtNZ.js +156 -0
- package/dist/@vitest/utils/constants.d.ts +21 -0
- package/dist/@vitest/utils/constants.js +49 -0
- package/dist/@vitest/utils/diff.d.ts +93 -0
- package/dist/@vitest/utils/diff.js +2199 -0
- package/dist/@vitest/utils/display.d.ts +29 -0
- package/dist/@vitest/utils/display.js +742 -0
- package/dist/@vitest/utils/error.d.ts +7 -0
- package/dist/@vitest/utils/error.js +42 -0
- package/dist/@vitest/utils/helpers.d.ts +73 -0
- package/dist/@vitest/utils/helpers.js +295 -0
- package/dist/@vitest/utils/highlight.d.ts +9 -0
- package/dist/@vitest/utils/highlight.js +538 -0
- package/dist/@vitest/utils/index.d.ts +5 -0
- package/dist/@vitest/utils/index.js +1 -0
- package/dist/@vitest/utils/offset.d.ts +5 -0
- package/dist/@vitest/utils/offset.js +32 -0
- package/dist/@vitest/utils/resolver.d.ts +7 -0
- package/dist/@vitest/utils/resolver.js +71 -0
- package/dist/@vitest/utils/serialize.d.ts +3 -0
- package/dist/@vitest/utils/serialize.js +118 -0
- package/dist/@vitest/utils/source-map.d.ts +55 -0
- package/dist/@vitest/utils/source-map.js +478 -0
- package/dist/@vitest/utils/timers.d.ts +33 -0
- package/dist/@vitest/utils/timers.js +49 -0
- package/dist/@vitest/utils/types.d-BCElaP-c.d.ts +53 -0
- package/dist/@vitest/utils/types.d.ts +34 -0
- package/dist/@vitest/utils/types.js +1 -0
- package/dist/browser-compat.js +3 -0
- package/dist/browser.d.ts +46 -0
- package/dist/browser.js +20 -0
- package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +6 -0
- package/dist/chunks/base.CJ0Y4ePK.js +165 -0
- package/dist/chunks/benchmark.B3N2zMcH.js +40 -0
- package/dist/chunks/benchmark.d.DAaHLpsq.d.ts +24 -0
- package/dist/chunks/browser.d.ChKACdzH.d.ts +59 -0
- package/dist/chunks/cac.DVeoLl0M.js +1409 -0
- package/dist/chunks/cli-api.B7PN_QUv.js +13672 -0
- package/dist/chunks/config.d.Cy95HiCx.d.ts +210 -0
- package/dist/chunks/console.Cf-YriPC.js +146 -0
- package/dist/chunks/constants.D_Q9UYh-.js +36 -0
- package/dist/chunks/coverage.AVPTjMgw.js +3292 -0
- package/dist/chunks/coverage.D_JHT54q.js +25 -0
- package/dist/chunks/coverage.d.BZtK59WP.d.ts +37 -0
- package/dist/chunks/creator.DAmOKTvJ.js +673 -0
- package/dist/chunks/date.Bq6ZW5rf.js +73 -0
- package/dist/chunks/defaults.BOqNVLsY.js +74 -0
- package/dist/chunks/env.D4Lgay0q.js +8 -0
- package/dist/chunks/environment.d.CrsxCzP1.d.ts +29 -0
- package/dist/chunks/evaluatedModules.Dg1zASAC.js +17 -0
- package/dist/chunks/evaluatedModules.d.BxJ5omdx.d.ts +7 -0
- package/dist/chunks/git.Bm2pzPAa.js +71 -0
- package/dist/chunks/global.d.B15mdLcR.d.ts +99 -0
- package/dist/chunks/globals.DOayXfHP.js +30 -0
- package/dist/chunks/index.6Qv1eEA6.js +109 -0
- package/dist/chunks/index.C5r1PdPD.js +231 -0
- package/dist/chunks/index.Chj8NDwU.js +206 -0
- package/dist/chunks/index.CyBMJtT7.js +727 -0
- package/dist/chunks/index.D3XRDfWc.js +213 -0
- package/dist/chunks/index.D4KonVSU.js +6343 -0
- package/dist/chunks/index.M8mOzt4Y.js +3839 -0
- package/dist/chunks/index.Z5E_ObnR.js +37 -0
- package/dist/chunks/init-forks._y3TW739.js +41 -0
- package/dist/chunks/init-threads.DBO2kn-p.js +18 -0
- package/dist/chunks/init.B6MLFIaN.js +334 -0
- package/dist/chunks/inspector.CvyFGlXm.js +53 -0
- package/dist/chunks/modules.BJuCwlRJ.js +36 -0
- package/dist/chunks/node.Ce0vMQM7.js +14 -0
- package/dist/chunks/plugin.d.CtqpEehP.d.ts +38 -0
- package/dist/chunks/reporters.d.CWXNI2jG.d.ts +3271 -0
- package/dist/chunks/rpc.BoxB0q7B.js +76 -0
- package/dist/chunks/rpc.d.RH3apGEf.d.ts +64 -0
- package/dist/chunks/setup-common.Cm-kSBVi.js +60 -0
- package/dist/chunks/startModuleRunner.DEj0jb3e.js +861 -0
- package/dist/chunks/suite.d.BJWk38HB.d.ts +10 -0
- package/dist/chunks/test.B8ej_ZHS.js +254 -0
- package/dist/chunks/traces.CCmnQaNT.js +217 -0
- package/dist/chunks/traces.d.402V_yFI.d.ts +18 -0
- package/dist/chunks/utils.DvEY5TfP.js +52 -0
- package/dist/chunks/vi.2VT5v0um.js +3919 -0
- package/dist/chunks/vm.D3epNOPZ.js +744 -0
- package/dist/chunks/worker.d.Dyxm8DEL.d.ts +255 -0
- package/dist/cli.js +28 -0
- package/dist/client/.vite/manifest.json +24 -0
- package/dist/client/__vitest__/assets/index-BUCFJtth.js +57 -0
- package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +1 -0
- package/dist/client/__vitest__/bg.png +0 -0
- package/dist/client/__vitest__/favicon.ico +0 -0
- package/dist/client/__vitest__/favicon.svg +5 -0
- package/dist/client/__vitest__/index.html +32 -0
- package/dist/client/__vitest_browser__/orchestrator-S_3e_uzt.js +345 -0
- package/dist/client/__vitest_browser__/tester-k74mgIRa.js +2171 -0
- package/dist/client/__vitest_browser__/utils-uxqdqUz8.js +223 -0
- package/dist/client/error-catcher.js +82 -0
- package/dist/client/esm-client-injector.js +67 -0
- package/dist/client/favicon.svg +5 -0
- package/dist/client/orchestrator.html +35 -0
- package/dist/client/tester/tester.html +13 -0
- package/dist/client.js +456 -0
- package/dist/config.cjs +94 -0
- package/dist/config.d.ts +104 -0
- package/dist/config.js +15 -0
- package/dist/context.js +541 -0
- package/dist/coverage.d.ts +118 -0
- package/dist/coverage.js +23 -0
- package/dist/dummy.js +2 -0
- package/dist/environments.d.ts +22 -0
- package/dist/environments.js +3 -0
- package/dist/expect-element.js +27 -0
- package/dist/index-D6m36C6U.js +6 -0
- package/dist/index-node.js +7 -0
- package/dist/index.d.ts +510 -0
- package/dist/index.js +19 -0
- package/dist/locators.d.ts +354 -0
- package/dist/locators.js +1 -0
- package/dist/mocker.d.ts +1 -0
- package/dist/mocker.js +1 -0
- package/dist/module-evaluator.d.ts +124 -0
- package/dist/module-evaluator.js +343 -0
- package/dist/module-runner-stub.js +44 -0
- package/dist/module-runner.js +17 -0
- package/dist/node.d.ts +251 -0
- package/dist/node.js +98 -0
- package/dist/path.js +7 -0
- package/dist/plugins/browser-client.mjs +2 -0
- package/dist/plugins/browser-context.mjs +2 -0
- package/dist/plugins/browser-locators.mjs +2 -0
- package/dist/plugins/browser-playwright.mjs +2 -0
- package/dist/plugins/browser-preview.mjs +2 -0
- package/dist/plugins/browser-webdriverio.mjs +2 -0
- package/dist/plugins/browser.mjs +2 -0
- package/dist/plugins/expect.mjs +2 -0
- package/dist/plugins/mocker-automock.mjs +2 -0
- package/dist/plugins/mocker-browser.mjs +2 -0
- package/dist/plugins/mocker-node.mjs +2 -0
- package/dist/plugins/mocker-redirect.mjs +2 -0
- package/dist/plugins/mocker-register.mjs +2 -0
- package/dist/plugins/mocker.mjs +2 -0
- package/dist/plugins/pretty-format.mjs +2 -0
- package/dist/plugins/runner-types.mjs +2 -0
- package/dist/plugins/runner-utils.mjs +2 -0
- package/dist/plugins/runner.mjs +2 -0
- package/dist/plugins/snapshot-environment.mjs +2 -0
- package/dist/plugins/snapshot-manager.mjs +2 -0
- package/dist/plugins/snapshot.mjs +2 -0
- package/dist/plugins/spy.mjs +2 -0
- package/dist/plugins/utils-constants.mjs +2 -0
- package/dist/plugins/utils-diff.mjs +2 -0
- package/dist/plugins/utils-display.mjs +2 -0
- package/dist/plugins/utils-error.mjs +2 -0
- package/dist/plugins/utils-helpers.mjs +2 -0
- package/dist/plugins/utils-highlight.mjs +2 -0
- package/dist/plugins/utils-offset.mjs +2 -0
- package/dist/plugins/utils-resolver.mjs +2 -0
- package/dist/plugins/utils-serialize.mjs +2 -0
- package/dist/plugins/utils-source-map.mjs +2 -0
- package/dist/plugins/utils-timers.mjs +2 -0
- package/dist/plugins/utils.mjs +2 -0
- package/dist/reporters.d.ts +27 -0
- package/dist/reporters.js +24 -0
- package/dist/runners.d.ts +50 -0
- package/dist/runners.js +19 -0
- package/dist/shared/screenshotMatcher/types.d.ts +22 -0
- package/dist/snapshot.d.ts +9 -0
- package/dist/snapshot.js +4 -0
- package/dist/spy.js +1 -0
- package/dist/state.js +280 -0
- package/dist/suite.d.ts +5 -0
- package/dist/suite.js +6 -0
- package/dist/types.d.ts +69 -0
- package/dist/vendor/chai.d.mts +1 -0
- package/dist/vendor/chai.mjs +3577 -0
- package/dist/vendor/es-module-lexer.d.mts +193 -0
- package/dist/vendor/es-module-lexer.mjs +79 -0
- package/dist/vendor/estree-walker.d.mts +583 -0
- package/dist/vendor/estree-walker.mjs +339 -0
- package/dist/vendor/expect-type.d.mts +1574 -0
- package/dist/vendor/expect-type.mjs +214 -0
- package/dist/vendor/magic-string.d.mts +261 -0
- package/dist/vendor/magic-string.mjs +1700 -0
- package/dist/vendor/obug.d.mts +56 -0
- package/dist/vendor/obug.mjs +276 -0
- package/dist/vendor/pathe.d.mts +46 -0
- package/dist/vendor/pathe.mjs +496 -0
- package/dist/vendor/picomatch.d.mts +1 -0
- package/dist/vendor/picomatch.mjs +1855 -0
- package/dist/vendor/shared-3g9mwCWP.mjs +31 -0
- package/dist/vendor/std-env.d.mts +88 -0
- package/dist/vendor/std-env.mjs +159 -0
- package/dist/vendor/tinybench.d.mts +317 -0
- package/dist/vendor/tinybench.mjs +504 -0
- package/dist/vendor/tinyexec.d.mts +72 -0
- package/dist/vendor/tinyexec.mjs +637 -0
- package/dist/vendor/tinyglobby.d.mts +157 -0
- package/dist/vendor/tinyglobby.mjs +832 -0
- package/dist/vendor/tinyrainbow.d.mts +60 -0
- package/dist/vendor/tinyrainbow.mjs +93 -0
- package/dist/vendor/vitest_browser.mjs +2 -0
- package/dist/vendor/vitest_internal_browser.mjs +2 -0
- package/dist/vendor/vitest_runner.mjs +2 -0
- package/dist/vendor/vitest_runners.mjs +2 -0
- package/dist/worker.d.ts +32 -0
- package/dist/worker.js +48 -0
- package/dist/workers/forks.js +54 -0
- package/dist/workers/runVmTests.js +95 -0
- package/dist/workers/threads.js +55 -0
- package/dist/workers/vmForks.js +36 -0
- package/dist/workers/vmThreads.js +37 -0
- package/environments.d.ts +1 -0
- package/globals.d.ts +20 -0
- package/import-meta.d.ts +5 -0
- package/importMeta.d.ts +4 -0
- package/index.cjs +5 -0
- package/index.d.cts +1 -0
- package/jsdom.d.ts +6 -0
- package/mocker.d.ts +1 -0
- package/node.d.ts +1 -0
- package/optional-types.d.ts +7 -0
- package/package.json +335 -0
- package/reporters.d.ts +1 -0
- package/runners.d.ts +1 -0
- package/snapshot.d.ts +1 -0
- package/suite.d.ts +1 -0
- package/suppress-warnings.cjs +21 -0
- package/vitest.mjs +2 -0
- package/worker.d.ts +1 -0
|
@@ -0,0 +1,744 @@
|
|
|
1
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
2
|
+
import vm, { isContext, runInContext } from 'node:vm';
|
|
3
|
+
import { dirname, basename, extname, normalize, resolve } from '../vendor/pathe.mjs';
|
|
4
|
+
import { l as loadEnvironment, e as emitModuleRunner } from './init.B6MLFIaN.js';
|
|
5
|
+
import { distDir } from '../path.js';
|
|
6
|
+
import { createCustomConsole } from './console.Cf-YriPC.js';
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import { createRequire, Module, isBuiltin } from 'node:module';
|
|
9
|
+
import { toArray, isBareImport } from '../@vitest/utils/helpers.js';
|
|
10
|
+
import { findNearestPackageData } from '../@vitest/utils/resolver.js';
|
|
11
|
+
import { dirname as dirname$1 } from 'node:path';
|
|
12
|
+
import { CSS_LANGS_RE, KNOWN_ASSET_RE } from '../@vitest/utils/constants.js';
|
|
13
|
+
import { getDefaultRequestStubs } from '../module-evaluator.js';
|
|
14
|
+
import { s as startVitestModuleRunner, c as createNodeImportMeta, a as VITEST_VM_CONTEXT_SYMBOL } from './startModuleRunner.DEj0jb3e.js';
|
|
15
|
+
import { p as provideWorkerState } from './utils.DvEY5TfP.js';
|
|
16
|
+
|
|
17
|
+
function interopCommonJsModule(interopDefault, mod) {
|
|
18
|
+
if (isPrimitive(mod) || Array.isArray(mod) || mod instanceof Promise) return {
|
|
19
|
+
keys: [],
|
|
20
|
+
moduleExports: {},
|
|
21
|
+
defaultExport: mod
|
|
22
|
+
};
|
|
23
|
+
if (interopDefault !== false && "__esModule" in mod && !isPrimitive(mod.default)) {
|
|
24
|
+
const defaultKets = Object.keys(mod.default);
|
|
25
|
+
const moduleKeys = Object.keys(mod);
|
|
26
|
+
const allKeys = new Set([...defaultKets, ...moduleKeys]);
|
|
27
|
+
allKeys.delete("default");
|
|
28
|
+
return {
|
|
29
|
+
keys: Array.from(allKeys),
|
|
30
|
+
moduleExports: new Proxy(mod, { get(mod, prop) {
|
|
31
|
+
return mod[prop] ?? mod.default?.[prop];
|
|
32
|
+
} }),
|
|
33
|
+
defaultExport: mod
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
keys: Object.keys(mod).filter((key) => key !== "default"),
|
|
38
|
+
moduleExports: mod,
|
|
39
|
+
defaultExport: mod
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function isPrimitive(obj) {
|
|
43
|
+
return !(obj != null && (typeof obj === "object" || typeof obj === "function"));
|
|
44
|
+
}
|
|
45
|
+
const SyntheticModule = vm.SyntheticModule;
|
|
46
|
+
const SourceTextModule = vm.SourceTextModule;
|
|
47
|
+
|
|
48
|
+
const _require = createRequire(import.meta.url);
|
|
49
|
+
const requiresCache = /* @__PURE__ */ new WeakMap();
|
|
50
|
+
class CommonjsExecutor {
|
|
51
|
+
context;
|
|
52
|
+
requireCache = /* @__PURE__ */ new Map();
|
|
53
|
+
publicRequireCache = this.createProxyCache();
|
|
54
|
+
moduleCache = /* @__PURE__ */ new Map();
|
|
55
|
+
builtinCache = Object.create(null);
|
|
56
|
+
extensions = Object.create(null);
|
|
57
|
+
fs;
|
|
58
|
+
Module;
|
|
59
|
+
interopDefault;
|
|
60
|
+
constructor(options) {
|
|
61
|
+
this.context = options.context;
|
|
62
|
+
this.fs = options.fileMap;
|
|
63
|
+
this.interopDefault = options.interopDefault;
|
|
64
|
+
const primitives = vm.runInContext("({ Object, Array, Error })", this.context);
|
|
65
|
+
// eslint-disable-next-line ts/no-this-alias
|
|
66
|
+
const executor = this;
|
|
67
|
+
this.Module = class Module$1 {
|
|
68
|
+
exports;
|
|
69
|
+
isPreloading = false;
|
|
70
|
+
id;
|
|
71
|
+
filename;
|
|
72
|
+
loaded;
|
|
73
|
+
parent;
|
|
74
|
+
children = [];
|
|
75
|
+
path;
|
|
76
|
+
paths = [];
|
|
77
|
+
constructor(id = "", parent) {
|
|
78
|
+
this.exports = primitives.Object.create(Object.prototype);
|
|
79
|
+
// in our case the path should always be resolved already
|
|
80
|
+
this.path = dirname(id);
|
|
81
|
+
this.id = id;
|
|
82
|
+
this.filename = id;
|
|
83
|
+
this.loaded = false;
|
|
84
|
+
this.parent = parent;
|
|
85
|
+
}
|
|
86
|
+
get require() {
|
|
87
|
+
const require = requiresCache.get(this);
|
|
88
|
+
if (require) return require;
|
|
89
|
+
const _require = Module$1.createRequire(this.id);
|
|
90
|
+
requiresCache.set(this, _require);
|
|
91
|
+
return _require;
|
|
92
|
+
}
|
|
93
|
+
static getSourceMapsSupport = () => ({
|
|
94
|
+
enabled: false,
|
|
95
|
+
nodeModules: false,
|
|
96
|
+
generatedCode: false
|
|
97
|
+
});
|
|
98
|
+
static setSourceMapsSupport = () => {
|
|
99
|
+
// noop
|
|
100
|
+
};
|
|
101
|
+
static register = () => {
|
|
102
|
+
throw new Error(`[vitest] "register" is not available when running in Vitest.`);
|
|
103
|
+
};
|
|
104
|
+
static registerHooks = () => {
|
|
105
|
+
throw new Error(`[vitest] "registerHooks" is not available when running in Vitest.`);
|
|
106
|
+
};
|
|
107
|
+
_compile(code, filename) {
|
|
108
|
+
const cjsModule = Module$1.wrap(code);
|
|
109
|
+
const script = new vm.Script(cjsModule, {
|
|
110
|
+
filename,
|
|
111
|
+
importModuleDynamically: options.importModuleDynamically
|
|
112
|
+
});
|
|
113
|
+
// @ts-expect-error mark script with current identifier
|
|
114
|
+
script.identifier = filename;
|
|
115
|
+
const fn = script.runInContext(executor.context);
|
|
116
|
+
const __dirname = dirname(filename);
|
|
117
|
+
executor.requireCache.set(filename, this);
|
|
118
|
+
try {
|
|
119
|
+
fn(this.exports, this.require, this, filename, __dirname);
|
|
120
|
+
return this.exports;
|
|
121
|
+
} finally {
|
|
122
|
+
this.loaded = true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// exposed for external use, Node.js does the opposite
|
|
126
|
+
static _load = (request, parent, _isMain) => {
|
|
127
|
+
return Module$1.createRequire(parent?.filename ?? request)(request);
|
|
128
|
+
};
|
|
129
|
+
static wrap = (script) => {
|
|
130
|
+
return Module$1.wrapper[0] + script + Module$1.wrapper[1];
|
|
131
|
+
};
|
|
132
|
+
static wrapper = new primitives.Array("(function (exports, require, module, __filename, __dirname) { ", "\n});");
|
|
133
|
+
static builtinModules = Module.builtinModules;
|
|
134
|
+
static findSourceMap = Module.findSourceMap;
|
|
135
|
+
static SourceMap = Module.SourceMap;
|
|
136
|
+
static syncBuiltinESMExports = Module.syncBuiltinESMExports;
|
|
137
|
+
static _cache = executor.publicRequireCache;
|
|
138
|
+
static _extensions = executor.extensions;
|
|
139
|
+
static createRequire = (filename) => {
|
|
140
|
+
return executor.createRequire(filename);
|
|
141
|
+
};
|
|
142
|
+
static runMain = () => {
|
|
143
|
+
throw new primitives.Error("[vitest] \"runMain\" is not implemented.");
|
|
144
|
+
};
|
|
145
|
+
// @ts-expect-error not typed
|
|
146
|
+
static _resolveFilename = Module._resolveFilename;
|
|
147
|
+
// @ts-expect-error not typed
|
|
148
|
+
static _findPath = Module._findPath;
|
|
149
|
+
// @ts-expect-error not typed
|
|
150
|
+
static _initPaths = Module._initPaths;
|
|
151
|
+
// @ts-expect-error not typed
|
|
152
|
+
static _preloadModules = Module._preloadModules;
|
|
153
|
+
// @ts-expect-error not typed
|
|
154
|
+
static _resolveLookupPaths = Module._resolveLookupPaths;
|
|
155
|
+
// @ts-expect-error not typed
|
|
156
|
+
static globalPaths = Module.globalPaths;
|
|
157
|
+
static isBuiltin = Module.isBuiltin;
|
|
158
|
+
static constants = Module.constants;
|
|
159
|
+
static enableCompileCache = Module.enableCompileCache;
|
|
160
|
+
static getCompileCacheDir = Module.getCompileCacheDir;
|
|
161
|
+
static flushCompileCache = Module.flushCompileCache;
|
|
162
|
+
static stripTypeScriptTypes = Module.stripTypeScriptTypes;
|
|
163
|
+
static findPackageJSON = Module.findPackageJSON;
|
|
164
|
+
static Module = Module$1;
|
|
165
|
+
};
|
|
166
|
+
this.extensions[".js"] = this.requireJs;
|
|
167
|
+
this.extensions[".json"] = this.requireJson;
|
|
168
|
+
}
|
|
169
|
+
requireJs = (m, filename) => {
|
|
170
|
+
const content = this.fs.readFile(filename);
|
|
171
|
+
m._compile(content, filename);
|
|
172
|
+
};
|
|
173
|
+
requireJson = (m, filename) => {
|
|
174
|
+
const code = this.fs.readFile(filename);
|
|
175
|
+
m.exports = JSON.parse(code);
|
|
176
|
+
};
|
|
177
|
+
createRequire = (filename) => {
|
|
178
|
+
const _require = createRequire(filename);
|
|
179
|
+
const require = ((id) => {
|
|
180
|
+
const resolved = _require.resolve(id);
|
|
181
|
+
if (extname(resolved) === ".node" || isBuiltin(resolved)) return this.requireCoreModule(resolved);
|
|
182
|
+
const module = new this.Module(resolved);
|
|
183
|
+
return this.loadCommonJSModule(module, resolved);
|
|
184
|
+
});
|
|
185
|
+
require.resolve = _require.resolve;
|
|
186
|
+
Object.defineProperty(require, "extensions", {
|
|
187
|
+
get: () => this.extensions,
|
|
188
|
+
set: () => {},
|
|
189
|
+
configurable: true
|
|
190
|
+
});
|
|
191
|
+
require.main = void 0;
|
|
192
|
+
require.cache = this.publicRequireCache;
|
|
193
|
+
return require;
|
|
194
|
+
};
|
|
195
|
+
createProxyCache() {
|
|
196
|
+
return new Proxy(Object.create(null), {
|
|
197
|
+
defineProperty: () => true,
|
|
198
|
+
deleteProperty: () => true,
|
|
199
|
+
set: () => true,
|
|
200
|
+
get: (_, key) => this.requireCache.get(key),
|
|
201
|
+
has: (_, key) => this.requireCache.has(key),
|
|
202
|
+
ownKeys: () => Array.from(this.requireCache.keys()),
|
|
203
|
+
getOwnPropertyDescriptor() {
|
|
204
|
+
return {
|
|
205
|
+
configurable: true,
|
|
206
|
+
enumerable: true
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
// very naive implementation for Node.js require
|
|
212
|
+
loadCommonJSModule(module, filename) {
|
|
213
|
+
const cached = this.requireCache.get(filename);
|
|
214
|
+
if (cached) return cached.exports;
|
|
215
|
+
const extension = this.findLongestRegisteredExtension(filename);
|
|
216
|
+
(this.extensions[extension] || this.extensions[".js"])(module, filename);
|
|
217
|
+
return module.exports;
|
|
218
|
+
}
|
|
219
|
+
findLongestRegisteredExtension(filename) {
|
|
220
|
+
const name = basename(filename);
|
|
221
|
+
let currentExtension;
|
|
222
|
+
let index;
|
|
223
|
+
let startIndex = 0;
|
|
224
|
+
// eslint-disable-next-line no-cond-assign
|
|
225
|
+
while ((index = name.indexOf(".", startIndex)) !== -1) {
|
|
226
|
+
startIndex = index + 1;
|
|
227
|
+
if (index === 0) continue;
|
|
228
|
+
currentExtension = name.slice(index);
|
|
229
|
+
if (this.extensions[currentExtension]) return currentExtension;
|
|
230
|
+
}
|
|
231
|
+
return ".js";
|
|
232
|
+
}
|
|
233
|
+
getCoreSyntheticModule(identifier) {
|
|
234
|
+
if (this.moduleCache.has(identifier)) return this.moduleCache.get(identifier);
|
|
235
|
+
const exports$1 = this.require(identifier);
|
|
236
|
+
const keys = Object.keys(exports$1);
|
|
237
|
+
const module = new SyntheticModule([...keys, "default"], () => {
|
|
238
|
+
for (const key of keys) module.setExport(key, exports$1[key]);
|
|
239
|
+
module.setExport("default", exports$1);
|
|
240
|
+
}, {
|
|
241
|
+
context: this.context,
|
|
242
|
+
identifier
|
|
243
|
+
});
|
|
244
|
+
this.moduleCache.set(identifier, module);
|
|
245
|
+
return module;
|
|
246
|
+
}
|
|
247
|
+
getCjsSyntheticModule(path, identifier) {
|
|
248
|
+
if (this.moduleCache.has(identifier)) return this.moduleCache.get(identifier);
|
|
249
|
+
const exports$1 = this.require(path);
|
|
250
|
+
// TODO: technically module should be parsed to find static exports, implement for strict mode in #2854
|
|
251
|
+
const { keys, moduleExports, defaultExport } = interopCommonJsModule(this.interopDefault, exports$1);
|
|
252
|
+
const module = new SyntheticModule([...keys, "default"], function() {
|
|
253
|
+
for (const key of keys) this.setExport(key, moduleExports[key]);
|
|
254
|
+
this.setExport("default", defaultExport);
|
|
255
|
+
}, {
|
|
256
|
+
context: this.context,
|
|
257
|
+
identifier
|
|
258
|
+
});
|
|
259
|
+
this.moduleCache.set(identifier, module);
|
|
260
|
+
return module;
|
|
261
|
+
}
|
|
262
|
+
// TODO: use this in strict mode, when available in #2854
|
|
263
|
+
// private _getNamedCjsExports(path: string): Set<string> {
|
|
264
|
+
// const cachedNamedExports = this.cjsNamedExportsMap.get(path)
|
|
265
|
+
// if (cachedNamedExports) {
|
|
266
|
+
// return cachedNamedExports
|
|
267
|
+
// }
|
|
268
|
+
// if (extname(path) === '.node') {
|
|
269
|
+
// const moduleExports = this.require(path)
|
|
270
|
+
// const namedExports = new Set(Object.keys(moduleExports))
|
|
271
|
+
// this.cjsNamedExportsMap.set(path, namedExports)
|
|
272
|
+
// return namedExports
|
|
273
|
+
// }
|
|
274
|
+
// const code = this.fs.readFile(path)
|
|
275
|
+
// const { exports, reexports } = parseCjs(code, path)
|
|
276
|
+
// const namedExports = new Set(exports)
|
|
277
|
+
// this.cjsNamedExportsMap.set(path, namedExports)
|
|
278
|
+
// for (const reexport of reexports) {
|
|
279
|
+
// if (isNodeBuiltin(reexport)) {
|
|
280
|
+
// const exports = this.require(reexport)
|
|
281
|
+
// if (exports !== null && typeof exports === 'object') {
|
|
282
|
+
// for (const e of Object.keys(exports)) {
|
|
283
|
+
// namedExports.add(e)
|
|
284
|
+
// }
|
|
285
|
+
// }
|
|
286
|
+
// }
|
|
287
|
+
// else {
|
|
288
|
+
// const require = this.createRequire(path)
|
|
289
|
+
// const resolved = require.resolve(reexport)
|
|
290
|
+
// const exports = this._getNamedCjsExports(resolved)
|
|
291
|
+
// for (const e of exports) {
|
|
292
|
+
// namedExports.add(e)
|
|
293
|
+
// }
|
|
294
|
+
// }
|
|
295
|
+
// }
|
|
296
|
+
// return namedExports
|
|
297
|
+
// }
|
|
298
|
+
require(identifier) {
|
|
299
|
+
if (extname(identifier) === ".node" || isBuiltin(identifier)) return this.requireCoreModule(identifier);
|
|
300
|
+
const module = new this.Module(identifier);
|
|
301
|
+
return this.loadCommonJSModule(module, identifier);
|
|
302
|
+
}
|
|
303
|
+
requireCoreModule(identifier) {
|
|
304
|
+
const normalized = identifier.replace(/^node:/, "");
|
|
305
|
+
if (this.builtinCache[normalized]) return this.builtinCache[normalized].exports;
|
|
306
|
+
const moduleExports = _require(identifier);
|
|
307
|
+
if (identifier === "node:module" || identifier === "module") {
|
|
308
|
+
const module = new this.Module("/module.js");
|
|
309
|
+
module.exports = this.Module;
|
|
310
|
+
this.builtinCache[normalized] = module;
|
|
311
|
+
return module.exports;
|
|
312
|
+
}
|
|
313
|
+
this.builtinCache[normalized] = _require.cache[normalized];
|
|
314
|
+
// TODO: should we wrap module to rethrow context errors?
|
|
315
|
+
return moduleExports;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const dataURIRegex = /^data:(?<mime>text\/javascript|application\/json|application\/wasm)(?:;(?<encoding>charset=utf-8|base64))?,(?<code>.*)$/;
|
|
320
|
+
class EsmExecutor {
|
|
321
|
+
moduleCache = /* @__PURE__ */ new Map();
|
|
322
|
+
esmLinkMap = /* @__PURE__ */ new WeakMap();
|
|
323
|
+
context;
|
|
324
|
+
#httpIp = IPnumber("127.0.0.0");
|
|
325
|
+
constructor(executor, options) {
|
|
326
|
+
this.executor = executor;
|
|
327
|
+
this.context = options.context;
|
|
328
|
+
}
|
|
329
|
+
async evaluateModule(m) {
|
|
330
|
+
if (m.status === "unlinked") this.esmLinkMap.set(m, m.link((identifier, referencer) => this.executor.resolveModule(identifier, referencer.identifier)));
|
|
331
|
+
await this.esmLinkMap.get(m);
|
|
332
|
+
if (m.status === "linked") await m.evaluate();
|
|
333
|
+
return m;
|
|
334
|
+
}
|
|
335
|
+
async createEsModule(fileURL, getCode) {
|
|
336
|
+
const cached = this.moduleCache.get(fileURL);
|
|
337
|
+
if (cached) return cached;
|
|
338
|
+
const promise = this.loadEsModule(fileURL, getCode);
|
|
339
|
+
this.moduleCache.set(fileURL, promise);
|
|
340
|
+
return promise;
|
|
341
|
+
}
|
|
342
|
+
async loadEsModule(fileURL, getCode) {
|
|
343
|
+
const code = await getCode();
|
|
344
|
+
// TODO: should not be allowed in strict mode, implement in #2854
|
|
345
|
+
if (fileURL.endsWith(".json")) {
|
|
346
|
+
const m = new SyntheticModule(["default"], function() {
|
|
347
|
+
const result = JSON.parse(code);
|
|
348
|
+
this.setExport("default", result);
|
|
349
|
+
});
|
|
350
|
+
this.moduleCache.set(fileURL, m);
|
|
351
|
+
return m;
|
|
352
|
+
}
|
|
353
|
+
const m = new SourceTextModule(code, {
|
|
354
|
+
identifier: fileURL,
|
|
355
|
+
context: this.context,
|
|
356
|
+
importModuleDynamically: this.executor.importModuleDynamically,
|
|
357
|
+
initializeImportMeta: (meta, mod) => {
|
|
358
|
+
meta.url = mod.identifier;
|
|
359
|
+
if (mod.identifier.startsWith("file:")) {
|
|
360
|
+
const filename = fileURLToPath(mod.identifier);
|
|
361
|
+
meta.filename = filename;
|
|
362
|
+
meta.dirname = dirname$1(filename);
|
|
363
|
+
}
|
|
364
|
+
meta.resolve = (specifier, importer) => {
|
|
365
|
+
return this.executor.resolve(specifier, importer != null ? importer.toString() : mod.identifier);
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
this.moduleCache.set(fileURL, m);
|
|
370
|
+
return m;
|
|
371
|
+
}
|
|
372
|
+
async createWebAssemblyModule(fileUrl, getCode) {
|
|
373
|
+
const cached = this.moduleCache.get(fileUrl);
|
|
374
|
+
if (cached) return cached;
|
|
375
|
+
const m = this.loadWebAssemblyModule(getCode(), fileUrl);
|
|
376
|
+
this.moduleCache.set(fileUrl, m);
|
|
377
|
+
return m;
|
|
378
|
+
}
|
|
379
|
+
async createNetworkModule(fileUrl) {
|
|
380
|
+
// https://nodejs.org/api/esm.html#https-and-http-imports
|
|
381
|
+
if (fileUrl.startsWith("http:")) {
|
|
382
|
+
const url = new URL(fileUrl);
|
|
383
|
+
if (url.hostname !== "localhost" && url.hostname !== "::1" && (IPnumber(url.hostname) & IPmask(8)) !== this.#httpIp) throw new Error(
|
|
384
|
+
// we don't know the importer, so it's undefined (the same happens in --pool=threads)
|
|
385
|
+
`import of '${fileUrl}' by undefined is not supported: http can only be used to load local resources (use https instead).`
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
return this.createEsModule(fileUrl, () => fetch(fileUrl).then((r) => r.text()));
|
|
389
|
+
}
|
|
390
|
+
async loadWebAssemblyModule(source, identifier) {
|
|
391
|
+
const cached = this.moduleCache.get(identifier);
|
|
392
|
+
if (cached) return cached;
|
|
393
|
+
const wasmModule = await WebAssembly.compile(source);
|
|
394
|
+
const exports$1 = WebAssembly.Module.exports(wasmModule);
|
|
395
|
+
const imports = WebAssembly.Module.imports(wasmModule);
|
|
396
|
+
const moduleLookup = {};
|
|
397
|
+
for (const { module } of imports) if (moduleLookup[module] === void 0) moduleLookup[module] = await this.executor.resolveModule(module, identifier);
|
|
398
|
+
const evaluateModule = (module) => this.evaluateModule(module);
|
|
399
|
+
return new SyntheticModule(exports$1.map(({ name }) => name), async function() {
|
|
400
|
+
const importsObject = {};
|
|
401
|
+
for (const { module, name } of imports) {
|
|
402
|
+
if (!importsObject[module]) importsObject[module] = {};
|
|
403
|
+
await evaluateModule(moduleLookup[module]);
|
|
404
|
+
importsObject[module][name] = moduleLookup[module].namespace[name];
|
|
405
|
+
}
|
|
406
|
+
const wasmInstance = new WebAssembly.Instance(wasmModule, importsObject);
|
|
407
|
+
for (const { name } of exports$1) this.setExport(name, wasmInstance.exports[name]);
|
|
408
|
+
}, {
|
|
409
|
+
context: this.context,
|
|
410
|
+
identifier
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
cacheModule(identifier, module) {
|
|
414
|
+
this.moduleCache.set(identifier, module);
|
|
415
|
+
}
|
|
416
|
+
resolveCachedModule(identifier) {
|
|
417
|
+
return this.moduleCache.get(identifier);
|
|
418
|
+
}
|
|
419
|
+
async createDataModule(identifier) {
|
|
420
|
+
const cached = this.moduleCache.get(identifier);
|
|
421
|
+
if (cached) return cached;
|
|
422
|
+
const match = identifier.match(dataURIRegex);
|
|
423
|
+
if (!match || !match.groups) throw new Error("Invalid data URI");
|
|
424
|
+
const mime = match.groups.mime;
|
|
425
|
+
const encoding = match.groups.encoding;
|
|
426
|
+
if (mime === "application/wasm") {
|
|
427
|
+
if (!encoding) throw new Error("Missing data URI encoding");
|
|
428
|
+
if (encoding !== "base64") throw new Error(`Invalid data URI encoding: ${encoding}`);
|
|
429
|
+
const module = this.loadWebAssemblyModule(Buffer.from(match.groups.code, "base64"), identifier);
|
|
430
|
+
this.moduleCache.set(identifier, module);
|
|
431
|
+
return module;
|
|
432
|
+
}
|
|
433
|
+
let code = match.groups.code;
|
|
434
|
+
if (!encoding || encoding === "charset=utf-8") code = decodeURIComponent(code);
|
|
435
|
+
else if (encoding === "base64") code = Buffer.from(code, "base64").toString();
|
|
436
|
+
else throw new Error(`Invalid data URI encoding: ${encoding}`);
|
|
437
|
+
if (mime === "application/json") {
|
|
438
|
+
const module = new SyntheticModule(["default"], function() {
|
|
439
|
+
const obj = JSON.parse(code);
|
|
440
|
+
this.setExport("default", obj);
|
|
441
|
+
}, {
|
|
442
|
+
context: this.context,
|
|
443
|
+
identifier
|
|
444
|
+
});
|
|
445
|
+
this.moduleCache.set(identifier, module);
|
|
446
|
+
return module;
|
|
447
|
+
}
|
|
448
|
+
return this.createEsModule(identifier, () => code);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function IPnumber(address) {
|
|
452
|
+
const ip = address.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/);
|
|
453
|
+
if (ip) return (+ip[1] << 24) + (+ip[2] << 16) + (+ip[3] << 8) + +ip[4];
|
|
454
|
+
throw new Error(`Expected IP address, received ${address}`);
|
|
455
|
+
}
|
|
456
|
+
function IPmask(maskSize) {
|
|
457
|
+
return -1 << 32 - maskSize;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
const CLIENT_ID = "/@vite/client";
|
|
461
|
+
const CLIENT_FILE = pathToFileURL(CLIENT_ID).href;
|
|
462
|
+
class ViteExecutor {
|
|
463
|
+
esm;
|
|
464
|
+
constructor(options) {
|
|
465
|
+
this.options = options;
|
|
466
|
+
this.esm = options.esmExecutor;
|
|
467
|
+
}
|
|
468
|
+
resolve = (identifier) => {
|
|
469
|
+
if (identifier === CLIENT_ID) return identifier;
|
|
470
|
+
};
|
|
471
|
+
get workerState() {
|
|
472
|
+
return this.options.context.__vitest_worker__;
|
|
473
|
+
}
|
|
474
|
+
async createViteModule(fileUrl) {
|
|
475
|
+
if (fileUrl === CLIENT_FILE || fileUrl === CLIENT_ID) return this.createViteClientModule();
|
|
476
|
+
const cached = this.esm.resolveCachedModule(fileUrl);
|
|
477
|
+
if (cached) return cached;
|
|
478
|
+
return this.esm.createEsModule(fileUrl, async () => {
|
|
479
|
+
try {
|
|
480
|
+
const result = await this.options.transform(fileUrl);
|
|
481
|
+
if (result.code) return result.code;
|
|
482
|
+
} catch (cause) {
|
|
483
|
+
// rethrow vite error if it cannot load the module because it's not resolved
|
|
484
|
+
if (typeof cause === "object" && cause.code === "ERR_LOAD_URL" || typeof cause?.message === "string" && cause.message.includes("Failed to load url")) {
|
|
485
|
+
const error = new Error(`Cannot find module '${fileUrl}'`, { cause });
|
|
486
|
+
error.code = "ERR_MODULE_NOT_FOUND";
|
|
487
|
+
throw error;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
throw new Error(`[vitest] Failed to transform ${fileUrl}. Does the file exist?`);
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
createViteClientModule() {
|
|
494
|
+
const identifier = CLIENT_ID;
|
|
495
|
+
const cached = this.esm.resolveCachedModule(identifier);
|
|
496
|
+
if (cached) return cached;
|
|
497
|
+
const stub = this.options.viteClientModule;
|
|
498
|
+
const moduleKeys = Object.keys(stub);
|
|
499
|
+
const module = new SyntheticModule(moduleKeys, function() {
|
|
500
|
+
moduleKeys.forEach((key) => {
|
|
501
|
+
this.setExport(key, stub[key]);
|
|
502
|
+
});
|
|
503
|
+
}, {
|
|
504
|
+
context: this.options.context,
|
|
505
|
+
identifier
|
|
506
|
+
});
|
|
507
|
+
this.esm.cacheModule(identifier, module);
|
|
508
|
+
return module;
|
|
509
|
+
}
|
|
510
|
+
canResolve = (fileUrl) => {
|
|
511
|
+
if (fileUrl === CLIENT_FILE) return true;
|
|
512
|
+
const config = this.workerState.config.deps?.web || {};
|
|
513
|
+
const [modulePath] = fileUrl.split("?");
|
|
514
|
+
if (config.transformCss && CSS_LANGS_RE.test(modulePath)) return true;
|
|
515
|
+
if (config.transformAssets && KNOWN_ASSET_RE.test(modulePath)) return true;
|
|
516
|
+
if (toArray(config.transformGlobPattern).some((pattern) => pattern.test(modulePath))) return true;
|
|
517
|
+
return false;
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const { existsSync } = fs;
|
|
522
|
+
// always defined when we use vm pool
|
|
523
|
+
const nativeResolve = import.meta.resolve;
|
|
524
|
+
// TODO: improve Node.js strict mode support in #2854
|
|
525
|
+
class ExternalModulesExecutor {
|
|
526
|
+
cjs;
|
|
527
|
+
esm;
|
|
528
|
+
vite;
|
|
529
|
+
context;
|
|
530
|
+
fs;
|
|
531
|
+
resolvers = [];
|
|
532
|
+
#networkSupported = null;
|
|
533
|
+
constructor(options) {
|
|
534
|
+
this.options = options;
|
|
535
|
+
this.context = options.context;
|
|
536
|
+
this.fs = options.fileMap;
|
|
537
|
+
this.esm = new EsmExecutor(this, { context: this.context });
|
|
538
|
+
this.cjs = new CommonjsExecutor({
|
|
539
|
+
context: this.context,
|
|
540
|
+
importModuleDynamically: this.importModuleDynamically,
|
|
541
|
+
fileMap: options.fileMap,
|
|
542
|
+
interopDefault: options.interopDefault
|
|
543
|
+
});
|
|
544
|
+
this.vite = new ViteExecutor({
|
|
545
|
+
esmExecutor: this.esm,
|
|
546
|
+
context: this.context,
|
|
547
|
+
transform: options.transform,
|
|
548
|
+
viteClientModule: options.viteClientModule
|
|
549
|
+
});
|
|
550
|
+
this.resolvers = [this.vite.resolve];
|
|
551
|
+
}
|
|
552
|
+
async import(identifier) {
|
|
553
|
+
const module = await this.createModule(identifier);
|
|
554
|
+
await this.esm.evaluateModule(module);
|
|
555
|
+
return module.namespace;
|
|
556
|
+
}
|
|
557
|
+
require(identifier) {
|
|
558
|
+
return this.cjs.require(identifier);
|
|
559
|
+
}
|
|
560
|
+
createRequire(identifier) {
|
|
561
|
+
return this.cjs.createRequire(identifier);
|
|
562
|
+
}
|
|
563
|
+
// dynamic import can be used in both ESM and CJS, so we have it in the executor
|
|
564
|
+
importModuleDynamically = async (specifier, referencer) => {
|
|
565
|
+
const module = await this.resolveModule(specifier, referencer.identifier);
|
|
566
|
+
return await this.esm.evaluateModule(module);
|
|
567
|
+
};
|
|
568
|
+
resolveModule = async (specifier, referencer) => {
|
|
569
|
+
let identifier = this.resolve(specifier, referencer);
|
|
570
|
+
if (identifier instanceof Promise) identifier = await identifier;
|
|
571
|
+
return await this.createModule(identifier);
|
|
572
|
+
};
|
|
573
|
+
resolve(specifier, parent) {
|
|
574
|
+
for (const resolver of this.resolvers) {
|
|
575
|
+
const id = resolver(specifier, parent);
|
|
576
|
+
if (id) return id;
|
|
577
|
+
}
|
|
578
|
+
// import.meta.resolve can be asynchronous in older +18 Node versions
|
|
579
|
+
return nativeResolve(specifier, parent);
|
|
580
|
+
}
|
|
581
|
+
getModuleInformation(identifier) {
|
|
582
|
+
if (identifier.startsWith("data:")) return {
|
|
583
|
+
type: "data",
|
|
584
|
+
url: identifier,
|
|
585
|
+
path: identifier
|
|
586
|
+
};
|
|
587
|
+
const extension = extname(identifier);
|
|
588
|
+
if (extension === ".node" || isBuiltin(identifier)) return {
|
|
589
|
+
type: "builtin",
|
|
590
|
+
url: identifier,
|
|
591
|
+
path: identifier
|
|
592
|
+
};
|
|
593
|
+
if (this.isNetworkSupported && (identifier.startsWith("http:") || identifier.startsWith("https:"))) return {
|
|
594
|
+
type: "network",
|
|
595
|
+
url: identifier,
|
|
596
|
+
path: identifier
|
|
597
|
+
};
|
|
598
|
+
const isFileUrl = identifier.startsWith("file://");
|
|
599
|
+
const pathUrl = isFileUrl ? fileURLToPath(identifier.split("?")[0]) : identifier;
|
|
600
|
+
const fileUrl = isFileUrl ? identifier : pathToFileURL(pathUrl).toString();
|
|
601
|
+
let type;
|
|
602
|
+
if (this.vite.canResolve(fileUrl)) type = "vite";
|
|
603
|
+
else if (extension === ".mjs") type = "module";
|
|
604
|
+
else if (extension === ".cjs") type = "commonjs";
|
|
605
|
+
else if (extension === ".wasm")
|
|
606
|
+
// still experimental on NodeJS --experimental-wasm-modules
|
|
607
|
+
// cf. ESM_FILE_FORMAT(url) in https://nodejs.org/docs/latest-v20.x/api/esm.html#resolution-algorithm
|
|
608
|
+
type = "wasm";
|
|
609
|
+
else type = findNearestPackageData(normalize(pathUrl)).type === "module" ? "module" : "commonjs";
|
|
610
|
+
return {
|
|
611
|
+
type,
|
|
612
|
+
path: pathUrl,
|
|
613
|
+
url: fileUrl
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
createModule(identifier) {
|
|
617
|
+
const { type, url, path } = this.getModuleInformation(identifier);
|
|
618
|
+
// create ERR_MODULE_NOT_FOUND on our own since latest NodeJS's import.meta.resolve doesn't throw on non-existing namespace or path
|
|
619
|
+
// https://github.com/nodejs/node/pull/49038
|
|
620
|
+
if ((type === "module" || type === "commonjs" || type === "wasm") && !existsSync(path)) {
|
|
621
|
+
const error = /* @__PURE__ */ new Error(`Cannot find ${isBareImport(path) ? "package" : "module"} '${path}'`);
|
|
622
|
+
error.code = "ERR_MODULE_NOT_FOUND";
|
|
623
|
+
throw error;
|
|
624
|
+
}
|
|
625
|
+
switch (type) {
|
|
626
|
+
case "data": return this.esm.createDataModule(identifier);
|
|
627
|
+
case "builtin": return this.cjs.getCoreSyntheticModule(identifier);
|
|
628
|
+
case "vite": return this.vite.createViteModule(url);
|
|
629
|
+
case "wasm": return this.esm.createWebAssemblyModule(url, () => this.fs.readBuffer(path));
|
|
630
|
+
case "module": return this.esm.createEsModule(url, () => this.fs.readFileAsync(path));
|
|
631
|
+
case "commonjs": return this.cjs.getCjsSyntheticModule(path, identifier);
|
|
632
|
+
case "network": return this.esm.createNetworkModule(url);
|
|
633
|
+
default: return type;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
get isNetworkSupported() {
|
|
637
|
+
if (this.#networkSupported == null) if (process.execArgv.includes("--experimental-network-imports")) this.#networkSupported = true;
|
|
638
|
+
else if (process.env.NODE_OPTIONS?.includes("--experimental-network-imports")) this.#networkSupported = true;
|
|
639
|
+
else this.#networkSupported = false;
|
|
640
|
+
return this.#networkSupported;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
const { promises, readFileSync } = fs;
|
|
645
|
+
class FileMap {
|
|
646
|
+
fsCache = /* @__PURE__ */ new Map();
|
|
647
|
+
fsBufferCache = /* @__PURE__ */ new Map();
|
|
648
|
+
async readFileAsync(path) {
|
|
649
|
+
const cached = this.fsCache.get(path);
|
|
650
|
+
if (cached != null) return cached;
|
|
651
|
+
const source = await promises.readFile(path, "utf-8");
|
|
652
|
+
this.fsCache.set(path, source);
|
|
653
|
+
return source;
|
|
654
|
+
}
|
|
655
|
+
readFile(path) {
|
|
656
|
+
const cached = this.fsCache.get(path);
|
|
657
|
+
if (cached != null) return cached;
|
|
658
|
+
const source = readFileSync(path, "utf-8");
|
|
659
|
+
this.fsCache.set(path, source);
|
|
660
|
+
return source;
|
|
661
|
+
}
|
|
662
|
+
readBuffer(path) {
|
|
663
|
+
const cached = this.fsBufferCache.get(path);
|
|
664
|
+
if (cached != null) return cached;
|
|
665
|
+
const buffer = readFileSync(path);
|
|
666
|
+
this.fsBufferCache.set(path, buffer);
|
|
667
|
+
return buffer;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
const entryFile = pathToFileURL(resolve(distDir, "workers/runVmTests.js")).href;
|
|
672
|
+
const fileMap = new FileMap();
|
|
673
|
+
const packageCache = /* @__PURE__ */ new Map();
|
|
674
|
+
async function runVmTests(method, state, traces) {
|
|
675
|
+
const { ctx, rpc } = state;
|
|
676
|
+
const beforeEnvironmentTime = performance.now();
|
|
677
|
+
const { environment } = await loadEnvironment(ctx.environment.name, ctx.config.root, rpc, traces);
|
|
678
|
+
state.environment = environment;
|
|
679
|
+
if (!environment.setupVM) {
|
|
680
|
+
const envName = ctx.environment.name;
|
|
681
|
+
const packageId = envName[0] === "." ? envName : `vitest-environment-${envName}`;
|
|
682
|
+
throw new TypeError(`Environment "${ctx.environment.name}" is not a valid environment. Path "${packageId}" doesn't support vm environment because it doesn't provide "setupVM" method.`);
|
|
683
|
+
}
|
|
684
|
+
const vm = await traces.$("vitest.runtime.environment.setup", { attributes: {
|
|
685
|
+
"vitest.environment": environment.name,
|
|
686
|
+
"vitest.environment.vite_environment": environment.viteEnvironment || environment.name
|
|
687
|
+
} }, () => environment.setupVM(ctx.environment.options || ctx.config.environmentOptions || {}));
|
|
688
|
+
state.durations.environment = performance.now() - beforeEnvironmentTime;
|
|
689
|
+
process.env.VITEST_VM_POOL = "1";
|
|
690
|
+
if (!vm.getVmContext) throw new TypeError(`Environment ${environment.name} doesn't provide "getVmContext" method. It should return a context created by "vm.createContext" method.`);
|
|
691
|
+
const context = vm.getVmContext();
|
|
692
|
+
if (!isContext(context)) throw new TypeError(`Environment ${environment.name} doesn't provide a valid context. It should be created by "vm.createContext" method.`);
|
|
693
|
+
provideWorkerState(context, state);
|
|
694
|
+
// this is unfortunately needed for our own dependencies
|
|
695
|
+
// we need to find a way to not rely on this by default
|
|
696
|
+
// because browser doesn't provide these globals
|
|
697
|
+
context.process = process;
|
|
698
|
+
context.global = context;
|
|
699
|
+
context.console = state.config.disableConsoleIntercept ? console : createCustomConsole(state);
|
|
700
|
+
// TODO: don't hardcode setImmediate in fake timers defaults
|
|
701
|
+
context.setImmediate = setImmediate;
|
|
702
|
+
context.clearImmediate = clearImmediate;
|
|
703
|
+
const stubs = getDefaultRequestStubs(context);
|
|
704
|
+
const externalModulesExecutor = new ExternalModulesExecutor({
|
|
705
|
+
context,
|
|
706
|
+
fileMap,
|
|
707
|
+
packageCache,
|
|
708
|
+
transform: rpc.transform,
|
|
709
|
+
viteClientModule: stubs["/@vite/client"]
|
|
710
|
+
});
|
|
711
|
+
const moduleRunner = startVitestModuleRunner({
|
|
712
|
+
context,
|
|
713
|
+
evaluatedModules: state.evaluatedModules,
|
|
714
|
+
state,
|
|
715
|
+
externalModulesExecutor,
|
|
716
|
+
createImportMeta: createNodeImportMeta,
|
|
717
|
+
traces
|
|
718
|
+
});
|
|
719
|
+
emitModuleRunner(moduleRunner);
|
|
720
|
+
Object.defineProperty(context, VITEST_VM_CONTEXT_SYMBOL, {
|
|
721
|
+
value: {
|
|
722
|
+
context,
|
|
723
|
+
externalModulesExecutor
|
|
724
|
+
},
|
|
725
|
+
configurable: true,
|
|
726
|
+
enumerable: false,
|
|
727
|
+
writable: false
|
|
728
|
+
});
|
|
729
|
+
context.__vitest_mocker__ = moduleRunner.mocker;
|
|
730
|
+
if (ctx.config.serializedDefines) try {
|
|
731
|
+
runInContext(ctx.config.serializedDefines, context, { filename: "virtual:load-defines.js" });
|
|
732
|
+
} catch (error) {
|
|
733
|
+
throw new Error(`Failed to load custom "defines": ${error.message}`);
|
|
734
|
+
}
|
|
735
|
+
await moduleRunner.mocker.initializeSpyModule();
|
|
736
|
+
const { run } = await moduleRunner.import(entryFile);
|
|
737
|
+
try {
|
|
738
|
+
await run(method, ctx.files, ctx.config, moduleRunner, traces);
|
|
739
|
+
} finally {
|
|
740
|
+
await traces.$("vitest.runtime.environment.teardown", () => vm.teardown?.());
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
export { runVmTests as r };
|