vitest 0.28.3 → 0.28.5
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/dist/browser.d.ts +1 -1
- package/dist/browser.js +2 -2
- package/dist/{chunk-api-setup.ec61b167.js → chunk-api-setup.d88afda6.js} +3 -3
- package/dist/{chunk-install-pkg.4b6b9575.js → chunk-install-pkg.e1e08354.js} +2 -2
- package/dist/{chunk-integrations-globals.aacbac4d.js → chunk-integrations-globals.59432f4f.js} +4 -4
- package/dist/{chunk-integrations-utils.dae69d89.js → chunk-integrations-utils.9717ad89.js} +1 -1
- package/dist/{chunk-node-pkg.25890a5a.js → chunk-node-pkg.9a107dfb.js} +26 -30
- package/dist/{chunk-runtime-mocker.eb0c265c.js → chunk-runtime-mocker.dafe0f77.js} +22 -36
- package/dist/{chunk-runtime-setup.7dfc1a6a.js → chunk-runtime-setup.30ab0a4b.js} +1 -1
- package/dist/{chunk-snapshot-env.6457638e.js → chunk-snapshot-env.a347d647.js} +2 -2
- package/dist/{chunk-utils-import.0402c9db.js → chunk-utils-import.847b4a2d.js} +15 -26
- package/dist/{chunk-utils-tasks.a9a8d8e1.js → chunk-utils-tasks.d07dcea9.js} +13 -9
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +1 -1
- package/dist/entry.js +29 -19
- package/dist/environments.d.ts +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +5 -5
- package/dist/node.d.ts +6 -9
- package/dist/node.js +4 -3
- package/dist/runners.d.ts +3 -1
- package/dist/runners.js +219 -11
- package/dist/{types-aac763a5.d.ts → types-0373403c.d.ts} +2 -2
- package/dist/worker.js +9 -10
- package/package.json +6 -6
- package/dist/runners-chunk.js +0 -215
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { normalize } from 'pathe';
|
|
2
2
|
import cac from 'cac';
|
|
3
3
|
import c from 'picocolors';
|
|
4
|
-
import { v as version, s as startVitest, d as divider } from './chunk-node-pkg.
|
|
4
|
+
import { v as version, s as startVitest, d as divider } from './chunk-node-pkg.9a107dfb.js';
|
|
5
5
|
import './chunk-constants.797d3ebf.js';
|
|
6
6
|
import 'node:url';
|
|
7
7
|
import './chunk-utils-env.860d90c2.js';
|
|
@@ -43,7 +43,7 @@ import 'tinypool';
|
|
|
43
43
|
import './vendor-index.783e7f3e.js';
|
|
44
44
|
import 'perf_hooks';
|
|
45
45
|
import './chunk-utils-base.904102a8.js';
|
|
46
|
-
import './chunk-utils-tasks.
|
|
46
|
+
import './chunk-utils-tasks.d07dcea9.js';
|
|
47
47
|
import 'crypto';
|
|
48
48
|
import 'vite-node/utils';
|
|
49
49
|
import '@vitest/utils/diff';
|
package/dist/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UserConfig as UserConfig$2, ConfigEnv } from 'vite';
|
|
2
2
|
export { ConfigEnv } from 'vite';
|
|
3
|
-
import { a1 as ResolvedCoverageOptions, U as UserConfig$1, a4 as CoverageC8Options, _ as CoverageProviderModule, a2 as BaseCoverageOptions, a3 as CoverageIstanbulOptions, $ as CoverageReporter, F as FakeTimerInstallOpts } from './types-
|
|
3
|
+
import { a1 as ResolvedCoverageOptions, U as UserConfig$1, a4 as CoverageC8Options, _ as CoverageProviderModule, a2 as BaseCoverageOptions, a3 as CoverageIstanbulOptions, $ as CoverageReporter, F as FakeTimerInstallOpts } from './types-0373403c.js';
|
|
4
4
|
import '@vitest/expect';
|
|
5
5
|
import '@vitest/runner/types';
|
|
6
6
|
import '@vitest/runner';
|
package/dist/entry.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { promises, existsSync } from 'node:fs';
|
|
2
2
|
import { m as micromatch_1, t as takeCoverageInsideWorker } from './chunk-integrations-coverage.48e6286b.js';
|
|
3
3
|
import { startTests } from '@vitest/runner';
|
|
4
|
+
import { resolve } from 'pathe';
|
|
4
5
|
import { g as getWorkerState, r as resetModules } from './chunk-utils-global.442d1d33.js';
|
|
5
|
-
import { R as RealDate, g as globalExpect, a as vi } from './chunk-utils-import.
|
|
6
|
+
import { R as RealDate, g as globalExpect, a as vi } from './chunk-utils-import.847b4a2d.js';
|
|
6
7
|
import { e as environments, a as envs } from './chunk-env-node.ffd1183b.js';
|
|
8
|
+
import { d as distDir } from './chunk-constants.797d3ebf.js';
|
|
7
9
|
import { createRequire } from 'node:module';
|
|
8
10
|
import c from 'picocolors';
|
|
9
11
|
import { installSourcemapsSupport } from 'vite-node/source-map';
|
|
10
12
|
import { setColors, getSafeTimers } from '@vitest/utils';
|
|
11
|
-
import { i as index } from './chunk-integrations-utils.
|
|
12
|
-
import { s as setupSnapshotEnvironment } from './chunk-snapshot-env.
|
|
13
|
+
import { i as index } from './chunk-integrations-utils.9717ad89.js';
|
|
14
|
+
import { s as setupSnapshotEnvironment } from './chunk-snapshot-env.a347d647.js';
|
|
13
15
|
import { r as rpc } from './chunk-runtime-rpc.9c0386cc.js';
|
|
14
|
-
import { s as setupCommonEnv } from './chunk-runtime-setup.
|
|
15
|
-
import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './runners-chunk.js';
|
|
16
|
+
import { s as setupCommonEnv } from './chunk-runtime-setup.30ab0a4b.js';
|
|
16
17
|
import 'local-pkg';
|
|
17
18
|
import 'util';
|
|
18
19
|
import 'path';
|
|
19
|
-
import 'pathe';
|
|
20
20
|
import './chunk-utils-env.860d90c2.js';
|
|
21
21
|
import 'std-env';
|
|
22
22
|
import '@vitest/runner/utils';
|
|
@@ -24,9 +24,10 @@ import 'chai';
|
|
|
24
24
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
25
25
|
import '@vitest/expect';
|
|
26
26
|
import './chunk-utils-base.904102a8.js';
|
|
27
|
-
import './chunk-utils-tasks.
|
|
27
|
+
import './chunk-utils-tasks.d07dcea9.js';
|
|
28
28
|
import '@vitest/spy';
|
|
29
29
|
import 'node:console';
|
|
30
|
+
import 'node:url';
|
|
30
31
|
import './chunk-integrations-run-once.38756e30.js';
|
|
31
32
|
|
|
32
33
|
class NodeSnapshotEnvironment {
|
|
@@ -175,8 +176,8 @@ async function setupConsoleLogSpy() {
|
|
|
175
176
|
groupIndentation: 2
|
|
176
177
|
});
|
|
177
178
|
}
|
|
178
|
-
async function loadEnvironment(name) {
|
|
179
|
-
const pkg = await
|
|
179
|
+
async function loadEnvironment(name, executor) {
|
|
180
|
+
const pkg = await executor.executeId(`vitest-environment-${name}`);
|
|
180
181
|
if (!pkg || !pkg.default || typeof pkg.default !== "object" || typeof pkg.default.setup !== "function") {
|
|
181
182
|
throw new Error(
|
|
182
183
|
`Environment "${name}" is not a valid environment. Package "vitest-environment-${name}" should have default export with "setup" method.`
|
|
@@ -184,8 +185,8 @@ async function loadEnvironment(name) {
|
|
|
184
185
|
}
|
|
185
186
|
return pkg.default;
|
|
186
187
|
}
|
|
187
|
-
async function withEnv(name, options, fn) {
|
|
188
|
-
const config = environments[name] || await loadEnvironment(name);
|
|
188
|
+
async function withEnv(name, options, executor, fn) {
|
|
189
|
+
const config = environments[name] || await loadEnvironment(name, executor);
|
|
189
190
|
globalThis.__vitest_environment__ = config.name || name;
|
|
190
191
|
globalExpect.setState({
|
|
191
192
|
environment: config.name || name || "node"
|
|
@@ -198,6 +199,7 @@ async function withEnv(name, options, fn) {
|
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
201
|
|
|
202
|
+
const runnersFile = resolve(distDir, "runners.js");
|
|
201
203
|
function groupBy(collection, iteratee) {
|
|
202
204
|
return collection.reduce((acc, item) => {
|
|
203
205
|
const key = iteratee(item);
|
|
@@ -206,17 +208,24 @@ function groupBy(collection, iteratee) {
|
|
|
206
208
|
return acc;
|
|
207
209
|
}, {});
|
|
208
210
|
}
|
|
209
|
-
async function getTestRunnerConstructor(config) {
|
|
210
|
-
if (!config.runner)
|
|
211
|
+
async function getTestRunnerConstructor(config, executor) {
|
|
212
|
+
if (!config.runner) {
|
|
213
|
+
const { VitestTestRunner, NodeBenchmarkRunner } = await executor.executeFile(runnersFile);
|
|
211
214
|
return config.mode === "test" ? VitestTestRunner : NodeBenchmarkRunner;
|
|
212
|
-
|
|
215
|
+
}
|
|
216
|
+
const mod = await executor.executeId(config.runner);
|
|
213
217
|
if (!mod.default && typeof mod.default !== "function")
|
|
214
218
|
throw new Error(`Runner must export a default function, but got ${typeof mod.default} imported from ${config.runner}`);
|
|
215
219
|
return mod.default;
|
|
216
220
|
}
|
|
217
|
-
async function getTestRunner(config) {
|
|
218
|
-
const TestRunner = await getTestRunnerConstructor(config);
|
|
221
|
+
async function getTestRunner(config, executor) {
|
|
222
|
+
const TestRunner = await getTestRunnerConstructor(config, executor);
|
|
219
223
|
const testRunner = new TestRunner(config);
|
|
224
|
+
Object.defineProperty(testRunner, "__vitest_executor", {
|
|
225
|
+
value: executor,
|
|
226
|
+
enumerable: false,
|
|
227
|
+
configurable: false
|
|
228
|
+
});
|
|
220
229
|
if (!testRunner.config)
|
|
221
230
|
testRunner.config = config;
|
|
222
231
|
if (!testRunner.importFile)
|
|
@@ -240,10 +249,10 @@ async function getTestRunner(config) {
|
|
|
240
249
|
};
|
|
241
250
|
return testRunner;
|
|
242
251
|
}
|
|
243
|
-
async function run(files, config) {
|
|
252
|
+
async function run(files, config, executor) {
|
|
244
253
|
await setupGlobalEnv(config);
|
|
245
254
|
const workerState = getWorkerState();
|
|
246
|
-
const runner = await getTestRunner(config);
|
|
255
|
+
const runner = await getTestRunner(config, executor);
|
|
247
256
|
const filesWithEnv = await Promise.all(files.map(async (file) => {
|
|
248
257
|
var _a, _b;
|
|
249
258
|
const code = await promises.readFile(file, "utf-8");
|
|
@@ -279,7 +288,7 @@ async function run(files, config) {
|
|
|
279
288
|
const files3 = filesByOptions[options];
|
|
280
289
|
if (!files3 || !files3.length)
|
|
281
290
|
continue;
|
|
282
|
-
await withEnv(environment, files3[0].envOptions || config.environmentOptions || {}, async () => {
|
|
291
|
+
await withEnv(environment, files3[0].envOptions || config.environmentOptions || {}, executor, async () => {
|
|
283
292
|
for (const { file } of files3) {
|
|
284
293
|
if (config.isolate) {
|
|
285
294
|
workerState.mockMap.clear();
|
|
@@ -289,6 +298,7 @@ async function run(files, config) {
|
|
|
289
298
|
await startTests([file], runner);
|
|
290
299
|
workerState.filepath = void 0;
|
|
291
300
|
vi.resetConfig();
|
|
301
|
+
vi.restoreAllMocks();
|
|
292
302
|
}
|
|
293
303
|
});
|
|
294
304
|
}
|
package/dist/environments.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Test } from '@vitest/runner';
|
|
2
2
|
export { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
|
|
3
|
-
import { B as BenchmarkAPI, F as FakeTimerInstallOpts, M as MockFactoryWithHelper, R as RuntimeConfig, a as ResolvedConfig, b as ModuleGraphData, S as SnapshotResult, c as Reporter } from './types-
|
|
4
|
-
export { u as AfterSuiteRunMeta, A as ApiConfig, z as ArgumentsType, y as Arrayable, x as Awaitable, a2 as BaseCoverageOptions, a8 as BenchFunction, a6 as Benchmark, B as BenchmarkAPI, a7 as BenchmarkResult, a5 as BenchmarkUserOptions, h as BuiltinEnvironment, i as CSSModuleScopeStrategy, C as CollectLineNumbers, e as CollectLines, K as Constructable, g as Context, a4 as CoverageC8Options, a3 as CoverageIstanbulOptions, a0 as CoverageOptions, Y as CoverageProvider, _ as CoverageProviderModule, $ as CoverageReporter, G as DeepMerge, P as Environment, E as EnvironmentOptions, O as EnvironmentReturn, I as InlineConfig, J as JSDOMOptions, D as MergeInsertions, L as ModuleCache, b as ModuleGraphData, H as MutableArray, N as Nullable, X as OnServerRestartHandler, d as RawErrsMap, Z as ReportContext, c as Reporter, t as ResolveIdFunction, a as ResolvedConfig, a1 as ResolvedCoverageOptions, f as RootAndTarget, R as RuntimeConfig, j as SequenceHooks, n as SnapshotData, q as SnapshotMatchOptions, S as SnapshotResult, p as SnapshotStateOptions, s as SnapshotSummary, o as SnapshotUpdateState, T as TscErrorInfo, l as TypecheckConfig, r as UncheckedSnapshot, U as UserConfig, Q as UserConsoleLog, m as Vitest, V as VitestEnvironment, k as VitestRunMode, W as WorkerContext, w as WorkerGlobalState, v as WorkerRPC } from './types-
|
|
3
|
+
import { B as BenchmarkAPI, F as FakeTimerInstallOpts, M as MockFactoryWithHelper, R as RuntimeConfig, a as ResolvedConfig, b as ModuleGraphData, S as SnapshotResult, c as Reporter } from './types-0373403c.js';
|
|
4
|
+
export { u as AfterSuiteRunMeta, A as ApiConfig, z as ArgumentsType, y as Arrayable, x as Awaitable, a2 as BaseCoverageOptions, a8 as BenchFunction, a6 as Benchmark, B as BenchmarkAPI, a7 as BenchmarkResult, a5 as BenchmarkUserOptions, h as BuiltinEnvironment, i as CSSModuleScopeStrategy, C as CollectLineNumbers, e as CollectLines, K as Constructable, g as Context, a4 as CoverageC8Options, a3 as CoverageIstanbulOptions, a0 as CoverageOptions, Y as CoverageProvider, _ as CoverageProviderModule, $ as CoverageReporter, G as DeepMerge, P as Environment, E as EnvironmentOptions, O as EnvironmentReturn, I as InlineConfig, J as JSDOMOptions, D as MergeInsertions, L as ModuleCache, b as ModuleGraphData, H as MutableArray, N as Nullable, X as OnServerRestartHandler, d as RawErrsMap, Z as ReportContext, c as Reporter, t as ResolveIdFunction, a as ResolvedConfig, a1 as ResolvedCoverageOptions, f as RootAndTarget, R as RuntimeConfig, j as SequenceHooks, n as SnapshotData, q as SnapshotMatchOptions, S as SnapshotResult, p as SnapshotStateOptions, s as SnapshotSummary, o as SnapshotUpdateState, T as TscErrorInfo, l as TypecheckConfig, r as UncheckedSnapshot, U as UserConfig, Q as UserConsoleLog, m as Vitest, V as VitestEnvironment, k as VitestRunMode, W as WorkerContext, w as WorkerGlobalState, v as WorkerRPC } from './types-0373403c.js';
|
|
5
5
|
import { spyOn, fn, MaybeMockedDeep, MaybeMocked, MaybePartiallyMocked, MaybePartiallyMockedDeep, EnhancedSpy } from '@vitest/spy';
|
|
6
6
|
export { EnhancedSpy, Mock, MockContext, MockInstance, Mocked, MockedClass, MockedFunction, MockedObject, SpyInstance } from '@vitest/spy';
|
|
7
7
|
export { S as SnapshotEnvironment } from './env-afee91f0.js';
|
|
@@ -306,7 +306,7 @@ declare class VitestUtils {
|
|
|
306
306
|
*/
|
|
307
307
|
unstubAllGlobals(): this;
|
|
308
308
|
/**
|
|
309
|
-
* Reset
|
|
309
|
+
* Reset environmental variables to the ones that were available before first `vi.stubEnv` was called.
|
|
310
310
|
*/
|
|
311
311
|
unstubAllEnvs(): this;
|
|
312
312
|
resetModules(): this;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
|
|
2
|
-
export { b as bench, c as createExpect, g as expect, a as vi, v as vitest } from './chunk-utils-import.
|
|
2
|
+
export { b as bench, c as createExpect, g as expect, a as vi, v as vitest } from './chunk-utils-import.847b4a2d.js';
|
|
3
3
|
export { i as isFirstRun, r as runOnce } from './chunk-integrations-run-once.38756e30.js';
|
|
4
|
-
import { d as dist } from './chunk-integrations-utils.
|
|
5
|
-
export { b as assertType, g as getRunningMode, a as isWatchMode } from './chunk-integrations-utils.
|
|
4
|
+
import { d as dist } from './chunk-integrations-utils.9717ad89.js';
|
|
5
|
+
export { b as assertType, g as getRunningMode, a as isWatchMode } from './chunk-integrations-utils.9717ad89.js';
|
|
6
6
|
import * as chai from 'chai';
|
|
7
7
|
export { chai };
|
|
8
8
|
export { assert, should } from 'chai';
|
|
@@ -15,9 +15,9 @@ import 'std-env';
|
|
|
15
15
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
16
16
|
import '@vitest/expect';
|
|
17
17
|
import './chunk-runtime-rpc.9c0386cc.js';
|
|
18
|
-
import './chunk-snapshot-env.
|
|
18
|
+
import './chunk-snapshot-env.a347d647.js';
|
|
19
19
|
import './chunk-utils-base.904102a8.js';
|
|
20
|
-
import './chunk-utils-tasks.
|
|
20
|
+
import './chunk-utils-tasks.d07dcea9.js';
|
|
21
21
|
import 'util';
|
|
22
22
|
import '@vitest/spy';
|
|
23
23
|
|
package/dist/node.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { k as VitestRunMode, U as UserConfig, m as Vitest, a9 as MockFactory, aa as MockMap, ab as TestSequencer } from './types-
|
|
2
|
-
export { ab as TestSequencer, ad as TestSequencerConstructor, m as Vitest, ac as startVitest } from './types-
|
|
1
|
+
import { k as VitestRunMode, U as UserConfig, m as Vitest, a9 as MockFactory, aa as MockMap, ab as TestSequencer } from './types-0373403c.js';
|
|
2
|
+
export { ab as TestSequencer, ad as TestSequencerConstructor, m as Vitest, ac as startVitest } from './types-0373403c.js';
|
|
3
3
|
import { UserConfig as UserConfig$1, Plugin } from 'vite';
|
|
4
4
|
import { ViteNodeRunner } from 'vite-node/client';
|
|
5
5
|
import { ViteNodeRunnerOptions } from 'vite-node';
|
|
@@ -19,12 +19,10 @@ declare function VitestPlugin(options?: UserConfig, ctx?: Vitest): Promise<Plugi
|
|
|
19
19
|
|
|
20
20
|
type Key = string | symbol;
|
|
21
21
|
declare class VitestMocker {
|
|
22
|
-
|
|
22
|
+
executor: VitestExecutor;
|
|
23
23
|
private static pendingIds;
|
|
24
|
-
private static spyModulePath;
|
|
25
|
-
private static spyModule?;
|
|
26
24
|
private resolveCache;
|
|
27
|
-
constructor(
|
|
25
|
+
constructor(executor: VitestExecutor);
|
|
28
26
|
private get root();
|
|
29
27
|
private get base();
|
|
30
28
|
private get mockMap();
|
|
@@ -45,7 +43,6 @@ declare class VitestMocker {
|
|
|
45
43
|
mockPath(originalId: string, path: string, external: string | null, factory?: MockFactory): void;
|
|
46
44
|
importActual<T>(rawId: string, importee: string): Promise<T>;
|
|
47
45
|
importMock(rawId: string, importee: string): Promise<any>;
|
|
48
|
-
initializeSpyModule(): Promise<void>;
|
|
49
46
|
requestWithMock(url: string, callstack: string[]): Promise<any>;
|
|
50
47
|
queueMock(id: string, importer: string, factory?: MockFactory): void;
|
|
51
48
|
queueUnmock(id: string, importer: string): void;
|
|
@@ -54,7 +51,7 @@ declare class VitestMocker {
|
|
|
54
51
|
interface ExecuteOptions extends ViteNodeRunnerOptions {
|
|
55
52
|
mockMap: MockMap;
|
|
56
53
|
}
|
|
57
|
-
declare class
|
|
54
|
+
declare class VitestExecutor extends ViteNodeRunner {
|
|
58
55
|
options: ExecuteOptions;
|
|
59
56
|
mocker: VitestMocker;
|
|
60
57
|
constructor(options: ExecuteOptions);
|
|
@@ -71,4 +68,4 @@ declare class BaseSequencer implements TestSequencer {
|
|
|
71
68
|
sort(files: string[]): Promise<string[]>;
|
|
72
69
|
}
|
|
73
70
|
|
|
74
|
-
export { BaseSequencer, ExecuteOptions,
|
|
71
|
+
export { BaseSequencer, ExecuteOptions, VitestExecutor, VitestPlugin, createVitest };
|
package/dist/node.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { B as BaseSequencer, V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-node-pkg.
|
|
2
|
-
export { V as
|
|
1
|
+
export { B as BaseSequencer, V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-node-pkg.9a107dfb.js';
|
|
2
|
+
export { V as VitestExecutor } from './chunk-runtime-mocker.dafe0f77.js';
|
|
3
3
|
import 'pathe';
|
|
4
4
|
import './chunk-constants.797d3ebf.js';
|
|
5
5
|
import 'node:url';
|
|
@@ -43,7 +43,7 @@ import 'tinypool';
|
|
|
43
43
|
import './vendor-index.783e7f3e.js';
|
|
44
44
|
import 'perf_hooks';
|
|
45
45
|
import './chunk-utils-base.904102a8.js';
|
|
46
|
-
import './chunk-utils-tasks.
|
|
46
|
+
import './chunk-utils-tasks.d07dcea9.js';
|
|
47
47
|
import 'crypto';
|
|
48
48
|
import 'vite-node/utils';
|
|
49
49
|
import '@vitest/utils/diff';
|
|
@@ -56,3 +56,4 @@ import 'node:module';
|
|
|
56
56
|
import 'node:assert';
|
|
57
57
|
import 'node:v8';
|
|
58
58
|
import 'node:util';
|
|
59
|
+
import '@vitest/spy';
|
package/dist/runners.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VitestRunner, VitestRunnerImportSource, Suite, Test, TestContext } from '@vitest/runner';
|
|
2
|
-
import { a as ResolvedConfig } from './types-
|
|
2
|
+
import { a as ResolvedConfig } from './types-0373403c.js';
|
|
3
3
|
import '@vitest/expect';
|
|
4
4
|
import 'vite';
|
|
5
5
|
import '@vitest/runner/types';
|
|
@@ -16,6 +16,7 @@ declare class VitestTestRunner implements VitestRunner {
|
|
|
16
16
|
config: ResolvedConfig;
|
|
17
17
|
private snapshotClient;
|
|
18
18
|
private workerState;
|
|
19
|
+
private __vitest_executor;
|
|
19
20
|
constructor(config: ResolvedConfig);
|
|
20
21
|
importFile(filepath: string, source: VitestRunnerImportSource): unknown;
|
|
21
22
|
onBeforeRun(): void;
|
|
@@ -30,6 +31,7 @@ declare class VitestTestRunner implements VitestRunner {
|
|
|
30
31
|
|
|
31
32
|
declare class NodeBenchmarkRunner implements VitestRunner {
|
|
32
33
|
config: ResolvedConfig;
|
|
34
|
+
private __vitest_executor;
|
|
33
35
|
constructor(config: ResolvedConfig);
|
|
34
36
|
importFile(filepath: string, source: VitestRunnerImportSource): unknown;
|
|
35
37
|
runSuite(suite: Suite): Promise<void>;
|
package/dist/runners.js
CHANGED
|
@@ -1,18 +1,226 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
3
|
-
import './chunk-utils-
|
|
4
|
-
import '
|
|
1
|
+
import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
|
|
2
|
+
import { d as getSnapshotClient, c as createExpect, a as vi, e as getBenchOptions, f as getBenchFn } from './chunk-utils-import.847b4a2d.js';
|
|
3
|
+
import { g as getWorkerState } from './chunk-utils-global.442d1d33.js';
|
|
4
|
+
import { g as getFullName } from './chunk-utils-tasks.d07dcea9.js';
|
|
5
|
+
import { updateTask } from '@vitest/runner';
|
|
6
|
+
import { createDefer, getSafeTimers } from '@vitest/utils';
|
|
5
7
|
import '@vitest/runner/utils';
|
|
6
|
-
import '@vitest/utils';
|
|
7
|
-
import './chunk-utils-global.442d1d33.js';
|
|
8
|
-
import 'pathe';
|
|
9
|
-
import './chunk-utils-env.860d90c2.js';
|
|
10
|
-
import 'std-env';
|
|
11
8
|
import 'chai';
|
|
12
9
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
13
10
|
import './chunk-runtime-rpc.9c0386cc.js';
|
|
14
|
-
import '
|
|
11
|
+
import 'pathe';
|
|
12
|
+
import './chunk-snapshot-env.a347d647.js';
|
|
15
13
|
import './chunk-utils-base.904102a8.js';
|
|
16
|
-
import './chunk-utils-tasks.a9a8d8e1.js';
|
|
17
14
|
import 'util';
|
|
18
15
|
import '@vitest/spy';
|
|
16
|
+
import './chunk-utils-env.860d90c2.js';
|
|
17
|
+
import 'std-env';
|
|
18
|
+
|
|
19
|
+
class VitestTestRunner {
|
|
20
|
+
constructor(config) {
|
|
21
|
+
this.config = config;
|
|
22
|
+
this.snapshotClient = getSnapshotClient();
|
|
23
|
+
this.workerState = getWorkerState();
|
|
24
|
+
}
|
|
25
|
+
importFile(filepath, source) {
|
|
26
|
+
if (source === "setup")
|
|
27
|
+
this.workerState.moduleCache.delete(filepath);
|
|
28
|
+
return this.__vitest_executor.executeId(filepath);
|
|
29
|
+
}
|
|
30
|
+
onBeforeRun() {
|
|
31
|
+
this.snapshotClient.clear();
|
|
32
|
+
}
|
|
33
|
+
async onAfterRun() {
|
|
34
|
+
await this.snapshotClient.saveCurrent();
|
|
35
|
+
}
|
|
36
|
+
onAfterRunSuite(suite) {
|
|
37
|
+
if (this.config.logHeapUsage && typeof process !== "undefined")
|
|
38
|
+
suite.result.heap = process.memoryUsage().heapUsed;
|
|
39
|
+
}
|
|
40
|
+
onAfterRunTest(test) {
|
|
41
|
+
this.snapshotClient.clearTest();
|
|
42
|
+
if (this.config.logHeapUsage && typeof process !== "undefined")
|
|
43
|
+
test.result.heap = process.memoryUsage().heapUsed;
|
|
44
|
+
this.workerState.current = void 0;
|
|
45
|
+
}
|
|
46
|
+
async onBeforeRunTest(test) {
|
|
47
|
+
if (test.mode !== "run") {
|
|
48
|
+
this.snapshotClient.skipTestSnapshots(test);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
clearModuleMocks(this.config);
|
|
52
|
+
await this.snapshotClient.setTest(test);
|
|
53
|
+
this.workerState.current = test;
|
|
54
|
+
}
|
|
55
|
+
onBeforeTryTest(test) {
|
|
56
|
+
var _a;
|
|
57
|
+
setState({
|
|
58
|
+
assertionCalls: 0,
|
|
59
|
+
isExpectingAssertions: false,
|
|
60
|
+
isExpectingAssertionsError: null,
|
|
61
|
+
expectedAssertionsNumber: null,
|
|
62
|
+
expectedAssertionsNumberErrorGen: null,
|
|
63
|
+
testPath: (_a = test.suite.file) == null ? void 0 : _a.filepath,
|
|
64
|
+
currentTestName: getFullName(test),
|
|
65
|
+
snapshotState: this.snapshotClient.snapshotState
|
|
66
|
+
}, globalThis[GLOBAL_EXPECT]);
|
|
67
|
+
}
|
|
68
|
+
onAfterTryTest(test) {
|
|
69
|
+
const {
|
|
70
|
+
assertionCalls,
|
|
71
|
+
expectedAssertionsNumber,
|
|
72
|
+
expectedAssertionsNumberErrorGen,
|
|
73
|
+
isExpectingAssertions,
|
|
74
|
+
isExpectingAssertionsError
|
|
75
|
+
} = test.context._local ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
|
|
76
|
+
if (expectedAssertionsNumber !== null && assertionCalls !== expectedAssertionsNumber)
|
|
77
|
+
throw expectedAssertionsNumberErrorGen();
|
|
78
|
+
if (isExpectingAssertions === true && assertionCalls === 0)
|
|
79
|
+
throw isExpectingAssertionsError;
|
|
80
|
+
}
|
|
81
|
+
extendTestContext(context) {
|
|
82
|
+
let _expect;
|
|
83
|
+
Object.defineProperty(context, "expect", {
|
|
84
|
+
get() {
|
|
85
|
+
if (!_expect)
|
|
86
|
+
_expect = createExpect(context.meta);
|
|
87
|
+
return _expect;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(context, "_local", {
|
|
91
|
+
get() {
|
|
92
|
+
return _expect != null;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return context;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function clearModuleMocks(config) {
|
|
99
|
+
const { clearMocks, mockReset, restoreMocks, unstubEnvs, unstubGlobals } = config;
|
|
100
|
+
if (restoreMocks)
|
|
101
|
+
vi.restoreAllMocks();
|
|
102
|
+
else if (mockReset)
|
|
103
|
+
vi.resetAllMocks();
|
|
104
|
+
else if (clearMocks)
|
|
105
|
+
vi.clearAllMocks();
|
|
106
|
+
if (unstubEnvs)
|
|
107
|
+
vi.unstubAllEnvs();
|
|
108
|
+
if (unstubGlobals)
|
|
109
|
+
vi.unstubAllGlobals();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function importTinybench() {
|
|
113
|
+
if (!globalThis.EventTarget)
|
|
114
|
+
await import('./vendor-index.534e612c.js').then(function (n) { return n.i; });
|
|
115
|
+
return await import('tinybench');
|
|
116
|
+
}
|
|
117
|
+
function createBenchmarkResult(name) {
|
|
118
|
+
return {
|
|
119
|
+
name,
|
|
120
|
+
rank: 0,
|
|
121
|
+
rme: 0,
|
|
122
|
+
samples: []
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
async function runBenchmarkSuite(suite, runner) {
|
|
126
|
+
var _a;
|
|
127
|
+
const { Task, Bench } = await importTinybench();
|
|
128
|
+
const start = performance.now();
|
|
129
|
+
const benchmarkGroup = [];
|
|
130
|
+
const benchmarkSuiteGroup = [];
|
|
131
|
+
for (const task of suite.tasks) {
|
|
132
|
+
if (task.mode !== "run")
|
|
133
|
+
continue;
|
|
134
|
+
if ((_a = task.meta) == null ? void 0 : _a.benchmark)
|
|
135
|
+
benchmarkGroup.push(task);
|
|
136
|
+
else if (task.type === "suite")
|
|
137
|
+
benchmarkSuiteGroup.push(task);
|
|
138
|
+
}
|
|
139
|
+
if (benchmarkSuiteGroup.length)
|
|
140
|
+
await Promise.all(benchmarkSuiteGroup.map((subSuite) => runBenchmarkSuite(subSuite, runner)));
|
|
141
|
+
if (benchmarkGroup.length) {
|
|
142
|
+
const defer = createDefer();
|
|
143
|
+
const benchmarkMap = {};
|
|
144
|
+
suite.result = {
|
|
145
|
+
state: "run",
|
|
146
|
+
startTime: start,
|
|
147
|
+
benchmark: createBenchmarkResult(suite.name)
|
|
148
|
+
};
|
|
149
|
+
updateTask$1(suite);
|
|
150
|
+
benchmarkGroup.forEach((benchmark, idx) => {
|
|
151
|
+
const options = getBenchOptions(benchmark);
|
|
152
|
+
const benchmarkInstance = new Bench(options);
|
|
153
|
+
const benchmarkFn = getBenchFn(benchmark);
|
|
154
|
+
benchmark.result = {
|
|
155
|
+
state: "run",
|
|
156
|
+
startTime: start,
|
|
157
|
+
benchmark: createBenchmarkResult(benchmark.name)
|
|
158
|
+
};
|
|
159
|
+
const id = idx.toString();
|
|
160
|
+
benchmarkMap[id] = benchmark;
|
|
161
|
+
const task = new Task(benchmarkInstance, id, benchmarkFn);
|
|
162
|
+
benchmark.meta.task = task;
|
|
163
|
+
updateTask$1(benchmark);
|
|
164
|
+
});
|
|
165
|
+
benchmarkGroup.forEach((benchmark) => {
|
|
166
|
+
benchmark.meta.task.addEventListener("complete", (e) => {
|
|
167
|
+
const task = e.task;
|
|
168
|
+
const _benchmark = benchmarkMap[task.name || ""];
|
|
169
|
+
if (_benchmark) {
|
|
170
|
+
const taskRes = task.result;
|
|
171
|
+
const result = _benchmark.result.benchmark;
|
|
172
|
+
Object.assign(result, taskRes);
|
|
173
|
+
updateTask$1(_benchmark);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
benchmark.meta.task.addEventListener("error", (e) => {
|
|
177
|
+
const task = e.task;
|
|
178
|
+
const _benchmark = benchmarkMap[task.name || ""];
|
|
179
|
+
defer.reject(_benchmark ? task.result.error : e);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
Promise.all(benchmarkGroup.map(async (benchmark) => {
|
|
183
|
+
await benchmark.meta.task.warmup();
|
|
184
|
+
const { setTimeout } = getSafeTimers();
|
|
185
|
+
return await new Promise((resolve) => setTimeout(async () => {
|
|
186
|
+
resolve(await benchmark.meta.task.run());
|
|
187
|
+
}));
|
|
188
|
+
})).then((tasks) => {
|
|
189
|
+
suite.result.duration = performance.now() - start;
|
|
190
|
+
suite.result.state = "pass";
|
|
191
|
+
tasks.sort((a, b) => a.result.mean - b.result.mean).forEach((cycle, idx) => {
|
|
192
|
+
const benchmark = benchmarkMap[cycle.name || ""];
|
|
193
|
+
benchmark.result.state = "pass";
|
|
194
|
+
if (benchmark) {
|
|
195
|
+
const result = benchmark.result.benchmark;
|
|
196
|
+
result.rank = Number(idx) + 1;
|
|
197
|
+
updateTask$1(benchmark);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
updateTask$1(suite);
|
|
201
|
+
defer.resolve(null);
|
|
202
|
+
});
|
|
203
|
+
await defer;
|
|
204
|
+
}
|
|
205
|
+
function updateTask$1(task) {
|
|
206
|
+
updateTask(task, runner);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
class NodeBenchmarkRunner {
|
|
210
|
+
constructor(config) {
|
|
211
|
+
this.config = config;
|
|
212
|
+
}
|
|
213
|
+
importFile(filepath, source) {
|
|
214
|
+
if (source === "setup")
|
|
215
|
+
getWorkerState().moduleCache.delete(filepath);
|
|
216
|
+
return this.__vitest_executor.executeId(filepath);
|
|
217
|
+
}
|
|
218
|
+
async runSuite(suite) {
|
|
219
|
+
await runBenchmarkSuite(suite, this);
|
|
220
|
+
}
|
|
221
|
+
async runTest() {
|
|
222
|
+
throw new Error("`test()` and `it()` is only available in test mode.");
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export { NodeBenchmarkRunner, VitestTestRunner };
|
|
@@ -1026,7 +1026,7 @@ type ResolvedCoverageOptions<T extends Provider = Provider> = CoverageOptions<T>
|
|
|
1026
1026
|
};
|
|
1027
1027
|
interface BaseCoverageOptions {
|
|
1028
1028
|
/**
|
|
1029
|
-
* Enables coverage collection. Can be
|
|
1029
|
+
* Enables coverage collection. Can be overridden using `--coverage` CLI option.
|
|
1030
1030
|
*
|
|
1031
1031
|
* @default false
|
|
1032
1032
|
*/
|
|
@@ -1979,7 +1979,7 @@ declare global {
|
|
|
1979
1979
|
toBeInstanceOf<E>(expected: E): void;
|
|
1980
1980
|
toBeCalledTimes(times: number): void;
|
|
1981
1981
|
toHaveLength(length: number): void;
|
|
1982
|
-
toHaveProperty<E>(property: string | string[], value?: E): void;
|
|
1982
|
+
toHaveProperty<E>(property: string | (string | number)[], value?: E): void;
|
|
1983
1983
|
toBeCloseTo(number: number, numDigits?: number): void;
|
|
1984
1984
|
toHaveBeenCalledTimes(times: number): void;
|
|
1985
1985
|
toHaveBeenCalledOnce(): void;
|
package/dist/worker.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pathToFileURL } from 'node:url';
|
|
1
2
|
import { resolve, relative } from 'pathe';
|
|
2
3
|
import { c as createBirpc } from './vendor-index.783e7f3e.js';
|
|
3
4
|
import { workerId } from 'tinypool';
|
|
@@ -6,9 +7,8 @@ import { ModuleCacheMap } from 'vite-node/client';
|
|
|
6
7
|
import { isPrimitive } from 'vite-node/utils';
|
|
7
8
|
import { d as distDir } from './chunk-constants.797d3ebf.js';
|
|
8
9
|
import { g as getWorkerState } from './chunk-utils-global.442d1d33.js';
|
|
9
|
-
import {
|
|
10
|
+
import { c as createVitestExecutor } from './chunk-runtime-mocker.dafe0f77.js';
|
|
10
11
|
import { r as rpc } from './chunk-runtime-rpc.9c0386cc.js';
|
|
11
|
-
import 'node:url';
|
|
12
12
|
import './chunk-utils-env.860d90c2.js';
|
|
13
13
|
import 'std-env';
|
|
14
14
|
import '@vitest/utils';
|
|
@@ -22,6 +22,7 @@ import 'node:path';
|
|
|
22
22
|
import 'node:v8';
|
|
23
23
|
import 'node:util';
|
|
24
24
|
import './chunk-utils-base.904102a8.js';
|
|
25
|
+
import '@vitest/spy';
|
|
25
26
|
|
|
26
27
|
let _viteNode;
|
|
27
28
|
const moduleCache = new ModuleCacheMap();
|
|
@@ -48,10 +49,7 @@ async function startViteNode(ctx) {
|
|
|
48
49
|
}
|
|
49
50
|
process.on("uncaughtException", (e) => catchError(e, "Uncaught Exception"));
|
|
50
51
|
process.on("unhandledRejection", (e) => catchError(e, "Unhandled Rejection"));
|
|
51
|
-
const
|
|
52
|
-
files: [
|
|
53
|
-
resolve(distDir, "entry.js")
|
|
54
|
-
],
|
|
52
|
+
const executor = await createVitestExecutor({
|
|
55
53
|
fetchModule(id) {
|
|
56
54
|
return rpc().fetch(id);
|
|
57
55
|
},
|
|
@@ -63,8 +61,9 @@ async function startViteNode(ctx) {
|
|
|
63
61
|
interopDefault: config.deps.interopDefault,
|
|
64
62
|
root: config.root,
|
|
65
63
|
base: config.base
|
|
66
|
-
})
|
|
67
|
-
|
|
64
|
+
});
|
|
65
|
+
const { run: run2 } = await import(pathToFileURL(resolve(distDir, "entry.js")).href);
|
|
66
|
+
_viteNode = { run: run2, executor };
|
|
68
67
|
return _viteNode;
|
|
69
68
|
}
|
|
70
69
|
function init(ctx) {
|
|
@@ -102,8 +101,8 @@ function init(ctx) {
|
|
|
102
101
|
}
|
|
103
102
|
async function run(ctx) {
|
|
104
103
|
init(ctx);
|
|
105
|
-
const { run: run2 } = await startViteNode(ctx);
|
|
106
|
-
return run2(ctx.files, ctx.config);
|
|
104
|
+
const { run: run2, executor } = await startViteNode(ctx);
|
|
105
|
+
return run2(ctx.files, ctx.config, executor);
|
|
107
106
|
}
|
|
108
107
|
|
|
109
108
|
export { run };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.28.
|
|
4
|
+
"version": "0.28.5",
|
|
5
5
|
"description": "A blazing fast unit test framework powered by Vite",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -128,11 +128,11 @@
|
|
|
128
128
|
"tinyspy": "^1.0.2",
|
|
129
129
|
"vite": "^3.0.0 || ^4.0.0",
|
|
130
130
|
"why-is-node-running": "^2.2.2",
|
|
131
|
-
"
|
|
132
|
-
"
|
|
133
|
-
"@vitest/
|
|
134
|
-
"@vitest/
|
|
135
|
-
"@vitest/
|
|
131
|
+
"vite-node": "0.28.5",
|
|
132
|
+
"@vitest/expect": "0.28.5",
|
|
133
|
+
"@vitest/runner": "0.28.5",
|
|
134
|
+
"@vitest/utils": "0.28.5",
|
|
135
|
+
"@vitest/spy": "0.28.5"
|
|
136
136
|
},
|
|
137
137
|
"devDependencies": {
|
|
138
138
|
"@antfu/install-pkg": "^0.1.1",
|