vitest 0.23.2 → 0.23.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/dist/browser.d.ts +3 -3
- package/dist/browser.mjs +3 -3
- package/dist/{chunk-integrations-globals.ad5b1b51.mjs → chunk-integrations-globals.d8c90af9.mjs} +2 -2
- package/dist/{chunk-runtime-chain.7a7f3c3b.mjs → chunk-runtime-chain.0ab05798.mjs} +8 -8
- package/dist/{chunk-runtime-error.2723946b.mjs → chunk-runtime-error.f5506f40.mjs} +12 -10
- package/dist/{chunk-runtime-hooks.1a0bc3fd.mjs → chunk-runtime-hooks.e4219ed5.mjs} +1 -1
- package/dist/{chunk-runtime-mocker.8d4a2494.mjs → chunk-runtime-mocker.4bbb070f.mjs} +16 -6
- package/dist/{chunk-vite-node-externalize.f55c4577.mjs → chunk-vite-node-externalize.8d8032d0.mjs} +1110 -1062
- package/dist/cli-wrapper.mjs +3 -1
- package/dist/cli.mjs +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/entry.mjs +3 -3
- package/dist/environments.d.ts +1 -1
- package/dist/{global-d05ffb3f.d.ts → global-e98f203b.d.ts} +15 -3
- package/dist/{index-60e2a8e1.d.ts → index-6e18a03a.d.ts} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.mjs +2 -2
- package/dist/suite.mjs +1 -1
- package/dist/worker.mjs +1 -1
- package/package.json +7 -7
package/dist/browser.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { E as EnhancedSpy, r as Mock, u as MockContext, q as MockInstance, v as Mocked, w as MockedClass, o as MockedFunction, p as MockedObject, S as SpyInstance, j as afterAll, l as afterEach, h as beforeAll, k as beforeEach, n as createExpect, e as describe, m as expect, i as it, d as suite, t as test } from './index-
|
|
2
|
-
import { R as ResolvedConfig } from './global-
|
|
3
|
-
export { L as AfterSuiteRunMeta, A as ApiConfig, Y as ArgumentsType, X as Arrayable, P as Awaitable, ae as BaseCoverageOptions, ak as BenchFunction, ai as Benchmark, al as BenchmarkAPI, aj as BenchmarkResult, ah as BenchmarkUserOptions, B as BuiltinEnvironment, C as CSSModuleScopeStrategy, a0 as Constructable, ag as CoverageC8Options, af as CoverageIstanbulOptions, ac as CoverageOptions, a9 as CoverageProvider, aa as CoverageProviderModule, ab as CoverageReporter, _ as DeepMerge, D as DoneCallback, a3 as Environment, E as EnvironmentOptions, a2 as EnvironmentReturn, a7 as ErrorWithDiff, a as File, n as HookCleanupCallback, H as HookListener, I as InlineConfig, J as JSDOMOptions, Z as MergeInsertions, a1 as ModuleCache, M as ModuleGraphData, $ as MutableArray, Q as Nullable, a8 as OnServerRestartHandler, a6 as ParsedStack, a5 as Position, b as Reporter, K as ResolveIdFunction, R as ResolvedConfig, ad as ResolvedCoverageOptions, d as RunMode, r as RuntimeContext, u as SnapshotData, x as SnapshotMatchOptions, y as SnapshotResult, w as SnapshotStateOptions, G as SnapshotSummary, v as SnapshotUpdateState, S as Suite, m as SuiteAPI, p as SuiteCollector, q as SuiteFactory, o as SuiteHooks, i as Task, f as TaskBase, g as TaskResult, T as TaskResultPack, e as TaskState, h as Test, l as TestAPI, s as TestContext, j as TestFunction, k as TestOptions, z as UncheckedSnapshot, U as UserConfig, a4 as UserConsoleLog, t as Vitest, V as VitestEnvironment, c as VitestRunMode, W as WorkerContext, O as WorkerGlobalState, N as WorkerRPC } from './global-
|
|
1
|
+
export { E as EnhancedSpy, r as Mock, u as MockContext, q as MockInstance, v as Mocked, w as MockedClass, o as MockedFunction, p as MockedObject, S as SpyInstance, j as afterAll, l as afterEach, h as beforeAll, k as beforeEach, n as createExpect, e as describe, m as expect, i as it, d as suite, t as test } from './index-6e18a03a.js';
|
|
2
|
+
import { R as ResolvedConfig } from './global-e98f203b.js';
|
|
3
|
+
export { L as AfterSuiteRunMeta, A as ApiConfig, Y as ArgumentsType, X as Arrayable, P as Awaitable, ae as BaseCoverageOptions, ak as BenchFunction, ai as Benchmark, al as BenchmarkAPI, aj as BenchmarkResult, ah as BenchmarkUserOptions, B as BuiltinEnvironment, C as CSSModuleScopeStrategy, a0 as Constructable, ag as CoverageC8Options, af as CoverageIstanbulOptions, ac as CoverageOptions, a9 as CoverageProvider, aa as CoverageProviderModule, ab as CoverageReporter, _ as DeepMerge, D as DoneCallback, a3 as Environment, E as EnvironmentOptions, a2 as EnvironmentReturn, a7 as ErrorWithDiff, a as File, n as HookCleanupCallback, H as HookListener, I as InlineConfig, J as JSDOMOptions, Z as MergeInsertions, a1 as ModuleCache, M as ModuleGraphData, $ as MutableArray, Q as Nullable, a8 as OnServerRestartHandler, a6 as ParsedStack, a5 as Position, b as Reporter, K as ResolveIdFunction, R as ResolvedConfig, ad as ResolvedCoverageOptions, d as RunMode, r as RuntimeContext, u as SnapshotData, x as SnapshotMatchOptions, y as SnapshotResult, w as SnapshotStateOptions, G as SnapshotSummary, v as SnapshotUpdateState, S as Suite, m as SuiteAPI, p as SuiteCollector, q as SuiteFactory, o as SuiteHooks, i as Task, f as TaskBase, g as TaskResult, T as TaskResultPack, e as TaskState, h as Test, l as TestAPI, s as TestContext, j as TestFunction, k as TestOptions, z as UncheckedSnapshot, U as UserConfig, a4 as UserConsoleLog, t as Vitest, V as VitestEnvironment, c as VitestRunMode, W as WorkerContext, O as WorkerGlobalState, N as WorkerRPC } from './global-e98f203b.js';
|
|
4
4
|
import * as chai from 'chai';
|
|
5
5
|
export { chai };
|
|
6
6
|
export { assert, should } from 'chai';
|
package/dist/browser.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { c as createExpect, d as describe, e as expect, i as it, s as suite, t as test } from './chunk-runtime-chain.
|
|
2
|
-
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach } from './chunk-runtime-hooks.
|
|
3
|
-
export { a as setupGlobalEnv, s as startTests } from './chunk-runtime-error.
|
|
1
|
+
export { c as createExpect, d as describe, e as expect, i as it, s as suite, t as test } from './chunk-runtime-chain.0ab05798.mjs';
|
|
2
|
+
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach } from './chunk-runtime-hooks.e4219ed5.mjs';
|
|
3
|
+
export { a as setupGlobalEnv, s as startTests } from './chunk-runtime-error.f5506f40.mjs';
|
|
4
4
|
import * as chai from 'chai';
|
|
5
5
|
export { chai };
|
|
6
6
|
export { assert, should } from 'chai';
|
package/dist/{chunk-integrations-globals.ad5b1b51.mjs → chunk-integrations-globals.d8c90af9.mjs}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { k as globalApis } from './chunk-constants.71e8a211.mjs';
|
|
2
|
-
import { i as index } from './chunk-runtime-hooks.
|
|
2
|
+
import { i as index } from './chunk-runtime-hooks.e4219ed5.mjs';
|
|
3
3
|
import 'tty';
|
|
4
4
|
import 'url';
|
|
5
5
|
import 'path';
|
|
6
|
-
import './chunk-runtime-chain.
|
|
6
|
+
import './chunk-runtime-chain.0ab05798.mjs';
|
|
7
7
|
import 'util';
|
|
8
8
|
import './chunk-mock-date.2917be60.mjs';
|
|
9
9
|
import 'local-pkg';
|
|
@@ -2222,12 +2222,12 @@ function createSuiteHooks() {
|
|
|
2222
2222
|
};
|
|
2223
2223
|
}
|
|
2224
2224
|
function createSuiteCollector(name, factory = () => {
|
|
2225
|
-
}, mode, concurrent, shuffle) {
|
|
2225
|
+
}, mode, concurrent, shuffle, suiteOptions) {
|
|
2226
2226
|
const tasks = [];
|
|
2227
2227
|
const factoryQueue = [];
|
|
2228
2228
|
let suite2;
|
|
2229
2229
|
initSuite();
|
|
2230
|
-
const test2 = createTest(function(name2, fn = noop, options) {
|
|
2230
|
+
const test2 = createTest(function(name2, fn = noop, options = suiteOptions) {
|
|
2231
2231
|
if (!isRunningInTest())
|
|
2232
2232
|
throw new Error("`test()` and `it()` is only available in test mode.");
|
|
2233
2233
|
const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
|
|
@@ -2258,7 +2258,7 @@ function createSuiteCollector(name, factory = () => {
|
|
|
2258
2258
|
tasks.push(test3);
|
|
2259
2259
|
});
|
|
2260
2260
|
const benchmark = createBenchmark(function(name2, fn = noop, options) {
|
|
2261
|
-
const mode2 = this.skip ? "skip" : "run";
|
|
2261
|
+
const mode2 = this.only ? "only" : this.skip ? "skip" : "run";
|
|
2262
2262
|
if (!isRunningInBenchmark())
|
|
2263
2263
|
throw new Error("`bench()` is only available in benchmark mode. Run with `vitest bench` instead.");
|
|
2264
2264
|
const benchmark2 = {
|
|
@@ -2322,16 +2322,16 @@ function createSuiteCollector(name, factory = () => {
|
|
|
2322
2322
|
return collector;
|
|
2323
2323
|
}
|
|
2324
2324
|
function createSuite() {
|
|
2325
|
-
function suiteFn(name, factory) {
|
|
2325
|
+
function suiteFn(name, factory, options) {
|
|
2326
2326
|
const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
|
|
2327
|
-
return createSuiteCollector(name, factory, mode, this.concurrent, this.shuffle);
|
|
2327
|
+
return createSuiteCollector(name, factory, mode, this.concurrent, this.shuffle, options);
|
|
2328
2328
|
}
|
|
2329
2329
|
suiteFn.each = function(cases) {
|
|
2330
2330
|
const suite2 = this.withContext();
|
|
2331
|
-
return (name, fn) => {
|
|
2331
|
+
return (name, fn, options) => {
|
|
2332
2332
|
cases.forEach((i, idx) => {
|
|
2333
2333
|
const items = Array.isArray(i) ? i : [i];
|
|
2334
|
-
suite2(formatTitle(name, items, idx), () => fn(...items));
|
|
2334
|
+
suite2(formatTitle(name, items, idx), () => fn(...items), options);
|
|
2335
2335
|
});
|
|
2336
2336
|
};
|
|
2337
2337
|
};
|
|
@@ -2362,7 +2362,7 @@ function createTest(fn) {
|
|
|
2362
2362
|
}
|
|
2363
2363
|
function createBenchmark(fn) {
|
|
2364
2364
|
const benchmark = createChainable(
|
|
2365
|
-
["skip"],
|
|
2365
|
+
["skip", "only"],
|
|
2366
2366
|
fn
|
|
2367
2367
|
);
|
|
2368
2368
|
benchmark.skipIf = (condition) => condition ? benchmark.skip : benchmark;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { performance } from 'perf_hooks';
|
|
2
2
|
import { t as takeCoverageInsideWorker, p as pLimit } from './chunk-integrations-coverage.99c020eb.mjs';
|
|
3
|
-
import { r as resetRunOnceCounter, i as index, v as vi } from './chunk-runtime-hooks.
|
|
3
|
+
import { r as resetRunOnceCounter, i as index, v as vi } from './chunk-runtime-hooks.e4219ed5.mjs';
|
|
4
4
|
import { k as deepClone, l as getType, o as isNode, g as getWorkerState, R as RealDate, t as toArray, p as relativePath, q as isBrowser, h as isRunningInBenchmark, u as partitionSuiteChildren, v as shuffle, w as hasTests, x as hasFailed, y as createDefer, e as getFullName } from './chunk-mock-date.2917be60.mjs';
|
|
5
|
-
import { f as clearCollectorContext, h as defaultSuite, j as setHooks, k as getHooks, l as collectorContext, m as getFn, n as setState, G as GLOBAL_EXPECT, o as getState } from './chunk-runtime-chain.
|
|
5
|
+
import { f as clearCollectorContext, h as defaultSuite, j as setHooks, k as getHooks, l as collectorContext, m as getFn, n as setState, G as GLOBAL_EXPECT, o as getState } from './chunk-runtime-chain.0ab05798.mjs';
|
|
6
6
|
import { r as rpc } from './chunk-runtime-rpc.00a890d2.mjs';
|
|
7
7
|
import util$1 from 'util';
|
|
8
8
|
import { util } from 'chai';
|
|
@@ -154,7 +154,7 @@ async function setupGlobalEnv(config) {
|
|
|
154
154
|
if (isNode)
|
|
155
155
|
await setupConsoleLogSpy();
|
|
156
156
|
if (config.globals)
|
|
157
|
-
(await import('./chunk-integrations-globals.
|
|
157
|
+
(await import('./chunk-integrations-globals.d8c90af9.mjs')).registerApiGlobally();
|
|
158
158
|
}
|
|
159
159
|
function setupDefines(defines) {
|
|
160
160
|
for (const key in defines)
|
|
@@ -490,7 +490,7 @@ async function sendTasksUpdate() {
|
|
|
490
490
|
async function runTest(test) {
|
|
491
491
|
var _a, _b;
|
|
492
492
|
if (test.mode !== "run") {
|
|
493
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
493
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.0ab05798.mjs').then(function (n) { return n.q; });
|
|
494
494
|
getSnapshotClient().skipTestSnapshots(test);
|
|
495
495
|
return;
|
|
496
496
|
}
|
|
@@ -506,7 +506,7 @@ async function runTest(test) {
|
|
|
506
506
|
updateTask(test);
|
|
507
507
|
clearModuleMocks();
|
|
508
508
|
if (isNode) {
|
|
509
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
509
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.0ab05798.mjs').then(function (n) { return n.q; });
|
|
510
510
|
await getSnapshotClient().setTest(test);
|
|
511
511
|
}
|
|
512
512
|
const workerState = getWorkerState();
|
|
@@ -566,7 +566,7 @@ async function runTest(test) {
|
|
|
566
566
|
if (isBrowser && test.result.error)
|
|
567
567
|
console.error(test.result.error.message, test.result.error.stackStr);
|
|
568
568
|
if (isNode) {
|
|
569
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
569
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.0ab05798.mjs').then(function (n) { return n.q; });
|
|
570
570
|
getSnapshotClient().clearTest();
|
|
571
571
|
}
|
|
572
572
|
test.result.duration = now() - start;
|
|
@@ -606,7 +606,7 @@ async function runSuite(suite) {
|
|
|
606
606
|
try {
|
|
607
607
|
const beforeAllCleanups = await callSuiteHook(suite, suite, "beforeAll", [suite]);
|
|
608
608
|
if (isRunningInBenchmark()) {
|
|
609
|
-
await
|
|
609
|
+
await runBenchmarkSuite(suite);
|
|
610
610
|
} else {
|
|
611
611
|
for (let tasksGroup of partitionSuiteChildren(suite)) {
|
|
612
612
|
if (tasksGroup[0].concurrent === true) {
|
|
@@ -656,19 +656,21 @@ function createBenchmarkResult(name) {
|
|
|
656
656
|
samples: []
|
|
657
657
|
};
|
|
658
658
|
}
|
|
659
|
-
async function
|
|
659
|
+
async function runBenchmarkSuite(suite) {
|
|
660
660
|
const { Task, Bench } = await importTinybench();
|
|
661
661
|
const start = performance.now();
|
|
662
662
|
const benchmarkGroup = [];
|
|
663
663
|
const benchmarkSuiteGroup = [];
|
|
664
664
|
for (const task of suite.tasks) {
|
|
665
|
+
if (task.mode !== "run")
|
|
666
|
+
continue;
|
|
665
667
|
if (task.type === "benchmark")
|
|
666
668
|
benchmarkGroup.push(task);
|
|
667
669
|
else if (task.type === "suite")
|
|
668
670
|
benchmarkSuiteGroup.push(task);
|
|
669
671
|
}
|
|
670
672
|
if (benchmarkSuiteGroup.length)
|
|
671
|
-
await Promise.all(benchmarkSuiteGroup.map((subSuite) =>
|
|
673
|
+
await Promise.all(benchmarkSuiteGroup.map((subSuite) => runBenchmarkSuite(subSuite)));
|
|
672
674
|
if (benchmarkGroup.length) {
|
|
673
675
|
const defer = createDefer();
|
|
674
676
|
const benchmarkMap = {};
|
|
@@ -767,7 +769,7 @@ async function startTestsBrowser(paths, config) {
|
|
|
767
769
|
async function startTestsNode(paths, config) {
|
|
768
770
|
const files = await collectTests(paths, config);
|
|
769
771
|
rpc().onCollected(files);
|
|
770
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
772
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.0ab05798.mjs').then(function (n) { return n.q; });
|
|
771
773
|
getSnapshotClient().clear();
|
|
772
774
|
await runFiles(files, config);
|
|
773
775
|
const coverage = await takeCoverageInsideWorker(config.coverage);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, b as bench, c as createExpect, e as globalExpect } from './chunk-runtime-chain.
|
|
1
|
+
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, b as bench, c as createExpect, e as globalExpect } from './chunk-runtime-chain.0ab05798.mjs';
|
|
2
2
|
import { g as getWorkerState, R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-mock-date.2917be60.mjs';
|
|
3
3
|
import { p as parseStacktrace } from './chunk-utils-source-map.2be5aa48.mjs';
|
|
4
4
|
import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
|
|
@@ -3,7 +3,7 @@ import { normalizePath } from 'vite';
|
|
|
3
3
|
import { g as getWorkerState, G as mergeSlashes, s as slash, l as getType, H as getAllMockableProperties } from './chunk-mock-date.2917be60.mjs';
|
|
4
4
|
import { existsSync, readdirSync } from 'fs';
|
|
5
5
|
import { n as normalizeRequestId, p as pathFromRoot, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.473cd0b2.mjs';
|
|
6
|
-
import { d as dirname, j as join, b as basename, a as resolve, c as distDir } from './chunk-constants.71e8a211.mjs';
|
|
6
|
+
import { d as dirname, j as join, b as basename, h as extname, a as resolve, c as distDir } from './chunk-constants.71e8a211.mjs';
|
|
7
7
|
|
|
8
8
|
class RefTracker {
|
|
9
9
|
constructor() {
|
|
@@ -76,10 +76,20 @@ const _VitestMocker = class {
|
|
|
76
76
|
const cached = (_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports;
|
|
77
77
|
if (cached)
|
|
78
78
|
return cached;
|
|
79
|
-
|
|
79
|
+
let exports;
|
|
80
|
+
try {
|
|
81
|
+
exports = await mock();
|
|
82
|
+
} catch (err) {
|
|
83
|
+
const vitestError = new Error(
|
|
84
|
+
"[vitest] There was an error, when mocking a module. If you are using vi.mock, make sure you are not using top level variables inside, since this call is hoisted. Read more: https://vitest.dev/api/#vi-mock"
|
|
85
|
+
);
|
|
86
|
+
vitestError.cause = err;
|
|
87
|
+
throw vitestError;
|
|
88
|
+
}
|
|
80
89
|
if (exports === null || typeof exports !== "object")
|
|
81
90
|
throw new Error('[vitest] vi.mock(path: string, factory?: () => unknown) is not returning an object. Did you mean to return an object with a "default" key?');
|
|
82
91
|
this.moduleCache.set(dep, { exports });
|
|
92
|
+
const filepath = dep.slice("mock:".length);
|
|
83
93
|
const exportHandler = {
|
|
84
94
|
get(target, prop) {
|
|
85
95
|
const val = target[prop];
|
|
@@ -87,7 +97,7 @@ const _VitestMocker = class {
|
|
|
87
97
|
if (target instanceof Promise)
|
|
88
98
|
return target.then.bind(target);
|
|
89
99
|
} else if (!(prop in target)) {
|
|
90
|
-
throw new Error(`[vitest] No "${prop}" export is defined on the "${
|
|
100
|
+
throw new Error(`[vitest] No "${prop}" export is defined on the "${filepath}"`);
|
|
91
101
|
}
|
|
92
102
|
return val;
|
|
93
103
|
}
|
|
@@ -116,10 +126,10 @@ const _VitestMocker = class {
|
|
|
116
126
|
if (!existsSync(mockFolder))
|
|
117
127
|
return null;
|
|
118
128
|
const files = readdirSync(mockFolder);
|
|
119
|
-
const
|
|
129
|
+
const baseOriginal = basename(path);
|
|
120
130
|
for (const file of files) {
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
131
|
+
const baseFile = basename(file, extname(file));
|
|
132
|
+
if (baseFile === baseOriginal)
|
|
123
133
|
return resolve(mockFolder, file);
|
|
124
134
|
}
|
|
125
135
|
return null;
|