vitest 0.28.5 → 0.29.0
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 +1 -1
- package/coverage.d.ts +1 -0
- package/dist/browser.d.ts +2 -1
- package/dist/browser.js +3 -3
- package/dist/child.js +89 -0
- package/dist/{chunk-api-setup.d88afda6.js → chunk-api-setup.d9eccaeb.js} +3 -3
- package/dist/{chunk-env-node.ffd1183b.js → chunk-env-node.affdd278.js} +1 -2
- package/dist/{chunk-install-pkg.e1e08354.js → chunk-install-pkg.ea1a5ef4.js} +9 -8
- package/dist/chunk-integrations-coverage.e0a6acd2.js +51 -0
- package/dist/{chunk-integrations-globals.59432f4f.js → chunk-integrations-globals.b56fcb06.js} +7 -7
- package/dist/{chunk-integrations-run-once.38756e30.js → chunk-integrations-run-once.9012f759.js} +1 -1
- package/dist/{chunk-integrations-utils.9717ad89.js → chunk-integrations-utils.233d6a3b.js} +2 -2
- package/dist/{chunk-node-git.d9ad64ab.js → chunk-node-git.ed5bded8.js} +1 -2
- package/dist/{chunk-node-pkg.9a107dfb.js → chunk-node-pkg.88e7e848.js} +4403 -246
- package/dist/{chunk-runtime-mocker.dafe0f77.js → chunk-runtime-mocker.a048e92d.js} +63 -13
- package/dist/chunk-runtime-rpc.971b3848.js +61 -0
- package/dist/{chunk-runtime-setup.30ab0a4b.js → chunk-runtime-setup.992bb661.js} +2 -2
- package/dist/{chunk-utils-base.904102a8.js → chunk-utils-base.81f83dbd.js} +15 -1
- package/dist/{chunk-utils-global.442d1d33.js → chunk-utils-global.727b6d25.js} +1 -7
- package/dist/{chunk-utils-import.847b4a2d.js → chunk-utils-import.ec15dcad.js} +5 -5
- package/dist/{chunk-utils-tasks.d07dcea9.js → chunk-utils-tasks.b41c8284.js} +1 -1
- package/dist/cli-wrapper.js +1 -2
- package/dist/cli.js +12 -11
- package/dist/config.cjs +1 -1
- package/dist/config.d.ts +8 -7
- package/dist/config.js +1 -1
- package/dist/coverage.d.ts +142 -0
- package/dist/coverage.js +49 -0
- package/dist/entry.js +30 -73
- package/dist/environments.d.ts +2 -1
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +8 -8
- package/dist/loader.js +2 -2
- package/dist/node.d.ts +5 -3
- package/dist/node.js +13 -12
- package/dist/runners.d.ts +2 -1
- package/dist/runners.js +5 -5
- package/dist/{types-0373403c.d.ts → types-7cd96283.d.ts} +162 -37
- package/dist/{vendor-index.618ca5a1.js → vendor-index.2cbcdd1e.js} +18 -13
- package/dist/worker.js +12 -53
- package/package.json +16 -10
- package/dist/chunk-integrations-coverage.48e6286b.js +0 -3993
- package/dist/chunk-runtime-rpc.9c0386cc.js +0 -31
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { pathToFileURL } from 'node:url';
|
|
2
|
+
import { ModuleCacheMap, ViteNodeRunner } from 'vite-node/client';
|
|
3
|
+
import { isInternalRequest, isPrimitive } from 'vite-node/utils';
|
|
4
|
+
import { isAbsolute, dirname, join, basename, extname, resolve, normalize, relative } from 'pathe';
|
|
4
5
|
import { i as isNodeBuiltin } from './vendor-index.bdee400f.js';
|
|
5
|
-
import {
|
|
6
|
+
import { processError } from '@vitest/runner/utils';
|
|
7
|
+
import { g as getWorkerState, b as getCurrentEnvironment } from './chunk-utils-global.727b6d25.js';
|
|
8
|
+
import { d as distDir } from './chunk-constants.797d3ebf.js';
|
|
6
9
|
import { existsSync, readdirSync } from 'node:fs';
|
|
7
10
|
import { getColors, getType } from '@vitest/utils';
|
|
8
|
-
import {
|
|
11
|
+
import { e as getAllMockableProperties } from './chunk-utils-base.81f83dbd.js';
|
|
9
12
|
import { spyOn } from '@vitest/spy';
|
|
13
|
+
import { r as rpc } from './chunk-runtime-rpc.971b3848.js';
|
|
10
14
|
|
|
11
15
|
class RefTracker {
|
|
12
16
|
constructor() {
|
|
@@ -46,6 +50,11 @@ const _VitestMocker = class {
|
|
|
46
50
|
get moduleCache() {
|
|
47
51
|
return this.executor.moduleCache;
|
|
48
52
|
}
|
|
53
|
+
deleteCachedItem(id) {
|
|
54
|
+
const mockId = this.getMockPath(id);
|
|
55
|
+
if (this.moduleCache.has(mockId))
|
|
56
|
+
this.moduleCache.delete(mockId);
|
|
57
|
+
}
|
|
49
58
|
getSuiteFilepath() {
|
|
50
59
|
return getWorkerState().filepath || "global";
|
|
51
60
|
}
|
|
@@ -218,9 +227,7 @@ ${c.green(`vi.mock("${mockpath}", async () => {
|
|
|
218
227
|
const mock = this.mockMap.get(suitefile);
|
|
219
228
|
if (mock && id in mock)
|
|
220
229
|
delete mock[id];
|
|
221
|
-
|
|
222
|
-
if (this.moduleCache.get(mockId))
|
|
223
|
-
this.moduleCache.delete(mockId);
|
|
230
|
+
this.deleteCachedItem(id);
|
|
224
231
|
}
|
|
225
232
|
mockPath(originalId, path, external, factory) {
|
|
226
233
|
const suitefile = this.getSuiteFilepath();
|
|
@@ -231,6 +238,7 @@ ${c.green(`vi.mock("${mockpath}", async () => {
|
|
|
231
238
|
resolves[id] = originalId;
|
|
232
239
|
this.mockMap.set(suitefile, mocks);
|
|
233
240
|
this.resolveCache.set(suitefile, resolves);
|
|
241
|
+
this.deleteCachedItem(id);
|
|
234
242
|
}
|
|
235
243
|
async importActual(rawId, importee) {
|
|
236
244
|
const { id, fsPath } = await this.resolvePath(rawId, importee);
|
|
@@ -292,6 +300,48 @@ async function createVitestExecutor(options) {
|
|
|
292
300
|
await runner.executeId("/@vite/env");
|
|
293
301
|
return runner;
|
|
294
302
|
}
|
|
303
|
+
let _viteNode;
|
|
304
|
+
const moduleCache = new ModuleCacheMap();
|
|
305
|
+
const mockMap = /* @__PURE__ */ new Map();
|
|
306
|
+
async function startViteNode(ctx) {
|
|
307
|
+
if (_viteNode)
|
|
308
|
+
return _viteNode;
|
|
309
|
+
const { config } = ctx;
|
|
310
|
+
const processExit = process.exit;
|
|
311
|
+
process.exit = (code = process.exitCode || 0) => {
|
|
312
|
+
const error = new Error(`process.exit called with "${code}"`);
|
|
313
|
+
rpc().onWorkerExit(error, code);
|
|
314
|
+
return processExit(code);
|
|
315
|
+
};
|
|
316
|
+
function catchError(err, type) {
|
|
317
|
+
var _a;
|
|
318
|
+
const worker = getWorkerState();
|
|
319
|
+
const error = processError(err);
|
|
320
|
+
if (worker.filepath && !isPrimitive(error)) {
|
|
321
|
+
error.VITEST_TEST_NAME = (_a = worker.current) == null ? void 0 : _a.name;
|
|
322
|
+
error.VITEST_TEST_PATH = relative(config.root, worker.filepath);
|
|
323
|
+
}
|
|
324
|
+
rpc().onUnhandledError(error, type);
|
|
325
|
+
}
|
|
326
|
+
process.on("uncaughtException", (e) => catchError(e, "Uncaught Exception"));
|
|
327
|
+
process.on("unhandledRejection", (e) => catchError(e, "Unhandled Rejection"));
|
|
328
|
+
const executor = await createVitestExecutor({
|
|
329
|
+
fetchModule(id) {
|
|
330
|
+
return rpc().fetch(id, ctx.environment.name);
|
|
331
|
+
},
|
|
332
|
+
resolveId(id, importer) {
|
|
333
|
+
return rpc().resolveId(id, importer, ctx.environment.name);
|
|
334
|
+
},
|
|
335
|
+
moduleCache,
|
|
336
|
+
mockMap,
|
|
337
|
+
interopDefault: config.deps.interopDefault,
|
|
338
|
+
root: config.root,
|
|
339
|
+
base: config.base
|
|
340
|
+
});
|
|
341
|
+
const { run } = await import(pathToFileURL(resolve(distDir, "entry.js")).href);
|
|
342
|
+
_viteNode = { run, executor };
|
|
343
|
+
return _viteNode;
|
|
344
|
+
}
|
|
295
345
|
class VitestExecutor extends ViteNodeRunner {
|
|
296
346
|
constructor(options) {
|
|
297
347
|
super(options);
|
|
@@ -309,10 +359,10 @@ class VitestExecutor extends ViteNodeRunner {
|
|
|
309
359
|
const environment = getCurrentEnvironment();
|
|
310
360
|
return environment === "node" ? !isNodeBuiltin(id) : !id.startsWith("node:");
|
|
311
361
|
}
|
|
312
|
-
async resolveUrl(id,
|
|
313
|
-
if (
|
|
314
|
-
|
|
315
|
-
return super.resolveUrl(id,
|
|
362
|
+
async resolveUrl(id, importer) {
|
|
363
|
+
if (importer && importer.startsWith("mock:"))
|
|
364
|
+
importer = importer.slice(5);
|
|
365
|
+
return super.resolveUrl(id, importer);
|
|
316
366
|
}
|
|
317
367
|
async dependencyRequest(id, fsPath, callstack) {
|
|
318
368
|
const mocked = await this.mocker.requestWithMock(fsPath, callstack);
|
|
@@ -331,4 +381,4 @@ class VitestExecutor extends ViteNodeRunner {
|
|
|
331
381
|
}
|
|
332
382
|
}
|
|
333
383
|
|
|
334
|
-
export { VitestExecutor as V,
|
|
384
|
+
export { VitestExecutor as V, mockMap as a, moduleCache as m, startViteNode as s };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { getSafeTimers } from '@vitest/utils';
|
|
2
|
+
import { g as getWorkerState } from './chunk-utils-global.727b6d25.js';
|
|
3
|
+
|
|
4
|
+
const { get } = Reflect;
|
|
5
|
+
const safeRandom = Math.random;
|
|
6
|
+
function withSafeTimers(fn) {
|
|
7
|
+
const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers();
|
|
8
|
+
const currentSetTimeout = globalThis.setTimeout;
|
|
9
|
+
const currentClearTimeout = globalThis.clearTimeout;
|
|
10
|
+
const currentRandom = globalThis.Math.random;
|
|
11
|
+
const currentNextTick = globalThis.process.nextTick;
|
|
12
|
+
const currentSetImmediate = globalThis.setImmediate;
|
|
13
|
+
const currentClearImmediate = globalThis.clearImmediate;
|
|
14
|
+
try {
|
|
15
|
+
globalThis.setTimeout = setTimeout;
|
|
16
|
+
globalThis.clearTimeout = clearTimeout;
|
|
17
|
+
globalThis.Math.random = safeRandom;
|
|
18
|
+
globalThis.process.nextTick = nextTick;
|
|
19
|
+
globalThis.setImmediate = setImmediate;
|
|
20
|
+
globalThis.clearImmediate = clearImmediate;
|
|
21
|
+
const result = fn();
|
|
22
|
+
return result;
|
|
23
|
+
} finally {
|
|
24
|
+
globalThis.setTimeout = currentSetTimeout;
|
|
25
|
+
globalThis.clearTimeout = currentClearTimeout;
|
|
26
|
+
globalThis.Math.random = currentRandom;
|
|
27
|
+
globalThis.setImmediate = currentSetImmediate;
|
|
28
|
+
globalThis.clearImmediate = currentClearImmediate;
|
|
29
|
+
nextTick(() => {
|
|
30
|
+
globalThis.process.nextTick = currentNextTick;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const promises = /* @__PURE__ */ new Set();
|
|
35
|
+
const rpcDone = () => {
|
|
36
|
+
if (!promises.size)
|
|
37
|
+
return;
|
|
38
|
+
const awaitable = Array.from(promises);
|
|
39
|
+
return Promise.all(awaitable);
|
|
40
|
+
};
|
|
41
|
+
const rpc = () => {
|
|
42
|
+
const { rpc: rpc2 } = getWorkerState();
|
|
43
|
+
return new Proxy(rpc2, {
|
|
44
|
+
get(target, p, handler) {
|
|
45
|
+
const sendCall = get(target, p, handler);
|
|
46
|
+
const safeSendCall = (...args) => withSafeTimers(async () => {
|
|
47
|
+
const result = sendCall(...args);
|
|
48
|
+
promises.add(result);
|
|
49
|
+
try {
|
|
50
|
+
return await result;
|
|
51
|
+
} finally {
|
|
52
|
+
promises.delete(result);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
safeSendCall.asEvent = sendCall.asEvent;
|
|
56
|
+
return safeSendCall;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export { rpcDone as a, rpc as r };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setSafeTimers } from '@vitest/utils';
|
|
2
|
-
import { a as resetRunOnceCounter } from './chunk-integrations-run-once.
|
|
2
|
+
import { a as resetRunOnceCounter } from './chunk-integrations-run-once.9012f759.js';
|
|
3
3
|
|
|
4
4
|
let globalSetup = false;
|
|
5
5
|
async function setupCommonEnv(config) {
|
|
@@ -10,7 +10,7 @@ async function setupCommonEnv(config) {
|
|
|
10
10
|
globalSetup = true;
|
|
11
11
|
setSafeTimers();
|
|
12
12
|
if (config.globals)
|
|
13
|
-
(await import('./chunk-integrations-globals.
|
|
13
|
+
(await import('./chunk-integrations-globals.b56fcb06.js')).registerApiGlobally();
|
|
14
14
|
}
|
|
15
15
|
function setupDefines(defines) {
|
|
16
16
|
for (const key in defines)
|
|
@@ -6,6 +6,14 @@ function collectOwnProperties(obj, collector) {
|
|
|
6
6
|
Object.getOwnPropertyNames(obj).forEach(collect);
|
|
7
7
|
Object.getOwnPropertySymbols(obj).forEach(collect);
|
|
8
8
|
}
|
|
9
|
+
function groupBy(collection, iteratee) {
|
|
10
|
+
return collection.reduce((acc, item) => {
|
|
11
|
+
const key = iteratee(item);
|
|
12
|
+
acc[key] || (acc[key] = []);
|
|
13
|
+
acc[key].push(item);
|
|
14
|
+
return acc;
|
|
15
|
+
}, {});
|
|
16
|
+
}
|
|
9
17
|
function getAllMockableProperties(obj, isModule) {
|
|
10
18
|
const allProps = /* @__PURE__ */ new Map();
|
|
11
19
|
let curr = obj;
|
|
@@ -70,5 +78,11 @@ function isMergeableObject(item) {
|
|
|
70
78
|
function stdout() {
|
|
71
79
|
return console._stdout || process.stdout;
|
|
72
80
|
}
|
|
81
|
+
function getEnvironmentTransformMode(config, environment) {
|
|
82
|
+
var _a, _b;
|
|
83
|
+
if (!((_b = (_a = config.deps) == null ? void 0 : _a.experimentalOptimizer) == null ? void 0 : _b.enabled))
|
|
84
|
+
return void 0;
|
|
85
|
+
return environment === "happy-dom" || environment === "jsdom" ? "web" : "ssr";
|
|
86
|
+
}
|
|
73
87
|
|
|
74
|
-
export {
|
|
88
|
+
export { getEnvironmentTransformMode as a, noop as b, stdout as c, deepMerge as d, getAllMockableProperties as e, groupBy as g, isObject as i, notNullish as n, slash as s, toArray as t };
|
|
@@ -63,11 +63,5 @@ function getCallLastIndex(code) {
|
|
|
63
63
|
}
|
|
64
64
|
return null;
|
|
65
65
|
}
|
|
66
|
-
class AggregateErrorPonyfill extends Error {
|
|
67
|
-
constructor(errors, message = "") {
|
|
68
|
-
super(message);
|
|
69
|
-
this.errors = [...errors];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
66
|
|
|
73
|
-
export {
|
|
67
|
+
export { getCallLastIndex as a, getCurrentEnvironment as b, relativePath as c, removeUndefinedValues as d, isWindows as e, getWorkerState as g, isRunningInBenchmark as i, resetModules as r };
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { getCurrentSuite } from '@vitest/runner';
|
|
2
2
|
import { createChainable, getNames } from '@vitest/runner/utils';
|
|
3
3
|
import { getSafeTimers, noop, createSimpleStackTrace } from '@vitest/utils';
|
|
4
|
-
import { g as getWorkerState, i as isRunningInBenchmark, a as getCallLastIndex, b as getCurrentEnvironment, r as resetModules } from './chunk-utils-global.
|
|
4
|
+
import { g as getWorkerState, i as isRunningInBenchmark, a as getCallLastIndex, b as getCurrentEnvironment, r as resetModules } from './chunk-utils-global.727b6d25.js';
|
|
5
5
|
import * as chai$1 from 'chai';
|
|
6
6
|
import { expect } from 'chai';
|
|
7
7
|
import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
|
|
8
8
|
import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, getState, setState } from '@vitest/expect';
|
|
9
|
-
import { r as rpc } from './chunk-runtime-rpc.
|
|
9
|
+
import { r as rpc } from './chunk-runtime-rpc.971b3848.js';
|
|
10
10
|
import { join, dirname } from 'pathe';
|
|
11
11
|
import { g as getSnapshotEnvironment } from './chunk-snapshot-env.a347d647.js';
|
|
12
|
-
import { i as isObject } from './chunk-utils-base.
|
|
13
|
-
import { p as positionToOffset, o as offsetToLineNumber, l as lineSplitRE, a as parseErrorStacktrace, g as getFullName, b as parseSingleStack } from './chunk-utils-tasks.
|
|
12
|
+
import { i as isObject } from './chunk-utils-base.81f83dbd.js';
|
|
13
|
+
import { p as positionToOffset, o as offsetToLineNumber, l as lineSplitRE, a as parseErrorStacktrace, g as getFullName, b as parseSingleStack } from './chunk-utils-tasks.b41c8284.js';
|
|
14
14
|
import require$$0 from 'util';
|
|
15
15
|
import { spyOn, fn, isMockFunction, spies } from '@vitest/spy';
|
|
16
16
|
|
|
@@ -2568,7 +2568,7 @@ const addSerializer = (plugin) => {
|
|
|
2568
2568
|
const getSerializers = () => PLUGINS;
|
|
2569
2569
|
|
|
2570
2570
|
const SNAPSHOT_VERSION = "1";
|
|
2571
|
-
const writeSnapshotVersion = () => `// Vitest Snapshot v${SNAPSHOT_VERSION}`;
|
|
2571
|
+
const writeSnapshotVersion = () => `// Vitest Snapshot v${SNAPSHOT_VERSION}, https://vitest.dev/guide/snapshot.html`;
|
|
2572
2572
|
const testNameToKey = (testName, count) => `${testName} ${count}`;
|
|
2573
2573
|
const keyToTestName = (key) => {
|
|
2574
2574
|
if (!/ \d+$/.test(key))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getNames, getTests } from '@vitest/runner/utils';
|
|
2
2
|
import { resolve } from 'pathe';
|
|
3
|
-
import { n as notNullish } from './chunk-utils-base.
|
|
3
|
+
import { n as notNullish } from './chunk-utils-base.81f83dbd.js';
|
|
4
4
|
|
|
5
5
|
function hasFailedSnapshot(suite) {
|
|
6
6
|
return getTests(suite).some((s) => {
|
package/dist/cli-wrapper.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fileURLToPath } from 'url';
|
|
2
2
|
import c from 'picocolors';
|
|
3
|
-
import { e as execa } from './vendor-index.
|
|
3
|
+
import { e as execa } from './vendor-index.2cbcdd1e.js';
|
|
4
4
|
import { E as EXIT_CODE_RESTART } from './chunk-constants.797d3ebf.js';
|
|
5
5
|
import 'node:buffer';
|
|
6
6
|
import 'node:path';
|
|
@@ -11,7 +11,6 @@ import 'path';
|
|
|
11
11
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
12
12
|
import 'fs';
|
|
13
13
|
import 'node:url';
|
|
14
|
-
import 'os';
|
|
15
14
|
import 'node:os';
|
|
16
15
|
import 'assert';
|
|
17
16
|
import 'events';
|
package/dist/cli.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
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.88e7e848.js';
|
|
5
5
|
import './chunk-constants.797d3ebf.js';
|
|
6
6
|
import 'node:url';
|
|
7
7
|
import './chunk-utils-env.860d90c2.js';
|
|
8
8
|
import 'std-env';
|
|
9
|
-
import './chunk-integrations-coverage.
|
|
9
|
+
import './chunk-integrations-coverage.e0a6acd2.js';
|
|
10
10
|
import 'local-pkg';
|
|
11
|
-
import '
|
|
12
|
-
import 'path';
|
|
13
|
-
import './chunk-env-node.ffd1183b.js';
|
|
11
|
+
import './chunk-env-node.affdd278.js';
|
|
14
12
|
import 'node:console';
|
|
15
13
|
import 'vite';
|
|
16
14
|
import 'node:path';
|
|
17
15
|
import 'node:process';
|
|
18
16
|
import 'node:fs';
|
|
17
|
+
import 'path';
|
|
19
18
|
import 'os';
|
|
19
|
+
import 'util';
|
|
20
20
|
import 'stream';
|
|
21
21
|
import 'events';
|
|
22
22
|
import 'fs';
|
|
23
23
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
24
24
|
import 'vite-node/client';
|
|
25
25
|
import 'vite-node/server';
|
|
26
|
-
import './chunk-utils-global.
|
|
26
|
+
import './chunk-utils-global.727b6d25.js';
|
|
27
27
|
import '@vitest/runner/utils';
|
|
28
28
|
import '@vitest/utils';
|
|
29
29
|
import 'node:fs/promises';
|
|
30
|
-
import './vendor-index.
|
|
30
|
+
import './vendor-index.2cbcdd1e.js';
|
|
31
31
|
import 'node:buffer';
|
|
32
32
|
import 'node:child_process';
|
|
33
33
|
import 'child_process';
|
|
@@ -38,12 +38,13 @@ import 'source-map';
|
|
|
38
38
|
import 'module';
|
|
39
39
|
import 'acorn';
|
|
40
40
|
import 'acorn-walk';
|
|
41
|
+
import 'node:v8';
|
|
42
|
+
import './vendor-index.783e7f3e.js';
|
|
43
|
+
import './chunk-utils-base.81f83dbd.js';
|
|
41
44
|
import 'node:worker_threads';
|
|
42
45
|
import 'tinypool';
|
|
43
|
-
import './vendor-index.783e7f3e.js';
|
|
44
46
|
import 'perf_hooks';
|
|
45
|
-
import './chunk-utils-
|
|
46
|
-
import './chunk-utils-tasks.d07dcea9.js';
|
|
47
|
+
import './chunk-utils-tasks.b41c8284.js';
|
|
47
48
|
import 'crypto';
|
|
48
49
|
import 'vite-node/utils';
|
|
49
50
|
import '@vitest/utils/diff';
|
|
@@ -53,7 +54,7 @@ import 'strip-literal';
|
|
|
53
54
|
import 'readline';
|
|
54
55
|
|
|
55
56
|
const cli = cac("vitest");
|
|
56
|
-
cli.version(version).option("-r, --root <path>", "Root path").option("-c, --config <path>", "Path to config file").option("-u, --update", "Update snapshot").option("-w, --watch", "Enable watch mode").option("-t, --testNamePattern <pattern>", "Run tests with full names matching the specified regexp pattern").option("--dir <path>", "Base directory to scan for the test files").option("--ui", "Enable UI").option("--open", "Open UI automatically (default: !process.env.CI))").option("--api [api]", "Serve API, available options: --api.port <port>, --api.host [host] and --api.strictPort").option("--threads", "Enabled threads (default: true)").option("--silent", "Silent console output from tests").option("--isolate", "Isolate environment for each test file (default: true)").option("--reporter <name>", "Specify reporters").option("--outputDiffMaxSize <length>", "Object diff output max size (default: 10000)").option("--outputDiffMaxLines <length>", "Max lines in diff output window (default: 50)").option("--outputTruncateLength <length>", "Diff output line length (default: 80)").option("--outputDiffLines <lines>", "Number of lines in single diff (default: 15)").option("--outputFile <filename/-s>", "Write test results to a file when supporter reporter is also specified, use cac's dot notation for individual outputs of multiple reporters").option("--coverage", "Enable coverage report").option("--run", "Disable watch mode").option("--mode <name>", "Override Vite mode (default: test)").option("--globals", "Inject apis globally").option("--dom", "Mock browser api with happy-dom").option("--browser", "Run tests in browser").option("--environment <env>", "Specify runner environment (default: node)").option("--passWithNoTests", "Pass when no tests found").option("--logHeapUsage", "Show the size of heap for each test").option("--allowOnly", "Allow tests and suites that are marked as only (default: !process.env.CI)").option("--dangerouslyIgnoreUnhandledErrors", "Ignore any unhandled errors that occur").option("--shard <shard>", "Test suite shard to execute in a format of <index>/<count>").option("--changed [since]", "Run tests that are affected by the changed files (default: false)").option("--sequence <options>", "Define in what order to run tests (use --sequence.shuffle to run tests in random order)").option("--segfaultRetry <times>", "Return tests on segment fault (default: 0)", { default: 0 }).option("--no-color", "Removes colors from the console output").option("--inspect", "Enable Node.js inspector").option("--inspect-brk", "Enable Node.js inspector with break").help();
|
|
57
|
+
cli.version(version).option("-r, --root <path>", "Root path").option("-c, --config <path>", "Path to config file").option("-u, --update", "Update snapshot").option("-w, --watch", "Enable watch mode").option("-t, --testNamePattern <pattern>", "Run tests with full names matching the specified regexp pattern").option("--dir <path>", "Base directory to scan for the test files").option("--ui", "Enable UI").option("--open", "Open UI automatically (default: !process.env.CI))").option("--api [api]", "Serve API, available options: --api.port <port>, --api.host [host] and --api.strictPort").option("--threads", "Enabled threads (default: true)").option("--single-thread", "Run tests inside a single thread, requires --threads (default: false)").option("--silent", "Silent console output from tests").option("--isolate", "Isolate environment for each test file (default: true)").option("--reporter <name>", "Specify reporters").option("--outputDiffMaxSize <length>", "Object diff output max size (default: 10000)").option("--outputDiffMaxLines <length>", "Max lines in diff output window (default: 50)").option("--outputTruncateLength <length>", "Diff output line length (default: 80)").option("--outputDiffLines <lines>", "Number of lines in single diff (default: 15)").option("--outputFile <filename/-s>", "Write test results to a file when supporter reporter is also specified, use cac's dot notation for individual outputs of multiple reporters").option("--coverage", "Enable coverage report").option("--run", "Disable watch mode").option("--mode <name>", "Override Vite mode (default: test)").option("--globals", "Inject apis globally").option("--dom", "Mock browser api with happy-dom").option("--browser", "Run tests in browser").option("--environment <env>", "Specify runner environment (default: node)").option("--passWithNoTests", "Pass when no tests found").option("--logHeapUsage", "Show the size of heap for each test").option("--allowOnly", "Allow tests and suites that are marked as only (default: !process.env.CI)").option("--dangerouslyIgnoreUnhandledErrors", "Ignore any unhandled errors that occur").option("--shard <shard>", "Test suite shard to execute in a format of <index>/<count>").option("--changed [since]", "Run tests that are affected by the changed files (default: false)").option("--sequence <options>", "Define in what order to run tests (use --sequence.shuffle to run tests in random order)").option("--segfaultRetry <times>", "Return tests on segment fault (default: 0)", { default: 0 }).option("--no-color", "Removes colors from the console output").option("--inspect", "Enable Node.js inspector").option("--inspect-brk", "Enable Node.js inspector with break").help();
|
|
57
58
|
cli.command("run [...filters]").action(run);
|
|
58
59
|
cli.command("related [...filters]").action(runRelated);
|
|
59
60
|
cli.command("watch [...filters]").action(watch);
|
package/dist/config.cjs
CHANGED
|
@@ -30,7 +30,7 @@ const coverageConfigDefaults = {
|
|
|
30
30
|
cleanOnRerun: true,
|
|
31
31
|
reportsDirectory: "./coverage",
|
|
32
32
|
exclude: defaultCoverageExcludes,
|
|
33
|
-
reporter: ["text", "html", "clover", "json"],
|
|
33
|
+
reporter: [["text", {}], ["html", {}], ["clover", {}], ["json", {}]],
|
|
34
34
|
extension: [".js", ".cjs", ".mjs", ".ts", ".mts", ".cts", ".tsx", ".jsx", ".vue", ".svelte"]
|
|
35
35
|
};
|
|
36
36
|
const fakeTimersDefaults = {
|
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 {
|
|
3
|
+
import { a3 as ResolvedCoverageOptions, U as UserConfig$1, a6 as CoverageC8Options, a7 as CustomProviderOptions, a5 as CoverageIstanbulOptions, ah as HtmlOptions, ai as FileOptions, aj as CloverOptions, ak as CoberturaOptions, al as HtmlSpaOptions, am as LcovOptions, an as LcovOnlyOptions, ao as TeamcityOptions, ap as TextOptions, aq as ProjectOptions, F as FakeTimerInstallOpts } from './types-7cd96283.js';
|
|
4
4
|
import '@vitest/expect';
|
|
5
5
|
import '@vitest/runner/types';
|
|
6
6
|
import '@vitest/runner';
|
|
@@ -11,6 +11,7 @@ import 'vite-node/client';
|
|
|
11
11
|
import 'vite-node/server';
|
|
12
12
|
import 'node:worker_threads';
|
|
13
13
|
import 'vite-node';
|
|
14
|
+
import 'source-map';
|
|
14
15
|
import 'node:fs';
|
|
15
16
|
|
|
16
17
|
declare const defaultInclude: string[];
|
|
@@ -44,17 +45,17 @@ declare const config: {
|
|
|
44
45
|
include: never[];
|
|
45
46
|
};
|
|
46
47
|
coverage: {
|
|
47
|
-
provider
|
|
48
|
+
provider: "c8";
|
|
48
49
|
} & CoverageC8Options & Required<Pick<({
|
|
49
50
|
provider?: undefined;
|
|
50
51
|
} & CoverageC8Options) | ({
|
|
51
|
-
provider:
|
|
52
|
-
} &
|
|
53
|
-
provider
|
|
52
|
+
provider: "custom";
|
|
53
|
+
} & CustomProviderOptions) | ({
|
|
54
|
+
provider: "c8";
|
|
54
55
|
} & CoverageC8Options) | ({
|
|
55
56
|
provider: "istanbul";
|
|
56
|
-
} & CoverageIstanbulOptions), "exclude" | "enabled" | "clean" | "cleanOnRerun" | "reportsDirectory" | "extension"
|
|
57
|
-
reporter:
|
|
57
|
+
} & CoverageIstanbulOptions), "exclude" | "enabled" | "clean" | "cleanOnRerun" | "reportsDirectory" | "extension">> & {
|
|
58
|
+
reporter: (["html", Partial<HtmlOptions>] | ["json", Partial<FileOptions>] | ["none", {}] | ["clover", Partial<CloverOptions>] | ["cobertura", Partial<CoberturaOptions>] | ["html-spa", Partial<HtmlSpaOptions>] | ["json-summary", Partial<FileOptions>] | ["lcov", Partial<LcovOptions>] | ["lcovonly", Partial<LcovOnlyOptions>] | ["teamcity", Partial<TeamcityOptions>] | ["text", Partial<TextOptions>] | ["text-lcov", Partial<ProjectOptions>] | ["text-summary", Partial<FileOptions>])[];
|
|
58
59
|
};
|
|
59
60
|
fakeTimers: FakeTimerInstallOpts;
|
|
60
61
|
maxConcurrency: number;
|
package/dist/config.js
CHANGED
|
@@ -26,7 +26,7 @@ const coverageConfigDefaults = {
|
|
|
26
26
|
cleanOnRerun: true,
|
|
27
27
|
reportsDirectory: "./coverage",
|
|
28
28
|
exclude: defaultCoverageExcludes,
|
|
29
|
-
reporter: ["text", "html", "clover", "json"],
|
|
29
|
+
reporter: [["text", {}], ["html", {}], ["clover", {}], ["json", {}]],
|
|
30
30
|
extension: [".js", ".cjs", ".mjs", ".ts", ".mts", ".cts", ".tsx", ".jsx", ".vue", ".svelte"]
|
|
31
31
|
};
|
|
32
32
|
const fakeTimersDefaults = {
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { a4 as BaseCoverageOptions, a3 as ResolvedCoverageOptions } from './types-7cd96283.js';
|
|
2
|
+
import '@vitest/expect';
|
|
3
|
+
import 'vite';
|
|
4
|
+
import '@vitest/runner/types';
|
|
5
|
+
import '@vitest/runner';
|
|
6
|
+
import '@vitest/runner/utils';
|
|
7
|
+
import '@vitest/utils';
|
|
8
|
+
import 'tinybench';
|
|
9
|
+
import 'vite-node/client';
|
|
10
|
+
import 'vite-node/server';
|
|
11
|
+
import 'node:worker_threads';
|
|
12
|
+
import 'vite-node';
|
|
13
|
+
import 'source-map';
|
|
14
|
+
import 'node:fs';
|
|
15
|
+
|
|
16
|
+
// Type definitions for istanbul-lib-coverage 2.0
|
|
17
|
+
// Project: https://istanbul.js.org, https://github.com/istanbuljs/istanbuljs
|
|
18
|
+
// Definitions by: Jason Cheatham <https://github.com/jason0x43>
|
|
19
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
20
|
+
// TypeScript Version: 2.4
|
|
21
|
+
|
|
22
|
+
interface CoverageSummaryData {
|
|
23
|
+
lines: Totals;
|
|
24
|
+
statements: Totals;
|
|
25
|
+
branches: Totals;
|
|
26
|
+
functions: Totals;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare class CoverageSummary {
|
|
30
|
+
constructor(data: CoverageSummary | CoverageSummaryData);
|
|
31
|
+
merge(obj: CoverageSummary): CoverageSummary;
|
|
32
|
+
toJSON(): CoverageSummaryData;
|
|
33
|
+
isEmpty(): boolean;
|
|
34
|
+
data: CoverageSummaryData;
|
|
35
|
+
lines: Totals;
|
|
36
|
+
statements: Totals;
|
|
37
|
+
branches: Totals;
|
|
38
|
+
functions: Totals;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface CoverageMapData {
|
|
42
|
+
[key: string]: FileCoverage | FileCoverageData;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare class CoverageMap {
|
|
46
|
+
constructor(data: CoverageMapData | CoverageMap);
|
|
47
|
+
addFileCoverage(pathOrObject: string | FileCoverage | FileCoverageData): void;
|
|
48
|
+
files(): string[];
|
|
49
|
+
fileCoverageFor(filename: string): FileCoverage;
|
|
50
|
+
filter(callback: (key: string) => boolean): void;
|
|
51
|
+
getCoverageSummary(): CoverageSummary;
|
|
52
|
+
merge(data: CoverageMapData | CoverageMap): void;
|
|
53
|
+
toJSON(): CoverageMapData;
|
|
54
|
+
data: CoverageMapData;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface Location {
|
|
58
|
+
line: number;
|
|
59
|
+
column: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface Range {
|
|
63
|
+
start: Location;
|
|
64
|
+
end: Location;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface BranchMapping {
|
|
68
|
+
loc: Range;
|
|
69
|
+
type: string;
|
|
70
|
+
locations: Range[];
|
|
71
|
+
line: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface FunctionMapping {
|
|
75
|
+
name: string;
|
|
76
|
+
decl: Range;
|
|
77
|
+
loc: Range;
|
|
78
|
+
line: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface FileCoverageData {
|
|
82
|
+
path: string;
|
|
83
|
+
statementMap: { [key: string]: Range };
|
|
84
|
+
fnMap: { [key: string]: FunctionMapping };
|
|
85
|
+
branchMap: { [key: string]: BranchMapping };
|
|
86
|
+
s: { [key: string]: number };
|
|
87
|
+
f: { [key: string]: number };
|
|
88
|
+
b: { [key: string]: number[] };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface Totals {
|
|
92
|
+
total: number;
|
|
93
|
+
covered: number;
|
|
94
|
+
skipped: number;
|
|
95
|
+
pct: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface Coverage {
|
|
99
|
+
covered: number;
|
|
100
|
+
total: number;
|
|
101
|
+
coverage: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
declare class FileCoverage implements FileCoverageData {
|
|
105
|
+
constructor(data: string | FileCoverage | FileCoverageData);
|
|
106
|
+
merge(other: FileCoverageData): void;
|
|
107
|
+
getBranchCoverageByLine(): { [line: number]: Coverage };
|
|
108
|
+
getLineCoverage(): { [line: number]: number };
|
|
109
|
+
getUncoveredLines(): number[];
|
|
110
|
+
resetHits(): void;
|
|
111
|
+
computeBranchTotals(): Totals;
|
|
112
|
+
computeSimpleTotals(): Totals;
|
|
113
|
+
toSummary(): CoverageSummary;
|
|
114
|
+
toJSON(): object;
|
|
115
|
+
|
|
116
|
+
data: FileCoverageData;
|
|
117
|
+
path: string;
|
|
118
|
+
statementMap: { [key: string]: Range };
|
|
119
|
+
fnMap: { [key: string]: FunctionMapping };
|
|
120
|
+
branchMap: { [key: string]: BranchMapping };
|
|
121
|
+
s: { [key: string]: number };
|
|
122
|
+
f: { [key: string]: number };
|
|
123
|
+
b: { [key: string]: number[] };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
type Threshold = 'lines' | 'functions' | 'statements' | 'branches';
|
|
127
|
+
declare class BaseCoverageProvider {
|
|
128
|
+
/**
|
|
129
|
+
* Check if current coverage is above configured thresholds and bump the thresholds if needed
|
|
130
|
+
*/
|
|
131
|
+
updateThresholds({ configurationFile, coverageMap, thresholds }: {
|
|
132
|
+
coverageMap: CoverageMap;
|
|
133
|
+
thresholds: Record<Threshold, number | undefined>;
|
|
134
|
+
configurationFile?: string;
|
|
135
|
+
}): void;
|
|
136
|
+
/**
|
|
137
|
+
* Resolve reporters from various configuration options
|
|
138
|
+
*/
|
|
139
|
+
resolveReporters(configReporters: NonNullable<BaseCoverageOptions['reporter']>): ResolvedCoverageOptions['reporter'];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { BaseCoverageProvider };
|
package/dist/coverage.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
|
|
3
|
+
const THRESHOLD_KEYS = ["lines", "functions", "statements", "branches"];
|
|
4
|
+
class BaseCoverageProvider {
|
|
5
|
+
updateThresholds({ configurationFile, coverageMap, thresholds }) {
|
|
6
|
+
if (!configurationFile)
|
|
7
|
+
throw new Error('Missing configurationFile. The "coverage.thresholdAutoUpdate" can only be enabled when configuration file is used.');
|
|
8
|
+
const summary = coverageMap.getCoverageSummary();
|
|
9
|
+
const thresholdsToUpdate = [];
|
|
10
|
+
for (const key of THRESHOLD_KEYS) {
|
|
11
|
+
const threshold = thresholds[key] || 100;
|
|
12
|
+
const actual = summary[key].pct;
|
|
13
|
+
if (actual > threshold)
|
|
14
|
+
thresholdsToUpdate.push(key);
|
|
15
|
+
}
|
|
16
|
+
if (thresholdsToUpdate.length === 0)
|
|
17
|
+
return;
|
|
18
|
+
const originalConfig = readFileSync(configurationFile, "utf8");
|
|
19
|
+
let updatedConfig = originalConfig;
|
|
20
|
+
for (const threshold of thresholdsToUpdate) {
|
|
21
|
+
const previousThreshold = (thresholds[threshold] || 100).toString();
|
|
22
|
+
const pattern = new RegExp(`(${threshold}\\s*:\\s*)${previousThreshold.replace(".", "\\.")}`);
|
|
23
|
+
const matches = originalConfig.match(pattern);
|
|
24
|
+
if (matches)
|
|
25
|
+
updatedConfig = updatedConfig.replace(matches[0], matches[1] + summary[threshold].pct);
|
|
26
|
+
else
|
|
27
|
+
console.error(`Unable to update coverage threshold ${threshold}. No threshold found using pattern ${pattern}`);
|
|
28
|
+
}
|
|
29
|
+
if (updatedConfig !== originalConfig) {
|
|
30
|
+
console.log("Updating thresholds to configuration file. You may want to push with updated coverage thresholds.");
|
|
31
|
+
writeFileSync(configurationFile, updatedConfig, "utf-8");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
resolveReporters(configReporters) {
|
|
35
|
+
if (!Array.isArray(configReporters))
|
|
36
|
+
return [[configReporters, {}]];
|
|
37
|
+
const resolvedReporters = [];
|
|
38
|
+
for (const reporter of configReporters) {
|
|
39
|
+
if (Array.isArray(reporter)) {
|
|
40
|
+
resolvedReporters.push([reporter[0], reporter[1] || {}]);
|
|
41
|
+
} else {
|
|
42
|
+
resolvedReporters.push([reporter, {}]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return resolvedReporters;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { BaseCoverageProvider };
|