vitest 4.1.0 → 4.1.2
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 +1 -1
- package/dist/browser.js +3 -3
- package/dist/chunks/{base.DM0-RqVb.js → base.BPik1OqN.js} +8 -8
- package/dist/chunks/{benchmark.D0SlKNbZ.js → benchmark.CX_oY03V.js} +1 -1
- package/dist/chunks/{browser.d.X3SXoOCV.d.ts → browser.d.BMOr_Kmk.d.ts} +1 -1
- package/dist/chunks/{cac.CWGDZnXT.js → cac.DRKYQDPl.js} +22 -10
- package/dist/chunks/{cli-api.DuT9iuvY.js → cli-api.Bxr1Nn49.js} +154 -40
- package/dist/chunks/{config.d.EJLVE3es.d.ts → config.d.Cz9kPrQs.d.ts} +1 -0
- package/dist/chunks/{coverage.D_JHT54q.js → coverage.CTzCuANN.js} +4 -1
- package/dist/chunks/{coverage.Bri33R1t.js → coverage.kqM80boz.js} +26 -11
- package/dist/chunks/{defaults.CdU2lD-q.js → defaults.9aQKnqFk.js} +13 -5
- package/dist/chunks/{globals.BXNGLnTL.js → globals.CVqIbOyt.js} +3 -3
- package/dist/chunks/{index.DXMFO5MJ.js → index.0GYC6HAu.js} +627 -586
- package/dist/chunks/{index.EY6TCHpo.js → index.DC7d2Pf8.js} +2 -2
- package/dist/chunks/{index.DlDSLQD3.js → index.DOa3dzoN.js} +2 -2
- package/dist/chunks/{index.DGNSnENe.js → index.nZ2xqFgD.js} +2 -2
- package/dist/chunks/{init-forks.DeArv0jT.js → init-forks.UV3ZQGQH.js} +1 -1
- package/dist/chunks/{init-threads.-2OUl4Nn.js → init-threads.D3eCsY76.js} +1 -1
- package/dist/chunks/{init.DICorXCo.js → init.D98-gwRW.js} +5 -3
- package/dist/chunks/{nativeModuleMocker.DndvSdL6.js → nativeModuleMocker.BRN2oBJd.js} +2 -2
- package/dist/chunks/{plugin.d.BuW-flqo.d.ts → plugin.d.BWbK_Jpw.d.ts} +1 -1
- package/dist/chunks/{reporters.d.DVUYHHhe.d.ts → reporters.d.B0uk8id2.d.ts} +54 -33
- package/dist/chunks/{setup-common.B41N_kPE.js → setup-common.2wZXQUjS.js} +2 -2
- package/dist/chunks/{startVitestModuleRunner.C3ZR-4J3.js → startVitestModuleRunner.bRl2_oI_.js} +19 -5
- package/dist/chunks/{test.CTcmp4Su.js → test.p_J6dB8a.js} +3 -2
- package/dist/chunks/{traces.CCmnQaNT.js → traces.DT5aQ62U.js} +1 -1
- package/dist/chunks/utils.DK8FXp4T.js +189 -0
- package/dist/chunks/{vm.Dh2rTtmP.js → vm.BvVhnZPV.js} +2 -2
- package/dist/chunks/{worker.d.B84sVRy0.d.ts → worker.d.BT5j8dyR.d.ts} +1 -1
- package/dist/cli.js +2 -20
- package/dist/config.cjs +13 -5
- package/dist/config.d.ts +8 -8
- package/dist/config.js +1 -1
- package/dist/coverage.d.ts +7 -7
- package/dist/coverage.js +3 -3
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.js +3 -3
- package/dist/module-evaluator.js +2 -2
- package/dist/node.d.ts +7 -7
- package/dist/node.js +11 -11
- package/dist/reporters.d.ts +4 -4
- package/dist/reporters.js +6 -6
- package/dist/runners.d.ts +3 -2
- package/dist/runners.js +2 -2
- package/dist/runtime.js +3 -3
- package/dist/suite.js +1 -1
- package/dist/worker.d.ts +2 -2
- package/dist/worker.js +12 -11
- package/dist/workers/forks.js +13 -12
- package/dist/workers/runVmTests.js +6 -6
- package/dist/workers/threads.js +13 -12
- package/dist/workers/vmForks.js +7 -7
- package/dist/workers/vmThreads.js +7 -7
- package/optional-runtime-types.d.ts +6 -0
- package/package.json +19 -16
- package/dist/chunks/git.Bm2pzPAa.js +0 -71
- package/dist/chunks/index.CEzQDJGb.js +0 -231
package/dist/browser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as SerializedCoverageConfig, S as SerializedConfig } from './chunks/config.d.
|
|
1
|
+
import { a as SerializedCoverageConfig, S as SerializedConfig } from './chunks/config.d.Cz9kPrQs.js';
|
|
2
2
|
import { R as RuntimeCoverageModuleLoader } from './chunks/coverage.d.BZtK59WP.js';
|
|
3
3
|
import { SerializedDiffOptions } from '@vitest/utils/diff';
|
|
4
4
|
export { O as OTELCarrier, T as Traces } from './chunks/traces.d.402V_yFI.js';
|
package/dist/browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { l as loadDiffConfig, a as loadSnapshotSerializers, s as setupCommonEnv, b as startCoverageInsideWorker, c as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './chunks/setup-common.
|
|
2
|
-
export { T as Traces } from './chunks/traces.
|
|
1
|
+
export { l as loadDiffConfig, a as loadSnapshotSerializers, s as setupCommonEnv, b as startCoverageInsideWorker, c as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './chunks/setup-common.2wZXQUjS.js';
|
|
2
|
+
export { T as Traces } from './chunks/traces.DT5aQ62U.js';
|
|
3
3
|
export { collectTests, startTests } from '@vitest/runner';
|
|
4
4
|
import * as spyModule from '@vitest/spy';
|
|
5
5
|
export { spyModule as SpyModule };
|
|
@@ -8,7 +8,7 @@ export { processError } from '@vitest/utils/error';
|
|
|
8
8
|
export { getType } from '@vitest/utils/helpers';
|
|
9
9
|
export { DecodedMap, getOriginalPosition } from '@vitest/utils/source-map';
|
|
10
10
|
export { getSafeTimers, setSafeTimers } from '@vitest/utils/timers';
|
|
11
|
-
import './chunks/coverage.
|
|
11
|
+
import './chunks/coverage.CTzCuANN.js';
|
|
12
12
|
import '@vitest/snapshot';
|
|
13
13
|
import './chunks/utils.BX5Fg8C4.js';
|
|
14
14
|
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { runInThisContext } from 'node:vm';
|
|
2
2
|
import * as spyModule from '@vitest/spy';
|
|
3
|
-
import { r as resolveTestRunner, a as resolveSnapshotEnvironment, d as detectAsyncLeaks, s as setupChaiConfig } from './index.
|
|
4
|
-
import { l as loadEnvironment, e as emitModuleRunner, a as listenForErrors } from './init.
|
|
3
|
+
import { r as resolveTestRunner, a as resolveSnapshotEnvironment, d as detectAsyncLeaks, s as setupChaiConfig } from './index.nZ2xqFgD.js';
|
|
4
|
+
import { l as loadEnvironment, e as emitModuleRunner, a as listenForErrors } from './init.D98-gwRW.js';
|
|
5
5
|
import { N as NativeModuleRunner } from './nativeModuleRunner.BIakptoF.js';
|
|
6
|
-
import { T as Traces } from './traces.
|
|
6
|
+
import { T as Traces } from './traces.DT5aQ62U.js';
|
|
7
7
|
import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
|
|
8
|
-
import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startVitestModuleRunner.
|
|
8
|
+
import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startVitestModuleRunner.bRl2_oI_.js';
|
|
9
9
|
import { performance as performance$1 } from 'node:perf_hooks';
|
|
10
10
|
import { startTests, collectTests } from '@vitest/runner';
|
|
11
|
-
import { s as setupCommonEnv, b as startCoverageInsideWorker, c as stopCoverageInsideWorker } from './setup-common.
|
|
12
|
-
import { g as globalExpect, v as vi } from './test.
|
|
11
|
+
import { s as setupCommonEnv, b as startCoverageInsideWorker, c as stopCoverageInsideWorker } from './setup-common.2wZXQUjS.js';
|
|
12
|
+
import { g as globalExpect, v as vi } from './test.p_J6dB8a.js';
|
|
13
13
|
import { c as closeInspector } from './inspector.CvyFGlXm.js';
|
|
14
14
|
import { createRequire } from 'node:module';
|
|
15
15
|
import timers from 'node:timers';
|
|
16
16
|
import timersPromises from 'node:timers/promises';
|
|
17
17
|
import util from 'node:util';
|
|
18
18
|
import { KNOWN_ASSET_TYPES } from '@vitest/utils/constants';
|
|
19
|
-
import { i as index } from './index.
|
|
19
|
+
import { i as index } from './index.DOa3dzoN.js';
|
|
20
20
|
import { g as getWorkerState, r as resetModules, p as provideWorkerState, a as getSafeWorkerState } from './utils.BX5Fg8C4.js';
|
|
21
21
|
|
|
22
22
|
// this should only be used in Node
|
|
@@ -115,7 +115,7 @@ async function startModuleRunner(options) {
|
|
|
115
115
|
let mocker;
|
|
116
116
|
if (options.state.config.experimental.nodeLoader !== false) {
|
|
117
117
|
// this additionally imports acorn/magic-string
|
|
118
|
-
const { NativeModuleMocker } = await import('./nativeModuleMocker.
|
|
118
|
+
const { NativeModuleMocker } = await import('./nativeModuleMocker.BRN2oBJd.js');
|
|
119
119
|
mocker = new NativeModuleMocker({
|
|
120
120
|
async resolveId(id, importer) {
|
|
121
121
|
// TODO: use import.meta.resolve instead
|
|
@@ -20,7 +20,7 @@ const bench = createBenchmark(function(name, fn = noop, options = {}) {
|
|
|
20
20
|
benchFns.set(task, fn);
|
|
21
21
|
benchOptsMap.set(task, options);
|
|
22
22
|
// vitest runner sets mode to `todo` if handler is not passed down
|
|
23
|
-
// but we store handler
|
|
23
|
+
// but we store handler separately
|
|
24
24
|
if (!this.todo && task.mode === "todo") task.mode = "run";
|
|
25
25
|
});
|
|
26
26
|
function createBenchmark(fn) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FileSpecification } from '@vitest/runner';
|
|
2
2
|
import { O as OTELCarrier } from './traces.d.402V_yFI.js';
|
|
3
|
-
import { T as TestExecutionMethod } from './worker.d.
|
|
3
|
+
import { T as TestExecutionMethod } from './worker.d.BT5j8dyR.js';
|
|
4
4
|
|
|
5
5
|
type SerializedTestSpecification = [project: {
|
|
6
6
|
name: string | undefined;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { toArray } from '@vitest/utils/helpers';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { normalize } from 'pathe';
|
|
4
|
-
import c$2 from 'tinyrainbow';
|
|
4
|
+
import c$2, { disableDefaultColors } from 'tinyrainbow';
|
|
5
|
+
import './env.D4Lgay0q.js';
|
|
5
6
|
import { b as defaultPort, d as defaultBrowserPort } from './constants.CPYnjOGj.js';
|
|
6
|
-
import { R as ReportersMap } from './index.DXMFO5MJ.js';
|
|
7
7
|
import assert from 'node:assert';
|
|
8
|
+
import { isAgent } from 'std-env';
|
|
8
9
|
|
|
9
10
|
function toArr(any) {
|
|
10
11
|
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
@@ -620,7 +621,7 @@ class CAC extends EventEmitter {
|
|
|
620
621
|
|
|
621
622
|
const cac = (name = "") => new CAC(name);
|
|
622
623
|
|
|
623
|
-
var version = "4.1.
|
|
624
|
+
var version = "4.1.2";
|
|
624
625
|
|
|
625
626
|
const apiConfig = (port) => ({
|
|
626
627
|
port: {
|
|
@@ -700,7 +701,7 @@ const cliOptionsConfig = {
|
|
|
700
701
|
hideSkippedTests: { description: "Hide logs for skipped tests" },
|
|
701
702
|
reporters: {
|
|
702
703
|
alias: "reporter",
|
|
703
|
-
description: `Specify reporters (
|
|
704
|
+
description: `Specify reporters (default, agent, blob, verbose, dot, json, tap, tap-flat, junit, tree, hanging-process, github-actions)`,
|
|
704
705
|
argument: "<name>",
|
|
705
706
|
subcommands: null,
|
|
706
707
|
array: true
|
|
@@ -828,6 +829,11 @@ const cliOptionsConfig = {
|
|
|
828
829
|
if (value === "false" || value === "no" || value === false) return false;
|
|
829
830
|
return value;
|
|
830
831
|
}
|
|
832
|
+
},
|
|
833
|
+
excludeAfterRemap: { description: "Apply exclusions again after coverage has been remapped to original sources. (default: false)" },
|
|
834
|
+
htmlDir: {
|
|
835
|
+
description: "Directory of HTML coverage output to be served in UI mode and HTML reporter.",
|
|
836
|
+
argument: "<path>"
|
|
831
837
|
}
|
|
832
838
|
}
|
|
833
839
|
},
|
|
@@ -1167,7 +1173,7 @@ const cliOptionsConfig = {
|
|
|
1167
1173
|
description: "Use `bundle` to bundle the config with esbuild or `runner` (experimental) to process it on the fly. This is only available in vite version 6.1.0 and above. (default: `bundle`)",
|
|
1168
1174
|
argument: "<loader>"
|
|
1169
1175
|
},
|
|
1170
|
-
standalone: { description: "Start Vitest without running tests. Tests will be running only on change. This option is ignored when CLI file filters are passed. (default: `false`)" },
|
|
1176
|
+
standalone: { description: "Start Vitest without running tests. Tests will be running only on change. If browser mode is enabled, the UI will be opened automatically. This option is ignored when CLI file filters are passed. (default: `false`)" },
|
|
1171
1177
|
mergeReports: {
|
|
1172
1178
|
description: "Path to a blob reports directory. If this options is used, Vitest won't run any tests, it will only report previously recorded tests",
|
|
1173
1179
|
argument: "[path]",
|
|
@@ -1232,7 +1238,12 @@ const cliOptionsConfig = {
|
|
|
1232
1238
|
}
|
|
1233
1239
|
},
|
|
1234
1240
|
viteModuleRunner: { description: "Control whether Vitest uses Vite's module runner to run the code or fallback to the native `import`. (default: `true`)" },
|
|
1235
|
-
nodeLoader: { description: "Controls whether Vitest will use Node.js Loader API to process in-source or mocked files. This has no effect if `viteModuleRunner` is enabled. Disabling this can increase performance. (default: `true`)" }
|
|
1241
|
+
nodeLoader: { description: "Controls whether Vitest will use Node.js Loader API to process in-source or mocked files. This has no effect if `viteModuleRunner` is enabled. Disabling this can increase performance. (default: `true`)" },
|
|
1242
|
+
vcsProvider: {
|
|
1243
|
+
argument: "<path>",
|
|
1244
|
+
description: "Custom provider for detecting changed files. (default: `git`)",
|
|
1245
|
+
subcommands: null
|
|
1246
|
+
}
|
|
1236
1247
|
}
|
|
1237
1248
|
},
|
|
1238
1249
|
cliExclude: null,
|
|
@@ -2190,6 +2201,7 @@ function addCliOptions(cli, options) {
|
|
|
2190
2201
|
for (const [optionName, option] of Object.entries(options)) if (option) addCommand(cli, optionName, option);
|
|
2191
2202
|
}
|
|
2192
2203
|
function createCLI(options = {}) {
|
|
2204
|
+
if (isAgent) disableDefaultColors();
|
|
2193
2205
|
const cli = cac("vitest");
|
|
2194
2206
|
cli.version(version);
|
|
2195
2207
|
addCliOptions(cli, cliOptionsConfig);
|
|
@@ -2312,11 +2324,11 @@ function normalizeCliOptions(cliFilters, argv) {
|
|
|
2312
2324
|
}
|
|
2313
2325
|
async function start(mode, cliFilters, options) {
|
|
2314
2326
|
try {
|
|
2315
|
-
const { startVitest } = await import('./cli-api.
|
|
2327
|
+
const { startVitest } = await import('./cli-api.Bxr1Nn49.js').then(function (n) { return n.q; });
|
|
2316
2328
|
const ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
|
|
2317
2329
|
if (!ctx.shouldKeepServer()) await ctx.exit();
|
|
2318
2330
|
} catch (e) {
|
|
2319
|
-
const { errorBanner } = await import('./
|
|
2331
|
+
const { errorBanner } = await import('./utils.DK8FXp4T.js').then(function (n) { return n.u; });
|
|
2320
2332
|
console.error(`\n${errorBanner("Startup Error")}`);
|
|
2321
2333
|
console.error(e);
|
|
2322
2334
|
console.error("\n\n");
|
|
@@ -2334,7 +2346,7 @@ async function init(project) {
|
|
|
2334
2346
|
}
|
|
2335
2347
|
async function collect(mode, cliFilters, options) {
|
|
2336
2348
|
try {
|
|
2337
|
-
const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.
|
|
2349
|
+
const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.Bxr1Nn49.js').then(function (n) { return n.q; });
|
|
2338
2350
|
const ctx = await prepareVitest(mode, {
|
|
2339
2351
|
...normalizeCliOptions(cliFilters, options),
|
|
2340
2352
|
watch: false,
|
|
@@ -2356,7 +2368,7 @@ async function collect(mode, cliFilters, options) {
|
|
|
2356
2368
|
} else outputFileList(await ctx.getRelevantTestSpecifications(cliFilters.map(normalize)), options);
|
|
2357
2369
|
await ctx.close();
|
|
2358
2370
|
} catch (e) {
|
|
2359
|
-
const { errorBanner } = await import('./
|
|
2371
|
+
const { errorBanner } = await import('./utils.DK8FXp4T.js').then(function (n) { return n.u; });
|
|
2360
2372
|
console.error(`\n${errorBanner("Collect Error")}`);
|
|
2361
2373
|
console.error(e);
|
|
2362
2374
|
console.error("\n\n");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs, { promises, existsSync, mkdirSync, readFileSync, statSync, readdirSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { relative, resolve, dirname, join, extname, normalize, basename, isAbsolute } from 'pathe';
|
|
3
|
-
import { C as CoverageProviderMap } from './coverage.
|
|
3
|
+
import { C as CoverageProviderMap } from './coverage.CTzCuANN.js';
|
|
4
4
|
import path, { resolve as resolve$1 } from 'node:path';
|
|
5
5
|
import { unique, createDefer, slash, withTrailingSlash, cleanUrl, wrapId, isExternalUrl, unwrapId, toArray, noop, deepMerge, nanoid, deepClone, isPrimitive, notNullish } from '@vitest/utils/helpers';
|
|
6
6
|
import { a as any, p as prompt } from './index.og1WyBLx.js';
|
|
@@ -13,19 +13,20 @@ import nodeos__default, { tmpdir } from 'node:os';
|
|
|
13
13
|
import { generateHash as generateHash$1, createTaskName, validateTags, calculateSuiteHash, someTasksAreOnly, interpretTaskModes, hasFailed, generateFileHash, limitConcurrency, createFileTask as createFileTask$1, getTasks, isTestCase } from '@vitest/runner/utils';
|
|
14
14
|
import { SnapshotManager } from '@vitest/snapshot/manager';
|
|
15
15
|
import { serializeValue } from '@vitest/utils/serialize';
|
|
16
|
-
import { v as version$1 } from './cac.
|
|
16
|
+
import { v as version$1 } from './cac.DRKYQDPl.js';
|
|
17
17
|
import { rootDir, distDir } from '../path.js';
|
|
18
|
-
import {
|
|
18
|
+
import { f as createIndexLocationsMap, g as TraceMap, o as originalPositionFor, h as ancestor, s as stringify, p as parse, i as printError, j as Typechecker, k as generateCodeFrame, l as escapeRegExp, m as createDefinesScript, a as BenchmarkReportsMap, R as ReportersMap, n as groupBy, q as BlobReporter, r as readBlobs, t as convertTasksToEvents, H as HangingProcessReporter, w as wildcardPatternToRegExp, u as stdout } from './index.0GYC6HAu.js';
|
|
19
19
|
import { N as NativeModuleRunner } from './nativeModuleRunner.BIakptoF.js';
|
|
20
|
-
import { T as Traces } from './traces.
|
|
20
|
+
import { T as Traces } from './traces.DT5aQ62U.js';
|
|
21
21
|
import { createDebug } from 'obug';
|
|
22
|
-
import { h as hash, R as RandomSequencer, i as isBrowserEnabled, r as resolveConfig, g as getCoverageProvider, b as resolveApiServerConfig } from './coverage.
|
|
22
|
+
import { h as hash, R as RandomSequencer, i as isBrowserEnabled, r as resolveConfig, g as getCoverageProvider, b as resolveApiServerConfig } from './coverage.kqM80boz.js';
|
|
23
23
|
import { rm, readFile, writeFile, rename, stat, unlink, mkdir, copyFile } from 'node:fs/promises';
|
|
24
24
|
import c from 'tinyrainbow';
|
|
25
25
|
import { VitestModuleEvaluator } from '#module-evaluator';
|
|
26
26
|
import { ModuleRunner } from 'vite/module-runner';
|
|
27
27
|
import { Console } from 'node:console';
|
|
28
28
|
import { g as getDefaultExportFromCjs } from './_commonjsHelpers.D26ty3Ew.js';
|
|
29
|
+
import { g as formatProjectName, w as withLabel, e as errorBanner, d as divider } from './utils.DK8FXp4T.js';
|
|
29
30
|
import { createRequire, builtinModules, isBuiltin as isBuiltin$1 } from 'node:module';
|
|
30
31
|
import url, { fileURLToPath, pathToFileURL } from 'node:url';
|
|
31
32
|
import { i as isTTY, a as isWindows } from './env.D4Lgay0q.js';
|
|
@@ -49,16 +50,17 @@ import require$$0$2 from 'stream';
|
|
|
49
50
|
import require$$7 from 'url';
|
|
50
51
|
import require$$0 from 'zlib';
|
|
51
52
|
import require$$0$1 from 'buffer';
|
|
52
|
-
import { c as configDefaults } from './defaults.
|
|
53
|
+
import { c as configDefaults } from './defaults.9aQKnqFk.js';
|
|
54
|
+
import { isAgent } from 'std-env';
|
|
53
55
|
import MagicString from 'magic-string';
|
|
54
56
|
import { hoistMocksPlugin, automockPlugin } from '@vitest/mocker/node';
|
|
55
57
|
import { KNOWN_ASSET_RE } from '@vitest/utils/constants';
|
|
56
58
|
import { findNearestPackageData } from '@vitest/utils/resolver';
|
|
57
59
|
import * as esModuleLexer from 'es-module-lexer';
|
|
58
|
-
import { a as BenchmarkReportsMap } from './index.CEzQDJGb.js';
|
|
59
60
|
import assert$1 from 'node:assert';
|
|
60
61
|
import { parseErrorStacktrace } from '@vitest/utils/source-map';
|
|
61
62
|
import { extractSourcemapFromFile } from '@vitest/utils/source-map/node';
|
|
63
|
+
import { x } from 'tinyexec';
|
|
62
64
|
import readline from 'node:readline';
|
|
63
65
|
import { stripVTControlCharacters } from 'node:util';
|
|
64
66
|
|
|
@@ -178,6 +180,8 @@ function astParseFile(filepath, code) {
|
|
|
178
180
|
"scoped",
|
|
179
181
|
"override"
|
|
180
182
|
].includes(property)) return;
|
|
183
|
+
// skip properties on return values of calls - e.g., test('name', fn).skip()
|
|
184
|
+
if (callee.type === "MemberExpression" && callee.object?.type === "CallExpression") return;
|
|
181
185
|
// derive mode from the full chain (handles any order like .skip.concurrent or .concurrent.skip)
|
|
182
186
|
let mode = "run";
|
|
183
187
|
for (const prop of properties) if (prop === "skip" || prop === "only" || prop === "todo") mode = prop;
|
|
@@ -455,7 +459,7 @@ class BrowserSessions {
|
|
|
455
459
|
this.sessions.delete(sessionId);
|
|
456
460
|
}
|
|
457
461
|
createSession(sessionId, project, pool) {
|
|
458
|
-
// this promise only waits for the WS connection with the
|
|
462
|
+
// this promise only waits for the WS connection with the orchestrator to be established
|
|
459
463
|
const defer = createDefer();
|
|
460
464
|
const timeout = setTimeout(() => {
|
|
461
465
|
defer.reject(/* @__PURE__ */ new Error(`Failed to connect to the browser session "${sessionId}" [${project.name}] within the timeout.`));
|
|
@@ -1990,7 +1994,7 @@ class Logger {
|
|
|
1990
1994
|
this.log(PAD + c.dim(c.green(`API started at ${new URL("/", origin)}`)));
|
|
1991
1995
|
}
|
|
1992
1996
|
if (this.ctx.coverageProvider) this.log(PAD + c.dim("Coverage enabled with ") + c.yellow(this.ctx.coverageProvider.name));
|
|
1993
|
-
if (this.ctx.config.standalone) this.log(c.yellow(`\nVitest is running in standalone mode. Edit a test file to rerun tests
|
|
1997
|
+
if (this.ctx.config.standalone) this.log(c.yellow(`\nVitest is running in standalone mode. Edit a test file to rerun tests.\n`));
|
|
1994
1998
|
else this.log();
|
|
1995
1999
|
}
|
|
1996
2000
|
printBrowserBanner(project) {
|
|
@@ -2393,13 +2397,7 @@ function createBrowserPool(vitest) {
|
|
|
2393
2397
|
const ensurePool = (project) => {
|
|
2394
2398
|
if (projectPools.has(project)) return projectPools.get(project);
|
|
2395
2399
|
debug?.("creating pool for project %s", project.name);
|
|
2396
|
-
const
|
|
2397
|
-
const origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0];
|
|
2398
|
-
if (!origin) throw new Error(`Can't find browser origin URL for project "${project.name}"`);
|
|
2399
|
-
const pool = new BrowserPool(project, {
|
|
2400
|
-
maxWorkers: getThreadsCount(project),
|
|
2401
|
-
origin
|
|
2402
|
-
});
|
|
2400
|
+
const pool = new BrowserPool(project, { maxWorkers: getThreadsCount(project) });
|
|
2403
2401
|
projectPools.set(project, pool);
|
|
2404
2402
|
vitest.onCancel(() => {
|
|
2405
2403
|
pool.cancel();
|
|
@@ -2498,7 +2496,7 @@ class BrowserPool {
|
|
|
2498
2496
|
_queue = [];
|
|
2499
2497
|
_promise;
|
|
2500
2498
|
_providedContext;
|
|
2501
|
-
readySessions
|
|
2499
|
+
readySessions;
|
|
2502
2500
|
_traces;
|
|
2503
2501
|
_otel;
|
|
2504
2502
|
constructor(project, options) {
|
|
@@ -2510,6 +2508,7 @@ class BrowserPool {
|
|
|
2510
2508
|
"vitest.project": project.name,
|
|
2511
2509
|
"vitest.browser.provider": this.project.browser.provider.name
|
|
2512
2510
|
});
|
|
2511
|
+
this.readySessions = project._browserReadySessions;
|
|
2513
2512
|
}
|
|
2514
2513
|
cancel() {
|
|
2515
2514
|
this._queue = [];
|
|
@@ -2566,14 +2565,10 @@ class BrowserPool {
|
|
|
2566
2565
|
return this._promise;
|
|
2567
2566
|
}
|
|
2568
2567
|
async openPage(sessionId, options) {
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
const otelCarrier = this._traces.getContextCarrier();
|
|
2574
|
-
if (otelCarrier) url.searchParams.set("otelCarrier", JSON.stringify(otelCarrier));
|
|
2575
|
-
const pagePromise = browser.provider.openPage(sessionId, url.toString(), options);
|
|
2576
|
-
await Promise.all([sessionPromise, pagePromise]);
|
|
2568
|
+
await this.project._openBrowserPage(sessionId, {
|
|
2569
|
+
reject: (error) => this.reject(error),
|
|
2570
|
+
parallel: options.parallel
|
|
2571
|
+
});
|
|
2577
2572
|
}
|
|
2578
2573
|
getOrchestrator(sessionId) {
|
|
2579
2574
|
const orchestrator = this.orchestrators.get(sessionId);
|
|
@@ -9007,7 +9002,7 @@ function setup(ctx, _server) {
|
|
|
9007
9002
|
try {
|
|
9008
9003
|
result.source = result.source || (moduleNode.file ? await promises.readFile(moduleNode.file, "utf-8") : void 0);
|
|
9009
9004
|
} catch {}
|
|
9010
|
-
// TODO: store this in HTML reporter
|
|
9005
|
+
// TODO: store this in HTML reporter separately
|
|
9011
9006
|
const transformDuration = ctx.state.metadata[projectName]?.duration[moduleNode.url]?.[0];
|
|
9012
9007
|
if (transformDuration != null) result.transformTime = transformDuration;
|
|
9013
9008
|
try {
|
|
@@ -9253,7 +9248,8 @@ function serializeConfig(project) {
|
|
|
9253
9248
|
tags: config.tags || [],
|
|
9254
9249
|
tagsFilter: config.tagsFilter,
|
|
9255
9250
|
strictTags: config.strictTags ?? true,
|
|
9256
|
-
slowTestThreshold: config.slowTestThreshold ?? globalConfig.slowTestThreshold ?? configDefaults.slowTestThreshold
|
|
9251
|
+
slowTestThreshold: config.slowTestThreshold ?? globalConfig.slowTestThreshold ?? configDefaults.slowTestThreshold,
|
|
9252
|
+
isAgent
|
|
9257
9253
|
};
|
|
9258
9254
|
}
|
|
9259
9255
|
|
|
@@ -10611,7 +10607,8 @@ class TestProject {
|
|
|
10611
10607
|
/** @internal */ _resolver;
|
|
10612
10608
|
/** @internal */ _fetcher;
|
|
10613
10609
|
/** @internal */ _serializedDefines;
|
|
10614
|
-
/** @
|
|
10610
|
+
/** @internal */ testFilesList = null;
|
|
10611
|
+
/** @internal */ _browserReadySessions = /* @__PURE__ */ new Set();
|
|
10615
10612
|
runner;
|
|
10616
10613
|
closingPromise;
|
|
10617
10614
|
typecheckFilesList = null;
|
|
@@ -10942,6 +10939,32 @@ class TestProject {
|
|
|
10942
10939
|
_getViteEnvironments() {
|
|
10943
10940
|
return [...Object.values(this.browser?.vite.environments || {}), ...Object.values(this.vite.environments || {})];
|
|
10944
10941
|
}
|
|
10942
|
+
/** @internal */
|
|
10943
|
+
async _openBrowserPage(sessionId, pool) {
|
|
10944
|
+
if (!this.browser) throw new Error(`browser is not initialized`);
|
|
10945
|
+
const resolvedUrls = this.browser.vite.resolvedUrls;
|
|
10946
|
+
const origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0];
|
|
10947
|
+
if (!origin) throw new Error(`Can't find browser origin URL for project "${this.name}"`);
|
|
10948
|
+
const url = new URL("/__vitest_test__/", origin);
|
|
10949
|
+
url.searchParams.set("sessionId", sessionId);
|
|
10950
|
+
const otelCarrier = this.vitest._traces.getContextCarrier();
|
|
10951
|
+
if (otelCarrier) url.searchParams.set("otelCarrier", JSON.stringify(otelCarrier));
|
|
10952
|
+
this.vitest._browserSessions.sessionIds.add(sessionId);
|
|
10953
|
+
const sessionPromise = this.vitest._browserSessions.createSession(sessionId, this, pool);
|
|
10954
|
+
const pagePromise = this.browser.provider.openPage(sessionId, url.toString(), { parallel: pool.parallel ?? false });
|
|
10955
|
+
await Promise.all([sessionPromise, pagePromise]);
|
|
10956
|
+
}
|
|
10957
|
+
/** @internal */
|
|
10958
|
+
async _standalone() {
|
|
10959
|
+
if (!this.isBrowserEnabled()) return;
|
|
10960
|
+
await this._initBrowserProvider();
|
|
10961
|
+
if (!this.browser) return;
|
|
10962
|
+
const sessionId = crypto.randomUUID();
|
|
10963
|
+
await this._openBrowserPage(sessionId, { reject: (error) => {
|
|
10964
|
+
this.vitest.state.catchError(error, "Browser Error");
|
|
10965
|
+
} });
|
|
10966
|
+
this._browserReadySessions.add(sessionId);
|
|
10967
|
+
}
|
|
10945
10968
|
_serializeOverriddenConfig() {
|
|
10946
10969
|
// TODO: serialize the config _once_ or when needed
|
|
10947
10970
|
const config = serializeConfig(this);
|
|
@@ -11438,12 +11461,10 @@ class VitestSpecifications {
|
|
|
11438
11461
|
}
|
|
11439
11462
|
async filterTestsBySource(specs) {
|
|
11440
11463
|
if (this.vitest.config.changed && !this.vitest.config.related) {
|
|
11441
|
-
const
|
|
11442
|
-
|
|
11443
|
-
|
|
11444
|
-
|
|
11445
|
-
throw new GitNotFoundError();
|
|
11446
|
-
}
|
|
11464
|
+
const related = await this.vitest.vcs.findChangedFiles({
|
|
11465
|
+
root: this.vitest.config.root,
|
|
11466
|
+
changedSince: this.vitest.config.changed
|
|
11467
|
+
});
|
|
11447
11468
|
this.vitest.config.related = Array.from(new Set(related));
|
|
11448
11469
|
}
|
|
11449
11470
|
const related = this.vitest.config.related;
|
|
@@ -12028,7 +12049,7 @@ class StateManager {
|
|
|
12028
12049
|
return Array.from(this.idMap.values()).filter((t) => t.result?.state === "fail").length;
|
|
12029
12050
|
}
|
|
12030
12051
|
cancelFiles(files, project) {
|
|
12031
|
-
// if we don't filter existing modules, they will be
|
|
12052
|
+
// if we don't filter existing modules, they will be overridden by `collectFiles`
|
|
12032
12053
|
const nonRegisteredFiles = files.filter(({ filepath }) => {
|
|
12033
12054
|
const id = generateFileHash(relative(project.config.root, filepath), project.name);
|
|
12034
12055
|
return !this.idMap.has(id);
|
|
@@ -12674,6 +12695,83 @@ function sanitizeFilePath(s) {
|
|
|
12674
12695
|
return s.replace(/[\x00-\x2C\x2E\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, "-");
|
|
12675
12696
|
}
|
|
12676
12697
|
|
|
12698
|
+
class GitVCSProvider {
|
|
12699
|
+
root;
|
|
12700
|
+
async resolveFilesWithGitCommand(args) {
|
|
12701
|
+
let result;
|
|
12702
|
+
try {
|
|
12703
|
+
result = await x("git", args, { nodeOptions: { cwd: this.root } });
|
|
12704
|
+
} catch (e) {
|
|
12705
|
+
e.message = e.stderr;
|
|
12706
|
+
throw e;
|
|
12707
|
+
}
|
|
12708
|
+
return result.stdout.split("\n").filter((s) => s !== "").map((changedPath) => resolve(this.root, changedPath));
|
|
12709
|
+
}
|
|
12710
|
+
async findChangedFiles(options) {
|
|
12711
|
+
const root = this.root || await this.getRoot(options.root);
|
|
12712
|
+
if (!root) throw new GitNotFoundError();
|
|
12713
|
+
this.root = root;
|
|
12714
|
+
const changedSince = options.changedSince;
|
|
12715
|
+
if (typeof changedSince === "string") {
|
|
12716
|
+
const [committed, staged, unstaged] = await Promise.all([
|
|
12717
|
+
this.getFilesSince(changedSince),
|
|
12718
|
+
this.getStagedFiles(),
|
|
12719
|
+
this.getUnstagedFiles()
|
|
12720
|
+
]);
|
|
12721
|
+
return [
|
|
12722
|
+
...committed,
|
|
12723
|
+
...staged,
|
|
12724
|
+
...unstaged
|
|
12725
|
+
];
|
|
12726
|
+
}
|
|
12727
|
+
const [staged, unstaged] = await Promise.all([this.getStagedFiles(), this.getUnstagedFiles()]);
|
|
12728
|
+
return [...staged, ...unstaged];
|
|
12729
|
+
}
|
|
12730
|
+
getFilesSince(hash) {
|
|
12731
|
+
return this.resolveFilesWithGitCommand([
|
|
12732
|
+
"diff",
|
|
12733
|
+
"--name-only",
|
|
12734
|
+
`${hash}...HEAD`
|
|
12735
|
+
]);
|
|
12736
|
+
}
|
|
12737
|
+
getStagedFiles() {
|
|
12738
|
+
return this.resolveFilesWithGitCommand([
|
|
12739
|
+
"diff",
|
|
12740
|
+
"--cached",
|
|
12741
|
+
"--name-only"
|
|
12742
|
+
]);
|
|
12743
|
+
}
|
|
12744
|
+
getUnstagedFiles() {
|
|
12745
|
+
return this.resolveFilesWithGitCommand([
|
|
12746
|
+
"ls-files",
|
|
12747
|
+
"--other",
|
|
12748
|
+
"--modified",
|
|
12749
|
+
"--exclude-standard"
|
|
12750
|
+
]);
|
|
12751
|
+
}
|
|
12752
|
+
async getRoot(cwd) {
|
|
12753
|
+
const args = ["rev-parse", "--show-cdup"];
|
|
12754
|
+
try {
|
|
12755
|
+
return resolve(cwd, (await x("git", args, { nodeOptions: { cwd } })).stdout.trim());
|
|
12756
|
+
} catch {
|
|
12757
|
+
return null;
|
|
12758
|
+
}
|
|
12759
|
+
}
|
|
12760
|
+
}
|
|
12761
|
+
|
|
12762
|
+
async function loadVCSProvider(runner, vcsProvider) {
|
|
12763
|
+
if (typeof vcsProvider === "object" && vcsProvider != null) return wrapVCSProvider(vcsProvider);
|
|
12764
|
+
if (!vcsProvider || vcsProvider === "git") return new GitVCSProvider();
|
|
12765
|
+
const module = await runner.import(vcsProvider);
|
|
12766
|
+
if (!module.default || typeof module.default !== "object" || typeof module.default.findChangedFiles !== "function") throw new Error(`The vcsProvider module '${vcsProvider}' doesn't have a default export with \`findChangedFiles\` method.`);
|
|
12767
|
+
return wrapVCSProvider(module.default);
|
|
12768
|
+
}
|
|
12769
|
+
function wrapVCSProvider(provider) {
|
|
12770
|
+
return { async findChangedFiles(options) {
|
|
12771
|
+
return (await provider.findChangedFiles(options)).map((file) => resolve(options.root, file));
|
|
12772
|
+
} };
|
|
12773
|
+
}
|
|
12774
|
+
|
|
12677
12775
|
class VitestWatcher {
|
|
12678
12776
|
/**
|
|
12679
12777
|
* Modules that will be invalidated on the next run.
|
|
@@ -12874,6 +12972,13 @@ class Vitest {
|
|
|
12874
12972
|
* Vitest behaviour.
|
|
12875
12973
|
*/
|
|
12876
12974
|
watcher;
|
|
12975
|
+
/**
|
|
12976
|
+
* The version control system provider used to detect changed files.
|
|
12977
|
+
* This is used with the `--changed` flag to determine which test files to run.
|
|
12978
|
+
* By default, Vitest uses Git. You can provide a custom implementation via
|
|
12979
|
+
* `experimental.vcsProvider` in your config.
|
|
12980
|
+
*/
|
|
12981
|
+
vcs;
|
|
12877
12982
|
/** @internal */ configOverride = {};
|
|
12878
12983
|
/** @internal */ filenamePattern;
|
|
12879
12984
|
/** @internal */ runningPromise;
|
|
@@ -12995,6 +13100,7 @@ class Vitest {
|
|
|
12995
13100
|
configurable: true
|
|
12996
13101
|
});
|
|
12997
13102
|
}
|
|
13103
|
+
this.vcs = await loadVCSProvider(this.runner, resolved.experimental.vcsProvider);
|
|
12998
13104
|
if (this.config.watch) {
|
|
12999
13105
|
// hijack server restart
|
|
13000
13106
|
const serverRestart = server.restart;
|
|
@@ -13342,10 +13448,17 @@ class Vitest {
|
|
|
13342
13448
|
});
|
|
13343
13449
|
}
|
|
13344
13450
|
/**
|
|
13451
|
+
* @deprecated use `standalone()` instead
|
|
13452
|
+
*/
|
|
13453
|
+
init() {
|
|
13454
|
+
this.logger.deprecate("`vitest.init()` is deprecated. Use `vitest.standalone()` instead.");
|
|
13455
|
+
return this.standalone();
|
|
13456
|
+
}
|
|
13457
|
+
/**
|
|
13345
13458
|
* Initialize reporters and the coverage provider. This method doesn't run any tests.
|
|
13346
13459
|
* If the `--watch` flag is provided, Vitest will still run changed tests even if this method was not called.
|
|
13347
13460
|
*/
|
|
13348
|
-
async
|
|
13461
|
+
async standalone() {
|
|
13349
13462
|
await this._traces.$("vitest.init", async () => {
|
|
13350
13463
|
try {
|
|
13351
13464
|
await this.initCoverageProvider();
|
|
@@ -13355,6 +13468,7 @@ class Vitest {
|
|
|
13355
13468
|
}
|
|
13356
13469
|
// populate test files cache so watch mode can trigger a file rerun
|
|
13357
13470
|
await this.globTestSpecifications();
|
|
13471
|
+
await Promise.all(this.projects.map((project) => project._standalone()));
|
|
13358
13472
|
if (this.config.watch) await this.report("onWatcherStart");
|
|
13359
13473
|
});
|
|
13360
13474
|
}
|
|
@@ -14173,8 +14287,8 @@ ${c.dim(` ...and ${remainingResultCount} more ${remainingResultCount === 1 ? "
|
|
|
14173
14287
|
if (this.stdin.isTTY) this.stdin.setRawMode(false);
|
|
14174
14288
|
}
|
|
14175
14289
|
restoreCursor() {
|
|
14176
|
-
const
|
|
14177
|
-
this.write(`${ESC}${
|
|
14290
|
+
const cursorPos = this.keywordOffset() + (this.currentKeyword?.length || 0);
|
|
14291
|
+
this.write(`${ESC}${cursorPos}G`);
|
|
14178
14292
|
}
|
|
14179
14293
|
write(data) {
|
|
14180
14294
|
this.stdout.write(data);
|
|
@@ -14369,14 +14483,14 @@ async function startVitest(mode, cliFilters = [], options = {}, viteOverrides, v
|
|
|
14369
14483
|
let stdinCleanup;
|
|
14370
14484
|
if (stdin.isTTY && ctx.config.watch) stdinCleanup = registerConsoleShortcuts(ctx, stdin, stdout);
|
|
14371
14485
|
ctx.onAfterSetServer(() => {
|
|
14372
|
-
if (ctx.config.standalone) ctx.
|
|
14486
|
+
if (ctx.config.standalone) ctx.standalone();
|
|
14373
14487
|
else ctx.start(cliFilters);
|
|
14374
14488
|
});
|
|
14375
14489
|
try {
|
|
14376
14490
|
if (ctx.config.listTags) await ctx.listTags();
|
|
14377
14491
|
else if (ctx.config.clearCache) await ctx.experimental_clearCache();
|
|
14378
14492
|
else if (ctx.config.mergeReports) await ctx.mergeReports();
|
|
14379
|
-
else if (ctx.config.standalone) await ctx.
|
|
14493
|
+
else if (ctx.config.standalone) await ctx.standalone();
|
|
14380
14494
|
else await ctx.start(cliFilters);
|
|
14381
14495
|
return ctx;
|
|
14382
14496
|
} catch (e) {
|
|
@@ -206,6 +206,7 @@ interface SerializedConfig {
|
|
|
206
206
|
tagsFilter: string[] | undefined;
|
|
207
207
|
strictTags: boolean;
|
|
208
208
|
slowTestThreshold: number | undefined;
|
|
209
|
+
isAgent: boolean;
|
|
209
210
|
}
|
|
210
211
|
interface SerializedCoverageConfig {
|
|
211
212
|
provider: "istanbul" | "v8" | "custom" | undefined;
|
|
@@ -8,7 +8,10 @@ async function resolveCoverageProviderModule(options, loader) {
|
|
|
8
8
|
if (provider === "v8" || provider === "istanbul") {
|
|
9
9
|
let builtInModule = CoverageProviderMap[provider];
|
|
10
10
|
if (provider === "v8" && loader.isBrowser) builtInModule += "/browser";
|
|
11
|
-
const { default: coverageModule } = await loader.import(builtInModule)
|
|
11
|
+
const { default: coverageModule } = loader.isBrowser ? await loader.import(builtInModule) : await import(
|
|
12
|
+
/* @vite-ignore */
|
|
13
|
+
builtInModule
|
|
14
|
+
);
|
|
12
15
|
if (!coverageModule) throw new Error(`Failed to load ${CoverageProviderMap[provider]}. Default export is missing.`);
|
|
13
16
|
return coverageModule;
|
|
14
17
|
}
|