vitest 5.1.0-beta.1 → 5.1.1
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 +8 -6
- package/dist/browser.js +10 -10
- package/dist/chunks/{base.PJyN9N0u.js → base.C2su7_N0.js} +16 -21
- package/dist/chunks/{browser.d.D7a15z82.d.ts → browser.d.B-QwH_F6.d.ts} +3 -3
- package/dist/chunks/{cac.Ccf5Je_F.js → cac.BK306qhQ.js} +29 -22
- package/dist/chunks/{cli-api.DE22LIzq.js → cli-api.D6E8EtSi.js} +990 -166
- package/dist/chunks/{config.d.BgktgHfG.d.ts → config.d.BpJq6tRA.d.ts} +43 -2
- package/dist/chunks/{console.DrMPSuFo.js → console.VJUxd1rM.js} +3 -3
- package/dist/chunks/{coverage.-bm5IxnW.js → coverage.9iqXE2gN.js} +1 -1
- package/dist/chunks/{coverage.cTDc4uSS.js → coverage.jGCktcGP.js} +1 -1
- package/dist/chunks/{creator.BQ3onxbh.js → creator.CoOCr85O.js} +17 -15
- package/dist/chunks/{display.BlTmubjj.js → display.Cj2h2zsY.js} +1 -1
- package/dist/chunks/{doctor.CPlMs7-y.js → doctor.SRjZIZuA.js} +2 -2
- package/dist/chunks/{environment.d.CbTLsZSj.d.ts → environment.d.rlpAM-ON.d.ts} +1 -1
- package/dist/chunks/{globals.TipXUFcZ.js → globals.Mxora3_v.js} +11 -10
- package/dist/chunks/{index.BFXLpwll.js → index.C7Nn66Gy.js} +79 -41
- package/dist/chunks/{index.DmDMHCg8.js → index.CAmut2NG.js} +25 -1
- package/dist/chunks/{index.BXttT2gP.js → index.DNcttN5a.js} +288 -437
- package/dist/chunks/{index.B03wg4V0.js → index.Da_szXbS.js} +5 -5
- package/dist/chunks/{index.D14IAvnE.js → index.ER9afepi.js} +269 -141
- package/dist/chunks/{index.D0heQG4v.js → index.Or9psEGe.js} +1 -1
- package/dist/chunks/{init-forks.BL1E3__4.js → init-forks.q4IoGYZe.js} +7 -1
- package/dist/chunks/{init-threads.CYXAGzKQ.js → init-threads.Bf1Frg9S.js} +1 -1
- package/dist/chunks/{init.DVorxUyL.js → init.dGO4K2C0.js} +17 -9
- package/dist/chunks/{inspector.CvyFGlXm.js → inspector.D6o1NPo1.js} +12 -1
- package/dist/chunks/{module-dependencies.CwNPkcV4.js → module-dependencies._2Eei3FO.js} +1 -1
- package/dist/chunks/{modules.BJuCwlRJ.js → moduleSourceMap.Dp1WduWi.js} +31 -1
- package/dist/chunks/{native.cdzHIdmv.js → native.D5q1ylZC.js} +3 -2
- package/dist/chunks/{nativeModuleMocker.3uBcOd84.js → nativeModuleMocker.ihb3q7Cg.js} +6 -4
- package/dist/chunks/{nativeModuleRunner.xi64Afb2.js → nativeModuleRunner.9xPIMzi7.js} +1 -1
- package/dist/chunks/{node.uQulW0ei.js → node.B9mkVmLH.js} +1 -1
- package/dist/chunks/{pathe.M-eThtNZ.Ba-7h1rE.js → pathe.M-eThtNZ.zq3TM4NT.js} +1 -1
- package/dist/chunks/{plugin.d.olEn8IL9.d.ts → plugin.d.Du7hHZwb.d.ts} +115 -41
- package/dist/chunks/{plugins.DPQHVT0p.js → plugins.BPruPOR8.js} +1 -1
- package/dist/chunks/rawSnapshot.DvoRLRNr.js +356 -0
- package/dist/chunks/{resolver.CtCcxIy1.js → resolver.BzpmeQeT.js} +1 -1
- package/dist/chunks/{rpc.BV0XpJ5q.js → rpc.CNYWPa97.js} +3 -19
- package/dist/chunks/{rpc.d.DGFP7vWr.d.ts → rpc.d.DHfuwqP0.d.ts} +2 -2
- package/dist/chunks/{run.BfrMbGVD.js → run.zBhXlcZQ.js} +118 -51
- package/dist/chunks/{setup-common.llxJkJaD.js → setup-common.wwc_NYRJ.js} +3 -3
- package/dist/chunks/{source-map.BjWcsIL9.js → source-map.DPHGMWvM.js} +14 -14
- package/dist/chunks/{source-map.d.C5A_Tr6V.d.ts → source-map.d.xB6_75fl.d.ts} +2 -1
- package/dist/chunks/{spy.DDMXghXv.js → spy.BO0hTE3G.js} +76 -53
- package/dist/chunks/{task-utils.d.BUh7ylUT.d.ts → task-utils.d.DgSjIb7r.d.ts} +1 -1
- package/dist/chunks/{utils.DSfl_w8V.js → utils.sAsh2ClK.js} +7 -8
- package/dist/chunks/{vm.Cwj01UFE.js → vm.agn4qnmT.js} +15 -13
- package/dist/chunks/{worker.d.gsA26mmR.d.ts → worker.d.BigfbIsH.d.ts} +3 -3
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +8 -8
- package/dist/index.d.ts +17 -12
- package/dist/index.js +11 -10
- package/dist/module-evaluator.d.ts +3 -3
- package/dist/module-evaluator.js +1 -1
- package/dist/node.d.ts +12 -11
- package/dist/node.js +23 -19
- package/dist/runtime.d.ts +5 -4
- package/dist/runtime.js +7 -5
- package/dist/spy.js +1 -1
- package/dist/task-utils.js +7 -3
- package/dist/worker.d.ts +4 -4
- package/dist/worker.js +23 -21
- package/dist/workers/forks.js +24 -22
- package/dist/workers/runVmTests.js +20 -17
- package/dist/workers/threads.js +24 -22
- package/dist/workers/vmForks.js +16 -15
- package/dist/workers/vmThreads.js +16 -15
- package/dist/workers/watchdog.js +20 -0
- package/package.json +21 -21
|
@@ -1,52 +1,53 @@
|
|
|
1
1
|
import { promises, existsSync, mkdirSync, writeFileSync, linkSync, renameSync, rmSync, chmodSync, readFileSync, statfsSync, realpathSync, statSync, readdirSync } from 'node:fs';
|
|
2
2
|
import url, { pathToFileURL, fileURLToPath } from 'node:url';
|
|
3
|
-
import { c as cleanUrl, r as resolve,
|
|
4
|
-
import { N as NativeModuleRunner, i as isPackageExists, r as resolveModule } from './nativeModuleRunner.
|
|
3
|
+
import { c as cleanUrl, r as resolve, k as extname, d as dirname, j as join, l as KNOWN_ASSET_RE, H as withTrailingSlash, I as wrapId, i as isAbsolute, J as isExternalUrl, L as unwrapId, a as relative, A as unique, s as slash, t as toArray, b as basename, p as isPrimitive, n as normalize, G as deepMerge, e as createDefer, u as deepClone } from './pathe.M-eThtNZ.zq3TM4NT.js';
|
|
4
|
+
import { N as NativeModuleRunner, i as isPackageExists, r as resolveModule } from './nativeModuleRunner.9xPIMzi7.js';
|
|
5
5
|
import { glob, isDynamicPattern } from 'tinyglobby';
|
|
6
6
|
import { $ } from './tinyrainbow.Do8I1XRG.js';
|
|
7
7
|
import * as vite from 'vite';
|
|
8
8
|
import { createServer, normalizePath, isFileLoadingAllowed, fetchModule, parseAst, searchForWorkspaceRoot, version, isRunnableDevEnvironment, mergeConfig, resolveConfig as resolveConfig$1 } from 'vite';
|
|
9
9
|
import { a as defaultPort, c as configFiles, d as defaultBrowserPort, b as defaultInspectPort } from './constants.DLYM6cZY.js';
|
|
10
10
|
import { c as configDefaults, e as benchmarkConfigDefaults } from './defaults.B1FCaFfh.js';
|
|
11
|
+
import { i as isInspectorOpen } from './inspector.D6o1NPo1.js';
|
|
11
12
|
import { b as isWindows, i as isForceColor, a as isTTY } from './env.BKKtU2WC.js';
|
|
12
13
|
import * as os from 'node:os';
|
|
13
14
|
import os__default, { availableParallelism, homedir, tmpdir } from 'node:os';
|
|
14
|
-
import crypto from 'node:crypto';
|
|
15
|
+
import crypto, { hash } from 'node:crypto';
|
|
15
16
|
import { isBuiltin, builtinModules, createRequire } from 'node:module';
|
|
16
17
|
import { rootDir, distDir } from '../path.js';
|
|
17
|
-
import { i as isBuiltin$1, a as isBrowserExternal, t as toBuiltin } from './
|
|
18
|
+
import { i as isBuiltin$1, a as isBrowserExternal, s as splitSourceMap, w as withInlineSourceMap, t as toBuiltin } from './moduleSourceMap.Dp1WduWi.js';
|
|
18
19
|
import MagicString from 'magic-string';
|
|
19
20
|
import { findMockRedirect, hoistMocksPlugin, automockPlugin } from '@vitest/mocker/node';
|
|
20
21
|
import { Console } from 'node:console';
|
|
21
22
|
import { Writable } from 'node:stream';
|
|
22
23
|
import { stripVTControlCharacters } from 'node:util';
|
|
23
|
-
import { i as inspect } from './display.
|
|
24
|
+
import { i as inspect } from './display.Cj2h2zsY.js';
|
|
25
|
+
import { execFile, fork } from 'node:child_process';
|
|
24
26
|
import { performance as performance$1 } from 'node:perf_hooks';
|
|
25
|
-
import { T as TraceMap, o as originalPositionFor, i as generatedPositionFor, j as eachMapping, k as stackIgnorePatterns, e as parseErrorStacktrace } from './source-map.
|
|
27
|
+
import { T as TraceMap, o as originalPositionFor, i as generatedPositionFor, j as eachMapping, k as stackIgnorePatterns, e as parseErrorStacktrace } from './source-map.DPHGMWvM.js';
|
|
26
28
|
import { x } from 'tinyexec';
|
|
27
|
-
import {
|
|
29
|
+
import { D as validateTags, B as limitConcurrency, E as shuffle } from './run.zBhXlcZQ.js';
|
|
28
30
|
import { createDebug } from 'obug';
|
|
29
31
|
import { createFileTask as createFileTask$1, createTaskName, calculateSuiteHash, convertTasksToEvents, hasFailed, generateFileHash } from '../task-utils.js';
|
|
30
32
|
import { readFile, mkdir, writeFile, rm, stat } from 'node:fs/promises';
|
|
31
|
-
import { l as lookupPackageScopeType } from './resolver.
|
|
33
|
+
import { l as lookupPackageScopeType } from './resolver.BzpmeQeT.js';
|
|
32
34
|
import * as esModuleLexer from 'es-module-lexer';
|
|
33
35
|
import { ssrImportKey, ssrModuleExportsKey, ssrExportAllKey, ssrImportMetaKey, ModuleRunner } from 'vite/module-runner';
|
|
34
36
|
import path, { resolve as resolve$1 } from 'node:path';
|
|
35
37
|
import { p as positionToOffset, l as lineSplitRE } from './offset.Dy-5Fdfn.js';
|
|
36
|
-
import {
|
|
38
|
+
import { j as errorBanner, c as F_POINTER, k as divider, o as truncateString, w as withLabel, e as formatProjectName } from './utils.sAsh2ClK.js';
|
|
37
39
|
import { VitestModuleEvaluator } from '#module-evaluator';
|
|
40
|
+
import { V as VitestEvaluatedModules, c as createBirpc } from './index.CAmut2NG.js';
|
|
38
41
|
import pm from 'picomatch';
|
|
39
|
-
import { t as trackNativeImports, c as collectDependencies, n as nativeImports, g as getEvaluatedImports } from './module-dependencies.
|
|
40
|
-
import { g as getCoverageFilesDirectory } from './coverage.
|
|
42
|
+
import { t as trackNativeImports, c as collectDependencies, n as nativeImports, g as getEvaluatedImports } from './module-dependencies._2Eei3FO.js';
|
|
43
|
+
import { g as getCoverageFilesDirectory } from './coverage.jGCktcGP.js';
|
|
41
44
|
import { isAgent, isCI, provider } from 'std-env';
|
|
42
45
|
import process$1 from 'node:process';
|
|
43
46
|
import { isatty } from 'node:tty';
|
|
44
47
|
import EventEmitter$1, { EventEmitter } from 'node:events';
|
|
45
|
-
import { c as createBirpc } from './index.DmDMHCg8.js';
|
|
46
|
-
import { fork } from 'node:child_process';
|
|
47
48
|
import { Worker } from 'node:worker_threads';
|
|
48
|
-
import { v as version$1 } from './cac.
|
|
49
|
-
import { g as getDefaultExportFromCjs } from './index.
|
|
49
|
+
import { v as version$1 } from './cac.BK306qhQ.js';
|
|
50
|
+
import { g as getDefaultExportFromCjs } from './index.Or9psEGe.js';
|
|
50
51
|
import require$$0 from 'readline';
|
|
51
52
|
import require$$0$1 from 'events';
|
|
52
53
|
|
|
@@ -637,8 +638,6 @@ function detectCodeBlock(content) {
|
|
|
637
638
|
};
|
|
638
639
|
}
|
|
639
640
|
|
|
640
|
-
const hash = crypto.hash ?? ((algorithm, data, outputEncoding) => crypto.createHash(algorithm).update(data).digest(outputEncoding));
|
|
641
|
-
|
|
642
641
|
class VitestResolver {
|
|
643
642
|
options;
|
|
644
643
|
externalizeConcurrentCache = /* @__PURE__ */ new Map();
|
|
@@ -877,7 +876,7 @@ function findRedirect(config, specifier, resolvedId) {
|
|
|
877
876
|
const id = resolvedId ?? specifier;
|
|
878
877
|
const moduleDirectories = config.deps.moduleDirectories ?? ["/node_modules/"];
|
|
879
878
|
const external = !isAbsolute(id) || moduleDirectories.some((dir) => id.includes(dir)) ? specifier : null;
|
|
880
|
-
return findMockRedirect(config.root, cleanUrl(id), external);
|
|
879
|
+
return findMockRedirect(config.root, cleanUrl(id), external, specifier);
|
|
881
880
|
}
|
|
882
881
|
|
|
883
882
|
const debugFs = createDebugger("vitest:cache:fs");
|
|
@@ -959,10 +958,13 @@ class ModuleTransformService {
|
|
|
959
958
|
if (moduleGraphModule.file) trace.setAttribute("code.file.path", moduleGraphModule.file);
|
|
960
959
|
if (options?.cached && cached) return { cache: true };
|
|
961
960
|
const externalize = await this.resolver.shouldExternalize(moduleGraphModule.id);
|
|
962
|
-
if (externalize)
|
|
963
|
-
externalize
|
|
964
|
-
|
|
965
|
-
|
|
961
|
+
if (externalize) {
|
|
962
|
+
if (this.fsCacheEnabled) this.fsCache.recordManifestExternal(this.config, environment, moduleGraphModule.url, externalize);
|
|
963
|
+
return {
|
|
964
|
+
externalize,
|
|
965
|
+
type: "module"
|
|
966
|
+
};
|
|
967
|
+
}
|
|
966
968
|
const cachePath = await this.getCachePath(environment, moduleGraphModule);
|
|
967
969
|
// full fs caching is disabled, but we still want to keep tmp files if makeTmpCopies is enabled
|
|
968
970
|
// this is primarily used by the forks pool to avoid using process.send(bigBuffer)
|
|
@@ -984,6 +986,7 @@ class ModuleTransformService {
|
|
|
984
986
|
return result;
|
|
985
987
|
});
|
|
986
988
|
}
|
|
989
|
+
this.fsCache.recordManifestModule(this.config, environment, moduleGraphModule.url, cachePath);
|
|
987
990
|
if (saveCachePromises.has(cachePath)) return saveCachePromises.get(cachePath).then((result) => {
|
|
988
991
|
this.recordResult(trace, result);
|
|
989
992
|
return result;
|
|
@@ -997,7 +1000,8 @@ class ModuleTransformService {
|
|
|
997
1000
|
const imports = this.getCachedImports(environment, moduleGraphModule);
|
|
998
1001
|
const map = moduleGraphModule.transformResult?.map;
|
|
999
1002
|
const mappings = map && !("version" in map) && map.mappings === "";
|
|
1000
|
-
const
|
|
1003
|
+
const coverageData = this.fsCache.getCoverageData(environment, moduleGraphModule.id);
|
|
1004
|
+
const cachedResult = await this.cacheResult(result, cachePath, moduleGraphModule.transformResult, imports, !!mappings, coverageData);
|
|
1001
1005
|
// remember where the code is stored on disk so that repeat fetches and the
|
|
1002
1006
|
// `fetchWarmModules` snapshot can point at it in this session already, not
|
|
1003
1007
|
// only after the cache is read back in the next one
|
|
@@ -1033,7 +1037,7 @@ class ModuleTransformService {
|
|
|
1033
1037
|
if ("code" in result) trace.setAttribute("vitest.fetched_module.code_length", result.code.length);
|
|
1034
1038
|
}
|
|
1035
1039
|
async getCachePath(environment, moduleGraphModule) {
|
|
1036
|
-
if (!this.fsCacheEnabled) return null;
|
|
1040
|
+
if (!this.fsCacheEnabled || this.fsCache.getCacheRoot(this.config) == null) return null;
|
|
1037
1041
|
const moduleId = moduleGraphModule.id;
|
|
1038
1042
|
const memoryCacheKey = this.fsCache.getMemoryCachePath(environment, moduleId);
|
|
1039
1043
|
// undefined means there is no key in memory
|
|
@@ -1073,8 +1077,11 @@ class ModuleTransformService {
|
|
|
1073
1077
|
if (!cachedModule) return;
|
|
1074
1078
|
const importedModules = await this.resolveCachedImports(environment, cachedModule);
|
|
1075
1079
|
if (!importedModules) return;
|
|
1080
|
+
if (cachedModule.file) this.fsCache.watchFile(cachedModule.file);
|
|
1081
|
+
// Notify coverage provider that cached results were read
|
|
1082
|
+
if (cachedModule.hasCoverageData) this.fsCache.restoreCoverageData(environment, cachedModule.id, cachedModule.coverageData);
|
|
1076
1083
|
// keep the module graph in sync
|
|
1077
|
-
let map =
|
|
1084
|
+
let map = cachedModule.sourceMap ? parseSourceMap(cachedModule.sourceMap) : null;
|
|
1078
1085
|
if (map && cachedModule.file) map.file = cachedModule.file;
|
|
1079
1086
|
// mappings is a special source map identifier in rollup
|
|
1080
1087
|
if (!map && cachedModule.mappings) map = { mappings: "" };
|
|
@@ -1087,7 +1094,8 @@ class ModuleTransformService {
|
|
|
1087
1094
|
dynamicDeps: cachedModule.dynamicDeps,
|
|
1088
1095
|
__vitestTmp: cachePath,
|
|
1089
1096
|
__vitestModuleType: moduleType,
|
|
1090
|
-
__vitestStaticMocks: cachedModule.staticMocks
|
|
1097
|
+
__vitestStaticMocks: cachedModule.staticMocks,
|
|
1098
|
+
__vitestSourceMap: cachedModule.sourceMap ?? null
|
|
1091
1099
|
};
|
|
1092
1100
|
// we populate the module graph to make the watch mode work because it relies on importers
|
|
1093
1101
|
if (importer) {
|
|
@@ -1153,10 +1161,10 @@ class ModuleTransformService {
|
|
|
1153
1161
|
if (transformResult) transformResult.__vitestModuleType = moduleType;
|
|
1154
1162
|
return moduleType;
|
|
1155
1163
|
}
|
|
1156
|
-
async cacheResult(result, cachePath, transformResult, imports, mappings = false) {
|
|
1164
|
+
async cacheResult(result, cachePath, transformResult, imports, mappings = false, coverageData) {
|
|
1157
1165
|
const returnResult = "code" in result ? getCachedResult(result, cachePath) : result;
|
|
1158
1166
|
if (saveCachePromises.has(cachePath)) return saveCachePromises.get(cachePath);
|
|
1159
|
-
const savePromise = this.fsCache.saveCachedModule(cachePath, result, transformResult, imports, mappings).then(() => returnResult).catch((error) => {
|
|
1167
|
+
const savePromise = this.fsCache.saveCachedModule(cachePath, result, transformResult, imports, mappings, coverageData).then(() => returnResult).catch((error) => {
|
|
1160
1168
|
debugFs?.(`failed to cache ${cachePath}, serving it inline: ${error}`);
|
|
1161
1169
|
return result;
|
|
1162
1170
|
}).finally(() => {
|
|
@@ -1192,41 +1200,38 @@ function getSafeModulePaths(environment) {
|
|
|
1192
1200
|
}
|
|
1193
1201
|
let SOURCEMAPPING_URL = "sourceMa";
|
|
1194
1202
|
SOURCEMAPPING_URL += "ppingURL";
|
|
1195
|
-
|
|
1203
|
+
// the source map is sent next to the code, so V8 doesn't compile it with every module
|
|
1196
1204
|
function processResultSource(environment, result) {
|
|
1197
1205
|
if (!("code" in result)) return result;
|
|
1198
1206
|
const node = environment.moduleGraph.getModuleById(result.id);
|
|
1199
|
-
|
|
1200
|
-
// this also overrides node.transformResult.code which is also what the module
|
|
1201
|
-
// runner does under the hood by default (we disable source maps inlining)
|
|
1202
|
-
inlineSourceMap(node.transformResult);
|
|
1207
|
+
const sourceMap = node?.transformResult ? getSourceMap(node.transformResult) : void 0;
|
|
1203
1208
|
return {
|
|
1204
1209
|
...result,
|
|
1205
|
-
code: node?.transformResult?.code || result.code
|
|
1210
|
+
code: node?.transformResult?.code || result.code,
|
|
1211
|
+
sourceMap
|
|
1206
1212
|
};
|
|
1207
1213
|
}
|
|
1208
1214
|
const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,([A-Za-z0-9+/=]+)$`, "gm");
|
|
1209
|
-
// we
|
|
1215
|
+
// we don't let Vite inline the source map, because
|
|
1210
1216
|
// - we don't need //# sourceURL since we are running code in VM
|
|
1211
1217
|
// - important in stack traces and the V8 coverage
|
|
1212
1218
|
// - we need to inject an empty line for --inspect-brk
|
|
1213
|
-
function
|
|
1219
|
+
function getSourceMap(result) {
|
|
1220
|
+
if (result.__vitestSourceMap !== void 0) return result.__vitestSourceMap ?? void 0;
|
|
1214
1221
|
const map = result.map;
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1222
|
+
if (!map || !("version" in map)) {
|
|
1223
|
+
result.__vitestSourceMap = null;
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
// to reduce the payload size, we only keep vite node source map, because it's also the only one we use
|
|
1218
1227
|
OTHER_SOURCE_MAP_REGEXP.lastIndex = 0;
|
|
1219
|
-
if (OTHER_SOURCE_MAP_REGEXP.test(code)) code = code.replace(OTHER_SOURCE_MAP_REGEXP, "");
|
|
1228
|
+
if (OTHER_SOURCE_MAP_REGEXP.test(result.code)) result.code = result.code.replace(OTHER_SOURCE_MAP_REGEXP, "");
|
|
1220
1229
|
const sourceMap = { ...map };
|
|
1221
1230
|
// If the first line is not present on source maps, add simple 1:1 mapping ([0,0,0,0], [1,0,0,0])
|
|
1222
1231
|
// so that debuggers can be set to break on first line
|
|
1223
1232
|
if (sourceMap.mappings[0] === ";") sourceMap.mappings = `AAAA,CAAA${sourceMap.mappings}`;
|
|
1224
|
-
result.
|
|
1225
|
-
return result;
|
|
1226
|
-
}
|
|
1227
|
-
function genSourceMapUrl(map) {
|
|
1228
|
-
if (typeof map !== "string") map = JSON.stringify(map);
|
|
1229
|
-
return `data:application/json;base64,${Buffer.from(map).toString("base64")}`;
|
|
1233
|
+
result.__vitestSourceMap = JSON.stringify(sourceMap);
|
|
1234
|
+
return result.__vitestSourceMap;
|
|
1230
1235
|
}
|
|
1231
1236
|
function getCachedResult(result, tmp) {
|
|
1232
1237
|
return {
|
|
@@ -1239,15 +1244,9 @@ function getCachedResult(result, tmp) {
|
|
|
1239
1244
|
moduleType: result.moduleType
|
|
1240
1245
|
};
|
|
1241
1246
|
}
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
const lastIndex = code.lastIndexOf(pattern);
|
|
1246
|
-
if (lastIndex === -1) return null;
|
|
1247
|
-
const mapString = MODULE_RUNNER_SOURCEMAPPING_REGEXP.exec(code.slice(lastIndex))?.[1];
|
|
1248
|
-
if (!mapString) return null;
|
|
1249
|
-
const sourceMap = JSON.parse(Buffer.from(mapString, "base64").toString("utf-8"));
|
|
1250
|
-
// remove source map mapping added by "inlineSourceMap" to keep the original behaviour of transformRequest
|
|
1247
|
+
function parseSourceMap(map) {
|
|
1248
|
+
const sourceMap = JSON.parse(map);
|
|
1249
|
+
// remove source map mapping added by "getSourceMap" to keep the original behaviour of transformRequest
|
|
1251
1250
|
if (sourceMap.mappings.startsWith("AAAA,CAAA;"))
|
|
1252
1251
|
// 9 because we want to only remove "AAAA,CAAA", but keep ; at the start
|
|
1253
1252
|
sourceMap.mappings = sourceMap.mappings.slice(9);
|
|
@@ -1289,6 +1288,26 @@ function isTestFunctionName(name) {
|
|
|
1289
1288
|
function isVitestFunctionName(name) {
|
|
1290
1289
|
return name === "describe" || name === "suite" || isTestFunctionName(name);
|
|
1291
1290
|
}
|
|
1291
|
+
function isStringNode(node) {
|
|
1292
|
+
return node.type === "Literal" && typeof node.value === "string" || node.type === "TemplateLiteral" || node.type === "BinaryExpression" && node.operator === "+" && (isStringNode(node.left) || isStringNode(node.right));
|
|
1293
|
+
}
|
|
1294
|
+
function isNumberNode(node) {
|
|
1295
|
+
return node.type === "Literal" && typeof node.value === "number" || node.type === "UnaryExpression" && node.operator === "-" && isNumberNode(node.argument);
|
|
1296
|
+
}
|
|
1297
|
+
function isTaskNameNode(node) {
|
|
1298
|
+
switch (node.type) {
|
|
1299
|
+
case "Identifier":
|
|
1300
|
+
case "MemberExpression": return true;
|
|
1301
|
+
case "ConditionalExpression": return isTaskNameNode(node.consequent) && isTaskNameNode(node.alternate);
|
|
1302
|
+
case "LogicalExpression": return node.operator !== "&&" && isTaskNameNode(node.left) && isTaskNameNode(node.right);
|
|
1303
|
+
// an imported binding is transformed into `(0, __vite_ssr_import_0__.name)`
|
|
1304
|
+
case "SequenceExpression": {
|
|
1305
|
+
const [e0, e1] = node.expressions;
|
|
1306
|
+
return node.expressions.length === 2 && e0.type === "Literal" && e0.value === 0 && isTaskNameNode(e1);
|
|
1307
|
+
}
|
|
1308
|
+
default: return isStringNode(node) || isNumberNode(node);
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1292
1311
|
function astParseFile(filepath, code) {
|
|
1293
1312
|
const ast = parseAst(code);
|
|
1294
1313
|
if (verbose) verbose("Collecting", filepath, code);
|
|
@@ -1351,12 +1370,13 @@ function astParseFile(filepath, code) {
|
|
|
1351
1370
|
if (callee.type === "CallExpression" || callee.type === "SequenceExpression" || callee.type === "TaggedTemplateExpression") start = callee.end;
|
|
1352
1371
|
else start = node.start;
|
|
1353
1372
|
const messageNode = node.arguments?.[0];
|
|
1354
|
-
if (messageNode == null) {
|
|
1373
|
+
if (messageNode == null || !isTaskNameNode(messageNode)) {
|
|
1355
1374
|
verbose?.(`Skipping node at ${node.start} because it doesn't have a name`);
|
|
1356
1375
|
return;
|
|
1357
1376
|
}
|
|
1358
1377
|
let message;
|
|
1359
|
-
if (messageNode
|
|
1378
|
+
if (messageNode.type === "Literal" && typeof messageNode.value === "number") message = String(messageNode.value);
|
|
1379
|
+
else if (messageNode.type === "Literal" || messageNode.type === "TemplateLiteral") message = code.slice(messageNode.start + 1, messageNode.end - 1);
|
|
1360
1380
|
else {
|
|
1361
1381
|
message = code.slice(messageNode.start, messageNode.end);
|
|
1362
1382
|
if (message.endsWith(".name")) message = message.slice(0, -5);
|
|
@@ -1838,7 +1858,7 @@ async function createClusterServer(vitest, viteConfig, config, children) {
|
|
|
1838
1858
|
const contribution = config._browserContribution;
|
|
1839
1859
|
if (!contribution) {
|
|
1840
1860
|
const server = await createViteServer(viteConfig);
|
|
1841
|
-
if (config.api.port) await server.listen(config.api.port);
|
|
1861
|
+
if (config.api.port != null) await server.listen(config.api.port);
|
|
1842
1862
|
return { server };
|
|
1843
1863
|
}
|
|
1844
1864
|
const parent = contribution.createParent({
|
|
@@ -2838,6 +2858,8 @@ function stripLiteral(code, options) {
|
|
|
2838
2858
|
return result;
|
|
2839
2859
|
}
|
|
2840
2860
|
|
|
2861
|
+
// `=`, `||=`, `??=`, `+=`, etc., but not `==` or `===`
|
|
2862
|
+
const ASSIGNMENT_RE = /\s*(?:\*\*|<<|>>>?|&&|\|\||\?\?|[-+*/%&|^])?=(?!=)/y;
|
|
2841
2863
|
// so people can reassign envs at runtime
|
|
2842
2864
|
// import.meta.env.VITE_NAME = 'app' -> process.env.VITE_NAME = 'app'
|
|
2843
2865
|
function MetaEnvReplacerPlugin() {
|
|
@@ -2847,11 +2869,17 @@ function MetaEnvReplacerPlugin() {
|
|
|
2847
2869
|
transform(code, id) {
|
|
2848
2870
|
if (!/\bimport\.meta\.env\b/.test(code)) return null;
|
|
2849
2871
|
let s = null;
|
|
2850
|
-
const
|
|
2872
|
+
const cleanCode = stripLiteral(code);
|
|
2873
|
+
const envs = cleanCode.matchAll(/\bimport\.meta\.env\b/g);
|
|
2851
2874
|
for (const env of envs) {
|
|
2852
|
-
s ||= new MagicString(code);
|
|
2853
2875
|
const startIndex = env.index;
|
|
2854
2876
|
const endIndex = startIndex + env[0].length;
|
|
2877
|
+
// `import.meta.env = ...` is left as is, since `Object.assign(...) = ...`
|
|
2878
|
+
// is not a valid assignment target. Reads and property writes like
|
|
2879
|
+
// `import.meta.env.FOO = 1` are still rewritten.
|
|
2880
|
+
ASSIGNMENT_RE.lastIndex = endIndex;
|
|
2881
|
+
if (ASSIGNMENT_RE.test(cleanCode)) continue;
|
|
2882
|
+
s ||= new MagicString(code);
|
|
2855
2883
|
s.overwrite(startIndex, endIndex, `Object.assign(/* istanbul ignore next */ globalThis.__vitest_worker__?.metaEnv ?? import.meta.env)`);
|
|
2856
2884
|
}
|
|
2857
2885
|
if (s) return {
|
|
@@ -3075,8 +3103,9 @@ Possible solutions:
|
|
|
3075
3103
|
return typesErrors;
|
|
3076
3104
|
}
|
|
3077
3105
|
async stop() {
|
|
3078
|
-
this.process
|
|
3106
|
+
const child = this.process;
|
|
3079
3107
|
this.process = void 0;
|
|
3108
|
+
if (child) await killProcessTree(child);
|
|
3080
3109
|
}
|
|
3081
3110
|
async ensurePackageInstalled(ctx, checker) {
|
|
3082
3111
|
if (checker !== "tsc" && checker !== "vue-tsc") return;
|
|
@@ -3244,6 +3273,24 @@ function findGeneratedPosition(traceMap, { line, column, source }) {
|
|
|
3244
3273
|
column: null
|
|
3245
3274
|
};
|
|
3246
3275
|
}
|
|
3276
|
+
function killProcessTree(child) {
|
|
3277
|
+
// on Windows the checker runs behind a `cmd.exe` shim, and `kill()` stops only the shim
|
|
3278
|
+
if (process.platform !== "win32" || child.pid == null || child.exitCode != null) {
|
|
3279
|
+
child.kill();
|
|
3280
|
+
return Promise.resolve();
|
|
3281
|
+
}
|
|
3282
|
+
return new Promise((resolve) => {
|
|
3283
|
+
execFile("taskkill", [
|
|
3284
|
+
"/pid",
|
|
3285
|
+
String(child.pid),
|
|
3286
|
+
"/T",
|
|
3287
|
+
"/F"
|
|
3288
|
+
], { windowsHide: true }, (error) => {
|
|
3289
|
+
if (error) child.kill();
|
|
3290
|
+
resolve();
|
|
3291
|
+
});
|
|
3292
|
+
});
|
|
3293
|
+
}
|
|
3247
3294
|
|
|
3248
3295
|
// use Logger with custom Console to capture entire error printing
|
|
3249
3296
|
function capturePrintError(error, ctx, options) {
|
|
@@ -3575,21 +3622,23 @@ class ServerModuleRunner extends ModuleRunner {
|
|
|
3575
3622
|
constructor(environment, transformService, config) {
|
|
3576
3623
|
super({
|
|
3577
3624
|
hmr: false,
|
|
3625
|
+
evaluatedModules: new VitestEvaluatedModules(),
|
|
3578
3626
|
transport: { async invoke(event) {
|
|
3579
3627
|
if (event.type !== "custom") throw new Error(`Vitest Module Runner doesn't support Vite HMR events.`);
|
|
3580
3628
|
const { name, data } = event.data;
|
|
3581
3629
|
if (name === "getBuiltins") return await environment.hot.handleInvoke(event);
|
|
3582
3630
|
if (name !== "fetchModule") return { error: /* @__PURE__ */ new Error(`Unknown method: ${name}. Expected "fetchModule".`) };
|
|
3583
3631
|
try {
|
|
3584
|
-
|
|
3632
|
+
let result = await transformService.fetch(data[0], data[1], environment, false, data[2]);
|
|
3585
3633
|
if ("tmp" in result) {
|
|
3586
|
-
const code = await readFile(result.tmp);
|
|
3587
|
-
|
|
3634
|
+
const { code, sourceMap } = splitSourceMap(await readFile(result.tmp, "utf-8"));
|
|
3635
|
+
result = {
|
|
3588
3636
|
...result,
|
|
3589
|
-
code
|
|
3590
|
-
|
|
3637
|
+
code,
|
|
3638
|
+
sourceMap
|
|
3639
|
+
};
|
|
3591
3640
|
}
|
|
3592
|
-
return { result };
|
|
3641
|
+
return { result: config.inspector.openInMainProcess ? withInlineSourceMap(result) : result };
|
|
3593
3642
|
} catch (error) {
|
|
3594
3643
|
return { error };
|
|
3595
3644
|
}
|
|
@@ -3869,7 +3918,7 @@ function processWildcard(dep, moduleDirectories) {
|
|
|
3869
3918
|
if (typeof dep !== "string") return dep;
|
|
3870
3919
|
if (typeof dep === "string" && dep.includes("*")) {
|
|
3871
3920
|
const directories = (moduleDirectories || ["/node_modules/"]).map((r) => escapeRegExp(r));
|
|
3872
|
-
return new RegExp(`(${directories.join("|")})${dep.
|
|
3921
|
+
return new RegExp(`(${directories.join("|")})${escapeRegExp(dep).replaceAll("\\*", "[\\w/.-]+")}`);
|
|
3873
3922
|
}
|
|
3874
3923
|
return dep;
|
|
3875
3924
|
}
|
|
@@ -4147,6 +4196,8 @@ function serializeConfig(project) {
|
|
|
4147
4196
|
viteModuleRunner: config.experimental.viteModuleRunner ?? true,
|
|
4148
4197
|
nodeLoader: config.experimental.nodeLoader ?? true,
|
|
4149
4198
|
recordDependencies: !!globalConfig.experimental.recordDependencies && !!globalConfig.cache,
|
|
4199
|
+
// browser mode records its own trace through `browser.traceView`
|
|
4200
|
+
traceTimeline: !!config.experimental.traceTimeline && !config.browser.enabled,
|
|
4150
4201
|
openTelemetry: config.experimental.openTelemetry
|
|
4151
4202
|
},
|
|
4152
4203
|
tags: config.tags || [],
|
|
@@ -4406,6 +4457,16 @@ function createBrowserPool(vitest) {
|
|
|
4406
4457
|
isCancelled = true;
|
|
4407
4458
|
cancel();
|
|
4408
4459
|
});
|
|
4460
|
+
// an invalidated module keeps its url, so a browser context that cached it
|
|
4461
|
+
// in an earlier run would serve the old code
|
|
4462
|
+
if (vitest._browserCacheStale) {
|
|
4463
|
+
vitest._browserCacheStale = false;
|
|
4464
|
+
// runs don't overlap (`runFiles` waits for the previous one), so no worker should be
|
|
4465
|
+
// active here; the check only keeps a running worker from being stopped
|
|
4466
|
+
Array.from(workers.values()).filter((worker) => !activeWorkers.has(worker)).forEach((worker) => stopWorker(worker));
|
|
4467
|
+
await Promise.all(exitPromises);
|
|
4468
|
+
if (isCancelled) return;
|
|
4469
|
+
}
|
|
4409
4470
|
const groupedFiles = await groupSpecifications(specs);
|
|
4410
4471
|
const tasks = await Promise.all(Array.from(groupedFiles.entries(), async ([project, files]) => {
|
|
4411
4472
|
await project._initBrowserProvider();
|
|
@@ -4869,13 +4930,7 @@ const warmExternals = /* @__PURE__ */ new WeakMap();
|
|
|
4869
4930
|
function createMethodsRPC(project, methodsOptions = {}) {
|
|
4870
4931
|
const vitest = project.vitest;
|
|
4871
4932
|
const cacheFs = methodsOptions.cacheFs ?? false;
|
|
4872
|
-
project.vitest.state.metadata[project.name] ??= {
|
|
4873
|
-
externalized: {},
|
|
4874
|
-
duration: {},
|
|
4875
|
-
tmps: {}
|
|
4876
|
-
};
|
|
4877
|
-
if (project.config.dumpDir && !existsSync(project.config.dumpDir)) mkdirSync(project.config.dumpDir, { recursive: true });
|
|
4878
|
-
project.vitest.state.metadata[project.name].dumpDir = project.config.dumpDir;
|
|
4933
|
+
project.vitest.state.metadata[project.name] ??= { duration: {} };
|
|
4879
4934
|
function getEnvironment(environmentName) {
|
|
4880
4935
|
const environment = project.vite.environments[environmentName];
|
|
4881
4936
|
if (!environment) throw new Error(`The environment ${environmentName} was not defined in the Vite config.`);
|
|
@@ -4887,7 +4942,6 @@ function createMethodsRPC(project, methodsOptions = {}) {
|
|
|
4887
4942
|
return await project._transformService.fetch(url, importer, environment, cacheFs, options, otelCarrier).then((result) => {
|
|
4888
4943
|
const metadata = state.metadata[project.name];
|
|
4889
4944
|
if ("externalize" in result) {
|
|
4890
|
-
metadata.externalized[url] = result.externalize;
|
|
4891
4945
|
// builtins and network urls are already resolved inside the worker
|
|
4892
4946
|
// without a round-trip, only module externalizations are worth sharing
|
|
4893
4947
|
if (result.type === "module" && url[0] === "/") {
|
|
@@ -4899,7 +4953,6 @@ function createMethodsRPC(project, methodsOptions = {}) {
|
|
|
4899
4953
|
externals[url] = result;
|
|
4900
4954
|
}
|
|
4901
4955
|
}
|
|
4902
|
-
if ("tmp" in result) metadata.tmps[url] = result.tmp;
|
|
4903
4956
|
if (accountModuleDuration) {
|
|
4904
4957
|
const duration = performance.now() - start;
|
|
4905
4958
|
metadata.duration[url] ??= [];
|
|
@@ -5435,6 +5488,60 @@ class PoolRunner {
|
|
|
5435
5488
|
}
|
|
5436
5489
|
}
|
|
5437
5490
|
|
|
5491
|
+
let watchdog;
|
|
5492
|
+
const watched = /* @__PURE__ */ new Set();
|
|
5493
|
+
function watchProcess(child, distPath) {
|
|
5494
|
+
const pid = child.pid;
|
|
5495
|
+
if (pid == null) return;
|
|
5496
|
+
watchdog ??= startWatchdog(distPath);
|
|
5497
|
+
watched.add(pid);
|
|
5498
|
+
send({
|
|
5499
|
+
type: "watch",
|
|
5500
|
+
pid
|
|
5501
|
+
});
|
|
5502
|
+
child.once("exit", () => {
|
|
5503
|
+
watched.delete(pid);
|
|
5504
|
+
send({
|
|
5505
|
+
type: "unwatch",
|
|
5506
|
+
pid
|
|
5507
|
+
});
|
|
5508
|
+
});
|
|
5509
|
+
}
|
|
5510
|
+
function stopWatchdog() {
|
|
5511
|
+
if (watchdog && watched.size === 0) {
|
|
5512
|
+
watchdog.disconnect();
|
|
5513
|
+
watchdog = void 0;
|
|
5514
|
+
}
|
|
5515
|
+
}
|
|
5516
|
+
function send(message) {
|
|
5517
|
+
if (watchdog?.connected) watchdog.send(message);
|
|
5518
|
+
}
|
|
5519
|
+
function startWatchdog(distPath) {
|
|
5520
|
+
/** Loads {@link file://./../../runtime/workers/watchdog.ts} */
|
|
5521
|
+
const child = fork(resolve$1(distPath, "workers/watchdog.js"), [], {
|
|
5522
|
+
stdio: [
|
|
5523
|
+
"ignore",
|
|
5524
|
+
"ignore",
|
|
5525
|
+
"ignore",
|
|
5526
|
+
"ipc"
|
|
5527
|
+
],
|
|
5528
|
+
execArgv: [],
|
|
5529
|
+
env: {
|
|
5530
|
+
...process.env,
|
|
5531
|
+
NODE_OPTIONS: void 0
|
|
5532
|
+
}
|
|
5533
|
+
});
|
|
5534
|
+
// must never keep the main process alive
|
|
5535
|
+
child.unref();
|
|
5536
|
+
child.channel?.unref();
|
|
5537
|
+
// losing the watchdog only loses the cleanup, the test run is not affected
|
|
5538
|
+
child.on("error", () => {});
|
|
5539
|
+
child.once("exit", () => {
|
|
5540
|
+
if (watchdog === child) watchdog = void 0;
|
|
5541
|
+
});
|
|
5542
|
+
return child;
|
|
5543
|
+
}
|
|
5544
|
+
|
|
5438
5545
|
// After a worker dies, its remaining stdio is drained into the parent-side
|
|
5439
5546
|
// readables asynchronously. Waiting for `end`/`close` before unpiping ensures
|
|
5440
5547
|
// the tail of the output still reaches the shared logger streams.
|
|
@@ -5457,6 +5564,7 @@ class ForksPoolWorker {
|
|
|
5457
5564
|
entrypoint;
|
|
5458
5565
|
execArgv;
|
|
5459
5566
|
env;
|
|
5567
|
+
distPath;
|
|
5460
5568
|
_fork;
|
|
5461
5569
|
stdout;
|
|
5462
5570
|
stderr;
|
|
@@ -5467,6 +5575,7 @@ class ForksPoolWorker {
|
|
|
5467
5575
|
this.env = options.env;
|
|
5468
5576
|
this.stdout = options.project.vitest.logger.outputStream;
|
|
5469
5577
|
this.stderr = options.project.vitest.logger.errorStream;
|
|
5578
|
+
this.distPath = options.distPath;
|
|
5470
5579
|
/** Loads {@link file://./../../../runtime/workers/forks.ts} */
|
|
5471
5580
|
this.entrypoint = resolve$1(options.distPath, "workers/forks.js");
|
|
5472
5581
|
}
|
|
@@ -5489,6 +5598,7 @@ class ForksPoolWorker {
|
|
|
5489
5598
|
serialization: "advanced"
|
|
5490
5599
|
});
|
|
5491
5600
|
this._fork.on("error", this.emitError);
|
|
5601
|
+
watchProcess(this._fork, this.distPath);
|
|
5492
5602
|
// `end: false`: the logger streams are shared by every worker, so one
|
|
5493
5603
|
// ending worker stream must not end them for everyone else
|
|
5494
5604
|
if (this._fork.stdout) {
|
|
@@ -5935,7 +6045,7 @@ class Pool {
|
|
|
5935
6045
|
await resolver.promise.catch((error) => span?.recordException(error)).finally(() => span?.end());
|
|
5936
6046
|
const index = this.activeTasks.indexOf(activeTask);
|
|
5937
6047
|
if (index !== -1) this.activeTasks.splice(index, 1);
|
|
5938
|
-
if (!task.isolate &&
|
|
6048
|
+
if (!task.isolate && runner.isStarted && !isMemoryLimitReached && this.queue[0]?.task.isolate === false && isEqualRunner(runner, this.queue[0].task)) {
|
|
5939
6049
|
this.sharedRunners.push(runner);
|
|
5940
6050
|
return this.schedule();
|
|
5941
6051
|
}
|
|
@@ -5976,6 +6086,7 @@ catch (error) {
|
|
|
5976
6086
|
}
|
|
5977
6087
|
async close() {
|
|
5978
6088
|
await this.cancel();
|
|
6089
|
+
stopWatchdog();
|
|
5979
6090
|
}
|
|
5980
6091
|
getPoolRunner(task, method) {
|
|
5981
6092
|
if (task.isolate === false) {
|
|
@@ -6075,20 +6186,13 @@ function createPool(ctx) {
|
|
|
6075
6186
|
state: ctx.state
|
|
6076
6187
|
}, ctx.logger);
|
|
6077
6188
|
const options = resolveOptions(ctx);
|
|
6078
|
-
const Sequencer = ctx.config.sequence.sequencer;
|
|
6079
|
-
const sequencer = new Sequencer(ctx);
|
|
6080
6189
|
let browserPool;
|
|
6081
6190
|
async function executeTests(method, specs, invalidates) {
|
|
6082
6191
|
ctx.onCancel(() => pool.cancel());
|
|
6083
|
-
if (ctx.config.shard) {
|
|
6084
|
-
if (!ctx.config.passWithNoTests && ctx.config.shard.count > specs.length) throw new Error(`--shard <count> must be a smaller than count of test files. Resolved ${specs.length} test files for --shard=${ctx.config.shard.index}/${ctx.config.shard.count}.`);
|
|
6085
|
-
specs = await sequencer.shard(Array.from(specs));
|
|
6086
|
-
}
|
|
6087
6192
|
const taskGroups = [];
|
|
6088
6193
|
let workerId = 1;
|
|
6089
|
-
const sorted = await sequencer.sort(specs);
|
|
6090
6194
|
const { environments, tags } = await getSpecificationsOptions(specs);
|
|
6091
|
-
const groups = groupSpecs(
|
|
6195
|
+
const groups = groupSpecs(specs, environments);
|
|
6092
6196
|
const projectEnvs = /* @__PURE__ */ new WeakMap();
|
|
6093
6197
|
const projectExecArgvs = /* @__PURE__ */ new WeakMap();
|
|
6094
6198
|
for (const group of groups) {
|
|
@@ -6151,6 +6255,7 @@ function createPool(ctx) {
|
|
|
6151
6255
|
testNames: spec.testNames,
|
|
6152
6256
|
testTagsFilter: spec.testTagsFilter
|
|
6153
6257
|
})),
|
|
6258
|
+
// Vitest's own pools don't read it, but a custom pool whose worker outlives a run can use it
|
|
6154
6259
|
invalidates,
|
|
6155
6260
|
providedContext: project.getProvidedContext(),
|
|
6156
6261
|
workerId: workerId++,
|
|
@@ -6354,6 +6459,30 @@ async function globProjectTestFiles(include, exclude, includeSource, cwd) {
|
|
|
6354
6459
|
}
|
|
6355
6460
|
return testFiles;
|
|
6356
6461
|
}
|
|
6462
|
+
/**
|
|
6463
|
+
* Keep the test files that match the CLI filters. With no filters, every file matches.
|
|
6464
|
+
*/
|
|
6465
|
+
function filterTestFiles(testFiles, filters, dir) {
|
|
6466
|
+
if (!filters.length) return testFiles;
|
|
6467
|
+
if (process.platform === "win32") filters = filters.map((f) => slash(f));
|
|
6468
|
+
const patterns = filters.map((f) => {
|
|
6469
|
+
const relativePath = f.endsWith("/") ? join(relative(dir, f), "/") : relative(dir, f);
|
|
6470
|
+
return {
|
|
6471
|
+
filter: f,
|
|
6472
|
+
isAbsolute: isAbsolute(f),
|
|
6473
|
+
lowerCase: f.toLocaleLowerCase(),
|
|
6474
|
+
relativeLowerCase: relativePath.toLocaleLowerCase()
|
|
6475
|
+
};
|
|
6476
|
+
});
|
|
6477
|
+
return testFiles.filter((t) => {
|
|
6478
|
+
const testFile = relative(dir, t).toLocaleLowerCase();
|
|
6479
|
+
return patterns.some((p) => {
|
|
6480
|
+
// if filter is a full file path, we should include it if it's in the same folder
|
|
6481
|
+
if (p.isAbsolute && t.startsWith(p.filter)) return true;
|
|
6482
|
+
return testFile.includes(p.lowerCase) || testFile.includes(p.relativeLowerCase);
|
|
6483
|
+
});
|
|
6484
|
+
});
|
|
6485
|
+
}
|
|
6357
6486
|
|
|
6358
6487
|
class TestSpecification {
|
|
6359
6488
|
/**
|
|
@@ -6610,8 +6739,8 @@ class TestProject {
|
|
|
6610
6739
|
const [testFiles, typecheckTestFiles] = await Promise.all([typecheck.enabled && typecheck.only ? [] : this.globAllTestFiles(include, exclude, includeSource, dir), typecheck.enabled ? this.typecheckFilesList || this.globFiles(typecheck.include, typecheck.exclude, dir) : []]);
|
|
6611
6740
|
this.typecheckFilesList = typecheckTestFiles;
|
|
6612
6741
|
return {
|
|
6613
|
-
testFiles:
|
|
6614
|
-
typecheckTestFiles:
|
|
6742
|
+
testFiles: filterTestFiles(testFiles, filters, dir),
|
|
6743
|
+
typecheckTestFiles: filterTestFiles(typecheckTestFiles, filters, dir)
|
|
6615
6744
|
};
|
|
6616
6745
|
});
|
|
6617
6746
|
}
|
|
@@ -6669,19 +6798,6 @@ class TestProject {
|
|
|
6669
6798
|
}
|
|
6670
6799
|
return false;
|
|
6671
6800
|
}
|
|
6672
|
-
filterFiles(testFiles, filters, dir) {
|
|
6673
|
-
if (filters.length && process.platform === "win32") filters = filters.map((f) => slash(f));
|
|
6674
|
-
if (filters.length) return testFiles.filter((t) => {
|
|
6675
|
-
const testFile = relative(dir, t).toLocaleLowerCase();
|
|
6676
|
-
return filters.some((f) => {
|
|
6677
|
-
// if filter is a full file path, we should include it if it's in the same folder
|
|
6678
|
-
if (isAbsolute(f) && t.startsWith(f)) return true;
|
|
6679
|
-
const relativePath = f.endsWith("/") ? join(relative(dir, f), "/") : relative(dir, f);
|
|
6680
|
-
return testFile.includes(f.toLocaleLowerCase()) || testFile.includes(relativePath.toLocaleLowerCase());
|
|
6681
|
-
});
|
|
6682
|
-
});
|
|
6683
|
-
return testFiles;
|
|
6684
|
-
}
|
|
6685
6801
|
/**
|
|
6686
6802
|
* The parent browser project that owns this cluster's single Vite server.
|
|
6687
6803
|
* Set on the primary (the hidden parent of a browser cluster) at server
|
|
@@ -6962,10 +7078,10 @@ async function resolveProjectEntries(harness, globalViteConfig, globalConfig, de
|
|
|
6962
7078
|
`The projects definition: ${JSON.stringify(definitions.map((p, index) => typeof p === "string" ? p : p instanceof Promise ? "Promise" : typeof p === "function" ? p.name : { name: p.test?.name ?? index }), null, 4)}.`
|
|
6963
7079
|
].join(""));
|
|
6964
7080
|
debug?.(`resolved projects: ${filtered.filter((e) => !e.hidden).map((e) => projectLabel(e.projectConfig.name)).join(", ")}`);
|
|
6965
|
-
await applyBrowserOptimizeDeps(harness, filtered);
|
|
7081
|
+
await applyBrowserOptimizeDeps(harness, filtered, globalConfig._cliFilters ?? []);
|
|
6966
7082
|
return filtered;
|
|
6967
7083
|
}
|
|
6968
|
-
async function applyBrowserOptimizeDeps(harness, entries) {
|
|
7084
|
+
async function applyBrowserOptimizeDeps(harness, entries, cliFilters) {
|
|
6969
7085
|
const groups = /* @__PURE__ */ new Map();
|
|
6970
7086
|
for (const entry of entries) {
|
|
6971
7087
|
const { viteConfig } = entry;
|
|
@@ -7001,7 +7117,8 @@ async function applyBrowserOptimizeDeps(harness, entries) {
|
|
|
7001
7117
|
if (!contribution) return;
|
|
7002
7118
|
const fileLists = await Promise.all(projectConfigs.map(globTestFiles));
|
|
7003
7119
|
projectEntries.forEach((entry, index) => {
|
|
7004
|
-
|
|
7120
|
+
const config = projectConfigs[index];
|
|
7121
|
+
entry.hasTestFiles = filterTestFiles(fileLists[index], cliFilters, config.dir || config.root).length > 0;
|
|
7005
7122
|
});
|
|
7006
7123
|
const testFiles = [...new Set(fileLists.flat())];
|
|
7007
7124
|
debug?.(`aggregating browser optimizeDeps from ${testFiles.length} test files of ${projectEntries.map((e) => projectLabel(e.projectConfig.name)).join(", ")}`);
|
|
@@ -7588,7 +7705,7 @@ async function resolveTestProjectConfigs(parentViteConfig, parentConfig, project
|
|
|
7588
7705
|
// directories that don't have a config file inside, but should be treated as projects
|
|
7589
7706
|
const nonConfigProjectDirectories = [];
|
|
7590
7707
|
for (const definition of projectsDefinition) if (typeof definition === "string") {
|
|
7591
|
-
const stringOption = definition.replace("<rootDir>", parentConfig.root);
|
|
7708
|
+
const stringOption = definition.replace("<rootDir>", () => parentConfig.root);
|
|
7592
7709
|
// if the string doesn't contain a glob, we can resolve it directly
|
|
7593
7710
|
// ['./vitest.config.js']
|
|
7594
7711
|
if (!isDynamicPattern(stringOption)) {
|
|
@@ -7849,9 +7966,18 @@ async function getFileSizes(files) {
|
|
|
7849
7966
|
class RandomSequencer extends BaseSequencer {
|
|
7850
7967
|
async sort(files) {
|
|
7851
7968
|
const { sequence } = this.ctx.config;
|
|
7852
|
-
|
|
7969
|
+
// the glob order can change between runs, so only the seed may decide the order
|
|
7970
|
+
const sorted = [...files].sort(compareSpecifications);
|
|
7971
|
+
return shuffle(sorted, sequence.seed);
|
|
7853
7972
|
}
|
|
7854
7973
|
}
|
|
7974
|
+
function compareSpecifications(a, b) {
|
|
7975
|
+
return compareStrings(a.project.name, b.project.name) || compareStrings(a.moduleId, b.moduleId) || compareStrings(a.pool, b.pool);
|
|
7976
|
+
}
|
|
7977
|
+
// `localeCompare` depends on the locale of the machine, which makes `--seed` unreproducible
|
|
7978
|
+
function compareStrings(a, b) {
|
|
7979
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
7980
|
+
}
|
|
7855
7981
|
|
|
7856
7982
|
var jsTokens_1;
|
|
7857
7983
|
var hasRequiredJsTokens;
|
|
@@ -8537,18 +8663,14 @@ class Logger {
|
|
|
8537
8663
|
this.log(withLabel(color, mode, `v${this.ctx.version} `) + $.gray(this.ctx.config.root));
|
|
8538
8664
|
const seed = this.ctx.getSeed();
|
|
8539
8665
|
if (seed != null) this.log(PAD + $.gray(`Running tests with seed "${seed}"`));
|
|
8540
|
-
|
|
8541
|
-
|
|
8542
|
-
|
|
8543
|
-
|
|
8544
|
-
|
|
8545
|
-
|
|
8546
|
-
|
|
8547
|
-
|
|
8548
|
-
// workaround for https://github.com/vitejs/vite/issues/15438, it was fixed in vite 5.1
|
|
8549
|
-
const fallbackUrl = `http://${this.ctx.config.api.host || "localhost"}:${this.ctx.config.api.port}`;
|
|
8550
|
-
const origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0] ?? fallbackUrl;
|
|
8551
|
-
this.log(PAD + $.dim($.green(`API started at ${new URL("/", origin)}`)));
|
|
8666
|
+
const resolvedUrls = this.ctx.vite.resolvedUrls;
|
|
8667
|
+
const origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0];
|
|
8668
|
+
if (origin && this.ctx.config._apiRequested) {
|
|
8669
|
+
if (this.ctx.config.ui) {
|
|
8670
|
+
const url = new URL(this.ctx.config.uiBase, origin);
|
|
8671
|
+
url.searchParams.set("token", this.ctx.config.api.token);
|
|
8672
|
+
this.log(PAD + $.dim($.green(`UI started at ${url}`)));
|
|
8673
|
+
} else this.log(PAD + $.dim($.green(`API started at ${new URL("/", origin)}`)));
|
|
8552
8674
|
}
|
|
8553
8675
|
if (this.ctx.coverageProvider) this.log(PAD + $.dim("Coverage enabled with ") + $.yellow(this.ctx.coverageProvider.name));
|
|
8554
8676
|
if (this.ctx.config.standalone) this.log($.yellow(`\nVitest is running in standalone mode. Edit a test file to rerun tests.\n`));
|
|
@@ -8730,14 +8852,14 @@ function resolveApiServerConfig(config, defaultPort, logger) {
|
|
|
8730
8852
|
} else api = { ...config.api };
|
|
8731
8853
|
}
|
|
8732
8854
|
if (api) {
|
|
8733
|
-
if (
|
|
8855
|
+
if (api.port == null && !api.middlewareMode) api.port = defaultPort;
|
|
8734
8856
|
} else api = { middlewareMode: true };
|
|
8735
8857
|
if (api && isBrowserEnabled) {
|
|
8736
8858
|
// Always force middlewareMode to false in browser mode
|
|
8737
8859
|
api.middlewareMode = false;
|
|
8738
8860
|
// The browser server is standalone, so it always needs a port even when the
|
|
8739
8861
|
// user didn't configure `api`/`ui` (in which case `api` defaulted above)
|
|
8740
|
-
if (
|
|
8862
|
+
if (api.port == null) api.port = defaultPort;
|
|
8741
8863
|
}
|
|
8742
8864
|
// if the API server is exposed to network, disable write operations by default
|
|
8743
8865
|
if (!api.middlewareMode && api.host && api.host !== "localhost" && api.host !== "127.0.0.1") {
|
|
@@ -8799,6 +8921,7 @@ function resolveTestConfig(logger, options, viteConfig, globalConfig) {
|
|
|
8799
8921
|
resolved.coverage = globalConfig.coverage;
|
|
8800
8922
|
resolved.attachmentsDir = globalConfig.attachmentsDir;
|
|
8801
8923
|
resolved.mergeReportsLabel = globalConfig.mergeReportsLabel;
|
|
8924
|
+
resolved.watch = globalConfig.watch;
|
|
8802
8925
|
}
|
|
8803
8926
|
if (!statSync(resolved.root, { throwIfNoEntry: false })?.isDirectory()) throw new Error(`Root path does not exist or is not a directory: ${resolved.root}`);
|
|
8804
8927
|
resolved.mode ??= viteConfig.mode ?? "test";
|
|
@@ -8844,7 +8967,8 @@ function resolveTestConfig(logger, options, viteConfig, globalConfig) {
|
|
|
8844
8967
|
...resolved.inspector,
|
|
8845
8968
|
...parseInspector(inspector),
|
|
8846
8969
|
enabled: !!inspector,
|
|
8847
|
-
waitForDebugger: options.inspector?.waitForDebugger ?? !!resolved.inspectBrk
|
|
8970
|
+
waitForDebugger: options.inspector?.waitForDebugger ?? !!resolved.inspectBrk,
|
|
8971
|
+
openInMainProcess: isInspectorOpen()
|
|
8848
8972
|
};
|
|
8849
8973
|
if (viteConfig.base !== "/") resolved.base = viteConfig.base;
|
|
8850
8974
|
resolved.clearScreen = resolved.clearScreen ?? viteConfig.clearScreen ?? true;
|
|
@@ -9120,7 +9244,7 @@ function resolveTestConfig(logger, options, viteConfig, globalConfig) {
|
|
|
9120
9244
|
};
|
|
9121
9245
|
resolved.typecheck ??= {};
|
|
9122
9246
|
resolved.typecheck.enabled ??= false;
|
|
9123
|
-
if (resolved.typecheck.enabled && !warnedTypeCheck) {
|
|
9247
|
+
if (resolved.typecheck.enabled && !warnedTypeCheck && !process.env.VITEST_DISABLE_EXPERIMENTAL_LOG) {
|
|
9124
9248
|
warnedTypeCheck = true;
|
|
9125
9249
|
logger.console.warn($.yellow("Testing types with tsc and vue-tsc is an experimental feature.\nBreaking changes might not follow SemVer, please pin Vitest's version when using it."));
|
|
9126
9250
|
}
|
|
@@ -9161,30 +9285,26 @@ function resolveTestConfig(logger, options, viteConfig, globalConfig) {
|
|
|
9161
9285
|
} else if (resolved.ui) resolved.includeTaskLocation ??= true;
|
|
9162
9286
|
if (typeof resolved.browser.trace === "string" || !resolved.browser.trace) resolved.browser.trace = { mode: resolved.browser.trace || "off" };
|
|
9163
9287
|
const traceView = resolved.browser.traceView;
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
|
|
9172
|
-
|
|
9173
|
-
ariaSnapshot: true
|
|
9288
|
+
const traceViewOptions = typeof traceView === "object" ? traceView : void 0;
|
|
9289
|
+
if (traceViewOptions?.enabled != null) logger.deprecate("`browser.traceView.enabled` is deprecated. Use `browser.traceView.mode` instead.");
|
|
9290
|
+
const traceViewMode = typeof traceView === "string" ? traceView : typeof traceView === "object" ? traceView.mode ?? (traceView.enabled === void 0 ? "failure-only" : traceView.enabled ? "on" : "off") : traceView === void 0 ? "failure-only" : traceView ? "on" : "off";
|
|
9291
|
+
resolved.browser.traceView = {
|
|
9292
|
+
enabled: traceViewMode !== "off",
|
|
9293
|
+
mode: traceViewMode,
|
|
9294
|
+
recordCanvas: traceViewOptions?.recordCanvas ?? false,
|
|
9295
|
+
inlineImages: traceViewOptions?.inlineImages ?? false,
|
|
9296
|
+
ariaSnapshot: traceViewOptions?.ariaSnapshot ?? true
|
|
9174
9297
|
};
|
|
9175
|
-
if (resolved.browser.enabled && resolved.browser.traceView.
|
|
9298
|
+
if (resolved.browser.enabled && resolved.browser.traceView.mode === "on") resolved.browser.detailsPanelPosition = "bottom";
|
|
9176
9299
|
if (resolved.browser.trace.tracesDir != null) resolved.browser.trace.tracesDir = resolvePath(resolved.browser.trace.tracesDir, resolved.root);
|
|
9177
9300
|
if (toArray(resolved.reporters).some((reporter) => {
|
|
9178
9301
|
if (Array.isArray(reporter)) return reporter[0] === "html";
|
|
9179
9302
|
return false;
|
|
9180
9303
|
})) resolved.includeTaskLocation ??= true;
|
|
9181
|
-
else if (resolved.browser.enabled && resolved.browser.traceView.enabled && !resolved.watch) logger.console.warn($.yellow(withLabel("yellow", "Vitest", "--browser.traceView is enabled without the HTML reporter.")));
|
|
9182
9304
|
resolved.server ??= {};
|
|
9183
9305
|
resolved.server.deps ??= {};
|
|
9184
|
-
|
|
9185
|
-
|
|
9186
|
-
resolved.dumpDir = resolve(resolved.root, typeof userFolder === "string" && userFolder !== "true" ? userFolder : ".vitest-dump", resolved.name || "root");
|
|
9187
|
-
}
|
|
9306
|
+
// projects inherit the root option, so they warn only when they set it themselves
|
|
9307
|
+
if (resolved.server.debug && (!globalConfig || !globalConfig.server.debug)) logger.deprecate("`server.debug` is deprecated and has no effect. To inspect or edit the transformed code, look up the module in the `fsModuleCache` manifest: https://vitest.dev/config/fsmodulecache#manifest");
|
|
9188
9308
|
resolved.testTimeout ??= resolved.browser.enabled ? 15e3 : 5e3;
|
|
9189
9309
|
resolved.hookTimeout ??= resolved.browser.enabled ? 3e4 : 1e4;
|
|
9190
9310
|
resolved.experimental ??= {};
|
|
@@ -9231,8 +9351,15 @@ function resolveTestConfig(logger, options, viteConfig, globalConfig) {
|
|
|
9231
9351
|
logger.deprecate("`experimental.fsModuleCachePath` is deprecated. Use the top-level `fsModuleCachePath` option instead.");
|
|
9232
9352
|
if (options.fsModuleCachePath === void 0) resolved.fsModuleCachePath = legacyExperimental.fsModuleCachePath;
|
|
9233
9353
|
}
|
|
9354
|
+
// the config and the CLI take priority over the environment
|
|
9355
|
+
const fsModuleCacheEnv = process.env.VITEST_FS_MODULE_CACHE;
|
|
9356
|
+
if (resolved.fsModuleCache == null && fsModuleCacheEnv) {
|
|
9357
|
+
resolved.fsModuleCache = fsModuleCacheEnv !== "false" && fsModuleCacheEnv !== "0";
|
|
9358
|
+
resolved.providedOptions.fsModuleCache = true;
|
|
9359
|
+
}
|
|
9234
9360
|
resolved.fsModuleCache ??= true;
|
|
9235
|
-
|
|
9361
|
+
const fsModuleCachePath = resolved.fsModuleCachePath || process.env.VITEST_FS_MODULE_CACHE_PATH;
|
|
9362
|
+
if (fsModuleCachePath) resolved.fsModuleCachePath = resolve(resolved.root, fsModuleCachePath);
|
|
9236
9363
|
return resolved;
|
|
9237
9364
|
}
|
|
9238
9365
|
/**
|
|
@@ -9269,7 +9396,7 @@ function resolveConfigPath(root, options) {
|
|
|
9269
9396
|
if (options.config) return resolveModule(options.config, { paths: [root] }) ?? resolve(root, options.config);
|
|
9270
9397
|
return findConfigFile(root);
|
|
9271
9398
|
}
|
|
9272
|
-
async function resolveConfig(options = {}, viteOverrides = {}, pluginsHarness = new PluginHarness()) {
|
|
9399
|
+
async function resolveConfig(options = {}, viteOverrides = {}, pluginsHarness = new PluginHarness(), cliFilters = []) {
|
|
9273
9400
|
// We clone CLI Options and Vite overrides to reuse when a watch mode is triggered.
|
|
9274
9401
|
const cliOptionsCopy = deepMerge({}, options);
|
|
9275
9402
|
const viteOverridesCopy = deepMerge({}, viteOverrides);
|
|
@@ -9326,6 +9453,7 @@ async function resolveConfig(options = {}, viteOverrides = {}, pluginsHarness =
|
|
|
9326
9453
|
rootConfig.cliOptions = cliOptionsCopy;
|
|
9327
9454
|
rootConfig.viteOverrides = viteOverridesCopy;
|
|
9328
9455
|
rootConfig._browserContribution = captures.browserContribution;
|
|
9456
|
+
rootConfig._cliFilters = cliFilters;
|
|
9329
9457
|
// projects never inherit `tagsFilter` and `browser` from the programmatic
|
|
9330
9458
|
// config (see `inheritRootViteOverrides`), so remove them from the base too
|
|
9331
9459
|
if (captures.rawTestConfig) {
|
|
@@ -15656,4 +15784,4 @@ var index = /*#__PURE__*/_mergeNamespaces({
|
|
|
15656
15784
|
default: prompt
|
|
15657
15785
|
}, [promptsExports]);
|
|
15658
15786
|
|
|
15659
|
-
export {
|
|
15787
|
+
export { printStack as A, BaseSequencer as B, LocationFilterFileNotFoundError as C, GitCommandError as D, VitestResolver as E, ForksPoolWorker as F, GitNotFoundError as G, createClusterServer as H, IncludeTaskLocationDisabledError as I, attachProjectsFromEntries as J, TestProject as K, Logger as L, ModuleTransformService as M, resolveAndAttachProjects as N, RandomSequencer as O, PluginHarness as P, createPool as Q, RangeLocationFilterProvidedError as R, ServerModuleRunner as S, ThreadsPoolWorker as T, astCollectTests as U, VitestPackageInstaller as V, createFailedFileTask as W, matchesProjectFilter as X, nanoid as Y, stdout as Z, BrowserConnectionError as a, FilesNotFoundError as b, TypecheckPoolWorker as c, VmForksPoolWorker as d, VmThreadsPoolWorker as e, createDebugger as f, createMethodsRPC as g, createViteLogger as h, escapeTestName as i, getFilePoolName as j, isFileServingAllowed as k, resolveConfig as l, resolveFsAllow as m, findConfigFile as n, parse as o, prompt as p, getSpecificationDocblock as q, resolveApiServerConfig as r, stringify as s, resolveStaticMocks as t, getStaticMocks as u, resolveCoverageReporters as v, createIndexLocationsMap as w, getOutputFile as x, groupBy as y, generateCodeFrame as z };
|