vitest 1.0.0-beta.2 → 1.0.0-beta.4
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 +17 -29
- package/dist/browser.d.ts +1 -2
- package/dist/browser.js +3 -3
- package/dist/child.js +13 -7
- package/dist/{chunk-api-setup.5d9a93c7.js → chunk-api-setup.6d19ab38.js} +6 -4
- package/dist/{chunk-install-pkg.43d58972.js → chunk-install-pkg.e1d6323e.js} +12 -14
- package/dist/{chunk-integrations-globals.9df12d91.js → chunk-integrations-globals.2b099e04.js} +6 -6
- package/dist/{chunk-node-git.2f1df48f.js → chunk-node-git.6c12e560.js} +1 -1
- package/dist/cli-wrapper.js +1 -1
- package/dist/cli.js +16 -20
- package/dist/config.cjs +1 -0
- package/dist/config.d.ts +2 -3
- package/dist/config.js +1 -0
- package/dist/coverage.d.ts +1 -2
- package/dist/coverage.js +2 -2
- package/dist/entry-vm.js +8 -8
- package/dist/entry.js +8 -8
- package/dist/environments.d.ts +1 -2
- package/dist/environments.js +1 -13
- package/dist/execute.d.ts +2 -3
- package/dist/execute.js +1 -2
- package/dist/index.d.ts +232 -59
- package/dist/index.js +7 -7
- package/dist/node.d.ts +10 -4
- package/dist/node.js +16 -18
- package/dist/{reporters-d10f25e1.d.ts → reporters-50c2bd49.d.ts} +100 -35
- package/dist/reporters.d.ts +1 -2
- package/dist/reporters.js +3 -3
- package/dist/runners.d.ts +3 -3
- package/dist/runners.js +37 -41
- package/dist/{suite-919dd548.d.ts → suite-ad69b7cd.d.ts} +1 -1
- package/dist/suite.d.ts +2 -3
- package/dist/suite.js +3 -3
- package/dist/{vendor-benchmark.44931cfa.js → vendor-benchmark.b6befc50.js} +1 -1
- package/dist/{vendor-environments.094f240c.js → vendor-environments.dcc4a34e.js} +4 -37
- package/dist/{vendor-execute.07d1a420.js → vendor-execute.157302d6.js} +3 -3
- package/dist/vendor-global.c3664e75.js +14 -0
- package/dist/{vendor-index.29282562.js → vendor-index.2b92937b.js} +1 -1
- package/dist/{vendor-index.d36f5516.js → vendor-index.57925a34.js} +8 -3
- package/dist/{vendor-index.68ecee35.js → vendor-index.72df742e.js} +11 -4
- package/dist/{vendor-index.e006069f.js → vendor-index.8efe7746.js} +371 -371
- package/dist/{vendor-index.0b5b3600.js → vendor-loader.9c966f23.js} +36 -9
- package/dist/{vendor-node.e5a35bfe.js → vendor-node.65461b16.js} +2660 -2021
- package/dist/{vendor-reporters.2953082e.js → vendor-reporters.d24d80a4.js} +42 -25
- package/dist/{vendor-rpc.cbd8e972.js → vendor-rpc.171f65fb.js} +1 -1
- package/dist/{vendor-run-once.3e5ef7d7.js → vendor-run-once.fb836747.js} +1 -1
- package/dist/{vendor-vi.d30b47ae.js → vendor-vi.3baa7c4a.js} +32 -35
- package/dist/vm.js +14 -8
- package/dist/worker.js +14 -8
- package/package.json +12 -28
- package/dist/loader.js +0 -100
- package/dist/vendor-global.97e4527c.js +0 -9
- package/dist/vendor-index.98139333.js +0 -129
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { resolve, normalize } from 'pathe';
|
|
2
|
-
import { r as resolvePath } from './vendor-index.0b5b3600.js';
|
|
3
|
-
import { ViteNodeRunner } from 'vite-node/client';
|
|
4
1
|
import { Console } from 'node:console';
|
|
5
2
|
import { importModule } from 'local-pkg';
|
|
6
3
|
|
|
@@ -479,7 +476,9 @@ var jsdom = {
|
|
|
479
476
|
"Response",
|
|
480
477
|
"BroadcastChannel",
|
|
481
478
|
"MessageChannel",
|
|
482
|
-
"MessagePort"
|
|
479
|
+
"MessagePort",
|
|
480
|
+
"TextEncoder",
|
|
481
|
+
"TextDecoder"
|
|
483
482
|
];
|
|
484
483
|
for (const name of globalNames) {
|
|
485
484
|
const value = globalThis[name];
|
|
@@ -646,9 +645,6 @@ const envPackageNames = {
|
|
|
646
645
|
"happy-dom": "happy-dom",
|
|
647
646
|
"edge-runtime": "@edge-runtime/vm"
|
|
648
647
|
};
|
|
649
|
-
function isBuiltinEnvironment(env) {
|
|
650
|
-
return env in environments;
|
|
651
|
-
}
|
|
652
648
|
function getEnvPackageName(env) {
|
|
653
649
|
if (env === "node")
|
|
654
650
|
return null;
|
|
@@ -658,34 +654,5 @@ function getEnvPackageName(env) {
|
|
|
658
654
|
return null;
|
|
659
655
|
return `vitest-environment-${env}`;
|
|
660
656
|
}
|
|
661
|
-
const _loaders = /* @__PURE__ */ new Map();
|
|
662
|
-
async function createEnvironmentLoader(options) {
|
|
663
|
-
if (!_loaders.has(options.root)) {
|
|
664
|
-
const loader = new ViteNodeRunner(options);
|
|
665
|
-
await loader.executeId("/@vite/env");
|
|
666
|
-
_loaders.set(options.root, loader);
|
|
667
|
-
}
|
|
668
|
-
return _loaders.get(options.root);
|
|
669
|
-
}
|
|
670
|
-
async function loadEnvironment(name, options) {
|
|
671
|
-
if (isBuiltinEnvironment(name))
|
|
672
|
-
return environments[name];
|
|
673
|
-
const loader = await createEnvironmentLoader(options);
|
|
674
|
-
const root = loader.root;
|
|
675
|
-
const packageId = name[0] === "." || name[0] === "/" ? resolve(root, name) : await resolvePath(`vitest-environment-${name}`, { url: [root] }) ?? resolve(root, name);
|
|
676
|
-
const pkg = await loader.executeId(normalize(packageId));
|
|
677
|
-
if (!pkg || !pkg.default || typeof pkg.default !== "object") {
|
|
678
|
-
throw new TypeError(
|
|
679
|
-
`Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "setup" or/and "setupVM" method.`
|
|
680
|
-
);
|
|
681
|
-
}
|
|
682
|
-
const environment = pkg.default;
|
|
683
|
-
if (environment.transformMode !== "web" && environment.transformMode !== "ssr") {
|
|
684
|
-
throw new TypeError(
|
|
685
|
-
`Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "transformMode" method equal to "ssr" or "web".`
|
|
686
|
-
);
|
|
687
|
-
}
|
|
688
|
-
return environment;
|
|
689
|
-
}
|
|
690
657
|
|
|
691
|
-
export { environments as e, getEnvPackageName as g,
|
|
658
|
+
export { environments as e, getEnvPackageName as g, populateGlobal as p };
|
|
@@ -5,7 +5,6 @@ import { isNodeBuiltin, isPrimitive, toArray, getCachedData, setCacheData, isInt
|
|
|
5
5
|
import { resolve, isAbsolute, dirname, join, basename, extname, normalize, relative } from 'pathe';
|
|
6
6
|
import { processError } from '@vitest/utils/error';
|
|
7
7
|
import { d as distDir } from './vendor-paths.84fc7a99.js';
|
|
8
|
-
import { g as getWorkerState } from './vendor-global.97e4527c.js';
|
|
9
8
|
import { existsSync, readdirSync, statSync, readFileSync } from 'node:fs';
|
|
10
9
|
import { getColors, getType } from '@vitest/utils';
|
|
11
10
|
import { b as getAllMockableProperties } from './vendor-base.9c08bbd0.js';
|
|
@@ -989,7 +988,7 @@ async function startViteNode(options) {
|
|
|
989
988
|
return _viteNode;
|
|
990
989
|
}
|
|
991
990
|
async function startVitestExecutor(options) {
|
|
992
|
-
const state = () =>
|
|
991
|
+
const state = () => globalThis.__vitest_worker__ || options.state;
|
|
993
992
|
const rpc = () => state().rpc;
|
|
994
993
|
const processExit = process.exit;
|
|
995
994
|
process.exit = (code = process.exitCode || 0) => {
|
|
@@ -1009,6 +1008,7 @@ async function startVitestExecutor(options) {
|
|
|
1009
1008
|
}
|
|
1010
1009
|
rpc().onUnhandledError(error, type);
|
|
1011
1010
|
}
|
|
1011
|
+
process.setMaxListeners(25);
|
|
1012
1012
|
process.on("uncaughtException", (e) => catchError(e, "Uncaught Exception"));
|
|
1013
1013
|
process.on("unhandledRejection", (e) => catchError(e, "Unhandled Rejection"));
|
|
1014
1014
|
const getTransformMode = () => {
|
|
@@ -1114,7 +1114,7 @@ class VitestExecutor extends ViteNodeRunner {
|
|
|
1114
1114
|
return this.primitives;
|
|
1115
1115
|
}
|
|
1116
1116
|
get state() {
|
|
1117
|
-
return
|
|
1117
|
+
return globalThis.__vitest_worker__ || this.options.state;
|
|
1118
1118
|
}
|
|
1119
1119
|
shouldResolveId(id, _importee) {
|
|
1120
1120
|
var _a;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function getWorkerState() {
|
|
2
|
+
const workerState = globalThis.__vitest_worker__;
|
|
3
|
+
if (!workerState) {
|
|
4
|
+
const errorMsg = 'Vitest failed to access its internal state.\n\nOne of the following is possible:\n- "vitest" is imported directly without running "vitest" command\n- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n';
|
|
5
|
+
throw new Error(errorMsg);
|
|
6
|
+
}
|
|
7
|
+
return workerState;
|
|
8
|
+
}
|
|
9
|
+
function getCurrentEnvironment() {
|
|
10
|
+
const state = getWorkerState();
|
|
11
|
+
return state == null ? void 0 : state.environment.name;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { getCurrentEnvironment as a, getWorkerState as g };
|
|
@@ -2,7 +2,7 @@ import { relative } from 'pathe';
|
|
|
2
2
|
import 'std-env';
|
|
3
3
|
import '@vitest/runner/utils';
|
|
4
4
|
import '@vitest/utils';
|
|
5
|
-
import { g as getWorkerState } from './vendor-global.
|
|
5
|
+
import { g as getWorkerState } from './vendor-global.c3664e75.js';
|
|
6
6
|
|
|
7
7
|
var _a;
|
|
8
8
|
const isNode = typeof process < "u" && typeof process.stdout < "u" && !((_a = process.versions) == null ? void 0 : _a.deno) && !globalThis.window;
|
|
@@ -2,8 +2,8 @@ import * as chai from 'chai';
|
|
|
2
2
|
import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
|
|
3
3
|
import { resolve } from 'pathe';
|
|
4
4
|
import { d as distDir } from './vendor-paths.84fc7a99.js';
|
|
5
|
-
import { g as getWorkerState } from './vendor-global.
|
|
6
|
-
import { a as rpc } from './vendor-rpc.
|
|
5
|
+
import { g as getWorkerState } from './vendor-global.c3664e75.js';
|
|
6
|
+
import { a as rpc } from './vendor-rpc.171f65fb.js';
|
|
7
7
|
import { t as takeCoverageInsideWorker } from './vendor-coverage.78040316.js';
|
|
8
8
|
import { loadDiffConfig } from './browser.js';
|
|
9
9
|
|
|
@@ -68,8 +68,13 @@ async function resolveTestRunner(config, executor) {
|
|
|
68
68
|
};
|
|
69
69
|
const originalOnAfterRun = testRunner.onAfterRunFiles;
|
|
70
70
|
testRunner.onAfterRunFiles = async (files) => {
|
|
71
|
+
const state = getWorkerState();
|
|
71
72
|
const coverage = await takeCoverageInsideWorker(config.coverage, executor);
|
|
72
|
-
rpc().onAfterSuiteRun({
|
|
73
|
+
rpc().onAfterSuiteRun({
|
|
74
|
+
coverage,
|
|
75
|
+
transformMode: state.environment.transformMode,
|
|
76
|
+
projectName: state.ctx.projectName
|
|
77
|
+
});
|
|
73
78
|
await (originalOnAfterRun == null ? void 0 : originalOnAfterRun.call(testRunner, files));
|
|
74
79
|
};
|
|
75
80
|
const originalOnAfterRunTask = testRunner.onAfterRunTask;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
|
|
2
|
-
import { b as bench } from './vendor-benchmark.
|
|
3
|
-
import { i as isFirstRun, r as runOnce } from './vendor-run-once.
|
|
4
|
-
import { c as createExpect, a as globalExpect, v as vi, b as vitest } from './vendor-vi.
|
|
2
|
+
import { b as bench } from './vendor-benchmark.b6befc50.js';
|
|
3
|
+
import { i as isFirstRun, r as runOnce } from './vendor-run-once.fb836747.js';
|
|
4
|
+
import { c as createExpect, a as globalExpect, v as vi, b as vitest } from './vendor-vi.3baa7c4a.js';
|
|
5
|
+
import { g as getWorkerState } from './vendor-global.c3664e75.js';
|
|
5
6
|
import * as chai from 'chai';
|
|
6
7
|
import { assert, should } from 'chai';
|
|
7
8
|
|
|
@@ -12,6 +13,11 @@ function isWatchMode() {
|
|
|
12
13
|
return getRunningMode() === "watch";
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
function inject(key) {
|
|
17
|
+
const workerState = getWorkerState();
|
|
18
|
+
return workerState.providedContext[key];
|
|
19
|
+
}
|
|
20
|
+
|
|
15
21
|
var dist = {};
|
|
16
22
|
|
|
17
23
|
(function (exports) {
|
|
@@ -106,6 +112,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
106
112
|
expect: globalExpect,
|
|
107
113
|
expectTypeOf: dist.expectTypeOf,
|
|
108
114
|
getRunningMode: getRunningMode,
|
|
115
|
+
inject: inject,
|
|
109
116
|
isFirstRun: isFirstRun,
|
|
110
117
|
isWatchMode: isWatchMode,
|
|
111
118
|
it: it,
|
|
@@ -118,4 +125,4 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
118
125
|
vitest: vitest
|
|
119
126
|
});
|
|
120
127
|
|
|
121
|
-
export {
|
|
128
|
+
export { inject as a, isWatchMode as b, assertType as c, dist as d, getRunningMode as g, index as i };
|