vitest 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.ts +21 -42
- package/dist/browser.js +5 -5
- package/dist/{vendor/base.Csk7BT3h.js → chunks/base.CC5R_kgU.js} +3 -3
- package/dist/{vendor/base.DRHPZCCj.js → chunks/base.DSsbfkDg.js} +1 -1
- package/dist/{vendor/benchmark.B6pblCp2.js → chunks/benchmark.DDmpNjj-.js} +1 -1
- package/dist/chunks/benchmark.puBFxyfE.d.ts +22 -0
- package/dist/{vendor/cac.DFtWvZc2.js → chunks/cac.DGgmCKmU.js} +17 -20
- package/dist/{vendor/cli-api.CTkP2Ier.js → chunks/cli-api.OKfd3qJ0.js} +416 -423
- package/dist/chunks/config.DCnyCTbs.d.ts +203 -0
- package/dist/chunks/{runtime-console.C2L2zykk.js → console.Bgn7_A1x.js} +11 -14
- package/dist/{vendor/constants.CsnA4eRy.js → chunks/constants.CaAN7icJ.js} +1 -3
- package/dist/{vendor/coverage.BhYSDdTT.js → chunks/coverage.CqfT4xaf.js} +4 -7
- package/dist/chunks/{browser-creator.CyaOd8pl.js → creator.a3OfuIEW.js} +8 -8
- package/dist/{vendor/env.2ltrQNq0.js → chunks/env.BU041cs9.js} +2 -3
- package/dist/chunks/environment.0M5R1SX_.d.ts +173 -0
- package/dist/{vendor/execute.jzOWtys_.js → chunks/execute.Cjlr2CRw.js} +27 -19
- package/dist/chunks/globals.BliuJFNR.js +31 -0
- package/dist/{vendor/index.DI9daj1Q.js → chunks/index.BfeNhc0N.js} +43 -43
- package/dist/{vendor/index.D6GZqexG.js → chunks/index.CM5UI-4O.js} +2 -2
- package/dist/{vendor/index.BJmtb_7W.js → chunks/index.DYufA6CZ.js} +2 -2
- package/dist/{vendor/index.CuuL9y4g.js → chunks/index.JbiJutJ_.js} +515 -255
- package/dist/{vendor/index.CVqMv71L.js → chunks/index.R1VjssW9.js} +11 -12
- package/dist/{vendor/index.D4nqnQWz.js → chunks/index.lVXYBqEP.js} +1 -18
- package/dist/{vendor/inspector.-FCQUzqR.js → chunks/inspector.70d6emsh.js} +4 -5
- package/dist/chunks/{environments-node.XE5FbRPQ.js → node.DS3zEPa7.js} +2 -2
- package/dist/{reporters-B7ebVMkT.d.ts → chunks/reporters.C_zwCd4j.d.ts} +847 -1000
- package/dist/{vendor/rpc.BGx7q_k2.js → chunks/rpc.B7Mfb-Yf.js} +3 -5
- package/dist/{vendor/run-once.Db8Hgq9X.js → chunks/run-once.Sxe67Wng.js} +1 -1
- package/dist/chunks/{runtime-runBaseTests.Dq_sJZq9.js → runBaseTests.CyvqmuC9.js} +21 -23
- package/dist/{vendor/setup-common.symvFZPh.js → chunks/setup-common.CNzatKMx.js} +2 -2
- package/dist/{suite-CRLAhsm0.d.ts → chunks/suite.CcK46U-P.d.ts} +1 -1
- package/dist/{vendor/tasks.DhVtQBtW.js → chunks/tasks.BZnCS9aT.js} +2 -3
- package/dist/{vendor/utils.DkxLWvS1.js → chunks/utils.C3_cBsyn.js} +3 -4
- package/dist/{vendor/global.7bFbnyXl.js → chunks/utils.Ck2hJTRs.js} +1 -1
- package/dist/{vendor/utils.BySfPUwy.js → chunks/utils.DpP_sDwr.js} +8 -21
- package/dist/{vendor/vi.Elqer9-7.js → chunks/vi.fiQ7lMRF.js} +13 -18
- package/dist/{vendor/vm.img-AOox.js → chunks/vm.DcSuuaHr.js} +40 -68
- package/dist/chunks/worker.C5iHKIaJ.d.ts +144 -0
- package/dist/chunks/worker.DKkAC4Qw.d.ts +8 -0
- package/dist/cli.js +3 -3
- package/dist/config.cjs +6 -8
- package/dist/config.d.ts +10 -8
- package/dist/config.js +6 -8
- package/dist/coverage.d.ts +10 -8
- package/dist/coverage.js +2 -2
- package/dist/environments.d.ts +3 -19
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +5 -14
- package/dist/execute.js +2 -2
- package/dist/index.d.ts +267 -34
- package/dist/index.js +12 -12
- package/dist/node.d.ts +15 -9
- package/dist/node.js +16 -19
- package/dist/reporters.d.ts +10 -8
- package/dist/reporters.js +12 -15
- package/dist/runners.d.ts +7 -19
- package/dist/runners.js +12 -13
- package/dist/snapshot.js +3 -3
- package/dist/suite.d.ts +2 -16
- package/dist/suite.js +4 -4
- package/dist/worker.js +7 -8
- package/dist/workers/forks.js +5 -5
- package/dist/workers/runVmTests.js +18 -19
- package/dist/workers/threads.js +5 -5
- package/dist/workers/vmForks.js +8 -8
- package/dist/workers/vmThreads.js +8 -8
- package/dist/workers.d.ts +13 -8
- package/dist/workers.js +13 -13
- package/package.json +13 -13
- package/dist/chunks/integrations-globals.nDMtdOcn.js +0 -31
- /package/dist/{vendor → chunks}/_commonjsHelpers.BFTU3MAI.js +0 -0
- /package/dist/{vendor → chunks}/date.W2xKR2qe.js +0 -0
- /package/dist/chunks/{node-git.ZtkbKc8u.js → git.ZtkbKc8u.js} +0 -0
- /package/dist/{vendor → chunks}/index.BMmMjLIQ.js +0 -0
- /package/dist/{vendor → chunks}/index.BpSiYbpB.js +0 -0
- /package/dist/chunks/{install-pkg.DNUmWFkO.js → index.DNUmWFkO.js} +0 -0
- /package/dist/{vendor → chunks}/spy.Cf_4R5Oe.js +0 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import fs$8, { existsSync, promises as promises$1, statSync as statSync$1, realpathSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join, resolve, isAbsolute, relative, dirname, normalize, basename, toNamespacedPath } from 'pathe';
|
|
3
|
-
import { g as getCoverageProvider, C as CoverageProviderMap } from './coverage.
|
|
4
|
-
import { g as getEnvPackageName } from './index.D4nqnQWz.js';
|
|
3
|
+
import { g as getCoverageProvider, C as CoverageProviderMap } from './coverage.CqfT4xaf.js';
|
|
5
4
|
import { searchForWorkspaceRoot, version, createServer, mergeConfig } from 'vite';
|
|
6
|
-
import { f as findUp, p as prompt } from './index.
|
|
7
|
-
import { A as API_PATH, e as extraInlineDeps, d as defaultPort, a as defaultBrowserPort, b as defaultInspectPort, w as workspacesFiles, C as CONFIG_NAMES, c as configFiles } from './constants.
|
|
5
|
+
import { f as findUp, p as prompt } from './index.CM5UI-4O.js';
|
|
6
|
+
import { A as API_PATH, e as extraInlineDeps, d as defaultPort, a as defaultBrowserPort, b as defaultInspectPort, w as workspacesFiles, C as CONFIG_NAMES, c as configFiles } from './constants.CaAN7icJ.js';
|
|
8
7
|
import { MessageChannel, isMainThread } from 'node:worker_threads';
|
|
9
8
|
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers.BFTU3MAI.js';
|
|
10
9
|
import require$$0 from 'os';
|
|
@@ -17,14 +16,14 @@ import require$$0$3 from 'fs';
|
|
|
17
16
|
import { ViteNodeRunner } from 'vite-node/client';
|
|
18
17
|
import { SnapshotManager } from '@vitest/snapshot/manager';
|
|
19
18
|
import { ViteNodeServer } from 'vite-node/server';
|
|
20
|
-
import { v as version$1 } from './cac.
|
|
19
|
+
import { v as version$1 } from './cac.DGgmCKmU.js';
|
|
21
20
|
import { hasFailed, createFileTask, getTasks, getTests, getNames } from '@vitest/runner/utils';
|
|
22
|
-
import { n as noop$1, b as isPrimitive, c as groupBy, A as AggregateErrorPonyfill, a as slash$1, t as toArray, d as deepMerge, e as nanoid, w as wildcardPatternToRegExp, f as stdout } from './base.
|
|
21
|
+
import { n as noop$1, b as isPrimitive, c as groupBy, A as AggregateErrorPonyfill, a as slash$1, t as toArray, d as deepMerge, e as nanoid, w as wildcardPatternToRegExp, f as stdout } from './base.DSsbfkDg.js';
|
|
23
22
|
import { createDefer, toArray as toArray$1, notNullish } from '@vitest/utils';
|
|
24
|
-
import { b as isWindows } from './env.
|
|
23
|
+
import { b as isWindows } from './env.BU041cs9.js';
|
|
25
24
|
import { rootDir, distDir } from '../path.js';
|
|
26
25
|
import { c as createBirpc } from './index.BpSiYbpB.js';
|
|
27
|
-
import { s as stringify, p as parse$3, w as wrapSerializableConfig,
|
|
26
|
+
import { s as stringify, p as parse$3, w as wrapSerializableConfig, j as Typechecker, R as ReportersMap, g as BenchmarkReportsMap, e as TestFile, f as TestSuite, d as TestCase, k as RandomSequencer, h as BaseSequencer, l as findNodeAround, m as generateCodeFrame, n as highlightCode, i as TestProject, L as Logger, o as BlobReporter, r as readBlobs } from './index.JbiJutJ_.js';
|
|
28
27
|
import require$$0$5 from 'zlib';
|
|
29
28
|
import require$$0$6 from 'buffer';
|
|
30
29
|
import require$$1 from 'crypto';
|
|
@@ -52,9 +51,9 @@ import { isCI, provider as provider$1 } from 'std-env';
|
|
|
52
51
|
import { normalizeRequestId, cleanUrl } from 'vite-node/utils';
|
|
53
52
|
import MagicString from 'magic-string';
|
|
54
53
|
import { esmWalker } from '@vitest/utils/ast';
|
|
55
|
-
import { a as removeUndefinedValues } from './index.
|
|
54
|
+
import { a as removeUndefinedValues } from './index.DYufA6CZ.js';
|
|
56
55
|
import readline from 'node:readline';
|
|
57
|
-
import { s as stripAnsi } from './utils.
|
|
56
|
+
import { s as stripAnsi } from './utils.DpP_sDwr.js';
|
|
58
57
|
|
|
59
58
|
async function getModuleGraph(ctx, projectName, id, browser = false) {
|
|
60
59
|
const graph = {};
|
|
@@ -62,10 +61,9 @@ async function getModuleGraph(ctx, projectName, id, browser = false) {
|
|
|
62
61
|
const inlined = /* @__PURE__ */ new Set();
|
|
63
62
|
const project = ctx.getProjectByName(projectName);
|
|
64
63
|
function clearId(id2) {
|
|
65
|
-
return
|
|
64
|
+
return id2?.replace(/\?v=\w+$/, "") || "";
|
|
66
65
|
}
|
|
67
66
|
async function get(mod, seen = /* @__PURE__ */ new Map()) {
|
|
68
|
-
var _a;
|
|
69
67
|
if (!mod || !mod.id) {
|
|
70
68
|
return;
|
|
71
69
|
}
|
|
@@ -77,7 +75,7 @@ async function getModuleGraph(ctx, projectName, id, browser = false) {
|
|
|
77
75
|
}
|
|
78
76
|
let id2 = clearId(mod.id);
|
|
79
77
|
seen.set(mod, id2);
|
|
80
|
-
const rewrote = browser ?
|
|
78
|
+
const rewrote = browser ? mod.file?.includes(project.browser.vite.config.cacheDir) ? mod.id : false : await project.vitenode.shouldExternalize(id2);
|
|
81
79
|
if (rewrote) {
|
|
82
80
|
id2 = rewrote;
|
|
83
81
|
externalized.add(id2);
|
|
@@ -8019,11 +8017,10 @@ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
|
|
|
8019
8017
|
var WebSocketServer$1 = /*@__PURE__*/getDefaultExportFromCjs(websocketServer);
|
|
8020
8018
|
|
|
8021
8019
|
function setup(ctx, _server) {
|
|
8022
|
-
var _a;
|
|
8023
8020
|
const wss = new WebSocketServer$1({ noServer: true });
|
|
8024
8021
|
const clients = /* @__PURE__ */ new Map();
|
|
8025
8022
|
const server = _server || ctx.server;
|
|
8026
|
-
|
|
8023
|
+
server.httpServer?.on("upgrade", (request, socket, head) => {
|
|
8027
8024
|
if (!request.url) {
|
|
8028
8025
|
return;
|
|
8029
8026
|
}
|
|
@@ -8039,10 +8036,6 @@ function setup(ctx, _server) {
|
|
|
8039
8036
|
function setupClient(ws) {
|
|
8040
8037
|
const rpc = createBirpc(
|
|
8041
8038
|
{
|
|
8042
|
-
async onCollected(files) {
|
|
8043
|
-
ctx.state.collectFiles(files);
|
|
8044
|
-
await ctx.report("onCollected", files);
|
|
8045
|
-
},
|
|
8046
8039
|
async onTaskUpdate(packs) {
|
|
8047
8040
|
ctx.state.updateTasks(packs);
|
|
8048
8041
|
await ctx.report("onTaskUpdate", packs);
|
|
@@ -8071,7 +8064,7 @@ function setup(ctx, _server) {
|
|
|
8071
8064
|
await ctx.rerunFiles(files);
|
|
8072
8065
|
},
|
|
8073
8066
|
getConfig() {
|
|
8074
|
-
return ctx.
|
|
8067
|
+
return ctx.getCoreWorkspaceProject().getSerializableConfig();
|
|
8075
8068
|
},
|
|
8076
8069
|
async getTransformResult(projectName, id, browser = false) {
|
|
8077
8070
|
const project = ctx.getProjectByName(projectName);
|
|
@@ -8142,8 +8135,7 @@ class WebSocketReporter {
|
|
|
8142
8135
|
return;
|
|
8143
8136
|
}
|
|
8144
8137
|
this.clients.forEach((client) => {
|
|
8145
|
-
|
|
8146
|
-
(_c = (_b = (_a = client.onCollected) == null ? void 0 : _a.call(client, files)) == null ? void 0 : _b.catch) == null ? void 0 : _c.call(_b, noop$1);
|
|
8138
|
+
client.onCollected?.(files)?.catch?.(noop$1);
|
|
8147
8139
|
});
|
|
8148
8140
|
}
|
|
8149
8141
|
onSpecsCollected(specs) {
|
|
@@ -8151,8 +8143,7 @@ class WebSocketReporter {
|
|
|
8151
8143
|
return;
|
|
8152
8144
|
}
|
|
8153
8145
|
this.clients.forEach((client) => {
|
|
8154
|
-
|
|
8155
|
-
(_c = (_b = (_a = client.onSpecsCollected) == null ? void 0 : _a.call(client, specs)) == null ? void 0 : _b.catch) == null ? void 0 : _c.call(_b, noop$1);
|
|
8146
|
+
client.onSpecsCollected?.(specs)?.catch?.(noop$1);
|
|
8156
8147
|
});
|
|
8157
8148
|
}
|
|
8158
8149
|
async onTaskUpdate(packs) {
|
|
@@ -8160,40 +8151,34 @@ class WebSocketReporter {
|
|
|
8160
8151
|
return;
|
|
8161
8152
|
}
|
|
8162
8153
|
packs.forEach(([taskId, result]) => {
|
|
8163
|
-
var _a;
|
|
8164
8154
|
const project = this.ctx.getProjectByTaskId(taskId);
|
|
8165
8155
|
const task = this.ctx.state.idMap.get(taskId);
|
|
8166
8156
|
const isBrowser = task && task.file.pool === "browser";
|
|
8167
|
-
|
|
8168
|
-
var _a2;
|
|
8157
|
+
result?.errors?.forEach((error) => {
|
|
8169
8158
|
if (isPrimitive(error)) {
|
|
8170
8159
|
return;
|
|
8171
8160
|
}
|
|
8172
|
-
const stacks = isBrowser ?
|
|
8161
|
+
const stacks = isBrowser ? project.browser?.parseErrorStacktrace(error) : parseErrorStacktrace(error);
|
|
8173
8162
|
error.stacks = stacks;
|
|
8174
8163
|
});
|
|
8175
8164
|
});
|
|
8176
8165
|
this.clients.forEach((client) => {
|
|
8177
|
-
|
|
8178
|
-
(_c = (_b = (_a = client.onTaskUpdate) == null ? void 0 : _a.call(client, packs)) == null ? void 0 : _b.catch) == null ? void 0 : _c.call(_b, noop$1);
|
|
8166
|
+
client.onTaskUpdate?.(packs)?.catch?.(noop$1);
|
|
8179
8167
|
});
|
|
8180
8168
|
}
|
|
8181
8169
|
onFinished(files, errors) {
|
|
8182
8170
|
this.clients.forEach((client) => {
|
|
8183
|
-
|
|
8184
|
-
(_c = (_b = (_a = client.onFinished) == null ? void 0 : _a.call(client, files, errors)) == null ? void 0 : _b.catch) == null ? void 0 : _c.call(_b, noop$1);
|
|
8171
|
+
client.onFinished?.(files, errors)?.catch?.(noop$1);
|
|
8185
8172
|
});
|
|
8186
8173
|
}
|
|
8187
8174
|
onFinishedReportCoverage() {
|
|
8188
8175
|
this.clients.forEach((client) => {
|
|
8189
|
-
|
|
8190
|
-
(_c = (_b = (_a = client.onFinishedReportCoverage) == null ? void 0 : _a.call(client)) == null ? void 0 : _b.catch) == null ? void 0 : _c.call(_b, noop$1);
|
|
8176
|
+
client.onFinishedReportCoverage?.()?.catch?.(noop$1);
|
|
8191
8177
|
});
|
|
8192
8178
|
}
|
|
8193
8179
|
onUserConsoleLog(log) {
|
|
8194
8180
|
this.clients.forEach((client) => {
|
|
8195
|
-
|
|
8196
|
-
(_c = (_b = (_a = client.onUserConsoleLog) == null ? void 0 : _a.call(client, log)) == null ? void 0 : _b.catch) == null ? void 0 : _c.call(_b, noop$1);
|
|
8181
|
+
client.onUserConsoleLog?.(log)?.catch?.(noop$1);
|
|
8197
8182
|
});
|
|
8198
8183
|
}
|
|
8199
8184
|
}
|
|
@@ -8217,9 +8202,8 @@ function getTransformMode(patterns, filename) {
|
|
|
8217
8202
|
async function groupFilesByEnv(files) {
|
|
8218
8203
|
const filesWithEnv = await Promise.all(
|
|
8219
8204
|
files.map(async ([project, file]) => {
|
|
8220
|
-
var _a, _b;
|
|
8221
8205
|
const code = await promises$1.readFile(file, "utf-8");
|
|
8222
|
-
let env =
|
|
8206
|
+
let env = code.match(/@(?:vitest|jest)-environment\s+([\w-]+)\b/)?.[1];
|
|
8223
8207
|
if (!env) {
|
|
8224
8208
|
for (const [glob, target] of project.config.environmentMatchGlobs || []) {
|
|
8225
8209
|
if (mm.isMatch(file, glob, { cwd: project.config.root })) {
|
|
@@ -8228,13 +8212,13 @@ async function groupFilesByEnv(files) {
|
|
|
8228
8212
|
}
|
|
8229
8213
|
}
|
|
8230
8214
|
}
|
|
8231
|
-
env
|
|
8215
|
+
env ||= project.config.environment || "node";
|
|
8232
8216
|
const transformMode = getTransformMode(
|
|
8233
8217
|
project.config.testTransformMode,
|
|
8234
8218
|
file
|
|
8235
8219
|
);
|
|
8236
|
-
let envOptionsJson =
|
|
8237
|
-
if (envOptionsJson
|
|
8220
|
+
let envOptionsJson = code.match(/@(?:vitest|jest)-environment-options\s+(.+)/)?.[1];
|
|
8221
|
+
if (envOptionsJson?.endsWith("*/")) {
|
|
8238
8222
|
envOptionsJson = envOptionsJson.slice(0, -2);
|
|
8239
8223
|
}
|
|
8240
8224
|
const envOptions = JSON.parse(envOptionsJson || "null");
|
|
@@ -8274,7 +8258,7 @@ function createMethodsRPC(project, options = {}) {
|
|
|
8274
8258
|
}
|
|
8275
8259
|
}
|
|
8276
8260
|
const r = await project.vitenode.transformRequest(id);
|
|
8277
|
-
return r
|
|
8261
|
+
return r?.map;
|
|
8278
8262
|
},
|
|
8279
8263
|
async fetch(id, transformMode) {
|
|
8280
8264
|
const result = await project.vitenode.fetchResult(id, transformMode);
|
|
@@ -8318,12 +8302,11 @@ function createMethodsRPC(project, options = {}) {
|
|
|
8318
8302
|
return ctx.report("onPathsCollected", paths);
|
|
8319
8303
|
},
|
|
8320
8304
|
onCollected(files) {
|
|
8321
|
-
ctx.state.collectFiles(files);
|
|
8305
|
+
ctx.state.collectFiles(project, files);
|
|
8322
8306
|
return ctx.report("onCollected", files);
|
|
8323
8307
|
},
|
|
8324
8308
|
onAfterSuiteRun(meta) {
|
|
8325
|
-
|
|
8326
|
-
(_a = ctx.coverageProvider) == null ? void 0 : _a.onAfterSuiteRun(meta);
|
|
8309
|
+
ctx.coverageProvider?.onAfterSuiteRun(meta);
|
|
8327
8310
|
},
|
|
8328
8311
|
onTaskUpdate(packs) {
|
|
8329
8312
|
ctx.state.updateTasks(packs);
|
|
@@ -8374,10 +8357,9 @@ function createChildProcessChannel$1(project) {
|
|
|
8374
8357
|
return { channel, cleanup };
|
|
8375
8358
|
}
|
|
8376
8359
|
function createForksPool(ctx, { execArgv, env }) {
|
|
8377
|
-
var _a;
|
|
8378
8360
|
const numCpus = typeof nodeos.availableParallelism === "function" ? nodeos.availableParallelism() : nodeos.cpus().length;
|
|
8379
8361
|
const threadsCount = ctx.config.watch ? Math.max(Math.floor(numCpus / 2), 1) : Math.max(numCpus - 1, 1);
|
|
8380
|
-
const poolOptions =
|
|
8362
|
+
const poolOptions = ctx.config.poolOptions?.forks ?? {};
|
|
8381
8363
|
const maxThreads = poolOptions.maxForks ?? ctx.config.maxWorkers ?? threadsCount;
|
|
8382
8364
|
const minThreads = poolOptions.minForks ?? ctx.config.minWorkers ?? threadsCount;
|
|
8383
8365
|
const worker = resolve(ctx.distPath, "workers/forks.js");
|
|
@@ -8425,7 +8407,7 @@ function createForksPool(ctx, { execArgv, env }) {
|
|
|
8425
8407
|
`Failed to terminate worker while running ${files.join(", ")}.`
|
|
8426
8408
|
);
|
|
8427
8409
|
} else if (ctx.isCancelling && error instanceof Error && /The task has been cancelled/.test(error.message)) {
|
|
8428
|
-
ctx.state.cancelFiles(files,
|
|
8410
|
+
ctx.state.cancelFiles(files, project);
|
|
8429
8411
|
} else {
|
|
8430
8412
|
throw error;
|
|
8431
8413
|
}
|
|
@@ -8452,16 +8434,10 @@ function createForksPool(ctx, { execArgv, env }) {
|
|
|
8452
8434
|
workspaceMap.set(file, workspaceFiles);
|
|
8453
8435
|
}
|
|
8454
8436
|
const singleFork = specs.filter(
|
|
8455
|
-
([project]) =>
|
|
8456
|
-
var _a2, _b;
|
|
8457
|
-
return (_b = (_a2 = project.config.poolOptions) == null ? void 0 : _a2.forks) == null ? void 0 : _b.singleFork;
|
|
8458
|
-
}
|
|
8437
|
+
([project]) => project.config.poolOptions?.forks?.singleFork
|
|
8459
8438
|
);
|
|
8460
8439
|
const multipleForks = specs.filter(
|
|
8461
|
-
([project]) =>
|
|
8462
|
-
var _a2, _b;
|
|
8463
|
-
return !((_b = (_a2 = project.config.poolOptions) == null ? void 0 : _a2.forks) == null ? void 0 : _b.singleFork);
|
|
8464
|
-
}
|
|
8440
|
+
([project]) => !project.config.poolOptions?.forks?.singleFork
|
|
8465
8441
|
);
|
|
8466
8442
|
if (multipleForks.length) {
|
|
8467
8443
|
const filesByEnv = await groupFilesByEnv(multipleForks);
|
|
@@ -8521,7 +8497,7 @@ function createForksPool(ctx, { execArgv, env }) {
|
|
|
8521
8497
|
);
|
|
8522
8498
|
for (const env2 of envs) {
|
|
8523
8499
|
const files = filesByEnv[env2];
|
|
8524
|
-
if (!
|
|
8500
|
+
if (!files?.length) {
|
|
8525
8501
|
continue;
|
|
8526
8502
|
}
|
|
8527
8503
|
const filesByOptions = groupBy(
|
|
@@ -8571,10 +8547,9 @@ function createWorkerChannel$1(project) {
|
|
|
8571
8547
|
return { workerPort, port };
|
|
8572
8548
|
}
|
|
8573
8549
|
function createThreadsPool(ctx, { execArgv, env }) {
|
|
8574
|
-
var _a;
|
|
8575
8550
|
const numCpus = typeof nodeos.availableParallelism === "function" ? nodeos.availableParallelism() : nodeos.cpus().length;
|
|
8576
8551
|
const threadsCount = ctx.config.watch ? Math.max(Math.floor(numCpus / 2), 1) : Math.max(numCpus - 1, 1);
|
|
8577
|
-
const poolOptions =
|
|
8552
|
+
const poolOptions = ctx.config.poolOptions?.threads ?? {};
|
|
8578
8553
|
const maxThreads = poolOptions.maxThreads ?? ctx.config.maxWorkers ?? threadsCount;
|
|
8579
8554
|
const minThreads = poolOptions.minThreads ?? ctx.config.minWorkers ?? threadsCount;
|
|
8580
8555
|
const worker = resolve(ctx.distPath, "workers/threads.js");
|
|
@@ -8628,7 +8603,7 @@ function createThreadsPool(ctx, { execArgv, env }) {
|
|
|
8628
8603
|
See https://vitest.dev/guide/common-errors.html#failed-to-terminate-worker for troubleshooting.`
|
|
8629
8604
|
);
|
|
8630
8605
|
} else if (ctx.isCancelling && error instanceof Error && /The task has been cancelled/.test(error.message)) {
|
|
8631
|
-
ctx.state.cancelFiles(files,
|
|
8606
|
+
ctx.state.cancelFiles(files, project);
|
|
8632
8607
|
} else {
|
|
8633
8608
|
throw error;
|
|
8634
8609
|
}
|
|
@@ -8655,16 +8630,10 @@ See https://vitest.dev/guide/common-errors.html#failed-to-terminate-worker for t
|
|
|
8655
8630
|
workspaceMap.set(file, workspaceFiles);
|
|
8656
8631
|
}
|
|
8657
8632
|
const singleThreads = specs.filter(
|
|
8658
|
-
([project]) =>
|
|
8659
|
-
var _a2, _b;
|
|
8660
|
-
return (_b = (_a2 = project.config.poolOptions) == null ? void 0 : _a2.threads) == null ? void 0 : _b.singleThread;
|
|
8661
|
-
}
|
|
8633
|
+
([project]) => project.config.poolOptions?.threads?.singleThread
|
|
8662
8634
|
);
|
|
8663
8635
|
const multipleThreads = specs.filter(
|
|
8664
|
-
([project]) =>
|
|
8665
|
-
var _a2, _b;
|
|
8666
|
-
return !((_b = (_a2 = project.config.poolOptions) == null ? void 0 : _a2.threads) == null ? void 0 : _b.singleThread);
|
|
8667
|
-
}
|
|
8636
|
+
([project]) => !project.config.poolOptions?.threads?.singleThread
|
|
8668
8637
|
);
|
|
8669
8638
|
if (multipleThreads.length) {
|
|
8670
8639
|
const filesByEnv = await groupFilesByEnv(multipleThreads);
|
|
@@ -8724,7 +8693,7 @@ See https://vitest.dev/guide/common-errors.html#failed-to-terminate-worker for t
|
|
|
8724
8693
|
);
|
|
8725
8694
|
for (const env2 of envs) {
|
|
8726
8695
|
const files = filesByEnv[env2];
|
|
8727
|
-
if (!
|
|
8696
|
+
if (!files?.length) {
|
|
8728
8697
|
continue;
|
|
8729
8698
|
}
|
|
8730
8699
|
const filesByOptions = groupBy(
|
|
@@ -8759,12 +8728,11 @@ function getDefaultThreadsCount(config) {
|
|
|
8759
8728
|
return config.watch ? Math.max(Math.floor(numCpus / 2), 1) : Math.max(numCpus - 1, 1);
|
|
8760
8729
|
}
|
|
8761
8730
|
function getWorkerMemoryLimit(config) {
|
|
8762
|
-
|
|
8763
|
-
const memoryLimit = (_b = (_a = config.poolOptions) == null ? void 0 : _a.vmThreads) == null ? void 0 : _b.memoryLimit;
|
|
8731
|
+
const memoryLimit = config.poolOptions?.vmThreads?.memoryLimit;
|
|
8764
8732
|
if (memoryLimit) {
|
|
8765
8733
|
return memoryLimit;
|
|
8766
8734
|
}
|
|
8767
|
-
return 1 / (
|
|
8735
|
+
return 1 / (config.poolOptions?.vmThreads?.maxThreads ?? getDefaultThreadsCount(config));
|
|
8768
8736
|
}
|
|
8769
8737
|
function stringToBytes(input, percentageReference) {
|
|
8770
8738
|
if (input === null || input === void 0) {
|
|
@@ -8840,10 +8808,9 @@ function createWorkerChannel(project) {
|
|
|
8840
8808
|
return { workerPort, port };
|
|
8841
8809
|
}
|
|
8842
8810
|
function createVmThreadsPool(ctx, { execArgv, env }) {
|
|
8843
|
-
var _a;
|
|
8844
8811
|
const numCpus = typeof nodeos.availableParallelism === "function" ? nodeos.availableParallelism() : nodeos.cpus().length;
|
|
8845
8812
|
const threadsCount = ctx.config.watch ? Math.max(Math.floor(numCpus / 2), 1) : Math.max(numCpus - 1, 1);
|
|
8846
|
-
const poolOptions =
|
|
8813
|
+
const poolOptions = ctx.config.poolOptions?.vmThreads ?? {};
|
|
8847
8814
|
const maxThreads = poolOptions.maxThreads ?? ctx.config.maxWorkers ?? threadsCount;
|
|
8848
8815
|
const minThreads = poolOptions.minThreads ?? ctx.config.minWorkers ?? threadsCount;
|
|
8849
8816
|
const worker = resolve(ctx.distPath, "workers/vmThreads.js");
|
|
@@ -8901,7 +8868,7 @@ function createVmThreadsPool(ctx, { execArgv, env }) {
|
|
|
8901
8868
|
See https://vitest.dev/guide/common-errors.html#failed-to-terminate-worker for troubleshooting.`
|
|
8902
8869
|
);
|
|
8903
8870
|
} else if (ctx.isCancelling && error instanceof Error && /The task has been cancelled/.test(error.message)) {
|
|
8904
|
-
ctx.state.cancelFiles(files,
|
|
8871
|
+
ctx.state.cancelFiles(files, project);
|
|
8905
8872
|
} else {
|
|
8906
8873
|
throw error;
|
|
8907
8874
|
}
|
|
@@ -8966,7 +8933,6 @@ function createTypecheckPool(ctx) {
|
|
|
8966
8933
|
const promisesMap = /* @__PURE__ */ new WeakMap();
|
|
8967
8934
|
const rerunTriggered = /* @__PURE__ */ new WeakMap();
|
|
8968
8935
|
async function onParseEnd(project, { files, sourceErrors }) {
|
|
8969
|
-
var _a;
|
|
8970
8936
|
const checker = project.typechecker;
|
|
8971
8937
|
await ctx.report("onTaskUpdate", checker.getTestPacks());
|
|
8972
8938
|
if (!project.config.typecheck.ignoreSourceErrors) {
|
|
@@ -8980,7 +8946,7 @@ function createTypecheckPool(ctx) {
|
|
|
8980
8946
|
error.stack = "";
|
|
8981
8947
|
ctx.state.catchError(error, "Typecheck Error");
|
|
8982
8948
|
}
|
|
8983
|
-
|
|
8949
|
+
promisesMap.get(project)?.resolve();
|
|
8984
8950
|
rerunTriggered.set(project, false);
|
|
8985
8951
|
if (ctx.config.watch && !ctx.runningPromise) {
|
|
8986
8952
|
await ctx.report("onFinished", files, []);
|
|
@@ -8998,7 +8964,7 @@ function createTypecheckPool(ctx) {
|
|
|
8998
8964
|
project.typechecker = checker;
|
|
8999
8965
|
checker.setFiles(files);
|
|
9000
8966
|
checker.onParseStart(async () => {
|
|
9001
|
-
ctx.state.collectFiles(checker.getTestFiles());
|
|
8967
|
+
ctx.state.collectFiles(project, checker.getTestFiles());
|
|
9002
8968
|
await ctx.report("onCollected");
|
|
9003
8969
|
});
|
|
9004
8970
|
checker.onParseEnd((result) => onParseEnd(project, result));
|
|
@@ -9013,7 +8979,7 @@ function createTypecheckPool(ctx) {
|
|
|
9013
8979
|
);
|
|
9014
8980
|
}
|
|
9015
8981
|
await checker.collectTests();
|
|
9016
|
-
ctx.state.collectFiles(checker.getTestFiles());
|
|
8982
|
+
ctx.state.collectFiles(project, checker.getTestFiles());
|
|
9017
8983
|
await ctx.report("onTaskUpdate", checker.getTestPacks());
|
|
9018
8984
|
await ctx.report("onCollected");
|
|
9019
8985
|
});
|
|
@@ -9036,7 +9002,7 @@ function createTypecheckPool(ctx) {
|
|
|
9036
9002
|
const checker = await createWorkspaceTypechecker(project, files);
|
|
9037
9003
|
checker.setFiles(files);
|
|
9038
9004
|
await checker.collectTests();
|
|
9039
|
-
ctx.state.collectFiles(checker.getTestFiles());
|
|
9005
|
+
ctx.state.collectFiles(project, checker.getTestFiles());
|
|
9040
9006
|
await ctx.report("onCollected");
|
|
9041
9007
|
}
|
|
9042
9008
|
}
|
|
@@ -9061,7 +9027,7 @@ function createTypecheckPool(ctx) {
|
|
|
9061
9027
|
});
|
|
9062
9028
|
const triggered = await _p;
|
|
9063
9029
|
if (project.typechecker && !triggered) {
|
|
9064
|
-
ctx.state.collectFiles(project.typechecker.getTestFiles());
|
|
9030
|
+
ctx.state.collectFiles(project, project.typechecker.getTestFiles());
|
|
9065
9031
|
await ctx.report("onCollected");
|
|
9066
9032
|
await onParseEnd(project, project.typechecker.getResult());
|
|
9067
9033
|
continue;
|
|
@@ -9078,10 +9044,7 @@ function createTypecheckPool(ctx) {
|
|
|
9078
9044
|
collectTests,
|
|
9079
9045
|
async close() {
|
|
9080
9046
|
const promises = ctx.projects.map(
|
|
9081
|
-
(project) =>
|
|
9082
|
-
var _a;
|
|
9083
|
-
return (_a = project.typechecker) == null ? void 0 : _a.stop();
|
|
9084
|
-
}
|
|
9047
|
+
(project) => project.typechecker?.stop()
|
|
9085
9048
|
);
|
|
9086
9049
|
await Promise.all(promises);
|
|
9087
9050
|
}
|
|
@@ -9118,10 +9081,9 @@ function createChildProcessChannel(project) {
|
|
|
9118
9081
|
return { channel, cleanup };
|
|
9119
9082
|
}
|
|
9120
9083
|
function createVmForksPool(ctx, { execArgv, env }) {
|
|
9121
|
-
var _a;
|
|
9122
9084
|
const numCpus = typeof nodeos.availableParallelism === "function" ? nodeos.availableParallelism() : nodeos.cpus().length;
|
|
9123
9085
|
const threadsCount = ctx.config.watch ? Math.max(Math.floor(numCpus / 2), 1) : Math.max(numCpus - 1, 1);
|
|
9124
|
-
const poolOptions =
|
|
9086
|
+
const poolOptions = ctx.config.poolOptions?.vmForks ?? {};
|
|
9125
9087
|
const maxThreads = poolOptions.maxForks ?? ctx.config.maxWorkers ?? threadsCount;
|
|
9126
9088
|
const minThreads = poolOptions.maxForks ?? ctx.config.minWorkers ?? threadsCount;
|
|
9127
9089
|
const worker = resolve(ctx.distPath, "workers/vmForks.js");
|
|
@@ -9173,7 +9135,7 @@ function createVmForksPool(ctx, { execArgv, env }) {
|
|
|
9173
9135
|
`Failed to terminate worker while running ${files.join(", ")}.`
|
|
9174
9136
|
);
|
|
9175
9137
|
} else if (ctx.isCancelling && error instanceof Error && /The task has been cancelled/.test(error.message)) {
|
|
9176
|
-
ctx.state.cancelFiles(files,
|
|
9138
|
+
ctx.state.cancelFiles(files, project);
|
|
9177
9139
|
} else {
|
|
9178
9140
|
throw error;
|
|
9179
9141
|
}
|
|
@@ -9323,12 +9285,12 @@ function createPool(ctx) {
|
|
|
9323
9285
|
);
|
|
9324
9286
|
}
|
|
9325
9287
|
const poolInstance = await pool.default(ctx, options);
|
|
9326
|
-
if (typeof
|
|
9288
|
+
if (typeof poolInstance?.name !== "string") {
|
|
9327
9289
|
throw new TypeError(
|
|
9328
9290
|
`Custom pool "${filepath}" should return an object with "name" property`
|
|
9329
9291
|
);
|
|
9330
9292
|
}
|
|
9331
|
-
if (typeof
|
|
9293
|
+
if (typeof poolInstance?.[method] !== "function") {
|
|
9332
9294
|
throw new TypeError(
|
|
9333
9295
|
`Custom pool "${filepath}" should return an object with "${method}" method`
|
|
9334
9296
|
);
|
|
@@ -9354,7 +9316,7 @@ function createPool(ctx) {
|
|
|
9354
9316
|
};
|
|
9355
9317
|
for (const spec of files) {
|
|
9356
9318
|
const pool = getFilePoolName(spec[0], spec[1]);
|
|
9357
|
-
filesByPool[pool]
|
|
9319
|
+
filesByPool[pool] ??= [];
|
|
9358
9320
|
filesByPool[pool].push(spec);
|
|
9359
9321
|
}
|
|
9360
9322
|
const Sequencer = ctx.config.sequence.sequencer;
|
|
@@ -9367,7 +9329,6 @@ function createPool(ctx) {
|
|
|
9367
9329
|
}
|
|
9368
9330
|
await Promise.all(
|
|
9369
9331
|
Object.entries(filesByPool).map(async (entry) => {
|
|
9370
|
-
var _a;
|
|
9371
9332
|
const [pool, files2] = entry;
|
|
9372
9333
|
if (!files2.length) {
|
|
9373
9334
|
return null;
|
|
@@ -9375,18 +9336,18 @@ function createPool(ctx) {
|
|
|
9375
9336
|
const specs = await sortSpecs(files2);
|
|
9376
9337
|
if (pool in factories) {
|
|
9377
9338
|
const factory = factories[pool];
|
|
9378
|
-
pools[pool]
|
|
9339
|
+
pools[pool] ??= factory();
|
|
9379
9340
|
return pools[pool][method](specs, invalidate);
|
|
9380
9341
|
}
|
|
9381
9342
|
if (pool === "browser") {
|
|
9382
|
-
pools[pool]
|
|
9343
|
+
pools[pool] ??= await (async () => {
|
|
9383
9344
|
const { createBrowserPool } = await import('@vitest/browser');
|
|
9384
9345
|
return createBrowserPool(ctx);
|
|
9385
|
-
})()
|
|
9346
|
+
})();
|
|
9386
9347
|
return pools[pool][method](specs, invalidate);
|
|
9387
9348
|
}
|
|
9388
9349
|
const poolHandler = await resolveCustomPool(pool);
|
|
9389
|
-
pools[
|
|
9350
|
+
pools[poolHandler.name] ??= poolHandler;
|
|
9390
9351
|
return poolHandler[method](specs, invalidate);
|
|
9391
9352
|
})
|
|
9392
9353
|
);
|
|
@@ -9396,10 +9357,7 @@ function createPool(ctx) {
|
|
|
9396
9357
|
runTests: (files, invalidates) => executeTests("runTests", files, invalidates),
|
|
9397
9358
|
collectTests: (files, invalidates) => executeTests("collectTests", files, invalidates),
|
|
9398
9359
|
async close() {
|
|
9399
|
-
await Promise.all(Object.values(pools).map((p) =>
|
|
9400
|
-
var _a;
|
|
9401
|
-
return (_a = p == null ? void 0 : p.close) == null ? void 0 : _a.call(p);
|
|
9402
|
-
}));
|
|
9360
|
+
await Promise.all(Object.values(pools).map((p) => p?.close?.()));
|
|
9403
9361
|
}
|
|
9404
9362
|
};
|
|
9405
9363
|
}
|
|
@@ -9483,6 +9441,7 @@ class StateManager {
|
|
|
9483
9441
|
taskFileMap = /* @__PURE__ */ new WeakMap();
|
|
9484
9442
|
errorsSet = /* @__PURE__ */ new Set();
|
|
9485
9443
|
processTimeoutCauses = /* @__PURE__ */ new Set();
|
|
9444
|
+
reportedTasksMap = /* @__PURE__ */ new WeakMap();
|
|
9486
9445
|
catchError(err, type) {
|
|
9487
9446
|
if (isAggregateError(err)) {
|
|
9488
9447
|
return err.errors.forEach((error) => this.catchError(error, type));
|
|
@@ -9497,7 +9456,7 @@ class StateManager {
|
|
|
9497
9456
|
const task = this.idMap.get(_err.taskId);
|
|
9498
9457
|
if (task) {
|
|
9499
9458
|
task.mode = "skip";
|
|
9500
|
-
task.result
|
|
9459
|
+
task.result ??= { state: "skip" };
|
|
9501
9460
|
task.result.state = "skip";
|
|
9502
9461
|
}
|
|
9503
9462
|
return;
|
|
@@ -9532,17 +9491,14 @@ class StateManager {
|
|
|
9532
9491
|
return Array.from(this.filesMap.keys());
|
|
9533
9492
|
}
|
|
9534
9493
|
getFailedFilepaths() {
|
|
9535
|
-
return this.getFiles().filter((i) =>
|
|
9536
|
-
var _a;
|
|
9537
|
-
return ((_a = i.result) == null ? void 0 : _a.state) === "fail";
|
|
9538
|
-
}).map((i) => i.filepath);
|
|
9494
|
+
return this.getFiles().filter((i) => i.result?.state === "fail").map((i) => i.filepath);
|
|
9539
9495
|
}
|
|
9540
9496
|
collectPaths(paths = []) {
|
|
9541
9497
|
paths.forEach((path) => {
|
|
9542
9498
|
this.pathsSet.add(path);
|
|
9543
9499
|
});
|
|
9544
9500
|
}
|
|
9545
|
-
collectFiles(files = []) {
|
|
9501
|
+
collectFiles(project, files = []) {
|
|
9546
9502
|
files.forEach((file) => {
|
|
9547
9503
|
const existing = this.filesMap.get(file.filepath) || [];
|
|
9548
9504
|
const otherProject = existing.filter(
|
|
@@ -9556,12 +9512,10 @@ class StateManager {
|
|
|
9556
9512
|
}
|
|
9557
9513
|
otherProject.push(file);
|
|
9558
9514
|
this.filesMap.set(file.filepath, otherProject);
|
|
9559
|
-
this.updateId(file);
|
|
9515
|
+
this.updateId(file, project);
|
|
9560
9516
|
});
|
|
9561
9517
|
}
|
|
9562
|
-
|
|
9563
|
-
clearFiles(_project, paths = []) {
|
|
9564
|
-
const project = _project;
|
|
9518
|
+
clearFiles(project, paths = []) {
|
|
9565
9519
|
paths.forEach((path) => {
|
|
9566
9520
|
const files = this.filesMap.get(path);
|
|
9567
9521
|
const fileTask = createFileTask(
|
|
@@ -9570,6 +9524,7 @@ class StateManager {
|
|
|
9570
9524
|
project.config.name
|
|
9571
9525
|
);
|
|
9572
9526
|
fileTask.local = true;
|
|
9527
|
+
TestFile.register(fileTask, project);
|
|
9573
9528
|
this.idMap.set(fileTask.id, fileTask);
|
|
9574
9529
|
if (!files) {
|
|
9575
9530
|
this.filesMap.set(path, [fileTask]);
|
|
@@ -9585,24 +9540,34 @@ class StateManager {
|
|
|
9585
9540
|
}
|
|
9586
9541
|
});
|
|
9587
9542
|
}
|
|
9588
|
-
updateId(task) {
|
|
9543
|
+
updateId(task, project) {
|
|
9589
9544
|
if (this.idMap.get(task.id) === task) {
|
|
9590
9545
|
return;
|
|
9591
9546
|
}
|
|
9547
|
+
if (task.type === "suite" && "filepath" in task) {
|
|
9548
|
+
TestFile.register(task, project);
|
|
9549
|
+
} else if (task.type === "suite") {
|
|
9550
|
+
TestSuite.register(task, project);
|
|
9551
|
+
} else {
|
|
9552
|
+
TestCase.register(task, project);
|
|
9553
|
+
}
|
|
9592
9554
|
this.idMap.set(task.id, task);
|
|
9593
9555
|
if (task.type === "suite") {
|
|
9594
9556
|
task.tasks.forEach((task2) => {
|
|
9595
|
-
this.updateId(task2);
|
|
9557
|
+
this.updateId(task2, project);
|
|
9596
9558
|
});
|
|
9597
9559
|
}
|
|
9598
9560
|
}
|
|
9561
|
+
getReportedEntity(task) {
|
|
9562
|
+
return this.reportedTasksMap.get(task);
|
|
9563
|
+
}
|
|
9599
9564
|
updateTasks(packs) {
|
|
9600
9565
|
for (const [id, result, meta] of packs) {
|
|
9601
9566
|
const task = this.idMap.get(id);
|
|
9602
9567
|
if (task) {
|
|
9603
9568
|
task.result = result;
|
|
9604
9569
|
task.meta = meta;
|
|
9605
|
-
if (
|
|
9570
|
+
if (result?.state === "skip") {
|
|
9606
9571
|
task.mode = "skip";
|
|
9607
9572
|
}
|
|
9608
9573
|
}
|
|
@@ -9619,15 +9584,15 @@ class StateManager {
|
|
|
9619
9584
|
}
|
|
9620
9585
|
getCountOfFailedTests() {
|
|
9621
9586
|
return Array.from(this.idMap.values()).filter(
|
|
9622
|
-
(t) =>
|
|
9623
|
-
var _a;
|
|
9624
|
-
return ((_a = t.result) == null ? void 0 : _a.state) === "fail";
|
|
9625
|
-
}
|
|
9587
|
+
(t) => t.result?.state === "fail"
|
|
9626
9588
|
).length;
|
|
9627
9589
|
}
|
|
9628
|
-
cancelFiles(files,
|
|
9590
|
+
cancelFiles(files, project) {
|
|
9629
9591
|
this.collectFiles(
|
|
9630
|
-
|
|
9592
|
+
project,
|
|
9593
|
+
files.map(
|
|
9594
|
+
(filepath) => createFileTask(filepath, project.config.root, project.config.name)
|
|
9595
|
+
)
|
|
9631
9596
|
);
|
|
9632
9597
|
}
|
|
9633
9598
|
}
|
|
@@ -11739,7 +11704,6 @@ function resolvePackage(name, options = {}) {
|
|
|
11739
11704
|
}
|
|
11740
11705
|
}
|
|
11741
11706
|
|
|
11742
|
-
var _a, _b;
|
|
11743
11707
|
const defaultInclude = ["**/*.{test,spec}.?(c|m)[jt]s?(x)"];
|
|
11744
11708
|
const defaultExclude = [
|
|
11745
11709
|
"**/node_modules/**",
|
|
@@ -11804,7 +11768,7 @@ const coverageConfigDefaults = {
|
|
|
11804
11768
|
ignoreEmptyLines: true,
|
|
11805
11769
|
processingConcurrency: Math.min(
|
|
11806
11770
|
20,
|
|
11807
|
-
|
|
11771
|
+
nodeos__default.availableParallelism?.() ?? nodeos__default.cpus().length
|
|
11808
11772
|
)
|
|
11809
11773
|
};
|
|
11810
11774
|
const fakeTimersDefaults = {
|
|
@@ -11830,6 +11794,8 @@ const config = {
|
|
|
11830
11794
|
clearMocks: false,
|
|
11831
11795
|
restoreMocks: false,
|
|
11832
11796
|
mockReset: false,
|
|
11797
|
+
unstubGlobals: false,
|
|
11798
|
+
unstubEnvs: false,
|
|
11833
11799
|
include: defaultInclude,
|
|
11834
11800
|
exclude: defaultExclude,
|
|
11835
11801
|
teardownTimeout: 1e4,
|
|
@@ -11860,8 +11826,7 @@ const config = {
|
|
|
11860
11826
|
const configDefaults = Object.freeze(config);
|
|
11861
11827
|
|
|
11862
11828
|
function getWorkersCountByPercentage(percent) {
|
|
11863
|
-
|
|
11864
|
-
const maxWorkersCount = ((_b = (_a = nodeos__default).availableParallelism) == null ? void 0 : _b.call(_a)) ?? nodeos__default.cpus().length;
|
|
11829
|
+
const maxWorkersCount = nodeos__default.availableParallelism?.() ?? nodeos__default.cpus().length;
|
|
11865
11830
|
const workersCountByPercentage = Math.round(Number.parseInt(percent) / 100 * maxWorkersCount);
|
|
11866
11831
|
return Math.max(1, Math.min(maxWorkersCount, workersCountByPercentage));
|
|
11867
11832
|
}
|
|
@@ -12059,9 +12024,8 @@ function resolveInlineWorkerOption(value) {
|
|
|
12059
12024
|
}
|
|
12060
12025
|
}
|
|
12061
12026
|
function resolveConfig(mode, options, viteConfig, logger) {
|
|
12062
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U;
|
|
12063
12027
|
if (options.dom) {
|
|
12064
|
-
if (
|
|
12028
|
+
if (viteConfig.test?.environment != null && viteConfig.test.environment !== "happy-dom") {
|
|
12065
12029
|
logger.console.warn(
|
|
12066
12030
|
c.yellow(
|
|
12067
12031
|
`${c.inverse(c.yellow(" Vitest "))} Your config.test.environment ("${viteConfig.test.environment}") conflicts with --dom flag ("happy-dom"), ignoring "${viteConfig.test.environment}"`
|
|
@@ -12081,7 +12045,7 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12081
12045
|
...resolved.inspector,
|
|
12082
12046
|
...parseInspector(inspector),
|
|
12083
12047
|
enabled: !!inspector,
|
|
12084
|
-
waitForDebugger:
|
|
12048
|
+
waitForDebugger: options.inspector?.waitForDebugger ?? !!resolved.inspectBrk
|
|
12085
12049
|
};
|
|
12086
12050
|
if (viteConfig.base !== "/") {
|
|
12087
12051
|
resolved.base = viteConfig.base;
|
|
@@ -12116,15 +12080,15 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12116
12080
|
if (resolved.minWorkers) {
|
|
12117
12081
|
resolved.minWorkers = resolveInlineWorkerOption(resolved.minWorkers);
|
|
12118
12082
|
}
|
|
12119
|
-
resolved.browser
|
|
12120
|
-
resolved.fileParallelism
|
|
12083
|
+
resolved.browser ??= {};
|
|
12084
|
+
resolved.fileParallelism ??= mode !== "benchmark";
|
|
12121
12085
|
if (!resolved.fileParallelism) {
|
|
12122
12086
|
resolved.maxWorkers = 1;
|
|
12123
12087
|
resolved.minWorkers = 1;
|
|
12124
12088
|
}
|
|
12125
12089
|
if (resolved.inspect || resolved.inspectBrk) {
|
|
12126
|
-
const isSingleThread = resolved.pool === "threads" &&
|
|
12127
|
-
const isSingleFork = resolved.pool === "forks" &&
|
|
12090
|
+
const isSingleThread = resolved.pool === "threads" && resolved.poolOptions?.threads?.singleThread;
|
|
12091
|
+
const isSingleFork = resolved.pool === "forks" && resolved.poolOptions?.forks?.singleFork;
|
|
12128
12092
|
if (resolved.fileParallelism && !isSingleThread && !isSingleFork) {
|
|
12129
12093
|
const inspectOption = `--inspect${resolved.inspectBrk ? "-brk" : ""}`;
|
|
12130
12094
|
throw new Error(
|
|
@@ -12154,9 +12118,9 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12154
12118
|
resolved.root
|
|
12155
12119
|
);
|
|
12156
12120
|
}
|
|
12157
|
-
resolved.expect
|
|
12158
|
-
resolved.deps
|
|
12159
|
-
|
|
12121
|
+
resolved.expect ??= {};
|
|
12122
|
+
resolved.deps ??= {};
|
|
12123
|
+
resolved.deps.moduleDirectories ??= [];
|
|
12160
12124
|
resolved.deps.moduleDirectories = resolved.deps.moduleDirectories.map(
|
|
12161
12125
|
(dir) => {
|
|
12162
12126
|
if (!dir.startsWith("/")) {
|
|
@@ -12171,17 +12135,17 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12171
12135
|
if (!resolved.deps.moduleDirectories.includes("/node_modules/")) {
|
|
12172
12136
|
resolved.deps.moduleDirectories.push("/node_modules/");
|
|
12173
12137
|
}
|
|
12174
|
-
|
|
12175
|
-
|
|
12176
|
-
|
|
12177
|
-
|
|
12178
|
-
|
|
12179
|
-
|
|
12180
|
-
|
|
12181
|
-
|
|
12182
|
-
|
|
12183
|
-
resolved.server
|
|
12184
|
-
|
|
12138
|
+
resolved.deps.optimizer ??= {};
|
|
12139
|
+
resolved.deps.optimizer.ssr ??= {};
|
|
12140
|
+
resolved.deps.optimizer.ssr.enabled ??= true;
|
|
12141
|
+
resolved.deps.optimizer.web ??= {};
|
|
12142
|
+
resolved.deps.optimizer.web.enabled ??= true;
|
|
12143
|
+
resolved.deps.web ??= {};
|
|
12144
|
+
resolved.deps.web.transformAssets ??= true;
|
|
12145
|
+
resolved.deps.web.transformCss ??= true;
|
|
12146
|
+
resolved.deps.web.transformGlobPattern ??= [];
|
|
12147
|
+
resolved.server ??= {};
|
|
12148
|
+
resolved.server.deps ??= {};
|
|
12185
12149
|
const deprecatedDepsOptions = ["inline", "external", "fallbackCJS"];
|
|
12186
12150
|
deprecatedDepsOptions.forEach((option) => {
|
|
12187
12151
|
if (resolved.deps[option] === void 0) {
|
|
@@ -12214,14 +12178,14 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12214
12178
|
}
|
|
12215
12179
|
if (resolved.server.deps.inline !== true) {
|
|
12216
12180
|
const ssrOptions = viteConfig.ssr;
|
|
12217
|
-
if (
|
|
12181
|
+
if (ssrOptions?.noExternal === true && resolved.server.deps.inline == null) {
|
|
12218
12182
|
resolved.server.deps.inline = true;
|
|
12219
12183
|
} else {
|
|
12220
|
-
|
|
12184
|
+
resolved.server.deps.inline ??= [];
|
|
12221
12185
|
resolved.server.deps.inline.push(...extraInlineDeps);
|
|
12222
12186
|
}
|
|
12223
12187
|
}
|
|
12224
|
-
|
|
12188
|
+
resolved.server.deps.moduleDirectories ??= [];
|
|
12225
12189
|
resolved.server.deps.moduleDirectories.push(
|
|
12226
12190
|
...resolved.deps.moduleDirectories
|
|
12227
12191
|
);
|
|
@@ -12247,7 +12211,7 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12247
12211
|
// resolved inside the worker
|
|
12248
12212
|
snapshotEnvironment: null
|
|
12249
12213
|
};
|
|
12250
|
-
resolved.snapshotSerializers
|
|
12214
|
+
resolved.snapshotSerializers ??= [];
|
|
12251
12215
|
resolved.snapshotSerializers = resolved.snapshotSerializers.map(
|
|
12252
12216
|
(file) => resolvePath(file, resolved.root)
|
|
12253
12217
|
);
|
|
@@ -12255,16 +12219,16 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12255
12219
|
if (options.resolveSnapshotPath) {
|
|
12256
12220
|
delete resolved.resolveSnapshotPath;
|
|
12257
12221
|
}
|
|
12258
|
-
resolved.pool
|
|
12222
|
+
resolved.pool ??= "threads";
|
|
12259
12223
|
if (process.env.VITEST_MAX_THREADS) {
|
|
12260
12224
|
resolved.poolOptions = {
|
|
12261
12225
|
...resolved.poolOptions,
|
|
12262
12226
|
threads: {
|
|
12263
|
-
...
|
|
12227
|
+
...resolved.poolOptions?.threads,
|
|
12264
12228
|
maxThreads: Number.parseInt(process.env.VITEST_MAX_THREADS)
|
|
12265
12229
|
},
|
|
12266
12230
|
vmThreads: {
|
|
12267
|
-
...
|
|
12231
|
+
...resolved.poolOptions?.vmThreads,
|
|
12268
12232
|
maxThreads: Number.parseInt(process.env.VITEST_MAX_THREADS)
|
|
12269
12233
|
}
|
|
12270
12234
|
};
|
|
@@ -12273,11 +12237,11 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12273
12237
|
resolved.poolOptions = {
|
|
12274
12238
|
...resolved.poolOptions,
|
|
12275
12239
|
threads: {
|
|
12276
|
-
...
|
|
12240
|
+
...resolved.poolOptions?.threads,
|
|
12277
12241
|
minThreads: Number.parseInt(process.env.VITEST_MIN_THREADS)
|
|
12278
12242
|
},
|
|
12279
12243
|
vmThreads: {
|
|
12280
|
-
...
|
|
12244
|
+
...resolved.poolOptions?.vmThreads,
|
|
12281
12245
|
minThreads: Number.parseInt(process.env.VITEST_MIN_THREADS)
|
|
12282
12246
|
}
|
|
12283
12247
|
};
|
|
@@ -12286,11 +12250,11 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12286
12250
|
resolved.poolOptions = {
|
|
12287
12251
|
...resolved.poolOptions,
|
|
12288
12252
|
forks: {
|
|
12289
|
-
...
|
|
12253
|
+
...resolved.poolOptions?.forks,
|
|
12290
12254
|
maxForks: Number.parseInt(process.env.VITEST_MAX_FORKS)
|
|
12291
12255
|
},
|
|
12292
12256
|
vmForks: {
|
|
12293
|
-
...
|
|
12257
|
+
...resolved.poolOptions?.vmForks,
|
|
12294
12258
|
maxForks: Number.parseInt(process.env.VITEST_MAX_FORKS)
|
|
12295
12259
|
}
|
|
12296
12260
|
};
|
|
@@ -12299,11 +12263,11 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12299
12263
|
resolved.poolOptions = {
|
|
12300
12264
|
...resolved.poolOptions,
|
|
12301
12265
|
forks: {
|
|
12302
|
-
...
|
|
12266
|
+
...resolved.poolOptions?.forks,
|
|
12303
12267
|
minForks: Number.parseInt(process.env.VITEST_MIN_FORKS)
|
|
12304
12268
|
},
|
|
12305
12269
|
vmForks: {
|
|
12306
|
-
...
|
|
12270
|
+
...resolved.poolOptions?.vmForks,
|
|
12307
12271
|
minForks: Number.parseInt(process.env.VITEST_MIN_FORKS)
|
|
12308
12272
|
}
|
|
12309
12273
|
};
|
|
@@ -12315,7 +12279,7 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12315
12279
|
["vmThreads", "maxThreads"]
|
|
12316
12280
|
];
|
|
12317
12281
|
for (const [poolOptionKey, workerOptionKey] of poolThreadsOptions) {
|
|
12318
|
-
if (
|
|
12282
|
+
if (resolved.poolOptions?.[poolOptionKey]?.[workerOptionKey]) {
|
|
12319
12283
|
resolved.poolOptions[poolOptionKey][workerOptionKey] = resolveInlineWorkerOption(resolved.poolOptions[poolOptionKey][workerOptionKey]);
|
|
12320
12284
|
}
|
|
12321
12285
|
}
|
|
@@ -12326,7 +12290,7 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12326
12290
|
["vmForks", "maxForks"]
|
|
12327
12291
|
];
|
|
12328
12292
|
for (const [poolOptionKey, workerOptionKey] of poolForksOptions) {
|
|
12329
|
-
if (
|
|
12293
|
+
if (resolved.poolOptions?.[poolOptionKey]?.[workerOptionKey]) {
|
|
12330
12294
|
resolved.poolOptions[poolOptionKey][workerOptionKey] = resolveInlineWorkerOption(resolved.poolOptions[poolOptionKey][workerOptionKey]);
|
|
12331
12295
|
}
|
|
12332
12296
|
}
|
|
@@ -12444,12 +12408,12 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12444
12408
|
}
|
|
12445
12409
|
}
|
|
12446
12410
|
if (resolved.changed) {
|
|
12447
|
-
resolved.passWithNoTests
|
|
12411
|
+
resolved.passWithNoTests ??= true;
|
|
12448
12412
|
}
|
|
12449
|
-
resolved.css
|
|
12413
|
+
resolved.css ??= {};
|
|
12450
12414
|
if (typeof resolved.css === "object") {
|
|
12451
|
-
|
|
12452
|
-
|
|
12415
|
+
resolved.css.modules ??= {};
|
|
12416
|
+
resolved.css.modules.classNameStrategy ??= "stable";
|
|
12453
12417
|
}
|
|
12454
12418
|
if (resolved.cache !== false) {
|
|
12455
12419
|
let cacheDir = VitestCache.resolveCacheDir(
|
|
@@ -12473,18 +12437,18 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12473
12437
|
}
|
|
12474
12438
|
resolved.cache = { dir: cacheDir };
|
|
12475
12439
|
}
|
|
12476
|
-
resolved.sequence
|
|
12440
|
+
resolved.sequence ??= {};
|
|
12477
12441
|
if (resolved.sequence.shuffle && typeof resolved.sequence.shuffle === "object") {
|
|
12478
12442
|
const { files, tests } = resolved.sequence.shuffle;
|
|
12479
|
-
|
|
12443
|
+
resolved.sequence.sequencer ??= files ? RandomSequencer : BaseSequencer;
|
|
12480
12444
|
resolved.sequence.shuffle = tests;
|
|
12481
12445
|
}
|
|
12482
|
-
if (!
|
|
12446
|
+
if (!resolved.sequence?.sequencer) {
|
|
12483
12447
|
resolved.sequence.sequencer = resolved.sequence.shuffle ? RandomSequencer : BaseSequencer;
|
|
12484
12448
|
}
|
|
12485
|
-
|
|
12449
|
+
resolved.sequence.hooks ??= "stack";
|
|
12486
12450
|
if (resolved.sequence.sequencer === RandomSequencer) {
|
|
12487
|
-
|
|
12451
|
+
resolved.sequence.seed ??= Date.now();
|
|
12488
12452
|
}
|
|
12489
12453
|
resolved.typecheck = {
|
|
12490
12454
|
...configDefaults.typecheck,
|
|
@@ -12493,8 +12457,8 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12493
12457
|
resolved.environmentMatchGlobs = (resolved.environmentMatchGlobs || []).map(
|
|
12494
12458
|
(i) => [resolve(resolved.root, i[0]), i[1]]
|
|
12495
12459
|
);
|
|
12496
|
-
resolved.typecheck
|
|
12497
|
-
|
|
12460
|
+
resolved.typecheck ??= {};
|
|
12461
|
+
resolved.typecheck.enabled ??= false;
|
|
12498
12462
|
if (resolved.typecheck.enabled) {
|
|
12499
12463
|
logger.console.warn(
|
|
12500
12464
|
c.yellow(
|
|
@@ -12502,12 +12466,12 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12502
12466
|
)
|
|
12503
12467
|
);
|
|
12504
12468
|
}
|
|
12505
|
-
resolved.browser
|
|
12506
|
-
|
|
12507
|
-
|
|
12508
|
-
|
|
12509
|
-
|
|
12510
|
-
|
|
12469
|
+
resolved.browser ??= {};
|
|
12470
|
+
resolved.browser.enabled ??= false;
|
|
12471
|
+
resolved.browser.headless ??= isCI;
|
|
12472
|
+
resolved.browser.isolate ??= true;
|
|
12473
|
+
resolved.browser.fileParallelism ??= options.fileParallelism ?? mode !== "benchmark";
|
|
12474
|
+
resolved.browser.ui ??= resolved.browser.headless === true ? false : !isCI;
|
|
12511
12475
|
if (resolved.browser.screenshotDirectory) {
|
|
12512
12476
|
resolved.browser.screenshotDirectory = resolve(
|
|
12513
12477
|
resolved.root,
|
|
@@ -12525,11 +12489,11 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12525
12489
|
));
|
|
12526
12490
|
resolved.browser.screenshotFailures = false;
|
|
12527
12491
|
} else {
|
|
12528
|
-
|
|
12492
|
+
resolved.browser.screenshotFailures ??= !isPreview && !resolved.browser.ui;
|
|
12529
12493
|
}
|
|
12530
|
-
|
|
12531
|
-
|
|
12532
|
-
|
|
12494
|
+
resolved.browser.viewport ??= {};
|
|
12495
|
+
resolved.browser.viewport.width ??= 414;
|
|
12496
|
+
resolved.browser.viewport.height ??= 896;
|
|
12533
12497
|
if (resolved.browser.enabled && provider$1 === "stackblitz") {
|
|
12534
12498
|
resolved.browser.provider = "preview";
|
|
12535
12499
|
}
|
|
@@ -12541,10 +12505,10 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12541
12505
|
};
|
|
12542
12506
|
if (resolved.browser.enabled) {
|
|
12543
12507
|
if (resolved.browser.ui) {
|
|
12544
|
-
resolved.includeTaskLocation
|
|
12508
|
+
resolved.includeTaskLocation ??= true;
|
|
12545
12509
|
}
|
|
12546
12510
|
} else if (resolved.ui) {
|
|
12547
|
-
resolved.includeTaskLocation
|
|
12511
|
+
resolved.includeTaskLocation ??= true;
|
|
12548
12512
|
}
|
|
12549
12513
|
const htmlReporter = toArray(resolved.reporters).some((reporter) => {
|
|
12550
12514
|
if (Array.isArray(reporter)) {
|
|
@@ -12553,16 +12517,15 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
12553
12517
|
return false;
|
|
12554
12518
|
});
|
|
12555
12519
|
if (htmlReporter) {
|
|
12556
|
-
resolved.includeTaskLocation
|
|
12520
|
+
resolved.includeTaskLocation ??= true;
|
|
12557
12521
|
}
|
|
12558
|
-
resolved.testTransformMode
|
|
12559
|
-
resolved.testTimeout
|
|
12560
|
-
resolved.hookTimeout
|
|
12522
|
+
resolved.testTransformMode ??= {};
|
|
12523
|
+
resolved.testTimeout ??= resolved.browser.enabled ? 15e3 : 5e3;
|
|
12524
|
+
resolved.hookTimeout ??= resolved.browser.enabled ? 3e4 : 1e4;
|
|
12561
12525
|
return resolved;
|
|
12562
12526
|
}
|
|
12563
12527
|
function isBrowserEnabled(config) {
|
|
12564
|
-
|
|
12565
|
-
return Boolean((_a = config.browser) == null ? void 0 : _a.enabled);
|
|
12528
|
+
return Boolean(config.browser?.enabled);
|
|
12566
12529
|
}
|
|
12567
12530
|
|
|
12568
12531
|
function generateCssFilenameHash(filepath) {
|
|
@@ -12583,9 +12546,7 @@ function CoverageTransform(ctx) {
|
|
|
12583
12546
|
return {
|
|
12584
12547
|
name: "vitest:coverage-transform",
|
|
12585
12548
|
transform(srcCode, id) {
|
|
12586
|
-
|
|
12587
|
-
return (_b = (_a = ctx.coverageProvider) == null ? void 0 : _a.onFileTransform) == null ? void 0 : _b.call(
|
|
12588
|
-
_a,
|
|
12549
|
+
return ctx.coverageProvider?.onFileTransform?.(
|
|
12589
12550
|
srcCode,
|
|
12590
12551
|
normalizeRequestId(id),
|
|
12591
12552
|
this
|
|
@@ -12645,12 +12606,11 @@ function CSSEnablerPlugin(ctx) {
|
|
|
12645
12606
|
name: "vitest:css-empty-post",
|
|
12646
12607
|
enforce: "post",
|
|
12647
12608
|
transform(_, id) {
|
|
12648
|
-
var _a;
|
|
12649
12609
|
if (!isCSS(id) || shouldProcessCSS(id)) {
|
|
12650
12610
|
return;
|
|
12651
12611
|
}
|
|
12652
12612
|
if (isCSSModule(id) && !isInline(id)) {
|
|
12653
|
-
const scopeStrategy = typeof ctx.config.css !== "boolean" &&
|
|
12613
|
+
const scopeStrategy = typeof ctx.config.css !== "boolean" && ctx.config.css.modules?.classNameStrategy || "stable";
|
|
12654
12614
|
const proxyReturn = getCSSModuleProxyReturn(
|
|
12655
12615
|
scopeStrategy,
|
|
12656
12616
|
relative(ctx.config.root, id)
|
|
@@ -13155,7 +13115,7 @@ function SsrReplacerPlugin() {
|
|
|
13155
13115
|
const cleanCode = stripLiteral(code);
|
|
13156
13116
|
const envs = cleanCode.matchAll(/\bimport\.meta\.env\b/g);
|
|
13157
13117
|
for (const env of envs) {
|
|
13158
|
-
s
|
|
13118
|
+
s ||= new MagicString(code);
|
|
13159
13119
|
const startIndex = env.index;
|
|
13160
13120
|
const endIndex = startIndex + env[0].length;
|
|
13161
13121
|
s.overwrite(startIndex, endIndex, "__vite_ssr_import_meta__.env");
|
|
@@ -13218,7 +13178,6 @@ function getBetterEnd(code, node) {
|
|
|
13218
13178
|
const regexpHoistable = /\b(?:vi|vitest)\s*\.\s*(?:mock|unmock|hoisted|doMock|doUnmock)\(/;
|
|
13219
13179
|
const hashbangRE = /^#!.*\n/;
|
|
13220
13180
|
function hoistMocks(code, id, parse, colors) {
|
|
13221
|
-
var _a;
|
|
13222
13181
|
const needHoisting = regexpHoistable.test(code);
|
|
13223
13182
|
if (!needHoisting) {
|
|
13224
13183
|
return;
|
|
@@ -13232,7 +13191,7 @@ function hoistMocks(code, id, parse, colors) {
|
|
|
13232
13191
|
${err.message}`);
|
|
13233
13192
|
return;
|
|
13234
13193
|
}
|
|
13235
|
-
const hoistIndex =
|
|
13194
|
+
const hoistIndex = code.match(hashbangRE)?.[0].length ?? 0;
|
|
13236
13195
|
let hoistedVitestImports = "";
|
|
13237
13196
|
let uid = 0;
|
|
13238
13197
|
const idToImportMap = /* @__PURE__ */ new Map();
|
|
@@ -13303,35 +13262,32 @@ ${err.message}`);
|
|
|
13303
13262
|
};
|
|
13304
13263
|
}
|
|
13305
13264
|
function assertNotDefaultExport(node, error) {
|
|
13306
|
-
|
|
13307
|
-
const defaultExport = (_a2 = findNodeAround(
|
|
13265
|
+
const defaultExport = findNodeAround(
|
|
13308
13266
|
ast,
|
|
13309
13267
|
node.start,
|
|
13310
13268
|
"ExportDefaultDeclaration"
|
|
13311
|
-
)
|
|
13312
|
-
if (
|
|
13269
|
+
)?.node;
|
|
13270
|
+
if (defaultExport?.declaration === node || defaultExport?.declaration.type === "AwaitExpression" && defaultExport.declaration.argument === node) {
|
|
13313
13271
|
throw createSyntaxError(defaultExport, error);
|
|
13314
13272
|
}
|
|
13315
13273
|
}
|
|
13316
13274
|
function assertNotNamedExport(node, error) {
|
|
13317
|
-
|
|
13318
|
-
const nodeExported = (_a2 = findNodeAround(
|
|
13275
|
+
const nodeExported = findNodeAround(
|
|
13319
13276
|
ast,
|
|
13320
13277
|
node.start,
|
|
13321
13278
|
"ExportNamedDeclaration"
|
|
13322
|
-
)
|
|
13323
|
-
if (
|
|
13279
|
+
)?.node;
|
|
13280
|
+
if (nodeExported?.declaration === node) {
|
|
13324
13281
|
throw createSyntaxError(nodeExported, error);
|
|
13325
13282
|
}
|
|
13326
13283
|
}
|
|
13327
13284
|
function getVariableDeclaration(node) {
|
|
13328
|
-
|
|
13329
|
-
const declarationNode = (_a2 = findNodeAround(
|
|
13285
|
+
const declarationNode = findNodeAround(
|
|
13330
13286
|
ast,
|
|
13331
13287
|
node.start,
|
|
13332
13288
|
"VariableDeclaration"
|
|
13333
|
-
)
|
|
13334
|
-
const init =
|
|
13289
|
+
)?.node;
|
|
13290
|
+
const init = declarationNode?.declarations[0]?.init;
|
|
13335
13291
|
if (init && (init === node || init.type === "AwaitExpression" && init.argument === node)) {
|
|
13336
13292
|
return declarationNode;
|
|
13337
13293
|
}
|
|
@@ -13359,7 +13315,6 @@ ${err.message}`);
|
|
|
13359
13315
|
}
|
|
13360
13316
|
},
|
|
13361
13317
|
onCallExpression(node) {
|
|
13362
|
-
var _a2;
|
|
13363
13318
|
if (node.callee.type === "MemberExpression" && isIdentifier(node.callee.object) && (node.callee.object.name === "vi" || node.callee.object.name === "vitest") && isIdentifier(node.callee.property)) {
|
|
13364
13319
|
const methodName = node.callee.property.name;
|
|
13365
13320
|
if (methodName === "mock" || methodName === "unmock") {
|
|
@@ -13407,13 +13362,13 @@ ${err.message}`);
|
|
|
13407
13362
|
);
|
|
13408
13363
|
hoistedNodes.push(declarationNode);
|
|
13409
13364
|
} else {
|
|
13410
|
-
const awaitedExpression =
|
|
13365
|
+
const awaitedExpression = findNodeAround(
|
|
13411
13366
|
ast,
|
|
13412
13367
|
node.start,
|
|
13413
13368
|
"AwaitExpression"
|
|
13414
|
-
)
|
|
13369
|
+
)?.node;
|
|
13415
13370
|
hoistedNodes.push(
|
|
13416
|
-
|
|
13371
|
+
awaitedExpression?.argument === node ? awaitedExpression : node
|
|
13417
13372
|
);
|
|
13418
13373
|
}
|
|
13419
13374
|
}
|
|
@@ -13654,19 +13609,18 @@ function MocksPlugins() {
|
|
|
13654
13609
|
}
|
|
13655
13610
|
|
|
13656
13611
|
function resolveOptimizerConfig(_testOptions, viteOptions, testConfig) {
|
|
13657
|
-
var _a;
|
|
13658
13612
|
const testOptions = _testOptions || {};
|
|
13659
13613
|
const newConfig = {};
|
|
13660
13614
|
const [major, minor, fix] = version.split(".").map(Number);
|
|
13661
13615
|
const allowed = major >= 5 || major === 4 && minor >= 4 || major === 4 && minor === 3 && fix >= 2;
|
|
13662
|
-
if (!allowed &&
|
|
13616
|
+
if (!allowed && testOptions?.enabled === true) {
|
|
13663
13617
|
console.warn(
|
|
13664
13618
|
`Vitest: "deps.optimizer" is only available in Vite >= 4.3.2, current Vite version: ${version}`
|
|
13665
13619
|
);
|
|
13666
13620
|
} else {
|
|
13667
|
-
testOptions.enabled
|
|
13621
|
+
testOptions.enabled ??= false;
|
|
13668
13622
|
}
|
|
13669
|
-
if (!allowed ||
|
|
13623
|
+
if (!allowed || testOptions?.enabled !== true) {
|
|
13670
13624
|
newConfig.cacheDir = void 0;
|
|
13671
13625
|
newConfig.optimizeDeps = {
|
|
13672
13626
|
// experimental in Vite >2.9.2, entries remains to help with older versions
|
|
@@ -13675,20 +13629,20 @@ function resolveOptimizerConfig(_testOptions, viteOptions, testConfig) {
|
|
|
13675
13629
|
};
|
|
13676
13630
|
} else {
|
|
13677
13631
|
const root = testConfig.root ?? process.cwd();
|
|
13678
|
-
const cacheDir = testConfig.cache !== false ?
|
|
13679
|
-
const currentInclude = testOptions.include ||
|
|
13632
|
+
const cacheDir = testConfig.cache !== false ? testConfig.cache?.dir : void 0;
|
|
13633
|
+
const currentInclude = testOptions.include || viteOptions?.include || [];
|
|
13680
13634
|
const exclude = [
|
|
13681
13635
|
"vitest",
|
|
13682
13636
|
// Ideally, we shouldn't optimize react in test mode, otherwise we need to optimize _every_ dependency that uses react.
|
|
13683
13637
|
"react",
|
|
13684
13638
|
"vue",
|
|
13685
|
-
...testOptions.exclude ||
|
|
13639
|
+
...testOptions.exclude || viteOptions?.exclude || []
|
|
13686
13640
|
];
|
|
13687
13641
|
const runtime = currentInclude.filter(
|
|
13688
13642
|
(n) => n.endsWith("jsx-dev-runtime") || n.endsWith("jsx-runtime")
|
|
13689
13643
|
);
|
|
13690
13644
|
exclude.push(...runtime);
|
|
13691
|
-
const include = (testOptions.include ||
|
|
13645
|
+
const include = (testOptions.include || viteOptions?.include || []).filter(
|
|
13692
13646
|
(n) => !exclude.includes(n)
|
|
13693
13647
|
);
|
|
13694
13648
|
newConfig.cacheDir = cacheDir ?? VitestCache.resolveCacheDir(root, cacheDir, testConfig.name);
|
|
@@ -13784,21 +13738,20 @@ function VitestOptimizer() {
|
|
|
13784
13738
|
config: {
|
|
13785
13739
|
order: "post",
|
|
13786
13740
|
handler(viteConfig) {
|
|
13787
|
-
var _a, _b, _c, _d, _e;
|
|
13788
13741
|
const testConfig = viteConfig.test || {};
|
|
13789
13742
|
const webOptimizer = resolveOptimizerConfig(
|
|
13790
|
-
|
|
13743
|
+
testConfig.deps?.optimizer?.web,
|
|
13791
13744
|
viteConfig.optimizeDeps,
|
|
13792
13745
|
testConfig
|
|
13793
13746
|
);
|
|
13794
13747
|
const ssrOptimizer = resolveOptimizerConfig(
|
|
13795
|
-
|
|
13796
|
-
|
|
13748
|
+
testConfig.deps?.optimizer?.ssr,
|
|
13749
|
+
viteConfig.ssr?.optimizeDeps,
|
|
13797
13750
|
testConfig
|
|
13798
13751
|
);
|
|
13799
13752
|
viteConfig.cacheDir = webOptimizer.cacheDir || ssrOptimizer.cacheDir || viteConfig.cacheDir;
|
|
13800
13753
|
viteConfig.optimizeDeps = webOptimizer.optimizeDeps;
|
|
13801
|
-
viteConfig.ssr
|
|
13754
|
+
viteConfig.ssr ??= {};
|
|
13802
13755
|
viteConfig.ssr.optimizeDeps = ssrOptimizer.optimizeDeps;
|
|
13803
13756
|
}
|
|
13804
13757
|
}
|
|
@@ -13812,7 +13765,7 @@ function NormalizeURLPlugin() {
|
|
|
13812
13765
|
name: "vitest:normalize-url",
|
|
13813
13766
|
enforce: "post",
|
|
13814
13767
|
transform(code, id, options) {
|
|
13815
|
-
const ssr =
|
|
13768
|
+
const ssr = options?.ssr === true;
|
|
13816
13769
|
if (ssr || !code.includes("new URL") || !code.includes("import.meta.url")) {
|
|
13817
13770
|
return;
|
|
13818
13771
|
}
|
|
@@ -13842,7 +13795,6 @@ function WorkspaceVitestPlugin(project, options) {
|
|
|
13842
13795
|
this.meta.watchMode = false;
|
|
13843
13796
|
},
|
|
13844
13797
|
config(viteConfig) {
|
|
13845
|
-
var _a, _b, _c, _d;
|
|
13846
13798
|
const defines = deleteDefineConfig(viteConfig);
|
|
13847
13799
|
const testConfig = viteConfig.test || {};
|
|
13848
13800
|
const root = testConfig.root || viteConfig.root || options.root;
|
|
@@ -13872,7 +13824,7 @@ function WorkspaceVitestPlugin(project, options) {
|
|
|
13872
13824
|
},
|
|
13873
13825
|
esbuild: viteConfig.esbuild === false ? false : {
|
|
13874
13826
|
// Lowest target Vitest supports is Node18
|
|
13875
|
-
target:
|
|
13827
|
+
target: viteConfig.esbuild?.target || "node18",
|
|
13876
13828
|
sourcemap: "external",
|
|
13877
13829
|
// Enables using ignore hint for coverage providers with @preserve keyword
|
|
13878
13830
|
legalComments: "inline"
|
|
@@ -13897,10 +13849,10 @@ function WorkspaceVitestPlugin(project, options) {
|
|
|
13897
13849
|
}
|
|
13898
13850
|
};
|
|
13899
13851
|
config.test.defines = defines;
|
|
13900
|
-
const classNameStrategy = typeof testConfig.css !== "boolean" &&
|
|
13852
|
+
const classNameStrategy = typeof testConfig.css !== "boolean" && testConfig.css?.modules?.classNameStrategy || "stable";
|
|
13901
13853
|
if (classNameStrategy !== "scoped") {
|
|
13902
|
-
config.css
|
|
13903
|
-
|
|
13854
|
+
config.css ??= {};
|
|
13855
|
+
config.css.modules ??= {};
|
|
13904
13856
|
if (config.css.modules) {
|
|
13905
13857
|
config.css.modules.generateScopedName = (name2, filename) => {
|
|
13906
13858
|
const root2 = project.config.root;
|
|
@@ -13982,8 +13934,127 @@ async function loadGlobalSetupFile(file, runner) {
|
|
|
13982
13934
|
}
|
|
13983
13935
|
}
|
|
13984
13936
|
|
|
13937
|
+
function serializeConfig(config, coreConfig, viteConfig) {
|
|
13938
|
+
const optimizer = config.deps?.optimizer;
|
|
13939
|
+
const poolOptions = config.poolOptions;
|
|
13940
|
+
const isolate = viteConfig?.test?.isolate;
|
|
13941
|
+
return {
|
|
13942
|
+
// TODO: remove functions from environmentOptions
|
|
13943
|
+
environmentOptions: config.environmentOptions,
|
|
13944
|
+
mode: config.mode,
|
|
13945
|
+
isolate: config.isolate,
|
|
13946
|
+
base: config.base,
|
|
13947
|
+
logHeapUsage: config.logHeapUsage,
|
|
13948
|
+
runner: config.runner,
|
|
13949
|
+
bail: config.bail,
|
|
13950
|
+
defines: config.defines,
|
|
13951
|
+
chaiConfig: config.chaiConfig,
|
|
13952
|
+
setupFiles: config.setupFiles,
|
|
13953
|
+
allowOnly: config.allowOnly,
|
|
13954
|
+
testTimeout: config.testTimeout,
|
|
13955
|
+
testNamePattern: config.testNamePattern,
|
|
13956
|
+
hookTimeout: config.hookTimeout,
|
|
13957
|
+
clearMocks: config.clearMocks,
|
|
13958
|
+
mockReset: config.mockReset,
|
|
13959
|
+
restoreMocks: config.restoreMocks,
|
|
13960
|
+
unstubEnvs: config.unstubEnvs,
|
|
13961
|
+
unstubGlobals: config.unstubGlobals,
|
|
13962
|
+
maxConcurrency: config.maxConcurrency,
|
|
13963
|
+
pool: config.pool,
|
|
13964
|
+
expect: config.expect,
|
|
13965
|
+
snapshotSerializers: config.snapshotSerializers,
|
|
13966
|
+
diff: config.diff,
|
|
13967
|
+
retry: config.retry,
|
|
13968
|
+
disableConsoleIntercept: config.disableConsoleIntercept,
|
|
13969
|
+
root: config.root,
|
|
13970
|
+
name: config.name,
|
|
13971
|
+
globals: config.globals,
|
|
13972
|
+
snapshotEnvironment: config.snapshotEnvironment,
|
|
13973
|
+
passWithNoTests: config.passWithNoTests,
|
|
13974
|
+
coverage: ((coverage) => {
|
|
13975
|
+
const htmlReporter = coverage.reporter.find(([reporterName]) => reporterName === "html");
|
|
13976
|
+
const subdir = htmlReporter && htmlReporter[1]?.subdir;
|
|
13977
|
+
return {
|
|
13978
|
+
reportsDirectory: coverage.reportsDirectory,
|
|
13979
|
+
provider: coverage.provider,
|
|
13980
|
+
enabled: coverage.enabled,
|
|
13981
|
+
htmlReporter: htmlReporter ? { subdir } : void 0,
|
|
13982
|
+
customProviderModule: "customProviderModule" in coverage ? coverage.customProviderModule : void 0
|
|
13983
|
+
};
|
|
13984
|
+
})(config.coverage),
|
|
13985
|
+
fakeTimers: config.fakeTimers,
|
|
13986
|
+
poolOptions: {
|
|
13987
|
+
forks: {
|
|
13988
|
+
singleFork: poolOptions?.forks?.singleFork ?? coreConfig.poolOptions?.forks?.singleFork ?? false,
|
|
13989
|
+
isolate: poolOptions?.forks?.isolate ?? isolate ?? coreConfig.poolOptions?.forks?.isolate ?? true
|
|
13990
|
+
},
|
|
13991
|
+
threads: {
|
|
13992
|
+
singleThread: poolOptions?.threads?.singleThread ?? coreConfig.poolOptions?.threads?.singleThread ?? false,
|
|
13993
|
+
isolate: poolOptions?.threads?.isolate ?? isolate ?? coreConfig.poolOptions?.threads?.isolate ?? true
|
|
13994
|
+
},
|
|
13995
|
+
vmThreads: {
|
|
13996
|
+
singleThread: poolOptions?.vmThreads?.singleThread ?? coreConfig.poolOptions?.vmThreads?.singleThread ?? false
|
|
13997
|
+
},
|
|
13998
|
+
vmForks: {
|
|
13999
|
+
singleFork: poolOptions?.vmForks?.singleFork ?? coreConfig.poolOptions?.vmForks?.singleFork ?? false
|
|
14000
|
+
}
|
|
14001
|
+
},
|
|
14002
|
+
deps: {
|
|
14003
|
+
web: config.deps.web || {},
|
|
14004
|
+
optimizer: {
|
|
14005
|
+
web: {
|
|
14006
|
+
enabled: optimizer?.web?.enabled ?? true
|
|
14007
|
+
},
|
|
14008
|
+
ssr: {
|
|
14009
|
+
enabled: optimizer?.ssr?.enabled ?? true
|
|
14010
|
+
}
|
|
14011
|
+
},
|
|
14012
|
+
interopDefault: config.deps.interopDefault,
|
|
14013
|
+
moduleDirectories: config.deps.moduleDirectories
|
|
14014
|
+
},
|
|
14015
|
+
snapshotOptions: {
|
|
14016
|
+
// TODO: store it differently, not on the config
|
|
14017
|
+
snapshotEnvironment: void 0,
|
|
14018
|
+
updateSnapshot: coreConfig.snapshotOptions.updateSnapshot,
|
|
14019
|
+
snapshotFormat: {
|
|
14020
|
+
...coreConfig.snapshotOptions.snapshotFormat,
|
|
14021
|
+
compareKeys: void 0
|
|
14022
|
+
},
|
|
14023
|
+
expand: config.snapshotOptions.expand ?? coreConfig.snapshotOptions.expand
|
|
14024
|
+
},
|
|
14025
|
+
sequence: {
|
|
14026
|
+
shuffle: coreConfig.sequence.shuffle,
|
|
14027
|
+
concurrent: coreConfig.sequence.concurrent,
|
|
14028
|
+
seed: coreConfig.sequence.seed,
|
|
14029
|
+
hooks: coreConfig.sequence.hooks,
|
|
14030
|
+
setupFiles: coreConfig.sequence.setupFiles
|
|
14031
|
+
},
|
|
14032
|
+
inspect: coreConfig.inspect,
|
|
14033
|
+
inspectBrk: coreConfig.inspectBrk,
|
|
14034
|
+
inspector: coreConfig.inspector,
|
|
14035
|
+
watch: config.watch,
|
|
14036
|
+
includeTaskLocation: config.includeTaskLocation ?? coreConfig.includeTaskLocation,
|
|
14037
|
+
env: {
|
|
14038
|
+
...viteConfig?.env,
|
|
14039
|
+
...config.env
|
|
14040
|
+
},
|
|
14041
|
+
browser: ((browser) => {
|
|
14042
|
+
return {
|
|
14043
|
+
name: browser.name,
|
|
14044
|
+
headless: browser.headless,
|
|
14045
|
+
isolate: browser.isolate,
|
|
14046
|
+
fileParallelism: browser.fileParallelism,
|
|
14047
|
+
ui: browser.ui,
|
|
14048
|
+
viewport: browser.viewport,
|
|
14049
|
+
screenshotFailures: browser.screenshotFailures
|
|
14050
|
+
};
|
|
14051
|
+
})(config.browser),
|
|
14052
|
+
standalone: config.standalone,
|
|
14053
|
+
printConsoleTrace: config.printConsoleTrace ?? coreConfig.printConsoleTrace
|
|
14054
|
+
};
|
|
14055
|
+
}
|
|
14056
|
+
|
|
13985
14057
|
async function initializeProject(workspacePath, ctx, options) {
|
|
13986
|
-
var _a;
|
|
13987
14058
|
const project = new WorkspaceProject(workspacePath, ctx, options);
|
|
13988
14059
|
const configFile = options.extends ? resolve(dirname(options.workspaceConfigPath), options.extends) : typeof workspacePath === "number" || workspacePath.endsWith("/") ? false : workspacePath;
|
|
13989
14060
|
const root = options.root || (typeof workspacePath === "number" ? void 0 : workspacePath.endsWith("/") ? workspacePath : dirname(workspacePath));
|
|
@@ -13993,7 +14064,7 @@ async function initializeProject(workspacePath, ctx, options) {
|
|
|
13993
14064
|
logLevel: "error",
|
|
13994
14065
|
configFile,
|
|
13995
14066
|
// this will make "mode": "test" | "benchmark" inside defineConfig
|
|
13996
|
-
mode:
|
|
14067
|
+
mode: options.test?.mode || options.mode || ctx.config.mode,
|
|
13997
14068
|
plugins: [
|
|
13998
14069
|
...options.plugins || [],
|
|
13999
14070
|
WorkspaceVitestPlugin(project, { ...options, root, workspacePath })
|
|
@@ -14017,6 +14088,7 @@ class WorkspaceProject {
|
|
|
14017
14088
|
typechecker;
|
|
14018
14089
|
closingPromise;
|
|
14019
14090
|
testFilesList = null;
|
|
14091
|
+
testProject;
|
|
14020
14092
|
id = nanoid();
|
|
14021
14093
|
tmpDir = join(tmpdir(), this.id);
|
|
14022
14094
|
_globalSetups;
|
|
@@ -14050,7 +14122,6 @@ class WorkspaceProject {
|
|
|
14050
14122
|
};
|
|
14051
14123
|
}
|
|
14052
14124
|
async initializeGlobalSetup() {
|
|
14053
|
-
var _a;
|
|
14054
14125
|
if (this._globalSetups) {
|
|
14055
14126
|
return;
|
|
14056
14127
|
}
|
|
@@ -14059,10 +14130,10 @@ class WorkspaceProject {
|
|
|
14059
14130
|
this.config.globalSetup
|
|
14060
14131
|
);
|
|
14061
14132
|
for (const globalSetupFile of this._globalSetups) {
|
|
14062
|
-
const teardown = await
|
|
14133
|
+
const teardown = await globalSetupFile.setup?.({
|
|
14063
14134
|
provide: (key, value) => this.provide(key, value),
|
|
14064
14135
|
config: this.config
|
|
14065
|
-
})
|
|
14136
|
+
});
|
|
14066
14137
|
if (teardown == null || !!globalSetupFile.teardown) {
|
|
14067
14138
|
continue;
|
|
14068
14139
|
}
|
|
@@ -14075,12 +14146,11 @@ class WorkspaceProject {
|
|
|
14075
14146
|
}
|
|
14076
14147
|
}
|
|
14077
14148
|
async teardownGlobalSetup() {
|
|
14078
|
-
var _a;
|
|
14079
14149
|
if (!this._globalSetups) {
|
|
14080
14150
|
return;
|
|
14081
14151
|
}
|
|
14082
14152
|
for (const globalSetupFile of [...this._globalSetups].reverse()) {
|
|
14083
|
-
await
|
|
14153
|
+
await globalSetupFile.teardown?.();
|
|
14084
14154
|
}
|
|
14085
14155
|
}
|
|
14086
14156
|
get logger() {
|
|
@@ -14088,22 +14158,15 @@ class WorkspaceProject {
|
|
|
14088
14158
|
}
|
|
14089
14159
|
// it's possible that file path was imported with different queries (?raw, ?url, etc)
|
|
14090
14160
|
getModulesByFilepath(file) {
|
|
14091
|
-
|
|
14092
|
-
const set = this.server.moduleGraph.getModulesByFile(file) || ((_a = this.browser) == null ? void 0 : _a.vite.moduleGraph.getModulesByFile(file));
|
|
14161
|
+
const set = this.server.moduleGraph.getModulesByFile(file) || this.browser?.vite.moduleGraph.getModulesByFile(file);
|
|
14093
14162
|
return set || /* @__PURE__ */ new Set();
|
|
14094
14163
|
}
|
|
14095
14164
|
getModuleById(id) {
|
|
14096
|
-
|
|
14097
|
-
return this.server.moduleGraph.getModuleById(id) || ((_a = this.browser) == null ? void 0 : _a.vite.moduleGraph.getModuleById(id));
|
|
14165
|
+
return this.server.moduleGraph.getModuleById(id) || this.browser?.vite.moduleGraph.getModuleById(id);
|
|
14098
14166
|
}
|
|
14099
14167
|
getSourceMapModuleById(id) {
|
|
14100
|
-
var _a, _b;
|
|
14101
14168
|
const mod = this.server.moduleGraph.getModuleById(id);
|
|
14102
|
-
return
|
|
14103
|
-
}
|
|
14104
|
-
getBrowserSourceMapModuleById(id) {
|
|
14105
|
-
var _a, _b, _c;
|
|
14106
|
-
return (_c = (_b = (_a = this.browser) == null ? void 0 : _a.vite.moduleGraph.getModuleById(id)) == null ? void 0 : _b.transformResult) == null ? void 0 : _c.map;
|
|
14169
|
+
return mod?.ssrTransformResult?.map || mod?.transformResult?.map;
|
|
14107
14170
|
}
|
|
14108
14171
|
get reporters() {
|
|
14109
14172
|
return this.ctx.reporters;
|
|
@@ -14127,7 +14190,7 @@ class WorkspaceProject {
|
|
|
14127
14190
|
return this.testFilesList;
|
|
14128
14191
|
}
|
|
14129
14192
|
const testFiles = await this.globFiles(include, exclude, cwd);
|
|
14130
|
-
if (includeSource
|
|
14193
|
+
if (includeSource?.length) {
|
|
14131
14194
|
const files = await this.globFiles(includeSource, exclude, cwd);
|
|
14132
14195
|
await Promise.all(
|
|
14133
14196
|
files.map(async (file) => {
|
|
@@ -14158,7 +14221,6 @@ class WorkspaceProject {
|
|
|
14158
14221
|
return files.map((file) => resolve(cwd, file));
|
|
14159
14222
|
}
|
|
14160
14223
|
async isTargetFile(id, source) {
|
|
14161
|
-
var _a;
|
|
14162
14224
|
const relativeId = relative(this.config.dir || this.config.root, id);
|
|
14163
14225
|
if (mm.isMatch(relativeId, this.config.exclude)) {
|
|
14164
14226
|
return false;
|
|
@@ -14166,7 +14228,7 @@ class WorkspaceProject {
|
|
|
14166
14228
|
if (mm.isMatch(relativeId, this.config.include)) {
|
|
14167
14229
|
return true;
|
|
14168
14230
|
}
|
|
14169
|
-
if (
|
|
14231
|
+
if (this.config.includeSource?.length && mm.isMatch(relativeId, this.config.includeSource)) {
|
|
14170
14232
|
source = source || await promises$1.readFile(id, "utf-8");
|
|
14171
14233
|
return this.isInSourceTestFile(source);
|
|
14172
14234
|
}
|
|
@@ -14194,13 +14256,12 @@ class WorkspaceProject {
|
|
|
14194
14256
|
return testFiles;
|
|
14195
14257
|
}
|
|
14196
14258
|
async initBrowserServer(configFile) {
|
|
14197
|
-
var _a;
|
|
14198
14259
|
if (!this.isBrowserEnabled()) {
|
|
14199
14260
|
return;
|
|
14200
14261
|
}
|
|
14201
14262
|
await this.ctx.packageInstaller.ensureInstalled("@vitest/browser", this.config.root);
|
|
14202
14263
|
const { createBrowserServer } = await import('@vitest/browser');
|
|
14203
|
-
await
|
|
14264
|
+
await this.browser?.close();
|
|
14204
14265
|
const browser = await createBrowserServer(
|
|
14205
14266
|
this,
|
|
14206
14267
|
configFile,
|
|
@@ -14221,6 +14282,7 @@ class WorkspaceProject {
|
|
|
14221
14282
|
project.server = ctx.server;
|
|
14222
14283
|
project.runner = ctx.runner;
|
|
14223
14284
|
project.config = ctx.config;
|
|
14285
|
+
project.testProject = new TestProject(project);
|
|
14224
14286
|
return project;
|
|
14225
14287
|
}
|
|
14226
14288
|
static async createCoreProject(ctx) {
|
|
@@ -14238,6 +14300,7 @@ class WorkspaceProject {
|
|
|
14238
14300
|
server.config,
|
|
14239
14301
|
this.ctx.logger
|
|
14240
14302
|
);
|
|
14303
|
+
this.testProject = new TestProject(this);
|
|
14241
14304
|
this.server = server;
|
|
14242
14305
|
this.vitenode = new ViteNodeServer(server, this.config.server);
|
|
14243
14306
|
const node = this.vitenode;
|
|
@@ -14256,91 +14319,27 @@ class WorkspaceProject {
|
|
|
14256
14319
|
isBrowserEnabled() {
|
|
14257
14320
|
return isBrowserEnabled(this.config);
|
|
14258
14321
|
}
|
|
14259
|
-
getSerializableConfig(
|
|
14260
|
-
|
|
14261
|
-
|
|
14262
|
-
|
|
14263
|
-
|
|
14264
|
-
const config = deepMerge(
|
|
14265
|
-
{
|
|
14266
|
-
...this.config,
|
|
14267
|
-
poolOptions: {
|
|
14268
|
-
forks: {
|
|
14269
|
-
singleFork: ((_e = poolOptions == null ? void 0 : poolOptions.forks) == null ? void 0 : _e.singleFork) ?? ((_g = (_f = this.ctx.config.poolOptions) == null ? void 0 : _f.forks) == null ? void 0 : _g.singleFork) ?? false,
|
|
14270
|
-
isolate: ((_h = poolOptions == null ? void 0 : poolOptions.forks) == null ? void 0 : _h.isolate) ?? isolate ?? ((_j = (_i = this.ctx.config.poolOptions) == null ? void 0 : _i.forks) == null ? void 0 : _j.isolate) ?? true
|
|
14271
|
-
},
|
|
14272
|
-
threads: {
|
|
14273
|
-
singleThread: ((_k = poolOptions == null ? void 0 : poolOptions.threads) == null ? void 0 : _k.singleThread) ?? ((_m = (_l = this.ctx.config.poolOptions) == null ? void 0 : _l.threads) == null ? void 0 : _m.singleThread) ?? false,
|
|
14274
|
-
isolate: ((_n = poolOptions == null ? void 0 : poolOptions.threads) == null ? void 0 : _n.isolate) ?? isolate ?? ((_p = (_o = this.ctx.config.poolOptions) == null ? void 0 : _o.threads) == null ? void 0 : _p.isolate) ?? true
|
|
14275
|
-
},
|
|
14276
|
-
vmThreads: {
|
|
14277
|
-
singleThread: ((_q = poolOptions == null ? void 0 : poolOptions.vmThreads) == null ? void 0 : _q.singleThread) ?? ((_s = (_r = this.ctx.config.poolOptions) == null ? void 0 : _r.vmThreads) == null ? void 0 : _s.singleThread) ?? false
|
|
14278
|
-
}
|
|
14279
|
-
},
|
|
14280
|
-
reporters: [],
|
|
14281
|
-
deps: {
|
|
14282
|
-
...this.config.deps,
|
|
14283
|
-
optimizer: {
|
|
14284
|
-
web: {
|
|
14285
|
-
enabled: ((_t = optimizer == null ? void 0 : optimizer.web) == null ? void 0 : _t.enabled) ?? true
|
|
14286
|
-
},
|
|
14287
|
-
ssr: {
|
|
14288
|
-
enabled: ((_u = optimizer == null ? void 0 : optimizer.ssr) == null ? void 0 : _u.enabled) ?? true
|
|
14289
|
-
}
|
|
14290
|
-
}
|
|
14291
|
-
},
|
|
14292
|
-
snapshotOptions: {
|
|
14293
|
-
...this.ctx.config.snapshotOptions,
|
|
14294
|
-
expand: this.config.snapshotOptions.expand ?? this.ctx.config.snapshotOptions.expand,
|
|
14295
|
-
resolveSnapshotPath: void 0
|
|
14296
|
-
},
|
|
14297
|
-
onConsoleLog: void 0,
|
|
14298
|
-
onStackTrace: void 0,
|
|
14299
|
-
sequence: {
|
|
14300
|
-
...this.ctx.config.sequence,
|
|
14301
|
-
sequencer: void 0
|
|
14302
|
-
},
|
|
14303
|
-
benchmark: {
|
|
14304
|
-
...this.config.benchmark,
|
|
14305
|
-
reporters: []
|
|
14306
|
-
},
|
|
14307
|
-
inspect: this.ctx.config.inspect,
|
|
14308
|
-
inspectBrk: this.ctx.config.inspectBrk,
|
|
14309
|
-
inspector: this.ctx.config.inspector,
|
|
14310
|
-
alias: [],
|
|
14311
|
-
includeTaskLocation: this.config.includeTaskLocation ?? this.ctx.config.includeTaskLocation,
|
|
14312
|
-
env: {
|
|
14313
|
-
...(_v = this.server) == null ? void 0 : _v.config.env,
|
|
14314
|
-
...this.config.env
|
|
14315
|
-
},
|
|
14316
|
-
browser: {
|
|
14317
|
-
...this.config.browser,
|
|
14318
|
-
orchestratorScripts: [],
|
|
14319
|
-
testerScripts: [],
|
|
14320
|
-
commands: {}
|
|
14321
|
-
},
|
|
14322
|
-
printConsoleTrace: this.config.printConsoleTrace ?? this.ctx.config.printConsoleTrace
|
|
14323
|
-
},
|
|
14324
|
-
this.ctx.configOverride || {}
|
|
14322
|
+
getSerializableConfig() {
|
|
14323
|
+
const config = serializeConfig(
|
|
14324
|
+
this.config,
|
|
14325
|
+
this.ctx.config,
|
|
14326
|
+
this.server.config
|
|
14325
14327
|
);
|
|
14326
|
-
if (
|
|
14327
|
-
config
|
|
14328
|
-
if (config.browser.provider && config.browser.provider !== "preview") {
|
|
14329
|
-
config.browser.headless = true;
|
|
14330
|
-
}
|
|
14331
|
-
config.snapshotSerializers = [];
|
|
14332
|
-
config.diff = void 0;
|
|
14328
|
+
if (!this.ctx.configOverride) {
|
|
14329
|
+
return config;
|
|
14333
14330
|
}
|
|
14334
|
-
return
|
|
14331
|
+
return deepMerge(
|
|
14332
|
+
config,
|
|
14333
|
+
this.ctx.configOverride
|
|
14334
|
+
);
|
|
14335
14335
|
}
|
|
14336
14336
|
close() {
|
|
14337
|
-
var _a, _b;
|
|
14338
14337
|
if (!this.closingPromise) {
|
|
14339
14338
|
this.closingPromise = Promise.all(
|
|
14340
14339
|
[
|
|
14341
14340
|
this.server.close(),
|
|
14342
|
-
|
|
14343
|
-
|
|
14341
|
+
this.typechecker?.stop(),
|
|
14342
|
+
this.browser?.close(),
|
|
14344
14343
|
this.clearTmpDir()
|
|
14345
14344
|
].filter(Boolean)
|
|
14346
14345
|
).then(() => this._provided = {});
|
|
@@ -14349,16 +14348,15 @@ class WorkspaceProject {
|
|
|
14349
14348
|
}
|
|
14350
14349
|
async clearTmpDir() {
|
|
14351
14350
|
try {
|
|
14352
|
-
await rm(this.tmpDir, {
|
|
14351
|
+
await rm(this.tmpDir, { recursive: true });
|
|
14353
14352
|
} catch {
|
|
14354
14353
|
}
|
|
14355
14354
|
}
|
|
14356
14355
|
async initBrowserProvider() {
|
|
14357
|
-
var _a;
|
|
14358
14356
|
if (!this.isBrowserEnabled()) {
|
|
14359
14357
|
return;
|
|
14360
14358
|
}
|
|
14361
|
-
await
|
|
14359
|
+
await this.browser?.initBrowserProvider();
|
|
14362
14360
|
}
|
|
14363
14361
|
}
|
|
14364
14362
|
|
|
@@ -14392,14 +14390,14 @@ class VitestPackageInstaller {
|
|
|
14392
14390
|
if (!promptInstall) {
|
|
14393
14391
|
return false;
|
|
14394
14392
|
}
|
|
14395
|
-
const prompts = await import('./index.
|
|
14393
|
+
const prompts = await import('./index.CM5UI-4O.js').then(function (n) { return n.i; });
|
|
14396
14394
|
const { install } = await prompts.prompt({
|
|
14397
14395
|
type: "confirm",
|
|
14398
14396
|
name: "install",
|
|
14399
14397
|
message: c.reset(`Do you want to install ${c.green(dependency)}?`)
|
|
14400
14398
|
});
|
|
14401
14399
|
if (install) {
|
|
14402
|
-
await (await import('
|
|
14400
|
+
await (await import('./index.DNUmWFkO.js')).installPackage(dependency, { dev: true });
|
|
14403
14401
|
process.stderr.write(
|
|
14404
14402
|
c.yellow(
|
|
14405
14403
|
`
|
|
@@ -14467,11 +14465,10 @@ class Vitest {
|
|
|
14467
14465
|
_onSetServer = [];
|
|
14468
14466
|
_onCancelListeners = [];
|
|
14469
14467
|
async setServer(options, server, cliOptions) {
|
|
14470
|
-
|
|
14471
|
-
(_a = this.unregisterWatcher) == null ? void 0 : _a.call(this);
|
|
14468
|
+
this.unregisterWatcher?.();
|
|
14472
14469
|
clearTimeout(this._rerunTimer);
|
|
14473
14470
|
this.restartsCount += 1;
|
|
14474
|
-
|
|
14471
|
+
this.pool?.close?.();
|
|
14475
14472
|
this.pool = void 0;
|
|
14476
14473
|
this.coverageProvider = void 0;
|
|
14477
14474
|
this.runningPromise = void 0;
|
|
@@ -14517,7 +14514,7 @@ class Vitest {
|
|
|
14517
14514
|
}
|
|
14518
14515
|
});
|
|
14519
14516
|
}
|
|
14520
|
-
this.reporters = resolved.mode === "benchmark" ? await createBenchmarkReporters(toArray(
|
|
14517
|
+
this.reporters = resolved.mode === "benchmark" ? await createBenchmarkReporters(toArray(resolved.benchmark?.reporters), this.runner) : await createReporters(resolved.reporters, this);
|
|
14521
14518
|
this.cache.results.setConfig(resolved.root, resolved.cache);
|
|
14522
14519
|
try {
|
|
14523
14520
|
await this.cache.results.readFromCache();
|
|
@@ -14551,9 +14548,8 @@ class Vitest {
|
|
|
14551
14548
|
return this.coreWorkspaceProject;
|
|
14552
14549
|
}
|
|
14553
14550
|
getProjectByTaskId(taskId) {
|
|
14554
|
-
var _a;
|
|
14555
14551
|
const task = this.state.idMap.get(taskId);
|
|
14556
|
-
const projectName = task.projectName ||
|
|
14552
|
+
const projectName = task.projectName || task?.file?.projectName || "";
|
|
14557
14553
|
return this.projects.find((p) => p.getName() === projectName) || this.getCoreWorkspaceProject() || this.projects[0];
|
|
14558
14554
|
}
|
|
14559
14555
|
getProjectByName(name = "") {
|
|
@@ -14626,7 +14622,7 @@ class Vitest {
|
|
|
14626
14622
|
}));
|
|
14627
14623
|
const workspacesByFolder = resolvedWorkspacesPaths.reduce((configByFolder, filepath) => {
|
|
14628
14624
|
const dir = filepath.endsWith("/") ? filepath.slice(0, -1) : dirname(filepath);
|
|
14629
|
-
configByFolder[dir]
|
|
14625
|
+
configByFolder[dir] ??= [];
|
|
14630
14626
|
configByFolder[dir].push(filepath);
|
|
14631
14627
|
return configByFolder;
|
|
14632
14628
|
}, {});
|
|
@@ -14707,7 +14703,10 @@ class Vitest {
|
|
|
14707
14703
|
if (this.coverageProvider !== void 0) {
|
|
14708
14704
|
return;
|
|
14709
14705
|
}
|
|
14710
|
-
this.coverageProvider = await getCoverageProvider(
|
|
14706
|
+
this.coverageProvider = await getCoverageProvider(
|
|
14707
|
+
this.config.coverage,
|
|
14708
|
+
this.runner
|
|
14709
|
+
);
|
|
14711
14710
|
if (this.coverageProvider) {
|
|
14712
14711
|
await this.coverageProvider.initialize(this);
|
|
14713
14712
|
this.config.coverage = this.coverageProvider.resolveOptions();
|
|
@@ -14718,7 +14717,6 @@ class Vitest {
|
|
|
14718
14717
|
return Promise.all(this.projects.map((w) => w.initBrowserProvider()));
|
|
14719
14718
|
}
|
|
14720
14719
|
async mergeReports() {
|
|
14721
|
-
var _a, _b;
|
|
14722
14720
|
if (this.reporters.some((r) => r instanceof BlobReporter)) {
|
|
14723
14721
|
throw new Error("Cannot merge reports when `--reporter=blob` is used. Remove blob reporter from the config first.");
|
|
14724
14722
|
}
|
|
@@ -14736,10 +14734,9 @@ class Vitest {
|
|
|
14736
14734
|
const filepaths = files2.map((f) => f.filepath);
|
|
14737
14735
|
this.state.clearFiles(project, filepaths);
|
|
14738
14736
|
files2.forEach((file) => {
|
|
14739
|
-
|
|
14740
|
-
(_a2 = file.logs) == null ? void 0 : _a2.forEach((log) => this.state.updateUserLog(log));
|
|
14737
|
+
file.logs?.forEach((log) => this.state.updateUserLog(log));
|
|
14741
14738
|
});
|
|
14742
|
-
this.state.collectFiles(files2);
|
|
14739
|
+
this.state.collectFiles(project, files2);
|
|
14743
14740
|
}
|
|
14744
14741
|
await this.report("onCollected", files).catch(noop$1);
|
|
14745
14742
|
for (const file of files) {
|
|
@@ -14763,7 +14760,7 @@ class Vitest {
|
|
|
14763
14760
|
}
|
|
14764
14761
|
await this.report("onFinished", files, errors);
|
|
14765
14762
|
await this.initCoverageProvider();
|
|
14766
|
-
await
|
|
14763
|
+
await this.coverageProvider?.mergeReports?.(coverages);
|
|
14767
14764
|
}
|
|
14768
14765
|
async collect(filters) {
|
|
14769
14766
|
this._onClose = [];
|
|
@@ -14781,11 +14778,10 @@ class Vitest {
|
|
|
14781
14778
|
};
|
|
14782
14779
|
}
|
|
14783
14780
|
async start(filters) {
|
|
14784
|
-
var _a, _b, _c, _d;
|
|
14785
14781
|
this._onClose = [];
|
|
14786
14782
|
try {
|
|
14787
14783
|
await this.initCoverageProvider();
|
|
14788
|
-
await
|
|
14784
|
+
await this.coverageProvider?.clean(this.config.coverage.clean);
|
|
14789
14785
|
await this.initBrowserProviders();
|
|
14790
14786
|
} finally {
|
|
14791
14787
|
await this.report("onInit", this);
|
|
@@ -14794,10 +14790,10 @@ class Vitest {
|
|
|
14794
14790
|
await this.globTestFiles(filters)
|
|
14795
14791
|
);
|
|
14796
14792
|
if (!files.length) {
|
|
14797
|
-
const coverage = await
|
|
14793
|
+
const coverage = await this.coverageProvider?.generateCoverage?.({ allTestsRun: true });
|
|
14798
14794
|
await this.reportCoverage(coverage, true);
|
|
14799
14795
|
this.logger.printNoTestFound(filters);
|
|
14800
|
-
if (!this.config.watch || !(this.config.changed ||
|
|
14796
|
+
if (!this.config.watch || !(this.config.changed || this.config.related?.length)) {
|
|
14801
14797
|
const exitCode = this.config.passWithNoTests ? 0 : 1;
|
|
14802
14798
|
process.exitCode = exitCode;
|
|
14803
14799
|
throw new FilesNotFoundError(this.mode);
|
|
@@ -14812,11 +14808,10 @@ class Vitest {
|
|
|
14812
14808
|
}
|
|
14813
14809
|
}
|
|
14814
14810
|
async init() {
|
|
14815
|
-
var _a;
|
|
14816
14811
|
this._onClose = [];
|
|
14817
14812
|
try {
|
|
14818
14813
|
await this.initCoverageProvider();
|
|
14819
|
-
await
|
|
14814
|
+
await this.coverageProvider?.clean(this.config.coverage.clean);
|
|
14820
14815
|
await this.initBrowserProviders();
|
|
14821
14816
|
} finally {
|
|
14822
14817
|
await this.report("onInit", this);
|
|
@@ -14833,7 +14828,7 @@ class Vitest {
|
|
|
14833
14828
|
}
|
|
14834
14829
|
deps.add(filepath2);
|
|
14835
14830
|
const mod = project.server.moduleGraph.getModuleById(filepath2);
|
|
14836
|
-
const transformed =
|
|
14831
|
+
const transformed = mod?.ssrTransformResult || await project.vitenode.transformRequest(filepath2);
|
|
14837
14832
|
if (!transformed) {
|
|
14838
14833
|
return;
|
|
14839
14834
|
}
|
|
@@ -14852,7 +14847,7 @@ class Vitest {
|
|
|
14852
14847
|
}
|
|
14853
14848
|
async filterTestsBySource(specs) {
|
|
14854
14849
|
if (this.config.changed && !this.config.related) {
|
|
14855
|
-
const { VitestGit } = await import('
|
|
14850
|
+
const { VitestGit } = await import('./git.ZtkbKc8u.js');
|
|
14856
14851
|
const vitestGit = new VitestGit(this.config.root);
|
|
14857
14852
|
const related2 = await vitestGit.findChangedFiles({
|
|
14858
14853
|
changedSince: this.config.changed
|
|
@@ -14901,7 +14896,7 @@ class Vitest {
|
|
|
14901
14896
|
if (!projects.has(coreProject)) {
|
|
14902
14897
|
projects.add(coreProject);
|
|
14903
14898
|
}
|
|
14904
|
-
for
|
|
14899
|
+
for (const project of projects) {
|
|
14905
14900
|
await project.initializeGlobalSetup();
|
|
14906
14901
|
}
|
|
14907
14902
|
}
|
|
@@ -14925,7 +14920,6 @@ class Vitest {
|
|
|
14925
14920
|
this._onCancelListeners = [];
|
|
14926
14921
|
this.isCancelling = false;
|
|
14927
14922
|
this.runningPromise = (async () => {
|
|
14928
|
-
var _a;
|
|
14929
14923
|
if (!this.pool) {
|
|
14930
14924
|
this.pool = createPool(this);
|
|
14931
14925
|
}
|
|
@@ -14934,7 +14928,7 @@ class Vitest {
|
|
|
14934
14928
|
this.snapshot.clear();
|
|
14935
14929
|
this.state.clearErrors();
|
|
14936
14930
|
if (!this.isFirstRun && this.config.coverage.cleanOnRerun) {
|
|
14937
|
-
await
|
|
14931
|
+
await this.coverageProvider?.clean();
|
|
14938
14932
|
}
|
|
14939
14933
|
await this.initializeGlobalSetup(specs);
|
|
14940
14934
|
try {
|
|
@@ -14949,9 +14943,8 @@ class Vitest {
|
|
|
14949
14943
|
this.cache.results.updateResults(files);
|
|
14950
14944
|
await this.cache.results.writeToCache();
|
|
14951
14945
|
})().finally(async () => {
|
|
14952
|
-
var _a;
|
|
14953
14946
|
const files = Array.from(new Set(specs.map(([, p]) => p)));
|
|
14954
|
-
const coverage = await
|
|
14947
|
+
const coverage = await this.coverageProvider?.generateCoverage({ allTestsRun });
|
|
14955
14948
|
await this.report("onFinished", this.state.getFiles(files), this.state.getUnhandledErrors(), coverage);
|
|
14956
14949
|
await this.reportCoverage(coverage, allTestsRun);
|
|
14957
14950
|
this.runningPromise = void 0;
|
|
@@ -15118,10 +15111,10 @@ class Vitest {
|
|
|
15118
15111
|
const projects = this.getModuleProjects(filepath);
|
|
15119
15112
|
projects.forEach(({ server, browser }) => {
|
|
15120
15113
|
const serverMods = server.moduleGraph.getModulesByFile(filepath);
|
|
15121
|
-
serverMods
|
|
15114
|
+
serverMods?.forEach((mod) => server.moduleGraph.invalidateModule(mod));
|
|
15122
15115
|
if (browser) {
|
|
15123
15116
|
const browserMods = browser.vite.moduleGraph.getModulesByFile(filepath);
|
|
15124
|
-
browserMods
|
|
15117
|
+
browserMods?.forEach((mod) => browser.vite.moduleGraph.invalidateModule(mod));
|
|
15125
15118
|
}
|
|
15126
15119
|
});
|
|
15127
15120
|
};
|
|
@@ -15151,10 +15144,9 @@ class Vitest {
|
|
|
15151
15144
|
updateLastChanged(id);
|
|
15152
15145
|
const matchingProjects = [];
|
|
15153
15146
|
await Promise.all(this.projects.map(async (project) => {
|
|
15154
|
-
var _a;
|
|
15155
15147
|
if (await project.isTargetFile(id)) {
|
|
15156
15148
|
matchingProjects.push(project);
|
|
15157
|
-
|
|
15149
|
+
project.testFilesList?.push(id);
|
|
15158
15150
|
}
|
|
15159
15151
|
}));
|
|
15160
15152
|
if (matchingProjects.length > 0) {
|
|
@@ -15260,8 +15252,7 @@ class Vitest {
|
|
|
15260
15252
|
}
|
|
15261
15253
|
if (this.pool) {
|
|
15262
15254
|
closePromises.push((async () => {
|
|
15263
|
-
|
|
15264
|
-
await ((_b = (_a = this.pool) == null ? void 0 : _a.close) == null ? void 0 : _b.call(_a));
|
|
15255
|
+
await this.pool?.close?.();
|
|
15265
15256
|
this.pool = void 0;
|
|
15266
15257
|
})());
|
|
15267
15258
|
}
|
|
@@ -15306,13 +15297,9 @@ class Vitest {
|
|
|
15306
15297
|
}
|
|
15307
15298
|
}
|
|
15308
15299
|
async report(name, ...args) {
|
|
15309
|
-
await Promise.all(this.reporters.map((r) =>
|
|
15310
|
-
|
|
15311
|
-
|
|
15312
|
-
r,
|
|
15313
|
-
...args
|
|
15314
|
-
);
|
|
15315
|
-
}));
|
|
15300
|
+
await Promise.all(this.reporters.map((r) => r[name]?.(
|
|
15301
|
+
...args
|
|
15302
|
+
)));
|
|
15316
15303
|
}
|
|
15317
15304
|
async getTestFilepaths() {
|
|
15318
15305
|
return this.globTestFiles().then((files) => files.map(([, file]) => file));
|
|
@@ -15332,8 +15319,7 @@ class Vitest {
|
|
|
15332
15319
|
}
|
|
15333
15320
|
// The server needs to be running for communication
|
|
15334
15321
|
shouldKeepServer() {
|
|
15335
|
-
|
|
15336
|
-
return !!((_a = this.config) == null ? void 0 : _a.watch);
|
|
15322
|
+
return !!this.config?.watch;
|
|
15337
15323
|
}
|
|
15338
15324
|
onServerRestart(fn) {
|
|
15339
15325
|
this._onRestartListeners.push(fn);
|
|
@@ -15351,10 +15337,7 @@ class Vitest {
|
|
|
15351
15337
|
|
|
15352
15338
|
async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
|
|
15353
15339
|
const userConfig = deepMerge({}, options);
|
|
15354
|
-
const getRoot = () =>
|
|
15355
|
-
var _a;
|
|
15356
|
-
return ((_a = ctx.config) == null ? void 0 : _a.root) || options.root || process.cwd();
|
|
15357
|
-
};
|
|
15340
|
+
const getRoot = () => ctx.config?.root || options.root || process.cwd();
|
|
15358
15341
|
async function UIPlugin() {
|
|
15359
15342
|
await ctx.packageInstaller.ensureInstalled("@vitest/ui", getRoot());
|
|
15360
15343
|
return (await import('@vitest/ui')).default(ctx);
|
|
@@ -15367,7 +15350,6 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
|
|
|
15367
15350
|
this.meta.watchMode = false;
|
|
15368
15351
|
},
|
|
15369
15352
|
async config(viteConfig) {
|
|
15370
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
15371
15353
|
if (options.watch) {
|
|
15372
15354
|
options = deepMerge({}, userConfig);
|
|
15373
15355
|
}
|
|
@@ -15385,10 +15367,10 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
|
|
|
15385
15367
|
open = testConfig.uiBase ?? "/__vitest__/";
|
|
15386
15368
|
}
|
|
15387
15369
|
const config = {
|
|
15388
|
-
root:
|
|
15370
|
+
root: viteConfig.test?.root || options.root,
|
|
15389
15371
|
esbuild: viteConfig.esbuild === false ? false : {
|
|
15390
15372
|
// Lowest target Vitest supports is Node18
|
|
15391
|
-
target:
|
|
15373
|
+
target: viteConfig.esbuild?.target || "node18",
|
|
15392
15374
|
sourcemap: "external",
|
|
15393
15375
|
// Enables using ignore hint for coverage providers with @preserve keyword
|
|
15394
15376
|
legalComments: "inline"
|
|
@@ -15421,25 +15403,25 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
|
|
|
15421
15403
|
test: {
|
|
15422
15404
|
poolOptions: {
|
|
15423
15405
|
threads: {
|
|
15424
|
-
isolate:
|
|
15406
|
+
isolate: options.poolOptions?.threads?.isolate ?? options.isolate ?? testConfig.poolOptions?.threads?.isolate ?? viteConfig.test?.isolate
|
|
15425
15407
|
},
|
|
15426
15408
|
forks: {
|
|
15427
|
-
isolate:
|
|
15409
|
+
isolate: options.poolOptions?.forks?.isolate ?? options.isolate ?? testConfig.poolOptions?.forks?.isolate ?? viteConfig.test?.isolate
|
|
15428
15410
|
}
|
|
15429
15411
|
}
|
|
15430
15412
|
}
|
|
15431
15413
|
};
|
|
15432
|
-
if (
|
|
15414
|
+
if (userConfig.coverage?.enabled && !userConfig.coverage.exclude && userConfig.include && config.test) {
|
|
15433
15415
|
config.test.coverage = {
|
|
15434
15416
|
exclude: [...coverageConfigDefaults.exclude, ...userConfig.include]
|
|
15435
15417
|
};
|
|
15436
15418
|
}
|
|
15437
|
-
if (
|
|
15438
|
-
const inline =
|
|
15419
|
+
if (viteConfig.ssr?.noExternal !== true) {
|
|
15420
|
+
const inline = testConfig.server?.deps?.inline;
|
|
15439
15421
|
if (inline === true) {
|
|
15440
15422
|
config.ssr = { noExternal: true };
|
|
15441
15423
|
} else {
|
|
15442
|
-
const noExternal =
|
|
15424
|
+
const noExternal = viteConfig.ssr?.noExternal;
|
|
15443
15425
|
const noExternalArray = typeof noExternal !== "undefined" ? toArray(noExternal) : void 0;
|
|
15444
15426
|
const uniqueInline = inline && noExternalArray ? inline.filter((dep) => !noExternalArray.includes(dep)) : inline;
|
|
15445
15427
|
config.ssr = {
|
|
@@ -15454,10 +15436,10 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
|
|
|
15454
15436
|
watch.usePolling = false;
|
|
15455
15437
|
}
|
|
15456
15438
|
}
|
|
15457
|
-
const classNameStrategy = typeof testConfig.css !== "boolean" &&
|
|
15439
|
+
const classNameStrategy = typeof testConfig.css !== "boolean" && testConfig.css?.modules?.classNameStrategy || "stable";
|
|
15458
15440
|
if (classNameStrategy !== "scoped") {
|
|
15459
|
-
config.css
|
|
15460
|
-
|
|
15441
|
+
config.css ??= {};
|
|
15442
|
+
config.css.modules ??= {};
|
|
15461
15443
|
if (config.css.modules) {
|
|
15462
15444
|
config.css.modules.generateScopedName = (name, filename) => {
|
|
15463
15445
|
const root = getRoot();
|
|
@@ -15472,7 +15454,6 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
|
|
|
15472
15454
|
return config;
|
|
15473
15455
|
},
|
|
15474
15456
|
async configResolved(viteConfig) {
|
|
15475
|
-
var _a, _b, _c;
|
|
15476
15457
|
const viteConfigTest = viteConfig.test || {};
|
|
15477
15458
|
if (viteConfigTest.watch === false) {
|
|
15478
15459
|
viteConfigTest.run = true;
|
|
@@ -15483,10 +15464,10 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
|
|
|
15483
15464
|
options = deepMerge({}, configDefaults, viteConfigTest, options);
|
|
15484
15465
|
options.api = resolveApiServerConfig(options, defaultPort);
|
|
15485
15466
|
const { PROD, DEV, ...envs } = viteConfig.env;
|
|
15486
|
-
|
|
15487
|
-
|
|
15467
|
+
process.env.PROD ??= PROD ? "1" : "";
|
|
15468
|
+
process.env.DEV ??= DEV ? "1" : "";
|
|
15488
15469
|
for (const name in envs) {
|
|
15489
|
-
|
|
15470
|
+
process.env[name] ??= envs[name];
|
|
15490
15471
|
}
|
|
15491
15472
|
if (!options.watch) {
|
|
15492
15473
|
viteConfig.server.watch = null;
|
|
@@ -15520,7 +15501,6 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
|
|
|
15520
15501
|
}
|
|
15521
15502
|
|
|
15522
15503
|
async function createVitest(mode, options, viteOverrides = {}, vitestOptions = {}) {
|
|
15523
|
-
var _a;
|
|
15524
15504
|
const ctx = new Vitest(mode, vitestOptions);
|
|
15525
15505
|
const root = resolve(options.root || process.cwd());
|
|
15526
15506
|
const configPath = options.config === false ? false : options.config ? resolve(root, options.config) : await findUp(configFiles, { cwd: root });
|
|
@@ -15535,7 +15515,7 @@ async function createVitest(mode, options, viteOverrides = {}, vitestOptions = {
|
|
|
15535
15515
|
const server = await createViteServer(
|
|
15536
15516
|
mergeConfig(config, mergeConfig(viteOverrides, { root: options.root }))
|
|
15537
15517
|
);
|
|
15538
|
-
if (
|
|
15518
|
+
if (ctx.config.api?.port) {
|
|
15539
15519
|
await server.listen();
|
|
15540
15520
|
}
|
|
15541
15521
|
return ctx;
|
|
@@ -15581,42 +15561,41 @@ class WatchFilter {
|
|
|
15581
15561
|
}
|
|
15582
15562
|
filterHandler(filterFunc, onSubmit) {
|
|
15583
15563
|
return async (str, key) => {
|
|
15584
|
-
var _a, _b;
|
|
15585
15564
|
switch (true) {
|
|
15586
15565
|
case key.sequence === "\x7F":
|
|
15587
|
-
if (this.currentKeyword &&
|
|
15588
|
-
this.currentKeyword =
|
|
15566
|
+
if (this.currentKeyword && this.currentKeyword?.length > 1) {
|
|
15567
|
+
this.currentKeyword = this.currentKeyword?.slice(0, -1);
|
|
15589
15568
|
} else {
|
|
15590
15569
|
this.currentKeyword = void 0;
|
|
15591
15570
|
}
|
|
15592
15571
|
break;
|
|
15593
|
-
case (
|
|
15594
|
-
case
|
|
15572
|
+
case (key?.ctrl && key?.name === "c"):
|
|
15573
|
+
case key?.name === "escape":
|
|
15595
15574
|
this.cancel();
|
|
15596
15575
|
onSubmit(void 0);
|
|
15597
15576
|
break;
|
|
15598
|
-
case
|
|
15599
|
-
case
|
|
15577
|
+
case key?.name === "enter":
|
|
15578
|
+
case key?.name === "return":
|
|
15600
15579
|
onSubmit(
|
|
15601
15580
|
this.results[this.selectionIndex] || this.currentKeyword || ""
|
|
15602
15581
|
);
|
|
15603
15582
|
this.currentKeyword = void 0;
|
|
15604
15583
|
break;
|
|
15605
|
-
case
|
|
15584
|
+
case key?.name === "up":
|
|
15606
15585
|
if (this.selectionIndex && this.selectionIndex > 0) {
|
|
15607
15586
|
this.selectionIndex--;
|
|
15608
15587
|
} else {
|
|
15609
15588
|
this.selectionIndex = -1;
|
|
15610
15589
|
}
|
|
15611
15590
|
break;
|
|
15612
|
-
case
|
|
15591
|
+
case key?.name === "down":
|
|
15613
15592
|
if (this.selectionIndex < this.results.length - 1) {
|
|
15614
15593
|
this.selectionIndex++;
|
|
15615
15594
|
} else if (this.selectionIndex >= this.results.length - 1) {
|
|
15616
15595
|
this.selectionIndex = this.results.length - 1;
|
|
15617
15596
|
}
|
|
15618
15597
|
break;
|
|
15619
|
-
case (!
|
|
15598
|
+
case (!key?.ctrl && !key?.meta):
|
|
15620
15599
|
if (this.currentKeyword === void 0) {
|
|
15621
15600
|
this.currentKeyword = str;
|
|
15622
15601
|
} else {
|
|
@@ -15695,8 +15674,7 @@ ${resultBody}`;
|
|
|
15695
15674
|
}
|
|
15696
15675
|
}
|
|
15697
15676
|
restoreCursor() {
|
|
15698
|
-
|
|
15699
|
-
const cursortPos = this.keywordOffset() + (((_a = this.currentKeyword) == null ? void 0 : _a.length) || 0);
|
|
15677
|
+
const cursortPos = this.keywordOffset() + (this.currentKeyword?.length || 0);
|
|
15700
15678
|
this.write(`${ESC}${cursortPos}G`);
|
|
15701
15679
|
}
|
|
15702
15680
|
cancel() {
|
|
@@ -15751,7 +15729,7 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
|
|
|
15751
15729
|
process.kill(process.pid, "SIGTSTP");
|
|
15752
15730
|
return;
|
|
15753
15731
|
}
|
|
15754
|
-
const name = key
|
|
15732
|
+
const name = key?.name;
|
|
15755
15733
|
if (ctx.runningPromise) {
|
|
15756
15734
|
if (cancelKeys.includes(name)) {
|
|
15757
15735
|
await ctx.cancelCurrentRun("keyboard-input");
|
|
@@ -15811,7 +15789,7 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
|
|
|
15811
15789
|
const files = ctx.state.getFilepaths();
|
|
15812
15790
|
const cliFiles = ctx.config.standalone && !files.length ? await ctx.getTestFilepaths() : void 0;
|
|
15813
15791
|
await ctx.changeNamePattern(
|
|
15814
|
-
|
|
15792
|
+
filter?.trim() || "",
|
|
15815
15793
|
cliFiles,
|
|
15816
15794
|
"change pattern"
|
|
15817
15795
|
);
|
|
@@ -15841,7 +15819,7 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
|
|
|
15841
15819
|
return files.map((file) => relative(ctx.config.root, file[1]));
|
|
15842
15820
|
});
|
|
15843
15821
|
on();
|
|
15844
|
-
latestFilename =
|
|
15822
|
+
latestFilename = filter?.trim() || "";
|
|
15845
15823
|
const lastResults = watchFilter.getLastResults();
|
|
15846
15824
|
await ctx.changeFilenamePattern(
|
|
15847
15825
|
latestFilename,
|
|
@@ -15859,7 +15837,7 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
|
|
|
15859
15837
|
stdin.on("keypress", keypressHandler);
|
|
15860
15838
|
}
|
|
15861
15839
|
function off() {
|
|
15862
|
-
rl
|
|
15840
|
+
rl?.close();
|
|
15863
15841
|
rl = void 0;
|
|
15864
15842
|
stdin.removeListener("keypress", keypressHandler);
|
|
15865
15843
|
if (stdin.isTTY) {
|
|
@@ -15890,8 +15868,8 @@ async function startVitest(mode, cliFilters = [], options = {}, viteOverrides, v
|
|
|
15890
15868
|
}
|
|
15891
15869
|
}
|
|
15892
15870
|
}
|
|
15893
|
-
const stdin =
|
|
15894
|
-
const stdout =
|
|
15871
|
+
const stdin = vitestOptions?.stdin || process.stdin;
|
|
15872
|
+
const stdout = vitestOptions?.stdout || process.stdout;
|
|
15895
15873
|
let stdinCleanup;
|
|
15896
15874
|
if (stdin.isTTY && ctx.config.watch) {
|
|
15897
15875
|
stdinCleanup = registerConsoleShortcuts(ctx, stdin, stdout);
|
|
@@ -15930,15 +15908,14 @@ async function startVitest(mode, cliFilters = [], options = {}, viteOverrides, v
|
|
|
15930
15908
|
if (ctx.shouldKeepServer()) {
|
|
15931
15909
|
return ctx;
|
|
15932
15910
|
}
|
|
15933
|
-
stdinCleanup
|
|
15911
|
+
stdinCleanup?.();
|
|
15934
15912
|
await ctx.close();
|
|
15935
15913
|
return ctx;
|
|
15936
15914
|
}
|
|
15937
15915
|
async function prepareVitest(mode, options = {}, viteOverrides, vitestOptions) {
|
|
15938
|
-
var _a, _b, _c;
|
|
15939
15916
|
process.env.TEST = "true";
|
|
15940
15917
|
process.env.VITEST = "true";
|
|
15941
|
-
|
|
15918
|
+
process.env.NODE_ENV ??= "test";
|
|
15942
15919
|
if (options.run) {
|
|
15943
15920
|
options.watch = false;
|
|
15944
15921
|
}
|
|
@@ -15946,8 +15923,8 @@ async function prepareVitest(mode, options = {}, viteOverrides, vitestOptions) {
|
|
|
15946
15923
|
if (typeof options.browser === "object" && !("enabled" in options.browser)) {
|
|
15947
15924
|
options.browser.enabled = true;
|
|
15948
15925
|
}
|
|
15949
|
-
if (typeof
|
|
15950
|
-
|
|
15926
|
+
if (typeof options.typecheck?.only === "boolean") {
|
|
15927
|
+
options.typecheck.enabled ??= true;
|
|
15951
15928
|
}
|
|
15952
15929
|
const ctx = await createVitest(mode, options, viteOverrides, vitestOptions);
|
|
15953
15930
|
const environmentPackage = getEnvPackageName(ctx.config.environment);
|
|
@@ -15960,8 +15937,7 @@ async function prepareVitest(mode, options = {}, viteOverrides, vitestOptions) {
|
|
|
15960
15937
|
function processCollected(ctx, files, options) {
|
|
15961
15938
|
let errorsPrinted = false;
|
|
15962
15939
|
forEachSuite(files, (suite) => {
|
|
15963
|
-
|
|
15964
|
-
const errors = ((_a = suite.result) == null ? void 0 : _a.errors) || [];
|
|
15940
|
+
const errors = suite.result?.errors || [];
|
|
15965
15941
|
errors.forEach((error) => {
|
|
15966
15942
|
errorsPrinted = true;
|
|
15967
15943
|
ctx.logger.printError(error, {
|
|
@@ -16025,6 +16001,23 @@ function formatCollectedAsString(files) {
|
|
|
16025
16001
|
});
|
|
16026
16002
|
}).flat();
|
|
16027
16003
|
}
|
|
16004
|
+
const envPackageNames = {
|
|
16005
|
+
"jsdom": "jsdom",
|
|
16006
|
+
"happy-dom": "happy-dom",
|
|
16007
|
+
"edge-runtime": "@edge-runtime/vm"
|
|
16008
|
+
};
|
|
16009
|
+
function getEnvPackageName(env) {
|
|
16010
|
+
if (env === "node") {
|
|
16011
|
+
return null;
|
|
16012
|
+
}
|
|
16013
|
+
if (env in envPackageNames) {
|
|
16014
|
+
return envPackageNames[env];
|
|
16015
|
+
}
|
|
16016
|
+
if (env[0] === "." || env[0] === "/") {
|
|
16017
|
+
return null;
|
|
16018
|
+
}
|
|
16019
|
+
return `vitest-environment-${env}`;
|
|
16020
|
+
}
|
|
16028
16021
|
|
|
16029
16022
|
var cliApi = /*#__PURE__*/Object.freeze({
|
|
16030
16023
|
__proto__: null,
|