vitest 4.0.0-beta.7 → 4.0.0-beta.9
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 +5 -5
- package/dist/browser.js +4 -4
- package/dist/chunks/{runBaseTests.D6sfuWBM.js → base.CA5N8Af0.js} +55 -26
- package/dist/chunks/{benchmark.UW6Ezvxy.js → benchmark.CJUa-Hsa.js} +1 -1
- package/dist/chunks/{browser.d.DOMmqJQx.d.ts → browser.d.DtfyY9yS.d.ts} +1 -1
- package/dist/chunks/{cac.Dsn7ixFt.js → cac.Dt7e1TIu.js} +6 -25
- package/dist/chunks/{cli-api.DfGJyldU.js → cli-api.eAzsLIxz.js} +88 -209
- package/dist/chunks/{config.d._GBBbReY.d.ts → config.d.DacWrqWe.d.ts} +1 -0
- package/dist/chunks/{console.B0quX7yH.js → console.7h5kHUIf.js} +1 -1
- package/dist/chunks/{coverage.Dvxug1RM.js → coverage.CDRAMTt7.js} +25 -56
- package/dist/chunks/{globals.lgsmH00r.js → globals.CJrTTbxC.js} +5 -6
- package/dist/chunks/{index.C3EbxYwt.js → index.BIP7prJq.js} +7 -3
- package/dist/chunks/{index.D2B6d2vv.js → index.BjKEiSn0.js} +1 -1
- package/dist/chunks/{index.AR8aAkCC.js → index.C832ioot.js} +5 -6
- package/dist/chunks/{moduleRunner.d.CX4DuqOx.d.ts → moduleRunner.d.DxTLreRD.d.ts} +4 -1
- package/dist/chunks/{node.BOqcT2jW.js → node.CyipiPvJ.js} +1 -1
- package/dist/chunks/{plugin.d.vcD4xbMS.d.ts → plugin.d.CIk0YiKb.d.ts} +1 -1
- package/dist/chunks/{reporters.d.BC86JJdB.d.ts → reporters.d.DmP-iHLr.d.ts} +451 -561
- package/dist/chunks/{index.CsFXYRkW.js → resolveSnapshotEnvironment.Bvv2zr69.js} +16 -21
- package/dist/chunks/{rpc.RpPylpp0.js → rpc.BKr6mtxz.js} +1 -1
- package/dist/chunks/{setup-common.hLGRxhC8.js → setup-common.B7I37Tji.js} +4 -4
- package/dist/chunks/{startModuleRunner.C8TW8zTN.js → startModuleRunner.BDRvKSdz.js} +7 -2
- package/dist/chunks/test.BAlBebnP.js +214 -0
- package/dist/chunks/{typechecker.DSo_maXz.js → typechecker.DB-fIMaH.js} +44 -1
- package/dist/chunks/{utils.C7__0Iv5.js → utils.D2R2NiOH.js} +1 -10
- package/dist/chunks/{vi.BfdOiD4j.js → vi.BB37KeLx.js} +16 -16
- package/dist/chunks/{vm.BHBje7cC.js → vm.CjLTDaST.js} +12 -7
- package/dist/chunks/{worker.d.DYlqbejz.d.ts → worker.d.B2r4Ln6p.d.ts} +1 -1
- package/dist/chunks/{worker.d.BKu8cnnX.d.ts → worker.d.DJ6qxO2w.d.ts} +1 -1
- package/dist/cli.js +3 -3
- package/dist/config.d.ts +10 -10
- package/dist/coverage.d.ts +8 -8
- package/dist/coverage.js +2 -2
- package/dist/index.d.ts +11 -12
- package/dist/index.js +5 -8
- package/dist/module-evaluator.d.ts +4 -3
- package/dist/module-evaluator.js +3 -3
- package/dist/module-runner.js +2 -2
- package/dist/node.d.ts +23 -14
- package/dist/node.js +8 -8
- package/dist/reporters.d.ts +8 -8
- package/dist/reporters.js +3 -3
- package/dist/runners.d.ts +1 -1
- package/dist/runners.js +11 -215
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +2 -3
- package/dist/workers/forks.js +27 -4
- package/dist/workers/runVmTests.js +18 -19
- package/dist/workers/threads.js +27 -4
- package/dist/workers/vmForks.js +4 -4
- package/dist/workers/vmThreads.js +4 -4
- package/dist/workers.d.ts +3 -3
- package/dist/workers.js +26 -8
- package/package.json +10 -14
- package/dist/chunks/base.BXI97p6t.js +0 -39
|
@@ -10,9 +10,9 @@ import { A as API_PATH, c as configFiles, d as defaultBrowserPort, a as defaultP
|
|
|
10
10
|
import nodeos__default, { tmpdir } from 'node:os';
|
|
11
11
|
import { generateHash as generateHash$1, calculateSuiteHash, someTasksAreOnly, interpretTaskModes, generateFileHash, limitConcurrency, createFileTask as createFileTask$1, hasFailed, getTasks, getTests } from '@vitest/runner/utils';
|
|
12
12
|
import { SnapshotManager } from '@vitest/snapshot/manager';
|
|
13
|
-
import { v as version$1 } from './cac.
|
|
13
|
+
import { v as version$1 } from './cac.Dt7e1TIu.js';
|
|
14
14
|
import { c as createBirpc } from './index.Bgo3tNWt.js';
|
|
15
|
-
import { p as parse, s as stringify, d as printError, f as formatProjectName, w as withLabel, e as errorBanner, h as divider, i as generateCodeFrame, R as ReportersMap, B as BlobReporter, r as readBlobs, H as HangingProcessReporter } from './index.
|
|
15
|
+
import { p as parse, s as stringify, d as printError, f as formatProjectName, w as withLabel, e as errorBanner, h as divider, i as generateCodeFrame, R as ReportersMap, B as BlobReporter, r as readBlobs, H as HangingProcessReporter } from './index.BIP7prJq.js';
|
|
16
16
|
import require$$0$3 from 'events';
|
|
17
17
|
import require$$1$1 from 'https';
|
|
18
18
|
import require$$2 from 'http';
|
|
@@ -26,8 +26,8 @@ import require$$0$1 from 'buffer';
|
|
|
26
26
|
import { g as getDefaultExportFromCjs } from './_commonjsHelpers.BFTU3MAI.js';
|
|
27
27
|
import crypto, { createHash } from 'node:crypto';
|
|
28
28
|
import { distDir, rootDir } from '../path.js';
|
|
29
|
-
import { h as hash, d as createFetchModuleFunction, n as normalizeResolvedIdToUrl, R as RandomSequencer, i as isPackageExists, g as getFilePoolName, e as isBrowserEnabled, r as resolveConfig, f as groupBy, j as getCoverageProvider, k as createPool, w as wildcardPatternToRegExp, a as resolveApiServerConfig, s as stdout } from './coverage.
|
|
30
|
-
import { b as ancestor, c as convertTasksToEvents } from './typechecker.
|
|
29
|
+
import { h as hash, d as createFetchModuleFunction, n as normalizeResolvedIdToUrl, R as RandomSequencer, i as isPackageExists, g as getFilePoolName, e as isBrowserEnabled, r as resolveConfig, f as groupBy, j as getCoverageProvider, k as createPool, w as wildcardPatternToRegExp, a as resolveApiServerConfig, s as stdout } from './coverage.CDRAMTt7.js';
|
|
30
|
+
import { b as ancestor, c as createDefinesScript, d as convertTasksToEvents } from './typechecker.DB-fIMaH.js';
|
|
31
31
|
import { TraceMap, originalPositionFor, parseErrorStacktrace } from '@vitest/utils/source-map';
|
|
32
32
|
import createDebug from 'debug';
|
|
33
33
|
import { VitestModuleEvaluator } from '#module-evaluator';
|
|
@@ -45,7 +45,7 @@ import { hoistMocksPlugin, automockPlugin } from '@vitest/mocker/node';
|
|
|
45
45
|
import { c as configDefaults } from './defaults.CXFFjsi8.js';
|
|
46
46
|
import { f as findNearestPackageData } from './resolver.Bx6lE0iq.js';
|
|
47
47
|
import * as esModuleLexer from 'es-module-lexer';
|
|
48
|
-
import { a as BenchmarkReportsMap } from './index.
|
|
48
|
+
import { a as BenchmarkReportsMap } from './index.BjKEiSn0.js';
|
|
49
49
|
import assert$1 from 'node:assert';
|
|
50
50
|
import { serializeError as serializeError$1 } from '@vitest/utils/error';
|
|
51
51
|
import readline from 'node:readline';
|
|
@@ -5081,7 +5081,7 @@ catch {}
|
|
|
5081
5081
|
}
|
|
5082
5082
|
|
|
5083
5083
|
function setup(ctx, _server) {
|
|
5084
|
-
const wss = new WebSocketServer({ noServer: true }), clients = /* @__PURE__ */ new Map(), server = _server || ctx.
|
|
5084
|
+
const wss = new WebSocketServer({ noServer: true }), clients = /* @__PURE__ */ new Map(), server = _server || ctx.vite;
|
|
5085
5085
|
server.httpServer?.on("upgrade", (request, socket, head) => {
|
|
5086
5086
|
if (!request.url) return;
|
|
5087
5087
|
const { pathname } = new URL(request.url, "http://localhost");
|
|
@@ -5326,7 +5326,7 @@ function createFailedFileTask(project, filepath, error) {
|
|
|
5326
5326
|
tasks: [],
|
|
5327
5327
|
start: 0,
|
|
5328
5328
|
end: 0,
|
|
5329
|
-
projectName: project.
|
|
5329
|
+
projectName: project.name,
|
|
5330
5330
|
meta: {},
|
|
5331
5331
|
pool: project.browser ? "browser" : project.config.pool,
|
|
5332
5332
|
file: null,
|
|
@@ -5521,7 +5521,7 @@ class FilesStatsCache {
|
|
|
5521
5521
|
}
|
|
5522
5522
|
async populateStats(root, specs) {
|
|
5523
5523
|
const promises = specs.map((spec) => {
|
|
5524
|
-
const key = `${spec
|
|
5524
|
+
const key = `${spec.project.name}:${relative(root, spec.moduleId)}`;
|
|
5525
5525
|
return this.updateStats(spec.moduleId, key);
|
|
5526
5526
|
});
|
|
5527
5527
|
await Promise.all(promises);
|
|
@@ -5773,10 +5773,10 @@ class Logger {
|
|
|
5773
5773
|
const color = this.ctx.config.watch ? "blue" : "cyan", mode = this.ctx.config.watch ? "DEV" : "RUN";
|
|
5774
5774
|
if (this.log(withLabel(color, mode, `v${this.ctx.version} `) + c.gray(this.ctx.config.root)), this.ctx.config.sequence.sequencer === RandomSequencer) this.log(PAD + c.gray(`Running tests with seed "${this.ctx.config.sequence.seed}"`));
|
|
5775
5775
|
if (this.ctx.config.ui) {
|
|
5776
|
-
const host = this.ctx.config.api?.host || "localhost", port = this.ctx.
|
|
5776
|
+
const host = this.ctx.config.api?.host || "localhost", port = this.ctx.vite.config.server.port, base = this.ctx.config.uiBase;
|
|
5777
5777
|
this.log(PAD + c.dim(c.green(`UI started at http://${host}:${c.bold(port)}${base}`)));
|
|
5778
5778
|
} else if (this.ctx.config.api?.port) {
|
|
5779
|
-
const resolvedUrls = this.ctx.
|
|
5779
|
+
const resolvedUrls = this.ctx.vite.resolvedUrls, fallbackUrl = `http://${this.ctx.config.api.host || "localhost"}:${this.ctx.config.api.port}`, origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0] ?? fallbackUrl;
|
|
5780
5780
|
this.log(PAD + c.dim(c.green(`API started at ${new URL("/", origin)}`)));
|
|
5781
5781
|
}
|
|
5782
5782
|
if (this.ctx.coverageProvider) this.log(PAD + c.dim("Coverage enabled with ") + c.yellow(this.ctx.coverageProvider.name));
|
|
@@ -5866,8 +5866,8 @@ class VitestPackageInstaller {
|
|
|
5866
5866
|
}
|
|
5867
5867
|
}
|
|
5868
5868
|
|
|
5869
|
-
function serializeConfig(
|
|
5870
|
-
const optimizer = config.deps?.optimizer || {}, poolOptions = config.poolOptions, isolate = viteConfig?.test?.isolate;
|
|
5869
|
+
function serializeConfig(project) {
|
|
5870
|
+
const { config, globalConfig } = project, viteConfig = project._vite?.config, optimizer = config.deps?.optimizer || {}, poolOptions = config.poolOptions, isolate = viteConfig?.test?.isolate;
|
|
5871
5871
|
return {
|
|
5872
5872
|
environmentOptions: config.environmentOptions,
|
|
5873
5873
|
mode: config.mode,
|
|
@@ -5913,15 +5913,15 @@ function serializeConfig(config, coreConfig, viteConfig) {
|
|
|
5913
5913
|
fakeTimers: config.fakeTimers,
|
|
5914
5914
|
poolOptions: {
|
|
5915
5915
|
forks: {
|
|
5916
|
-
singleFork: poolOptions?.forks?.singleFork ??
|
|
5917
|
-
isolate: poolOptions?.forks?.isolate ?? isolate ??
|
|
5916
|
+
singleFork: poolOptions?.forks?.singleFork ?? globalConfig.poolOptions?.forks?.singleFork ?? false,
|
|
5917
|
+
isolate: poolOptions?.forks?.isolate ?? isolate ?? globalConfig.poolOptions?.forks?.isolate ?? true
|
|
5918
5918
|
},
|
|
5919
5919
|
threads: {
|
|
5920
|
-
singleThread: poolOptions?.threads?.singleThread ??
|
|
5921
|
-
isolate: poolOptions?.threads?.isolate ?? isolate ??
|
|
5920
|
+
singleThread: poolOptions?.threads?.singleThread ?? globalConfig.poolOptions?.threads?.singleThread ?? false,
|
|
5921
|
+
isolate: poolOptions?.threads?.isolate ?? isolate ?? globalConfig.poolOptions?.threads?.isolate ?? true
|
|
5922
5922
|
},
|
|
5923
|
-
vmThreads: { singleThread: poolOptions?.vmThreads?.singleThread ??
|
|
5924
|
-
vmForks: { singleFork: poolOptions?.vmForks?.singleFork ??
|
|
5923
|
+
vmThreads: { singleThread: poolOptions?.vmThreads?.singleThread ?? globalConfig.poolOptions?.vmThreads?.singleThread ?? false },
|
|
5924
|
+
vmForks: { singleFork: poolOptions?.vmForks?.singleFork ?? globalConfig.poolOptions?.vmForks?.singleFork ?? false }
|
|
5925
5925
|
},
|
|
5926
5926
|
deps: {
|
|
5927
5927
|
web: config.deps.web || {},
|
|
@@ -5933,22 +5933,22 @@ function serializeConfig(config, coreConfig, viteConfig) {
|
|
|
5933
5933
|
},
|
|
5934
5934
|
snapshotOptions: {
|
|
5935
5935
|
snapshotEnvironment: void 0,
|
|
5936
|
-
updateSnapshot:
|
|
5937
|
-
snapshotFormat: { ...
|
|
5938
|
-
expand: config.snapshotOptions.expand ??
|
|
5936
|
+
updateSnapshot: globalConfig.snapshotOptions.updateSnapshot,
|
|
5937
|
+
snapshotFormat: { ...globalConfig.snapshotOptions.snapshotFormat },
|
|
5938
|
+
expand: config.snapshotOptions.expand ?? globalConfig.snapshotOptions.expand
|
|
5939
5939
|
},
|
|
5940
5940
|
sequence: {
|
|
5941
|
-
shuffle:
|
|
5942
|
-
concurrent:
|
|
5943
|
-
seed:
|
|
5944
|
-
hooks:
|
|
5945
|
-
setupFiles:
|
|
5941
|
+
shuffle: globalConfig.sequence.shuffle,
|
|
5942
|
+
concurrent: globalConfig.sequence.concurrent,
|
|
5943
|
+
seed: globalConfig.sequence.seed,
|
|
5944
|
+
hooks: globalConfig.sequence.hooks,
|
|
5945
|
+
setupFiles: globalConfig.sequence.setupFiles
|
|
5946
5946
|
},
|
|
5947
|
-
inspect:
|
|
5948
|
-
inspectBrk:
|
|
5949
|
-
inspector:
|
|
5947
|
+
inspect: globalConfig.inspect,
|
|
5948
|
+
inspectBrk: globalConfig.inspectBrk,
|
|
5949
|
+
inspector: globalConfig.inspector,
|
|
5950
5950
|
watch: config.watch,
|
|
5951
|
-
includeTaskLocation: config.includeTaskLocation ??
|
|
5951
|
+
includeTaskLocation: config.includeTaskLocation ?? globalConfig.includeTaskLocation,
|
|
5952
5952
|
env: {
|
|
5953
5953
|
...viteConfig?.env,
|
|
5954
5954
|
...config.env
|
|
@@ -5968,8 +5968,9 @@ function serializeConfig(config, coreConfig, viteConfig) {
|
|
|
5968
5968
|
};
|
|
5969
5969
|
})(config.browser),
|
|
5970
5970
|
standalone: config.standalone,
|
|
5971
|
-
printConsoleTrace: config.printConsoleTrace ??
|
|
5972
|
-
benchmark: config.benchmark && { includeSamples: config.benchmark.includeSamples }
|
|
5971
|
+
printConsoleTrace: config.printConsoleTrace ?? globalConfig.printConsoleTrace,
|
|
5972
|
+
benchmark: config.benchmark && { includeSamples: config.benchmark.includeSamples },
|
|
5973
|
+
serializedDefines: config.browser.enabled ? "" : project._serializedDefines || ""
|
|
5973
5974
|
};
|
|
5974
5975
|
}
|
|
5975
5976
|
|
|
@@ -5999,6 +6000,7 @@ async function loadGlobalSetupFile(file, runner) {
|
|
|
5999
6000
|
function CoverageTransform(ctx) {
|
|
6000
6001
|
return {
|
|
6001
6002
|
name: "vitest:coverage-transform",
|
|
6003
|
+
enforce: "post",
|
|
6002
6004
|
transform(srcCode, id) {
|
|
6003
6005
|
return ctx.coverageProvider?.onFileTransform?.(srcCode, id, this);
|
|
6004
6006
|
}
|
|
@@ -6840,7 +6842,7 @@ function VitestProjectResolver(ctx) {
|
|
|
6840
6842
|
if (id === "vitest" || id.startsWith("@vitest/") || id.startsWith("vitest/")) {
|
|
6841
6843
|
// always redirect the request to the root vitest plugin since
|
|
6842
6844
|
// it will be the one used to run Vitest
|
|
6843
|
-
const resolved = await ctx.
|
|
6845
|
+
const resolved = await ctx.vite.pluginContainer.resolveId(id, void 0, {
|
|
6844
6846
|
skip: new Set([plugin]),
|
|
6845
6847
|
ssr
|
|
6846
6848
|
});
|
|
@@ -7075,18 +7077,6 @@ function matchExternalizePattern(id, moduleDirectories, patterns) {
|
|
|
7075
7077
|
}
|
|
7076
7078
|
|
|
7077
7079
|
class TestSpecification {
|
|
7078
|
-
/**
|
|
7079
|
-
* @deprecated use `project` instead
|
|
7080
|
-
*/
|
|
7081
|
-
0;
|
|
7082
|
-
/**
|
|
7083
|
-
* @deprecated use `moduleId` instead
|
|
7084
|
-
*/
|
|
7085
|
-
1;
|
|
7086
|
-
/**
|
|
7087
|
-
* @deprecated use `pool` instead
|
|
7088
|
-
*/
|
|
7089
|
-
2;
|
|
7090
7080
|
/**
|
|
7091
7081
|
* The task ID associated with the test module.
|
|
7092
7082
|
*/
|
|
@@ -7109,7 +7099,6 @@ class TestSpecification {
|
|
|
7109
7099
|
*/
|
|
7110
7100
|
testLines;
|
|
7111
7101
|
constructor(project, moduleId, pool, testLines) {
|
|
7112
|
-
this[0] = project, this[1] = moduleId, this[2] = { pool };
|
|
7113
7102
|
const name = project.config.name, hashName = pool !== "typescript" ? name : name ? `${name}:__typecheck__` : "__typecheck__";
|
|
7114
7103
|
this.taskId = generateFileHash(relative(project.config.root, moduleId), hashName), this.project = project, this.moduleId = moduleId, this.pool = pool, this.testLines = testLines;
|
|
7115
7104
|
}
|
|
@@ -7133,13 +7122,6 @@ class TestSpecification {
|
|
|
7133
7122
|
}
|
|
7134
7123
|
];
|
|
7135
7124
|
}
|
|
7136
|
-
/**
|
|
7137
|
-
* for backwards compatibility
|
|
7138
|
-
* @deprecated
|
|
7139
|
-
*/
|
|
7140
|
-
*[Symbol.iterator]() {
|
|
7141
|
-
yield this.project, yield this.moduleId, yield this.pool;
|
|
7142
|
-
}
|
|
7143
7125
|
}
|
|
7144
7126
|
|
|
7145
7127
|
async function createViteServer(inlineConfig) {
|
|
@@ -7167,8 +7149,6 @@ class TestProject {
|
|
|
7167
7149
|
* Browser instance if the browser is enabled. This is initialized when the tests run for the first time.
|
|
7168
7150
|
*/
|
|
7169
7151
|
browser;
|
|
7170
|
-
/** @deprecated use `vitest` instead */
|
|
7171
|
-
ctx;
|
|
7172
7152
|
/**
|
|
7173
7153
|
* Temporary directory for the project. This is unique for each project. Vitest stores transformed content here.
|
|
7174
7154
|
*/
|
|
@@ -7178,14 +7158,15 @@ class TestProject {
|
|
|
7178
7158
|
/** @internal */ _vite;
|
|
7179
7159
|
/** @internal */ _hash;
|
|
7180
7160
|
/** @internal */ _resolver;
|
|
7161
|
+
/** @internal */ _serializedDefines;
|
|
7181
7162
|
/** @inetrnal */ testFilesList = null;
|
|
7182
7163
|
runner;
|
|
7183
7164
|
closingPromise;
|
|
7184
7165
|
typecheckFilesList = null;
|
|
7185
7166
|
_globalSetups;
|
|
7186
7167
|
_provided = {};
|
|
7187
|
-
constructor(
|
|
7188
|
-
this.
|
|
7168
|
+
constructor(vitest, options) {
|
|
7169
|
+
this.options = options, this.vitest = vitest, this.globalConfig = vitest.config;
|
|
7189
7170
|
}
|
|
7190
7171
|
/**
|
|
7191
7172
|
* The unique hash of this project. This value is consistent between the reruns.
|
|
@@ -7277,28 +7258,12 @@ class TestProject {
|
|
|
7277
7258
|
get serializedConfig() {
|
|
7278
7259
|
return this._serializeOverriddenConfig();
|
|
7279
7260
|
}
|
|
7280
|
-
/** @deprecated use `vite` instead */
|
|
7281
|
-
get server() {
|
|
7282
|
-
return this._vite;
|
|
7283
|
-
}
|
|
7284
7261
|
/**
|
|
7285
7262
|
* Check if this is the root project. The root project is the one that has the root config.
|
|
7286
7263
|
*/
|
|
7287
7264
|
isRootProject() {
|
|
7288
7265
|
return this.vitest.getRootProject() === this;
|
|
7289
7266
|
}
|
|
7290
|
-
/** @deprecated use `isRootProject` instead */
|
|
7291
|
-
isCore() {
|
|
7292
|
-
return this.isRootProject();
|
|
7293
|
-
}
|
|
7294
|
-
/** @deprecated use `createSpecification` instead */
|
|
7295
|
-
createSpec(moduleId, pool) {
|
|
7296
|
-
return new TestSpecification(this, moduleId, pool);
|
|
7297
|
-
}
|
|
7298
|
-
/** @deprecated */
|
|
7299
|
-
initializeGlobalSetup() {
|
|
7300
|
-
return this._initializeGlobalSetup();
|
|
7301
|
-
}
|
|
7302
7267
|
/** @internal */
|
|
7303
7268
|
async _initializeGlobalSetup() {
|
|
7304
7269
|
if (!this._globalSetups) {
|
|
@@ -7314,37 +7279,10 @@ class TestProject {
|
|
|
7314
7279
|
onTestsRerun(cb) {
|
|
7315
7280
|
this.vitest.onTestsRerun(cb);
|
|
7316
7281
|
}
|
|
7317
|
-
/** @deprecated */
|
|
7318
|
-
teardownGlobalSetup() {
|
|
7319
|
-
return this._teardownGlobalSetup();
|
|
7320
|
-
}
|
|
7321
7282
|
/** @internal */
|
|
7322
7283
|
async _teardownGlobalSetup() {
|
|
7323
7284
|
if (this._globalSetups) for (const globalSetupFile of [...this._globalSetups].reverse()) await globalSetupFile.teardown?.();
|
|
7324
7285
|
}
|
|
7325
|
-
/** @deprecated use `vitest.logger` instead */
|
|
7326
|
-
get logger() {
|
|
7327
|
-
return this.vitest.logger;
|
|
7328
|
-
}
|
|
7329
|
-
// it's possible that file path was imported with different queries (?raw, ?url, etc)
|
|
7330
|
-
/** @deprecated use `.vite` or `.browser.vite` directly */
|
|
7331
|
-
getModulesByFilepath(file) {
|
|
7332
|
-
const set = this.server.moduleGraph.getModulesByFile(file) || this.browser?.vite.moduleGraph.getModulesByFile(file);
|
|
7333
|
-
return set || /* @__PURE__ */ new Set();
|
|
7334
|
-
}
|
|
7335
|
-
/** @deprecated use `.vite` or `.browser.vite` directly */
|
|
7336
|
-
getModuleById(id) {
|
|
7337
|
-
return this.server.moduleGraph.getModuleById(id) || this.browser?.vite.moduleGraph.getModuleById(id);
|
|
7338
|
-
}
|
|
7339
|
-
/** @deprecated use `.vite` or `.browser.vite` directly */
|
|
7340
|
-
getSourceMapModuleById(id) {
|
|
7341
|
-
const mod = this.server.moduleGraph.getModuleById(id);
|
|
7342
|
-
return mod?.ssrTransformResult?.map || mod?.transformResult?.map;
|
|
7343
|
-
}
|
|
7344
|
-
/** @deprecated use `vitest.reporters` instead */
|
|
7345
|
-
get reporters() {
|
|
7346
|
-
return this.ctx.reporters;
|
|
7347
|
-
}
|
|
7348
7286
|
/**
|
|
7349
7287
|
* Get all files in the project that match the globs in the config and the filters.
|
|
7350
7288
|
* @param filters String filters to match the test files.
|
|
@@ -7396,10 +7334,6 @@ class TestProject {
|
|
|
7396
7334
|
_isCachedTypecheckFile(testPath) {
|
|
7397
7335
|
return !!this.typecheckFilesList && this.typecheckFilesList.includes(testPath);
|
|
7398
7336
|
}
|
|
7399
|
-
/** @deprecated use `serializedConfig` instead */
|
|
7400
|
-
getSerializableConfig() {
|
|
7401
|
-
return this._serializeOverriddenConfig();
|
|
7402
|
-
}
|
|
7403
7337
|
/** @internal */
|
|
7404
7338
|
async globFiles(include, exclude, cwd) {
|
|
7405
7339
|
const globOptions = {
|
|
@@ -7427,10 +7361,6 @@ class TestProject {
|
|
|
7427
7361
|
}
|
|
7428
7362
|
return false;
|
|
7429
7363
|
}
|
|
7430
|
-
/** @deprecated use `matchesTestGlob` instead */
|
|
7431
|
-
async isTargetFile(id, source) {
|
|
7432
|
-
return this.matchesTestGlob(id, source ? () => source : void 0);
|
|
7433
|
-
}
|
|
7434
7364
|
isInSourceTestCode(code) {
|
|
7435
7365
|
return code.includes("import.meta.vitest");
|
|
7436
7366
|
}
|
|
@@ -7495,14 +7425,6 @@ class TestProject {
|
|
|
7495
7425
|
import(moduleId) {
|
|
7496
7426
|
return this.runner.import(moduleId);
|
|
7497
7427
|
}
|
|
7498
|
-
/** @deprecated use `name` instead */
|
|
7499
|
-
getName() {
|
|
7500
|
-
return this.config.name || "";
|
|
7501
|
-
}
|
|
7502
|
-
/** @deprecated internal */
|
|
7503
|
-
setServer(options, server) {
|
|
7504
|
-
return this._configureServer(options, server);
|
|
7505
|
-
}
|
|
7506
7428
|
_setHash() {
|
|
7507
7429
|
this._hash = generateHash(this._config.root + this._config.name);
|
|
7508
7430
|
}
|
|
@@ -7516,13 +7438,13 @@ class TestProject {
|
|
|
7516
7438
|
// type is very strict here, so we cast it to any
|
|
7517
7439
|
this.provide(providedKey, this.config.provide[providedKey]);
|
|
7518
7440
|
}
|
|
7519
|
-
this.closingPromise = void 0, this._resolver = new VitestResolver(server.config.cacheDir, this._config), this._vite = server;
|
|
7441
|
+
this.closingPromise = void 0, this._resolver = new VitestResolver(server.config.cacheDir, this._config), this._vite = server, this._serializedDefines = createDefinesScript(server.config.define);
|
|
7520
7442
|
const environment = server.environments.__vitest__;
|
|
7521
7443
|
this.runner = new ServerModuleRunner(environment, this._resolver, this._config);
|
|
7522
7444
|
}
|
|
7523
7445
|
_serializeOverriddenConfig() {
|
|
7524
7446
|
// TODO: serialize the config _once_ or when needed
|
|
7525
|
-
const config = serializeConfig(this
|
|
7447
|
+
const config = serializeConfig(this);
|
|
7526
7448
|
return this.vitest.configOverride ? deepMerge(config, this.vitest.configOverride) : config;
|
|
7527
7449
|
}
|
|
7528
7450
|
async clearTmpDir() {
|
|
@@ -7530,10 +7452,6 @@ class TestProject {
|
|
|
7530
7452
|
await rm(this.tmpDir, { recursive: true });
|
|
7531
7453
|
} catch {}
|
|
7532
7454
|
}
|
|
7533
|
-
/** @deprecated */
|
|
7534
|
-
initBrowserProvider() {
|
|
7535
|
-
return this._initBrowserProvider();
|
|
7536
|
-
}
|
|
7537
7455
|
/** @internal */
|
|
7538
7456
|
_initBrowserProvider = deduped(async () => {
|
|
7539
7457
|
if (!(!this.isBrowserEnabled() || this.browser?.provider)) {
|
|
@@ -7551,13 +7469,13 @@ class TestProject {
|
|
|
7551
7469
|
}
|
|
7552
7470
|
/** @internal */
|
|
7553
7471
|
static _createBasicProject(vitest) {
|
|
7554
|
-
const project = new TestProject(vitest
|
|
7555
|
-
return project.runner = vitest.runner, project._vite = vitest.
|
|
7472
|
+
const project = new TestProject(vitest);
|
|
7473
|
+
return project.runner = vitest.runner, project._vite = vitest.vite, project._config = vitest.config, project._resolver = vitest._resolver, project._serializedDefines = createDefinesScript(vitest.vite.config.define), project._setHash(), project._provideObject(vitest.config.provide), project;
|
|
7556
7474
|
}
|
|
7557
7475
|
/** @internal */
|
|
7558
7476
|
static _cloneBrowserProject(parent, config) {
|
|
7559
|
-
const clone = new TestProject(parent.
|
|
7560
|
-
return clone.runner = parent.runner, clone._vite = parent._vite, clone._resolver = parent._resolver, clone._config = config, clone._setHash(), clone._parent = parent, clone._provideObject(config.provide), clone;
|
|
7477
|
+
const clone = new TestProject(parent.vitest);
|
|
7478
|
+
return clone.runner = parent.runner, clone._vite = parent._vite, clone._resolver = parent._resolver, clone._config = config, clone._setHash(), clone._parent = parent, clone._serializedDefines = parent._serializedDefines, clone._provideObject(config.provide), clone;
|
|
7561
7479
|
}
|
|
7562
7480
|
}
|
|
7563
7481
|
function deduped(cb) {
|
|
@@ -7570,7 +7488,7 @@ function deduped(cb) {
|
|
|
7570
7488
|
});
|
|
7571
7489
|
}
|
|
7572
7490
|
async function initializeProject(workspacePath, ctx, options) {
|
|
7573
|
-
const project = new TestProject(
|
|
7491
|
+
const project = new TestProject(ctx, options), { configFile,...restOptions } = options, config = {
|
|
7574
7492
|
...restOptions,
|
|
7575
7493
|
configFile,
|
|
7576
7494
|
configLoader: ctx.vite.config.inlineConfig.configLoader,
|
|
@@ -8956,7 +8874,7 @@ class TestRun {
|
|
|
8956
8874
|
// specification won't have the File task if they were filtered by the --shard command
|
|
8957
8875
|
const modules = specifications.map((spec) => spec.testModule).filter((s) => s != null), state = this.vitest.isCancelling ? "interrupted" : this.hasFailed(modules) ? "failed" : "passed";
|
|
8958
8876
|
if (state !== "passed") process.exitCode = 1;
|
|
8959
|
-
this.vitest.report("onTestRunEnd", modules, [...errors], state);
|
|
8877
|
+
await this.vitest.report("onTestRunEnd", modules, [...errors], state);
|
|
8960
8878
|
}
|
|
8961
8879
|
hasFailed(modules) {
|
|
8962
8880
|
return modules.length ? modules.some((m) => !m.ok()) : !this.vitest.config.passWithNoTests;
|
|
@@ -9186,7 +9104,6 @@ class Vitest {
|
|
|
9186
9104
|
*/
|
|
9187
9105
|
watcher;
|
|
9188
9106
|
/** @internal */ configOverride = {};
|
|
9189
|
-
/** @internal */ coverageProvider;
|
|
9190
9107
|
/** @internal */ filenamePattern;
|
|
9191
9108
|
/** @internal */ runningPromise;
|
|
9192
9109
|
/** @internal */ closingPromise;
|
|
@@ -9207,6 +9124,7 @@ class Vitest {
|
|
|
9207
9124
|
_state;
|
|
9208
9125
|
_cache;
|
|
9209
9126
|
_snapshot;
|
|
9127
|
+
_coverageProvider;
|
|
9210
9128
|
constructor(mode, cliOptions, options = {}) {
|
|
9211
9129
|
this.mode = mode, this._cliOptions = cliOptions, this.logger = new Logger(this, options.stdout, options.stderr), this.packageInstaller = options.packageInstaller || new VitestPackageInstaller(), this.specifications = new VitestSpecifications(this), this.watcher = new VitestWatcher(this).onWatcherRerun((file) => this.scheduleRerun(file));
|
|
9212
9130
|
}
|
|
@@ -9216,24 +9134,12 @@ class Vitest {
|
|
|
9216
9134
|
_onCancelListeners = [];
|
|
9217
9135
|
_onUserTestsRerun = [];
|
|
9218
9136
|
_onFilterWatchedSpecification = [];
|
|
9219
|
-
/** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
|
|
9220
|
-
get invalidates() {
|
|
9221
|
-
return this.watcher.invalidates;
|
|
9222
|
-
}
|
|
9223
|
-
/** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
|
|
9224
|
-
get changedTests() {
|
|
9225
|
-
return this.watcher.changedTests;
|
|
9226
|
-
}
|
|
9227
9137
|
/**
|
|
9228
9138
|
* The global config.
|
|
9229
9139
|
*/
|
|
9230
9140
|
get config() {
|
|
9231
9141
|
return assert(this._config, "config"), this._config;
|
|
9232
9142
|
}
|
|
9233
|
-
/** @deprecated use `vitest.vite` instead */
|
|
9234
|
-
get server() {
|
|
9235
|
-
return this._vite;
|
|
9236
|
-
}
|
|
9237
9143
|
/**
|
|
9238
9144
|
* Global Vite's dev server instance.
|
|
9239
9145
|
*/
|
|
@@ -9259,13 +9165,9 @@ class Vitest {
|
|
|
9259
9165
|
get cache() {
|
|
9260
9166
|
return assert(this._cache, "cache"), this._cache;
|
|
9261
9167
|
}
|
|
9262
|
-
/** @deprecated internal */
|
|
9263
|
-
setServer(options, server) {
|
|
9264
|
-
return this._setServer(options, server);
|
|
9265
|
-
}
|
|
9266
9168
|
/** @internal */
|
|
9267
9169
|
async _setServer(options, server) {
|
|
9268
|
-
this.watcher.unregisterWatcher(), clearTimeout(this._rerunTimer), this.restartsCount += 1, this.pool?.close?.(), this.pool = void 0, this.closingPromise = void 0, this.projects = [], this.
|
|
9170
|
+
this.watcher.unregisterWatcher(), clearTimeout(this._rerunTimer), this.restartsCount += 1, this.pool?.close?.(), this.pool = void 0, this.closingPromise = void 0, this.projects = [], this.runningPromise = void 0, this.coreWorkspaceProject = void 0, this.specifications.clearCache(), this._coverageProvider = void 0, this._onUserTestsRerun = [], this._vite = server;
|
|
9269
9171
|
const resolved = resolveConfig(this, options, server.config);
|
|
9270
9172
|
if (this._config = resolved, this._state = new StateManager({ onUnhandledError: resolved.onUnhandledError }), this._cache = new VitestCache(this.version), this._snapshot = new SnapshotManager({ ...resolved.snapshotOptions }), this._testRun = new TestRun(this), this.config.watch) this.watcher.registerWatcher();
|
|
9271
9173
|
this._resolver = new VitestResolver(server.config.cacheDir, resolved);
|
|
@@ -9306,6 +9208,26 @@ class Vitest {
|
|
|
9306
9208
|
if (this.config.testNamePattern) this.configOverride.testNamePattern = this.config.testNamePattern;
|
|
9307
9209
|
this.reporters = resolved.mode === "benchmark" ? await createBenchmarkReporters(toArray(resolved.benchmark?.reporters), this.runner) : await createReporters(resolved.reporters, this), await Promise.all(this._onSetServer.map((fn) => fn()));
|
|
9308
9210
|
}
|
|
9211
|
+
/** @internal */
|
|
9212
|
+
get coverageProvider() {
|
|
9213
|
+
return this.configOverride.coverage?.enabled === false ? null : this._coverageProvider;
|
|
9214
|
+
}
|
|
9215
|
+
async enableCoverage() {
|
|
9216
|
+
this.configOverride.coverage = {}, this.configOverride.coverage.enabled = true, await this.createCoverageProvider(), await this.coverageProvider?.onEnabled?.();
|
|
9217
|
+
}
|
|
9218
|
+
disableCoverage() {
|
|
9219
|
+
this.configOverride.coverage ??= {}, this.configOverride.coverage.enabled = false;
|
|
9220
|
+
}
|
|
9221
|
+
_coverageOverrideCache = /* @__PURE__ */ new WeakMap();
|
|
9222
|
+
/** @internal */
|
|
9223
|
+
get _coverageOptions() {
|
|
9224
|
+
if (!this.configOverride.coverage) return this.config.coverage;
|
|
9225
|
+
if (!this._coverageOverrideCache.has(this.configOverride.coverage)) {
|
|
9226
|
+
const coverage = deepClone(this.config.coverage), options = deepMerge(coverage, this.configOverride.coverage);
|
|
9227
|
+
this._coverageOverrideCache.set(this.configOverride.coverage, options);
|
|
9228
|
+
}
|
|
9229
|
+
return this._coverageOverrideCache.get(this.configOverride.coverage);
|
|
9230
|
+
}
|
|
9309
9231
|
/**
|
|
9310
9232
|
* Inject new test projects into the workspace.
|
|
9311
9233
|
* @param config Glob, config path or a custom config options.
|
|
@@ -9331,10 +9253,6 @@ class Vitest {
|
|
|
9331
9253
|
_ensureRootProject() {
|
|
9332
9254
|
return this.coreWorkspaceProject ||= TestProject._createBasicProject(this), this.coreWorkspaceProject;
|
|
9333
9255
|
}
|
|
9334
|
-
/** @deprecated use `getRootProject` instead */
|
|
9335
|
-
getCoreWorkspaceProject() {
|
|
9336
|
-
return this.getRootProject();
|
|
9337
|
-
}
|
|
9338
9256
|
/**
|
|
9339
9257
|
* Return project that has the root (or "global") config.
|
|
9340
9258
|
*/
|
|
@@ -9342,13 +9260,6 @@ class Vitest {
|
|
|
9342
9260
|
if (!this.coreWorkspaceProject) throw new Error(`Root project is not initialized. This means that the Vite server was not established yet and the the workspace config is not resolved.`);
|
|
9343
9261
|
return this.coreWorkspaceProject;
|
|
9344
9262
|
}
|
|
9345
|
-
/**
|
|
9346
|
-
* @deprecated use Reported Task API instead
|
|
9347
|
-
*/
|
|
9348
|
-
getProjectByTaskId(taskId) {
|
|
9349
|
-
const task = this.state.idMap.get(taskId), projectName = task.projectName || task?.file?.projectName || "";
|
|
9350
|
-
return this.getProjectByName(projectName);
|
|
9351
|
-
}
|
|
9352
9263
|
getProjectByName(name) {
|
|
9353
9264
|
const project = this.projects.find((p) => p.name === name) || this.coreWorkspaceProject || this.projects[0];
|
|
9354
9265
|
if (!project) throw new Error(`Project "${name}" was not found.`);
|
|
@@ -9365,9 +9276,9 @@ class Vitest {
|
|
|
9365
9276
|
* Creates a coverage provider if `coverage` is enabled in the config.
|
|
9366
9277
|
*/
|
|
9367
9278
|
async createCoverageProvider() {
|
|
9368
|
-
if (this.
|
|
9279
|
+
if (this._coverageProvider) return this._coverageProvider;
|
|
9369
9280
|
const coverageProvider = await this.initCoverageProvider();
|
|
9370
|
-
if (coverageProvider) await coverageProvider.clean(this.
|
|
9281
|
+
if (coverageProvider) await coverageProvider.clean(this._coverageOptions.clean);
|
|
9371
9282
|
return coverageProvider || null;
|
|
9372
9283
|
}
|
|
9373
9284
|
async resolveProjects(cliOptions) {
|
|
@@ -9387,10 +9298,10 @@ class Vitest {
|
|
|
9387
9298
|
return this.specifications.globTestSpecifications(filters);
|
|
9388
9299
|
}
|
|
9389
9300
|
async initCoverageProvider() {
|
|
9390
|
-
if (this.
|
|
9391
|
-
|
|
9392
|
-
|
|
9393
|
-
|
|
9301
|
+
if (this._coverageProvider != null) return;
|
|
9302
|
+
const coverageConfig = this.configOverride.coverage ? this.getRootProject().serializedConfig.coverage : this.config.coverage;
|
|
9303
|
+
if (this._coverageProvider = await getCoverageProvider(coverageConfig, this.runner), this._coverageProvider) await this._coverageProvider.initialize(this), this.config.coverage = this._coverageProvider.resolveOptions();
|
|
9304
|
+
return this._coverageProvider;
|
|
9394
9305
|
}
|
|
9395
9306
|
/**
|
|
9396
9307
|
* Merge reports from multiple runs located in the specified directory (value from `--merge-reports` if not specified).
|
|
@@ -9434,10 +9345,6 @@ class Vitest {
|
|
|
9434
9345
|
unhandledErrors: []
|
|
9435
9346
|
};
|
|
9436
9347
|
}
|
|
9437
|
-
/** @deprecated use `getRelevantTestSpecifications` instead */
|
|
9438
|
-
listFiles(filters) {
|
|
9439
|
-
return this.getRelevantTestSpecifications(filters);
|
|
9440
|
-
}
|
|
9441
9348
|
/**
|
|
9442
9349
|
* Returns the list of test files that match the config and filters.
|
|
9443
9350
|
* @param filters String filters to match the test files
|
|
@@ -9455,7 +9362,7 @@ class Vitest {
|
|
|
9455
9362
|
*/
|
|
9456
9363
|
async start(filters) {
|
|
9457
9364
|
try {
|
|
9458
|
-
await this.initCoverageProvider(), await this.coverageProvider?.clean(this.
|
|
9365
|
+
await this.initCoverageProvider(), await this.coverageProvider?.clean(this._coverageOptions.clean);
|
|
9459
9366
|
} finally {
|
|
9460
9367
|
await this.report("onInit", this);
|
|
9461
9368
|
}
|
|
@@ -9481,23 +9388,13 @@ class Vitest {
|
|
|
9481
9388
|
*/
|
|
9482
9389
|
async init() {
|
|
9483
9390
|
try {
|
|
9484
|
-
await this.initCoverageProvider(), await this.coverageProvider?.clean(this.
|
|
9391
|
+
await this.initCoverageProvider(), await this.coverageProvider?.clean(this._coverageOptions.clean);
|
|
9485
9392
|
} finally {
|
|
9486
9393
|
await this.report("onInit", this);
|
|
9487
9394
|
}
|
|
9488
9395
|
if (await this.globTestSpecifications(), this.config.watch) await this.report("onWatcherStart");
|
|
9489
9396
|
}
|
|
9490
9397
|
/**
|
|
9491
|
-
* @deprecated remove when vscode extension supports "getModuleSpecifications"
|
|
9492
|
-
*/
|
|
9493
|
-
getProjectsByTestFile(file) {
|
|
9494
|
-
return this.getModuleSpecifications(file);
|
|
9495
|
-
}
|
|
9496
|
-
/** @deprecated */
|
|
9497
|
-
getFileWorkspaceSpecs(file) {
|
|
9498
|
-
return this.getModuleSpecifications(file);
|
|
9499
|
-
}
|
|
9500
|
-
/**
|
|
9501
9398
|
* If there is a test run happening, returns a promise that will
|
|
9502
9399
|
* resolve when the test run is finished.
|
|
9503
9400
|
*/
|
|
@@ -9535,7 +9432,6 @@ class Vitest {
|
|
|
9535
9432
|
* @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
|
|
9536
9433
|
*/
|
|
9537
9434
|
async rerunTestSpecifications(specifications, allTestsRun = false) {
|
|
9538
|
-
this.configOverride.testNamePattern = void 0;
|
|
9539
9435
|
const files = specifications.map((spec) => spec.moduleId);
|
|
9540
9436
|
await Promise.all([this.report("onWatcherRerun", files, "rerun test"), ...this._onUserTestsRerun.map((fn) => fn(specifications))]);
|
|
9541
9437
|
const result = await this.runTestSpecifications(specifications, allTestsRun);
|
|
@@ -9546,7 +9442,7 @@ class Vitest {
|
|
|
9546
9442
|
try {
|
|
9547
9443
|
if (!this.pool) this.pool = createPool(this);
|
|
9548
9444
|
const invalidates = Array.from(this.watcher.invalidates);
|
|
9549
|
-
if (this.watcher.invalidates.clear(), this.snapshot.clear(), this.state.clearErrors(), !this.isFirstRun && this.
|
|
9445
|
+
if (this.watcher.invalidates.clear(), this.snapshot.clear(), this.state.clearErrors(), !this.isFirstRun && this._coverageOptions.cleanOnRerun) await this.coverageProvider?.clean();
|
|
9550
9446
|
await this.initializeGlobalSetup(specs);
|
|
9551
9447
|
try {
|
|
9552
9448
|
await this.pool.runTests(specs, invalidates);
|
|
@@ -9714,6 +9610,12 @@ class Vitest {
|
|
|
9714
9610
|
else this.configOverride.testNamePattern = pattern ? new RegExp(pattern) : void 0;
|
|
9715
9611
|
}
|
|
9716
9612
|
/**
|
|
9613
|
+
* Returns the regexp used for the global test name pattern.
|
|
9614
|
+
*/
|
|
9615
|
+
getGlobalTestNamePattern() {
|
|
9616
|
+
return this.configOverride.testNamePattern == null ? this.config.testNamePattern : this.configOverride.testNamePattern;
|
|
9617
|
+
}
|
|
9618
|
+
/**
|
|
9717
9619
|
* Resets the global test name pattern. This method doesn't run any tests.
|
|
9718
9620
|
*/
|
|
9719
9621
|
resetGlobalTestNamePattern() {
|
|
@@ -9755,17 +9657,13 @@ class Vitest {
|
|
|
9755
9657
|
});
|
|
9756
9658
|
});
|
|
9757
9659
|
}
|
|
9758
|
-
/** @deprecated use `invalidateFile` */
|
|
9759
|
-
updateLastChanged(filepath) {
|
|
9760
|
-
this.invalidateFile(filepath);
|
|
9761
|
-
}
|
|
9762
9660
|
/** @internal */
|
|
9763
9661
|
_checkUnhandledErrors(errors) {
|
|
9764
9662
|
if (errors.length && !this.config.dangerouslyIgnoreUnhandledErrors) process.exitCode = 1;
|
|
9765
9663
|
}
|
|
9766
9664
|
async reportCoverage(coverage, allTestsRun) {
|
|
9767
9665
|
if (this.state.getCountOfFailedTests() > 0) {
|
|
9768
|
-
if (await this.coverageProvider?.onTestFailure?.(), !this.
|
|
9666
|
+
if (await this.coverageProvider?.onTestFailure?.(), !this._coverageOptions.reportOnFailure) return;
|
|
9769
9667
|
}
|
|
9770
9668
|
if (this.coverageProvider) {
|
|
9771
9669
|
await this.coverageProvider.reportCoverage(coverage, { allTestsRun });
|
|
@@ -9829,25 +9727,6 @@ class Vitest {
|
|
|
9829
9727
|
return Array.from(new Set(specifications.map((spec) => spec.moduleId)));
|
|
9830
9728
|
}
|
|
9831
9729
|
/**
|
|
9832
|
-
* @deprecated use `globTestSpecifications` instead
|
|
9833
|
-
*/
|
|
9834
|
-
async globTestSpecs(filters = []) {
|
|
9835
|
-
return this.globTestSpecifications(filters);
|
|
9836
|
-
}
|
|
9837
|
-
/**
|
|
9838
|
-
* @deprecated use `globTestSpecifications` instead
|
|
9839
|
-
*/
|
|
9840
|
-
async globTestFiles(filters = []) {
|
|
9841
|
-
return this.globTestSpecifications(filters);
|
|
9842
|
-
}
|
|
9843
|
-
/** @deprecated filter by `this.projects` yourself */
|
|
9844
|
-
getModuleProjects(filepath) {
|
|
9845
|
-
return this.projects.filter((project) => {
|
|
9846
|
-
return project.getModulesByFilepath(filepath).size;
|
|
9847
|
-
// TODO: reevaluate || project.browser?.moduleGraph.getModulesByFile(id)?.size
|
|
9848
|
-
});
|
|
9849
|
-
}
|
|
9850
|
-
/**
|
|
9851
9730
|
* Should the server be kept running after the tests are done.
|
|
9852
9731
|
*/
|
|
9853
9732
|
shouldKeepServer() {
|
|
@@ -10264,8 +10143,8 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout) {
|
|
|
10264
10143
|
async function inputFilePattern() {
|
|
10265
10144
|
off();
|
|
10266
10145
|
const watchFilter = new WatchFilter("Input filename pattern", stdin, stdout), filter = await watchFilter.filter(async (str) => {
|
|
10267
|
-
const
|
|
10268
|
-
return
|
|
10146
|
+
const specifications = await ctx.globTestSpecifications([str]);
|
|
10147
|
+
return specifications.map((specification) => relative(ctx.config.root, specification.moduleId)).filter((file, index, all) => all.indexOf(file) === index);
|
|
10269
10148
|
});
|
|
10270
10149
|
if (on(), typeof filter === "undefined") return;
|
|
10271
10150
|
latestFilename = filter?.trim() || "";
|
|
@@ -10295,8 +10174,8 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout) {
|
|
|
10295
10174
|
*/
|
|
10296
10175
|
async function startVitest(mode, cliFilters = [], options = {}, viteOverrides, vitestOptions) {
|
|
10297
10176
|
const root = resolve(options.root || process.cwd()), ctx = await prepareVitest(mode, options, viteOverrides, vitestOptions, cliFilters);
|
|
10298
|
-
if (mode === "test" && ctx.
|
|
10299
|
-
const provider = ctx.
|
|
10177
|
+
if (mode === "test" && ctx._coverageOptions.enabled) {
|
|
10178
|
+
const provider = ctx._coverageOptions.provider || "v8", requiredPackages = CoverageProviderMap[provider];
|
|
10300
10179
|
if (requiredPackages) {
|
|
10301
10180
|
if (!await ctx.packageInstaller.ensureInstalled(requiredPackages, root, ctx.version)) return process.exitCode = 1, ctx;
|
|
10302
10181
|
}
|