vitest 3.2.0-beta.2 → 3.2.0-beta.3
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 +3 -3
- package/dist/browser.js +1 -1
- package/dist/chunks/{base.DwtwORaC.js → base.D4119yLM.js} +4 -3
- package/dist/chunks/{benchmark.BoF7jW0Q.js → benchmark.Cf_PACH1.js} +1 -1
- package/dist/chunks/{cac.I9MLYfT-.js → cac.DWaWHIIE.js} +18 -15
- package/dist/chunks/{cli-api.d6IK1pnk.js → cli-api.CnmEXkxs.js} +250 -49
- package/dist/chunks/{config.d.UqE-KR0o.d.ts → config.d.D2ROskhv.d.ts} +2 -0
- package/dist/chunks/{console.K1NMVOSc.js → console.Cwr-MFPV.js} +3 -2
- package/dist/chunks/{constants.BZZyIeIE.js → constants.DnKduX2e.js} +1 -0
- package/dist/chunks/{coverage.OGU09Jbh.js → coverage.C73DaDgS.js} +116 -12
- package/dist/chunks/{creator.DGAdZ4Hj.js → creator.C8WKy2eW.js} +10 -7
- package/dist/chunks/{date.CDOsz-HY.js → date.ByMsSlOr.js} +25 -0
- package/dist/chunks/{defaults.DSxsTG0h.js → defaults.DpVH7vbg.js} +1 -0
- package/dist/chunks/{environment.d.D8YDy2v5.d.ts → environment.d.cL3nLXbE.d.ts} +1 -0
- package/dist/chunks/{execute.JlGHLJZT.js → execute.B3q-2LPV.js} +25 -0
- package/dist/chunks/{global.d.BPa1eL3O.d.ts → global.d.BNLIi6yo.d.ts} +3 -1
- package/dist/chunks/{globals.CpxW8ccg.js → globals.CI21aWXF.js} +7 -6
- package/dist/chunks/{index.DFXFpH3w.js → index.2jgTs_Q5.js} +19 -1
- package/dist/chunks/{index.CV36oG_L.js → index.Bter3jj9.js} +83 -16
- package/dist/chunks/{index.DswW_LEs.js → index.CbT4iuwc.js} +7 -4
- package/dist/chunks/index.D3XRDfWc.js +213 -0
- package/dist/chunks/{index.CfXMNXHg.js → index.DNgLEKsQ.js} +4 -2
- package/dist/chunks/{index.CmC5OK9L.js → index.JOzufsrU.js} +2 -1
- package/dist/chunks/{inspector.DbDkSkFn.js → inspector.BFsh5KO0.js} +3 -0
- package/dist/chunks/{node.3xsWotC9.js → node.Be-ntJnD.js} +1 -1
- package/dist/chunks/{reporters.d.CLC9rhKy.d.ts → reporters.d.Bt4IGtsa.d.ts} +24 -6
- package/dist/chunks/{rpc.D9_013TY.js → rpc.BKExFSRG.js} +2 -1
- package/dist/chunks/{runBaseTests.Dn2vyej_.js → runBaseTests.B_M1TTsK.js} +19 -10
- package/dist/chunks/{setup-common.CYo3Y0dD.js → setup-common.CF-O-dZX.js} +2 -1
- package/dist/chunks/{typechecker.DnTrplSJ.js → typechecker.BgzF-6iO.js} +78 -21
- package/dist/chunks/{utils.CgTj3MsC.js → utils.BlI4TC7Y.js} +1 -0
- package/dist/chunks/{utils.BfxieIyZ.js → utils.DPCq3gzW.js} +3 -0
- package/dist/chunks/{vi.BFR5YIgu.js → vi.pkoYCV6A.js} +25 -2
- package/dist/chunks/{vite.d.CBZ3M_ru.d.ts → vite.d.B-Kx3KCF.d.ts} +3 -1
- package/dist/chunks/{vm.C1HHjtNS.js → vm.DPYem2so.js} +72 -4
- package/dist/chunks/{worker.d.CoCI7hzP.d.ts → worker.d.BKbBp2ga.d.ts} +2 -2
- package/dist/chunks/{worker.d.D5Xdi-Zr.d.ts → worker.d.Bl1O4kuf.d.ts} +1 -1
- package/dist/cli.js +4 -4
- package/dist/config.cjs +2 -0
- package/dist/config.d.ts +7 -6
- package/dist/config.js +2 -2
- package/dist/coverage.d.ts +4 -4
- package/dist/coverage.js +5 -5
- package/dist/environments.d.ts +6 -2
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +9 -3
- package/dist/execute.js +1 -1
- package/dist/index.d.ts +24 -12
- package/dist/index.js +5 -5
- package/dist/node.d.ts +18 -10
- package/dist/node.js +14 -12
- package/dist/reporters.d.ts +4 -4
- package/dist/reporters.js +3 -3
- package/dist/runners.d.ts +1 -1
- package/dist/runners.js +13 -5
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +9 -5
- package/dist/workers/forks.js +6 -4
- package/dist/workers/runVmTests.js +14 -9
- package/dist/workers/threads.js +4 -4
- package/dist/workers/vmForks.js +6 -6
- package/dist/workers/vmThreads.js +6 -6
- package/dist/workers.d.ts +4 -4
- package/dist/workers.js +10 -10
- package/package.json +18 -18
- package/dist/chunks/index.CK1YOQaa.js +0 -143
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import path, { resolve } from 'node:path';
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { x } from 'tinyexec';
|
|
6
|
+
|
|
7
|
+
const AGENTS = [
|
|
8
|
+
"npm",
|
|
9
|
+
"yarn",
|
|
10
|
+
"yarn@berry",
|
|
11
|
+
"pnpm",
|
|
12
|
+
"pnpm@6",
|
|
13
|
+
"bun",
|
|
14
|
+
"deno"
|
|
15
|
+
];
|
|
16
|
+
const LOCKS = {
|
|
17
|
+
"bun.lock": "bun",
|
|
18
|
+
"bun.lockb": "bun",
|
|
19
|
+
"deno.lock": "deno",
|
|
20
|
+
"pnpm-lock.yaml": "pnpm",
|
|
21
|
+
"pnpm-workspace.yaml": "pnpm",
|
|
22
|
+
"yarn.lock": "yarn",
|
|
23
|
+
"package-lock.json": "npm",
|
|
24
|
+
"npm-shrinkwrap.json": "npm"
|
|
25
|
+
};
|
|
26
|
+
const INSTALL_METADATA = {
|
|
27
|
+
"node_modules/.deno/": "deno",
|
|
28
|
+
"node_modules/.pnpm/": "pnpm",
|
|
29
|
+
"node_modules/.yarn-state.yml": "yarn",
|
|
30
|
+
// yarn v2+ (node-modules)
|
|
31
|
+
"node_modules/.yarn_integrity": "yarn",
|
|
32
|
+
// yarn v1
|
|
33
|
+
"node_modules/.package-lock.json": "npm",
|
|
34
|
+
".pnp.cjs": "yarn",
|
|
35
|
+
// yarn v3+ (pnp)
|
|
36
|
+
".pnp.js": "yarn",
|
|
37
|
+
// yarn v2 (pnp)
|
|
38
|
+
"bun.lock": "bun",
|
|
39
|
+
"bun.lockb": "bun"
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
async function pathExists(path2, type) {
|
|
43
|
+
try {
|
|
44
|
+
const stat = await fs.stat(path2);
|
|
45
|
+
return type === "file" ? stat.isFile() : stat.isDirectory();
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function* lookup(cwd = process.cwd()) {
|
|
51
|
+
let directory = path.resolve(cwd);
|
|
52
|
+
const { root } = path.parse(directory);
|
|
53
|
+
while (directory && directory !== root) {
|
|
54
|
+
yield directory;
|
|
55
|
+
directory = path.dirname(directory);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function parsePackageJson(filepath, onUnknown) {
|
|
59
|
+
return !filepath || !pathExists(filepath, "file") ? null : await handlePackageManager(filepath, onUnknown);
|
|
60
|
+
}
|
|
61
|
+
async function detect(options = {}) {
|
|
62
|
+
const {
|
|
63
|
+
cwd,
|
|
64
|
+
strategies = ["lockfile", "packageManager-field", "devEngines-field"],
|
|
65
|
+
onUnknown
|
|
66
|
+
} = options;
|
|
67
|
+
let stopDir;
|
|
68
|
+
if (typeof options.stopDir === "string") {
|
|
69
|
+
const resolved = path.resolve(options.stopDir);
|
|
70
|
+
stopDir = (dir) => dir === resolved;
|
|
71
|
+
} else {
|
|
72
|
+
stopDir = options.stopDir;
|
|
73
|
+
}
|
|
74
|
+
for (const directory of lookup(cwd)) {
|
|
75
|
+
for (const strategy of strategies) {
|
|
76
|
+
switch (strategy) {
|
|
77
|
+
case "lockfile": {
|
|
78
|
+
for (const lock of Object.keys(LOCKS)) {
|
|
79
|
+
if (await pathExists(path.join(directory, lock), "file")) {
|
|
80
|
+
const name = LOCKS[lock];
|
|
81
|
+
const result = await parsePackageJson(path.join(directory, "package.json"), onUnknown);
|
|
82
|
+
if (result)
|
|
83
|
+
return result;
|
|
84
|
+
else
|
|
85
|
+
return { name, agent: name };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case "packageManager-field":
|
|
91
|
+
case "devEngines-field": {
|
|
92
|
+
const result = await parsePackageJson(path.join(directory, "package.json"), onUnknown);
|
|
93
|
+
if (result)
|
|
94
|
+
return result;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case "install-metadata": {
|
|
98
|
+
for (const metadata of Object.keys(INSTALL_METADATA)) {
|
|
99
|
+
const fileOrDir = metadata.endsWith("/") ? "dir" : "file";
|
|
100
|
+
if (await pathExists(path.join(directory, metadata), fileOrDir)) {
|
|
101
|
+
const name = INSTALL_METADATA[metadata];
|
|
102
|
+
const agent = name === "yarn" ? isMetadataYarnClassic(metadata) ? "yarn" : "yarn@berry" : name;
|
|
103
|
+
return { name, agent };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (stopDir?.(directory))
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
function getNameAndVer(pkg) {
|
|
116
|
+
const handelVer = (version) => version?.match(/\d+(\.\d+){0,2}/)?.[0] ?? version;
|
|
117
|
+
if (typeof pkg.packageManager === "string") {
|
|
118
|
+
const [name, ver] = pkg.packageManager.replace(/^\^/, "").split("@");
|
|
119
|
+
return { name, ver: handelVer(ver) };
|
|
120
|
+
}
|
|
121
|
+
if (typeof pkg.devEngines?.packageManager?.name === "string") {
|
|
122
|
+
return {
|
|
123
|
+
name: pkg.devEngines.packageManager.name,
|
|
124
|
+
ver: handelVer(pkg.devEngines.packageManager.version)
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return void 0;
|
|
128
|
+
}
|
|
129
|
+
async function handlePackageManager(filepath, onUnknown) {
|
|
130
|
+
try {
|
|
131
|
+
const pkg = JSON.parse(await fs.readFile(filepath, "utf8"));
|
|
132
|
+
let agent;
|
|
133
|
+
const nameAndVer = getNameAndVer(pkg);
|
|
134
|
+
if (nameAndVer) {
|
|
135
|
+
const name = nameAndVer.name;
|
|
136
|
+
const ver = nameAndVer.ver;
|
|
137
|
+
let version = ver;
|
|
138
|
+
if (name === "yarn" && ver && Number.parseInt(ver) > 1) {
|
|
139
|
+
agent = "yarn@berry";
|
|
140
|
+
version = "berry";
|
|
141
|
+
return { name, agent, version };
|
|
142
|
+
} else if (name === "pnpm" && ver && Number.parseInt(ver) < 7) {
|
|
143
|
+
agent = "pnpm@6";
|
|
144
|
+
return { name, agent, version };
|
|
145
|
+
} else if (AGENTS.includes(name)) {
|
|
146
|
+
agent = name;
|
|
147
|
+
return { name, agent, version };
|
|
148
|
+
} else {
|
|
149
|
+
return onUnknown?.(pkg.packageManager) ?? null;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
} catch {
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
function isMetadataYarnClassic(metadataPath) {
|
|
157
|
+
return metadataPath.endsWith(".yarn_integrity");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/detect.ts
|
|
161
|
+
async function detectPackageManager(cwd = process.cwd()) {
|
|
162
|
+
const result = await detect({
|
|
163
|
+
cwd,
|
|
164
|
+
onUnknown(packageManager) {
|
|
165
|
+
console.warn("[@antfu/install-pkg] Unknown packageManager:", packageManager);
|
|
166
|
+
return void 0;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
return result?.agent || null;
|
|
170
|
+
}
|
|
171
|
+
async function installPackage(names, options = {}) {
|
|
172
|
+
const detectedAgent = options.packageManager || await detectPackageManager(options.cwd) || "npm";
|
|
173
|
+
const [agent] = detectedAgent.split("@");
|
|
174
|
+
if (!Array.isArray(names))
|
|
175
|
+
names = [names];
|
|
176
|
+
const args = (typeof options.additionalArgs === "function" ? options.additionalArgs(agent, detectedAgent) : options.additionalArgs) || [];
|
|
177
|
+
if (options.preferOffline) {
|
|
178
|
+
if (detectedAgent === "yarn@berry")
|
|
179
|
+
args.unshift("--cached");
|
|
180
|
+
else
|
|
181
|
+
args.unshift("--prefer-offline");
|
|
182
|
+
}
|
|
183
|
+
if (agent === "pnpm") {
|
|
184
|
+
args.unshift(
|
|
185
|
+
/**
|
|
186
|
+
* Prevent pnpm from removing installed devDeps while `NODE_ENV` is `production`
|
|
187
|
+
* @see https://pnpm.io/cli/install#--prod--p
|
|
188
|
+
*/
|
|
189
|
+
"--prod=false"
|
|
190
|
+
);
|
|
191
|
+
if (existsSync(resolve(options.cwd ?? process.cwd(), "pnpm-workspace.yaml"))) {
|
|
192
|
+
args.unshift("-w");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return x(
|
|
196
|
+
agent,
|
|
197
|
+
[
|
|
198
|
+
agent === "yarn" ? "add" : "install",
|
|
199
|
+
options.dev ? "-D" : "",
|
|
200
|
+
...args,
|
|
201
|
+
...names
|
|
202
|
+
].filter(Boolean),
|
|
203
|
+
{
|
|
204
|
+
nodeOptions: {
|
|
205
|
+
stdio: options.silent ? "ignore" : "inherit",
|
|
206
|
+
cwd: options.cwd
|
|
207
|
+
},
|
|
208
|
+
throwOnError: true
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export { detectPackageManager, installPackage };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as createExpect, a as globalExpect, i as inject, v as vi, b as vitest } from './vi.
|
|
2
|
-
import { b as bench } from './benchmark.
|
|
1
|
+
import { c as createExpect, a as globalExpect, i as inject, v as vi, b as vitest } from './vi.pkoYCV6A.js';
|
|
2
|
+
import { b as bench } from './benchmark.Cf_PACH1.js';
|
|
3
3
|
import { expectTypeOf } from 'expect-type';
|
|
4
4
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
|
|
5
5
|
import * as chai from 'chai';
|
|
@@ -7,6 +7,8 @@ import { assert, should } from 'chai';
|
|
|
7
7
|
|
|
8
8
|
const assertType = function assertType() {};
|
|
9
9
|
|
|
10
|
+
// TODO: deprecate <reference types="vitest" /> in favor of `<reference types="vitest/config" />`
|
|
11
|
+
|
|
10
12
|
var VitestIndex = /*#__PURE__*/Object.freeze({
|
|
11
13
|
__proto__: null,
|
|
12
14
|
afterAll: afterAll,
|
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import { getTasks, getFullName, getTests } from '@vitest/runner/utils';
|
|
3
3
|
import * as pathe from 'pathe';
|
|
4
4
|
import c from 'tinyrainbow';
|
|
5
|
-
import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName } from './index.
|
|
5
|
+
import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName } from './index.Bter3jj9.js';
|
|
6
6
|
import { stripVTControlCharacters } from 'node:util';
|
|
7
7
|
import { notNullish } from '@vitest/utils';
|
|
8
8
|
|
|
@@ -249,6 +249,7 @@ class BenchmarkReporter extends DefaultReporter {
|
|
|
249
249
|
}
|
|
250
250
|
async onFinished(files = this.ctx.state.getFiles(), errors = this.ctx.state.getUnhandledErrors()) {
|
|
251
251
|
super.onFinished(files, errors);
|
|
252
|
+
// write output for future comparison
|
|
252
253
|
let outputFile = this.ctx.config.benchmark?.outputJson;
|
|
253
254
|
if (outputFile) {
|
|
254
255
|
outputFile = pathe.resolve(this.ctx.config.root, outputFile);
|
|
@@ -13,11 +13,13 @@ function setupInspect(ctx) {
|
|
|
13
13
|
const isEnabled = config.inspector.enabled;
|
|
14
14
|
if (isEnabled) {
|
|
15
15
|
inspector = __require("node:inspector");
|
|
16
|
+
// Inspector may be open already if "isolate: false" is used
|
|
16
17
|
const isOpen = inspector.url() !== undefined;
|
|
17
18
|
if (!isOpen) {
|
|
18
19
|
inspector.open(config.inspector.port, config.inspector.host, config.inspector.waitForDebugger);
|
|
19
20
|
if (config.inspectBrk) {
|
|
20
21
|
const firstTestFile = typeof ctx.files[0] === "string" ? ctx.files[0] : ctx.files[0].filepath;
|
|
22
|
+
// Stop at first test file
|
|
21
23
|
if (firstTestFile) {
|
|
22
24
|
session = new inspector.Session();
|
|
23
25
|
session.connect();
|
|
@@ -46,6 +48,7 @@ function closeInspector(config) {
|
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
function shouldKeepOpen(config) {
|
|
51
|
+
// In watch mode the inspector can persist re-runs if isolation is disabled and a single worker is used
|
|
49
52
|
const isIsolatedSingleThread = config.pool === "threads" && config.poolOptions?.threads?.isolate === false && config.poolOptions?.threads?.singleThread;
|
|
50
53
|
const isIsolatedSingleFork = config.pool === "forks" && config.poolOptions?.forks?.isolate === false && config.poolOptions?.forks?.singleFork;
|
|
51
54
|
return config.watch && (isIsolatedSingleFork || isIsolatedSingleThread);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
|
|
2
|
-
import { g as getWorkerState } from './utils.
|
|
2
|
+
import { g as getWorkerState } from './utils.BlI4TC7Y.js';
|
|
3
3
|
import '@vitest/utils';
|
|
4
4
|
|
|
5
5
|
class VitestNodeSnapshotEnvironment extends NodeSnapshotEnvironment {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Task, TaskMeta, Suite, File, TaskResultPack, SequenceSetupFiles, SequenceHooks, CancelReason } from '@vitest/runner';
|
|
2
|
-
import { b as Awaitable, U as UserConsoleLog, c as Arrayable$1, A as AfterSuiteRunMeta, L as LabelColor, f as EnvironmentOptions, P as ProvidedContext } from './environment.d.
|
|
2
|
+
import { b as Awaitable, U as UserConsoleLog, c as Arrayable$1, A as AfterSuiteRunMeta, L as LabelColor, f as EnvironmentOptions, P as ProvidedContext } from './environment.d.cL3nLXbE.js';
|
|
3
3
|
import { ParsedStack, TestError, SerializedError, ErrorWithDiff, Arrayable, Awaitable as Awaitable$1 } from '@vitest/utils';
|
|
4
4
|
import { Writable } from 'node:stream';
|
|
5
5
|
import { TransformResult as TransformResult$1, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions, ViteDevServer, ModuleNode } from 'vite';
|
|
6
6
|
import { Console } from 'node:console';
|
|
7
7
|
import { MockedModule } from '@vitest/mocker';
|
|
8
8
|
import { StackTraceParserOptions } from '@vitest/utils/source-map';
|
|
9
|
-
import { T as TestExecutionMethod } from './worker.d.
|
|
10
|
-
import { a as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.
|
|
9
|
+
import { T as TestExecutionMethod } from './worker.d.BKbBp2ga.js';
|
|
10
|
+
import { a as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.D2ROskhv.js';
|
|
11
11
|
import { PrettyFormatOptions } from '@vitest/pretty-format';
|
|
12
12
|
import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
|
|
13
13
|
import { SerializedDiffOptions } from '@vitest/utils/diff';
|
|
@@ -714,7 +714,6 @@ declare class DefaultReporter extends BaseReporter {
|
|
|
714
714
|
onHookStart(hook: ReportedHookContext): void;
|
|
715
715
|
onHookEnd(hook: ReportedHookContext): void;
|
|
716
716
|
onInit(ctx: Vitest): void;
|
|
717
|
-
onPathsCollected(paths?: string[]): void;
|
|
718
717
|
onTestRunEnd(): void;
|
|
719
718
|
}
|
|
720
719
|
|
|
@@ -826,6 +825,9 @@ declare class FileCoverage implements FileCoverageData {
|
|
|
826
825
|
b: { [key: string]: number[] };
|
|
827
826
|
}
|
|
828
827
|
|
|
828
|
+
// for compatibility reasons, the reporter produces a JSON similar to the one produced by the Jest JSON reporter
|
|
829
|
+
// the following types are extracted from the Jest repository (and simplified)
|
|
830
|
+
// the commented-out fields are the missing ones
|
|
829
831
|
type Status = "passed" | "failed" | "skipped" | "pending" | "todo" | "disabled";
|
|
830
832
|
type Milliseconds = number;
|
|
831
833
|
interface Callsite {
|
|
@@ -946,8 +948,13 @@ declare class DotReporter extends BaseReporter {
|
|
|
946
948
|
private createSummary;
|
|
947
949
|
}
|
|
948
950
|
|
|
951
|
+
interface GithubActionsReporterOptions {
|
|
952
|
+
onWritePath?: (path: string) => string;
|
|
953
|
+
}
|
|
949
954
|
declare class GithubActionsReporter implements Reporter {
|
|
950
955
|
ctx: Vitest;
|
|
956
|
+
options: GithubActionsReporterOptions;
|
|
957
|
+
constructor(options?: GithubActionsReporterOptions);
|
|
951
958
|
onInit(ctx: Vitest): void;
|
|
952
959
|
onFinished(files?: File[], errors?: unknown[]): void;
|
|
953
960
|
}
|
|
@@ -1425,6 +1432,7 @@ interface Thresholds {
|
|
|
1425
1432
|
}
|
|
1426
1433
|
|
|
1427
1434
|
type BuiltinEnvironment = "node" | "jsdom" | "happy-dom" | "edge-runtime";
|
|
1435
|
+
// Record is used, so user can get intellisense for builtin environments, but still allow custom environments
|
|
1428
1436
|
type VitestEnvironment = BuiltinEnvironment | (string & Record<never, never>);
|
|
1429
1437
|
|
|
1430
1438
|
type CSSModuleScopeStrategy = "stable" | "scoped" | "non-scoped";
|
|
@@ -2173,6 +2181,11 @@ interface TypecheckConfig {
|
|
|
2173
2181
|
* Path to tsconfig, relative to the project root.
|
|
2174
2182
|
*/
|
|
2175
2183
|
tsconfig?: string;
|
|
2184
|
+
/**
|
|
2185
|
+
* Minimum time in milliseconds it takes to spawn the typechecker.
|
|
2186
|
+
* @default 10_000
|
|
2187
|
+
*/
|
|
2188
|
+
spawnTimeout?: number;
|
|
2176
2189
|
}
|
|
2177
2190
|
interface UserConfig extends InlineConfig {
|
|
2178
2191
|
/**
|
|
@@ -2351,6 +2364,7 @@ interface BrowserProvider {
|
|
|
2351
2364
|
openPage: (sessionId: string, url: string, beforeNavigate?: () => Promise<void>) => Promise<void>;
|
|
2352
2365
|
getCDPSession?: (sessionId: string) => Promise<CDPSession>;
|
|
2353
2366
|
close: () => Awaitable$1<void>;
|
|
2367
|
+
// eslint-disable-next-line ts/method-signature-style -- we want to allow extended options
|
|
2354
2368
|
initialize(ctx: TestProject, options: BrowserProviderInitializationOptions): Awaitable$1<void>;
|
|
2355
2369
|
}
|
|
2356
2370
|
interface BrowserProviderModule {
|
|
@@ -2613,6 +2627,8 @@ declare class TestProject {
|
|
|
2613
2627
|
* It is based on the root of the project (not consistent between OS) and its name.
|
|
2614
2628
|
*/
|
|
2615
2629
|
get hash(): string;
|
|
2630
|
+
// "provide" is a property, not a method to keep the context when destructed in the global setup,
|
|
2631
|
+
// making it a method would be a breaking change, and can be done in Vitest 3 at minimum
|
|
2616
2632
|
/**
|
|
2617
2633
|
* Provide a value to the test context. This value will be available to all tests with `inject`.
|
|
2618
2634
|
*/
|
|
@@ -2664,6 +2680,7 @@ declare class TestProject {
|
|
|
2664
2680
|
teardownGlobalSetup(): Promise<void>;
|
|
2665
2681
|
/** @deprecated use `vitest.logger` instead */
|
|
2666
2682
|
get logger(): Logger;
|
|
2683
|
+
// it's possible that file path was imported with different queries (?raw, ?url, etc)
|
|
2667
2684
|
/** @deprecated use `.vite` or `.browser.vite` directly */
|
|
2668
2685
|
getModulesByFilepath(file: string): Set<ModuleNode>;
|
|
2669
2686
|
/** @deprecated use `.vite` or `.browser.vite` directly */
|
|
@@ -2879,7 +2896,7 @@ declare class Vitest {
|
|
|
2879
2896
|
private _cache?;
|
|
2880
2897
|
private _snapshot?;
|
|
2881
2898
|
private _workspaceConfigPath?;
|
|
2882
|
-
constructor(mode: VitestRunMode, options?: VitestOptions);
|
|
2899
|
+
constructor(mode: VitestRunMode, cliOptions: UserConfig, options?: VitestOptions);
|
|
2883
2900
|
private _onRestartListeners;
|
|
2884
2901
|
private _onClose;
|
|
2885
2902
|
private _onSetServer;
|
|
@@ -2914,7 +2931,7 @@ declare class Vitest {
|
|
|
2914
2931
|
*/
|
|
2915
2932
|
get cache(): VitestCache;
|
|
2916
2933
|
/** @deprecated internal */
|
|
2917
|
-
setServer(options: UserConfig, server: ViteDevServer
|
|
2934
|
+
setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
|
|
2918
2935
|
/**
|
|
2919
2936
|
* Inject new test projects into the workspace.
|
|
2920
2937
|
* @param config Glob, config path or a custom config options.
|
|
@@ -3046,6 +3063,7 @@ declare class Vitest {
|
|
|
3046
3063
|
*/
|
|
3047
3064
|
resetGlobalTestNamePattern(): void;
|
|
3048
3065
|
private _rerunTimer;
|
|
3066
|
+
// we can't use a single `triggerId` yet because vscode extension relies on this
|
|
3049
3067
|
private scheduleRerun;
|
|
3050
3068
|
/**
|
|
3051
3069
|
* Invalidate a file in all projects.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getSafeTimers } from '@vitest/utils';
|
|
2
2
|
import { c as createBirpc } from './index.CJ0plNrh.js';
|
|
3
|
-
import { g as getWorkerState } from './utils.
|
|
3
|
+
import { g as getWorkerState } from './utils.BlI4TC7Y.js';
|
|
4
4
|
|
|
5
5
|
const { get } = Reflect;
|
|
6
6
|
function withSafeTimers(fn) {
|
|
@@ -56,6 +56,7 @@ function createRuntimeRpc(options) {
|
|
|
56
56
|
if (functionName === "fetch" || functionName === "transform" || functionName === "resolveId") {
|
|
57
57
|
message += ` with "${JSON.stringify(args)}"`;
|
|
58
58
|
}
|
|
59
|
+
// JSON.stringify cannot serialize Error instances
|
|
59
60
|
if (functionName === "onUnhandledError") {
|
|
60
61
|
message += ` with "${args[0]?.message || args[0]}"`;
|
|
61
62
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { performance } from 'node:perf_hooks';
|
|
2
2
|
import { startTests, collectTests } from '@vitest/runner';
|
|
3
|
-
import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.
|
|
4
|
-
import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.
|
|
5
|
-
import { a as globalExpect, v as vi } from './vi.
|
|
6
|
-
import { c as closeInspector } from './inspector.
|
|
3
|
+
import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.CbT4iuwc.js';
|
|
4
|
+
import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.CF-O-dZX.js';
|
|
5
|
+
import { a as globalExpect, v as vi } from './vi.pkoYCV6A.js';
|
|
6
|
+
import { c as closeInspector } from './inspector.BFsh5KO0.js';
|
|
7
7
|
import { createRequire } from 'node:module';
|
|
8
8
|
import timers from 'node:timers';
|
|
9
9
|
import timersPromises from 'node:timers/promises';
|
|
@@ -11,13 +11,13 @@ import util from 'node:util';
|
|
|
11
11
|
import { getSafeTimers } from '@vitest/utils';
|
|
12
12
|
import { KNOWN_ASSET_TYPES } from 'vite-node/constants';
|
|
13
13
|
import { installSourcemapsSupport } from 'vite-node/source-map';
|
|
14
|
-
import { V as VitestIndex } from './index.
|
|
15
|
-
import { g as getWorkerState, r as resetModules } from './utils.
|
|
14
|
+
import { V as VitestIndex } from './index.DNgLEKsQ.js';
|
|
15
|
+
import { g as getWorkerState, r as resetModules } from './utils.BlI4TC7Y.js';
|
|
16
16
|
import 'chai';
|
|
17
17
|
import 'node:path';
|
|
18
18
|
import '../path.js';
|
|
19
19
|
import 'node:url';
|
|
20
|
-
import './rpc.
|
|
20
|
+
import './rpc.BKExFSRG.js';
|
|
21
21
|
import './index.CJ0plNrh.js';
|
|
22
22
|
import './coverage.0iPg4Wrz.js';
|
|
23
23
|
import '@vitest/snapshot';
|
|
@@ -27,10 +27,11 @@ import './_commonjsHelpers.BFTU3MAI.js';
|
|
|
27
27
|
import '@vitest/utils/error';
|
|
28
28
|
import '@vitest/spy';
|
|
29
29
|
import '@vitest/utils/source-map';
|
|
30
|
-
import './date.
|
|
31
|
-
import './benchmark.
|
|
30
|
+
import './date.ByMsSlOr.js';
|
|
31
|
+
import './benchmark.Cf_PACH1.js';
|
|
32
32
|
import 'expect-type';
|
|
33
33
|
|
|
34
|
+
// this should only be used in Node
|
|
34
35
|
let globalSetup = false;
|
|
35
36
|
async function setupGlobalEnv(config, { environment }, executor) {
|
|
36
37
|
await setupCommonEnv(config);
|
|
@@ -48,10 +49,12 @@ async function setupGlobalEnv(config, { environment }, executor) {
|
|
|
48
49
|
globalSetup = true;
|
|
49
50
|
if (environment.transformMode === "web") {
|
|
50
51
|
const _require = createRequire(import.meta.url);
|
|
52
|
+
// always mock "required" `css` files, because we cannot process them
|
|
51
53
|
_require.extensions[".css"] = resolveCss;
|
|
52
54
|
_require.extensions[".scss"] = resolveCss;
|
|
53
55
|
_require.extensions[".sass"] = resolveCss;
|
|
54
56
|
_require.extensions[".less"] = resolveCss;
|
|
57
|
+
// since we are using Vite, we can assume how these will be resolved
|
|
55
58
|
KNOWN_ASSET_TYPES.forEach((type) => {
|
|
56
59
|
_require.extensions[`.${type}`] = resolveAsset;
|
|
57
60
|
});
|
|
@@ -59,6 +62,7 @@ async function setupGlobalEnv(config, { environment }, executor) {
|
|
|
59
62
|
} else {
|
|
60
63
|
process.env.SSR = "1";
|
|
61
64
|
}
|
|
65
|
+
// @ts-expect-error not typed global for patched timers
|
|
62
66
|
globalThis.__vitest_required__ = {
|
|
63
67
|
util,
|
|
64
68
|
timers,
|
|
@@ -76,22 +80,25 @@ function resolveAsset(mod, url) {
|
|
|
76
80
|
mod.exports = url;
|
|
77
81
|
}
|
|
78
82
|
async function setupConsoleLogSpy() {
|
|
79
|
-
const { createCustomConsole } = await import('./console.
|
|
83
|
+
const { createCustomConsole } = await import('./console.Cwr-MFPV.js');
|
|
80
84
|
globalThis.console = createCustomConsole();
|
|
81
85
|
}
|
|
82
86
|
async function withEnv({ environment }, options, fn) {
|
|
87
|
+
// @ts-expect-error untyped global
|
|
83
88
|
globalThis.__vitest_environment__ = environment.name;
|
|
84
89
|
globalExpect.setState({ environment: environment.name });
|
|
85
90
|
const env = await environment.setup(globalThis, options);
|
|
86
91
|
try {
|
|
87
92
|
await fn();
|
|
88
93
|
} finally {
|
|
94
|
+
// Run possible setTimeouts, e.g. the onces used by ConsoleLogSpy
|
|
89
95
|
const { setTimeout } = getSafeTimers();
|
|
90
96
|
await new Promise((resolve) => setTimeout(resolve));
|
|
91
97
|
await env.teardown(globalThis);
|
|
92
98
|
}
|
|
93
99
|
}
|
|
94
100
|
|
|
101
|
+
// browser shouldn't call this!
|
|
95
102
|
async function run(method, files, config, environment, executor) {
|
|
96
103
|
const workerState = getWorkerState();
|
|
97
104
|
const isIsolatedThreads = config.pool === "threads" && (config.poolOptions?.threads?.isolate ?? true);
|
|
@@ -122,7 +129,9 @@ async function run(method, files, config, environment, executor) {
|
|
|
122
129
|
} else {
|
|
123
130
|
await collectTests([file], runner);
|
|
124
131
|
}
|
|
132
|
+
// reset after tests, because user might call `vi.setConfig` in setupFile
|
|
125
133
|
vi.resetConfig();
|
|
134
|
+
// mocks should not affect different files
|
|
126
135
|
vi.restoreAllMocks();
|
|
127
136
|
}
|
|
128
137
|
await stopCoverageInsideWorker(config.coverage, executor, { isolate });
|
|
@@ -34,7 +34,7 @@ async function setupCommonEnv(config) {
|
|
|
34
34
|
globalSetup = true;
|
|
35
35
|
setSafeTimers();
|
|
36
36
|
if (config.globals) {
|
|
37
|
-
(await import('./globals.
|
|
37
|
+
(await import('./globals.CI21aWXF.js')).registerApiGlobally();
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
function setupDefines(defines) {
|
|
@@ -46,6 +46,7 @@ function setupEnv(env) {
|
|
|
46
46
|
if (typeof process === "undefined") {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
+
// same boolean-to-string assignment as VitestPlugin.configResolved
|
|
49
50
|
const { PROD, DEV,...restEnvs } = env;
|
|
50
51
|
process.env.PROD = PROD ? "1" : "";
|
|
51
52
|
process.env.DEV = DEV ? "1" : "";
|