vitest 1.5.2 → 1.6.0
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 +1 -1
- package/dist/chunks/environments-node.vcoXCoKs.js +19 -0
- package/dist/chunks/{integrations-globals.k0N5-dd1.js → integrations-globals.kw4co3rx.js} +7 -6
- package/dist/chunks/{runtime-console.kbFEN7E-.js → runtime-console.EO5ha7qv.js} +3 -3
- package/dist/chunks/{runtime-runBaseTests.-x-nNuJ_.js → runtime-runBaseTests.oAvMKtQC.js} +16 -16
- package/dist/cli.js +2 -2
- package/dist/config.cjs +3 -2
- package/dist/config.d.ts +1 -1
- package/dist/config.js +3 -2
- package/dist/coverage.d.ts +1 -1
- package/dist/environments.d.ts +1 -1
- package/dist/execute.d.ts +6 -4
- package/dist/execute.js +3 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +8 -7
- package/dist/node.d.ts +2 -2
- package/dist/node.js +12 -11
- package/dist/{reporters-xEmem8D4.d.ts → reporters-yx5ZTtEV.d.ts} +101 -26
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +11 -10
- package/dist/runners.d.ts +1 -1
- package/dist/runners.js +8 -7
- package/dist/snapshot.d.ts +9 -0
- package/dist/snapshot.js +8 -0
- package/dist/{suite-HPAKvIxA.d.ts → suite-IbNSsUWN.d.ts} +1 -1
- package/dist/suite.d.ts +3 -3
- package/dist/suite.js +5 -4
- package/dist/vendor/{base.Xt0Omgh7.js → base.5NT-gWu5.js} +9 -1
- package/dist/vendor/{base.gAwDs8Jc.js → base.Ybri3C14.js} +2 -2
- package/dist/vendor/{benchmark.eeqk2rd8.js → benchmark.yGkUTKnC.js} +1 -1
- package/dist/vendor/{cac.8mXc9Oj6.js → cac.EdDItJD-.js} +38 -15
- package/dist/vendor/{cli-api._n4_Wp_j.js → cli-api.E07AF1Yq.js} +155 -46
- package/dist/vendor/env.AtSIuHFg.js +7 -0
- package/dist/vendor/{execute.2_yoIC01.js → execute.fL3szUAI.js} +8 -3
- package/dist/vendor/{index.gHZzsRJQ.js → index.DpVgvm2P.js} +17 -18
- package/dist/vendor/{index.GlXSU9xI.js → index.Q04MCqDO.js} +690 -645
- package/dist/vendor/{index.ir9i0ywP.js → index.SMVOaj7F.js} +2 -6
- package/dist/vendor/{index.0RrMQKD8.js → index.dI9lHwVn.js} +2 -2
- package/dist/vendor/{setup-common.7SXMSI--.js → setup-common.8nJLd4ay.js} +1 -1
- package/dist/vendor/{utils.VYmeMh-u.js → utils.dEtNIEgr.js} +1 -1
- package/dist/vendor/{vi.Y_w82WR8.js → vi.YFlodzP_.js} +1 -1
- package/dist/vendor/{vm.I_IsyNig.js → vm.QEE48c0T.js} +135 -43
- package/dist/worker.js +8 -2
- package/dist/workers/forks.js +4 -4
- package/dist/workers/runVmTests.js +13 -10
- package/dist/workers/threads.js +4 -4
- package/dist/workers/vmForks.js +7 -7
- package/dist/workers/vmThreads.js +7 -7
- package/dist/workers.d.ts +1 -1
- package/dist/workers.js +8 -8
- package/package.json +13 -9
- package/snapshot.d.ts +1 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dirname, resolve, relative, normalize,
|
|
1
|
+
import { dirname, join, resolve, relative, normalize, basename, toNamespacedPath, isAbsolute } from 'pathe';
|
|
2
2
|
import { A as API_PATH, d as defaultPort, e as extraInlineDeps, a as defaultBrowserPort, b as defaultInspectPort, E as EXIT_CODE_RESTART, w as workspacesFiles, C as CONFIG_NAMES, c as configFiles } from './constants.5J7I254_.js';
|
|
3
3
|
import { g as getCoverageProvider, C as CoverageProviderMap } from './coverage.E7sG1b3r.js';
|
|
4
4
|
import { g as getEnvPackageName } from './index.GVFv9dZ0.js';
|
|
@@ -6,7 +6,7 @@ import { isFileServingAllowed, searchForWorkspaceRoot, version as version$1, cre
|
|
|
6
6
|
import path$8 from 'node:path';
|
|
7
7
|
import url, { fileURLToPath } from 'node:url';
|
|
8
8
|
import process$1 from 'node:process';
|
|
9
|
-
import fs$8, { promises, existsSync } from 'node:fs';
|
|
9
|
+
import fs$8, { promises as promises$1, existsSync, readFileSync } from 'node:fs';
|
|
10
10
|
import { MessageChannel, isMainThread } from 'node:worker_threads';
|
|
11
11
|
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers.jjO7Zipk.js';
|
|
12
12
|
import require$$0 from 'os';
|
|
@@ -19,7 +19,10 @@ import c from 'picocolors';
|
|
|
19
19
|
import { ViteNodeRunner } from 'vite-node/client';
|
|
20
20
|
import { SnapshotManager } from '@vitest/snapshot/manager';
|
|
21
21
|
import { ViteNodeServer } from 'vite-node/server';
|
|
22
|
-
import {
|
|
22
|
+
import { hasFailed, getTasks, getTests } from '@vitest/runner/utils';
|
|
23
|
+
import { n as noop$2, b as isPrimitive, c as groupBy, A as AggregateErrorPonyfill, a as slash$1, t as toArray, d as deepMerge, e as nanoid, w as wildcardPatternToRegExp, f as stdout } from './base.5NT-gWu5.js';
|
|
24
|
+
import { createDefer, toArray as toArray$1, notNullish } from '@vitest/utils';
|
|
25
|
+
import { a as isWindows } from './env.AtSIuHFg.js';
|
|
23
26
|
import { rootDir } from '../path.js';
|
|
24
27
|
import { c as createBirpc } from './index.8bPxjt7g.js';
|
|
25
28
|
import require$$0$4 from 'zlib';
|
|
@@ -30,27 +33,26 @@ import require$$2 from 'http';
|
|
|
30
33
|
import require$$3 from 'net';
|
|
31
34
|
import require$$4 from 'tls';
|
|
32
35
|
import require$$7 from 'url';
|
|
33
|
-
import { createDefer, toArray as toArray$1, notNullish } from '@vitest/utils';
|
|
34
36
|
import { parseErrorStacktrace } from '@vitest/utils/source-map';
|
|
35
|
-
import { n as noop$2, b as isPrimitive, c as groupBy, A as AggregateErrorPonyfill, a as slash$1, t as toArray, d as deepMerge, w as wildcardPatternToRegExp, e as stdout } from './base.Xt0Omgh7.js';
|
|
36
37
|
import v8 from 'node:v8';
|
|
37
38
|
import * as nodeos from 'node:os';
|
|
38
|
-
import nodeos__default from 'node:os';
|
|
39
|
+
import nodeos__default, { tmpdir } from 'node:os';
|
|
39
40
|
import EventEmitter$2 from 'node:events';
|
|
40
41
|
import Tinypool$1, { Tinypool } from 'tinypool';
|
|
41
|
-
import { w as wrapSerializableConfig, f as Typechecker, R as ReportersMap, e as BenchmarkReportsMap, g as RandomSequencer, B as BaseSequencer, h as generateCodeFrame, i as highlightCode, L as Logger } from './index.
|
|
42
|
-
import {
|
|
42
|
+
import { w as wrapSerializableConfig, f as Typechecker, R as ReportersMap, e as BenchmarkReportsMap, g as RandomSequencer, B as BaseSequencer, h as generateCodeFrame, i as highlightCode, L as Logger } from './index.Q04MCqDO.js';
|
|
43
|
+
import crypto, { createHash as createHash$2 } from 'node:crypto';
|
|
44
|
+
import { mkdir, writeFile, rm } from 'node:fs/promises';
|
|
43
45
|
import { resolveModule, isPackageExists } from 'local-pkg';
|
|
44
46
|
import { isCI, provider as provider$1 } from 'std-env';
|
|
45
|
-
import
|
|
46
|
-
import { v as version } from './cac.8mXc9Oj6.js';
|
|
47
|
+
import { v as version } from './cac.EdDItJD-.js';
|
|
47
48
|
import { normalizeRequestId, cleanUrl } from 'vite-node/utils';
|
|
48
49
|
import MagicString from 'magic-string';
|
|
49
50
|
import { findNodeAround } from 'acorn-walk';
|
|
50
51
|
import { esmWalker } from '@vitest/utils/ast';
|
|
51
52
|
import { stripLiteral } from 'strip-literal';
|
|
52
|
-
import { d as divider, s as stripAnsi } from './utils.
|
|
53
|
+
import { d as divider, s as stripAnsi } from './utils.dEtNIEgr.js';
|
|
53
54
|
import { createRequire } from 'node:module';
|
|
55
|
+
import { a as removeUndefinedValues } from './index.SMVOaj7F.js';
|
|
54
56
|
import readline from 'node:readline';
|
|
55
57
|
import require$$0$6 from 'readline';
|
|
56
58
|
|
|
@@ -328,7 +330,7 @@ async function locatePath(
|
|
|
328
330
|
checkType(type);
|
|
329
331
|
cwd = toPath$1(cwd);
|
|
330
332
|
|
|
331
|
-
const statFunction = allowSymlinks ? promises.stat : promises.lstat;
|
|
333
|
+
const statFunction = allowSymlinks ? promises$1.stat : promises$1.lstat;
|
|
332
334
|
|
|
333
335
|
return pLocate(paths, async path_ => {
|
|
334
336
|
try {
|
|
@@ -7681,28 +7683,28 @@ function setup(vitestOrWorkspace, _server) {
|
|
|
7681
7683
|
checkFileAccess(snapshotPath);
|
|
7682
7684
|
if (!existsSync(snapshotPath))
|
|
7683
7685
|
return null;
|
|
7684
|
-
return promises.readFile(snapshotPath, "utf-8");
|
|
7686
|
+
return promises$1.readFile(snapshotPath, "utf-8");
|
|
7685
7687
|
},
|
|
7686
7688
|
async readTestFile(id) {
|
|
7687
7689
|
if (!ctx.state.filesMap.has(id) || !existsSync(id))
|
|
7688
7690
|
return null;
|
|
7689
|
-
return promises.readFile(id, "utf-8");
|
|
7691
|
+
return promises$1.readFile(id, "utf-8");
|
|
7690
7692
|
},
|
|
7691
7693
|
async saveTestFile(id, content) {
|
|
7692
7694
|
if (!ctx.state.filesMap.has(id) || !existsSync(id))
|
|
7693
7695
|
throw new Error(`Test file "${id}" was not registered, so it cannot be updated using the API.`);
|
|
7694
|
-
return promises.writeFile(id, content, "utf-8");
|
|
7696
|
+
return promises$1.writeFile(id, content, "utf-8");
|
|
7695
7697
|
},
|
|
7696
7698
|
async saveSnapshotFile(id, content) {
|
|
7697
7699
|
checkFileAccess(id);
|
|
7698
|
-
await promises.mkdir(dirname(id), { recursive: true });
|
|
7699
|
-
return promises.writeFile(id, content, "utf-8");
|
|
7700
|
+
await promises$1.mkdir(dirname(id), { recursive: true });
|
|
7701
|
+
return promises$1.writeFile(id, content, "utf-8");
|
|
7700
7702
|
},
|
|
7701
7703
|
async removeSnapshotFile(id) {
|
|
7702
7704
|
checkFileAccess(id);
|
|
7703
7705
|
if (!existsSync(id))
|
|
7704
7706
|
throw new Error(`Snapshot file "${id}" does not exist.`);
|
|
7705
|
-
return promises.unlink(id);
|
|
7707
|
+
return promises$1.unlink(id);
|
|
7706
7708
|
},
|
|
7707
7709
|
snapshotSaved(snapshot) {
|
|
7708
7710
|
ctx.snapshot.add(snapshot);
|
|
@@ -7724,7 +7726,7 @@ function setup(vitestOrWorkspace, _server) {
|
|
|
7724
7726
|
const result = await ctx.vitenode.transformRequest(id);
|
|
7725
7727
|
if (result) {
|
|
7726
7728
|
try {
|
|
7727
|
-
result.source = result.source || await promises.readFile(id, "utf-8");
|
|
7729
|
+
result.source = result.source || await promises$1.readFile(id, "utf-8");
|
|
7728
7730
|
} catch {
|
|
7729
7731
|
}
|
|
7730
7732
|
return result;
|
|
@@ -7765,6 +7767,10 @@ function setup(vitestOrWorkspace, _server) {
|
|
|
7765
7767
|
},
|
|
7766
7768
|
getProvidedContext() {
|
|
7767
7769
|
return "ctx" in vitestOrWorkspace ? vitestOrWorkspace.getProvidedContext() : {};
|
|
7770
|
+
},
|
|
7771
|
+
async getTestFiles() {
|
|
7772
|
+
const spec = await ctx.globTestFiles();
|
|
7773
|
+
return spec.map(([project, file]) => [project.getName(), file]);
|
|
7768
7774
|
}
|
|
7769
7775
|
},
|
|
7770
7776
|
{
|
|
@@ -7861,7 +7867,7 @@ function getTransformMode(patterns, filename) {
|
|
|
7861
7867
|
async function groupFilesByEnv(files) {
|
|
7862
7868
|
const filesWithEnv = await Promise.all(files.map(async ([project, file]) => {
|
|
7863
7869
|
var _a, _b;
|
|
7864
|
-
const code = await promises.readFile(file, "utf-8");
|
|
7870
|
+
const code = await promises$1.readFile(file, "utf-8");
|
|
7865
7871
|
let env = (_a = code.match(/@(?:vitest|jest)-environment\s+?([\w-]+)\b/)) == null ? void 0 : _a[1];
|
|
7866
7872
|
if (!env) {
|
|
7867
7873
|
for (const [glob, target] of project.config.environmentMatchGlobs || []) {
|
|
@@ -7889,6 +7895,8 @@ async function groupFilesByEnv(files) {
|
|
|
7889
7895
|
return groupBy(filesWithEnv, ({ environment }) => environment.name);
|
|
7890
7896
|
}
|
|
7891
7897
|
|
|
7898
|
+
const created = /* @__PURE__ */ new Set();
|
|
7899
|
+
const promises = /* @__PURE__ */ new Map();
|
|
7892
7900
|
function createMethodsRPC(project) {
|
|
7893
7901
|
const ctx = project.ctx;
|
|
7894
7902
|
return {
|
|
@@ -7907,8 +7915,30 @@ function createMethodsRPC(project) {
|
|
|
7907
7915
|
const r = await project.vitenode.transformRequest(id);
|
|
7908
7916
|
return r == null ? void 0 : r.map;
|
|
7909
7917
|
},
|
|
7910
|
-
fetch(id, transformMode) {
|
|
7911
|
-
|
|
7918
|
+
async fetch(id, transformMode) {
|
|
7919
|
+
const result = await project.vitenode.fetchResult(id, transformMode);
|
|
7920
|
+
const code = result.code;
|
|
7921
|
+
if (result.externalize)
|
|
7922
|
+
return result;
|
|
7923
|
+
if ("id" in result && typeof result.id === "string")
|
|
7924
|
+
return { id: result.id };
|
|
7925
|
+
if (code == null)
|
|
7926
|
+
throw new Error(`Failed to fetch module ${id}`);
|
|
7927
|
+
const dir = join(project.tmpDir, transformMode);
|
|
7928
|
+
const name = createHash$2("sha1").update(id).digest("hex");
|
|
7929
|
+
const tmp = join(dir, name);
|
|
7930
|
+
if (promises.has(tmp)) {
|
|
7931
|
+
await promises.get(tmp);
|
|
7932
|
+
return { id: tmp };
|
|
7933
|
+
}
|
|
7934
|
+
if (!created.has(dir)) {
|
|
7935
|
+
await mkdir(dir, { recursive: true });
|
|
7936
|
+
created.add(dir);
|
|
7937
|
+
}
|
|
7938
|
+
promises.set(tmp, writeFile(tmp, code, "utf-8").finally(() => promises.delete(tmp)));
|
|
7939
|
+
await promises.get(tmp);
|
|
7940
|
+
Object.assign(result, { id: tmp });
|
|
7941
|
+
return { id: tmp };
|
|
7912
7942
|
},
|
|
7913
7943
|
resolveId(id, importer, transformMode) {
|
|
7914
7944
|
return project.vitenode.resolveId(id, importer, transformMode);
|
|
@@ -8782,6 +8812,10 @@ function createPool(ctx) {
|
|
|
8782
8812
|
...ctx.config.env
|
|
8783
8813
|
}
|
|
8784
8814
|
};
|
|
8815
|
+
if (isWindows) {
|
|
8816
|
+
for (const name in options.env)
|
|
8817
|
+
options.env[name.toUpperCase()] = options.env[name];
|
|
8818
|
+
}
|
|
8785
8819
|
const customPools = /* @__PURE__ */ new Map();
|
|
8786
8820
|
async function resolveCustomPool(filepath) {
|
|
8787
8821
|
if (customPools.has(filepath))
|
|
@@ -9063,7 +9097,7 @@ const defaultCoverageExcludes = [
|
|
|
9063
9097
|
"cypress/**",
|
|
9064
9098
|
"test?(s)/**",
|
|
9065
9099
|
"test?(-*).?(c|m)[jt]s?(x)",
|
|
9066
|
-
"**/*{.,-}{test,spec}.?(c|m)[jt]s?(x)",
|
|
9100
|
+
"**/*{.,-}{test,spec}?(-d).?(c|m)[jt]s?(x)",
|
|
9067
9101
|
"**/__tests__/**",
|
|
9068
9102
|
"**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*",
|
|
9069
9103
|
"**/vitest.{workspace,projects}.[jt]s?(on)",
|
|
@@ -9337,6 +9371,8 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
9337
9371
|
throw new Error("--shard <index> must be a positive number less then <count>");
|
|
9338
9372
|
resolved.shard = { index, count };
|
|
9339
9373
|
}
|
|
9374
|
+
if (resolved.standalone && !resolved.watch)
|
|
9375
|
+
throw new Error(`Vitest standalone mode requires --watch`);
|
|
9340
9376
|
if (resolved.maxWorkers)
|
|
9341
9377
|
resolved.maxWorkers = Number(resolved.maxWorkers);
|
|
9342
9378
|
if (resolved.minWorkers)
|
|
@@ -9419,6 +9455,8 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
9419
9455
|
resolved.server.deps.moduleDirectories.push(...resolved.deps.moduleDirectories);
|
|
9420
9456
|
if (resolved.runner)
|
|
9421
9457
|
resolved.runner = resolvePath(resolved.runner, resolved.root);
|
|
9458
|
+
if (resolved.snapshotEnvironment)
|
|
9459
|
+
resolved.snapshotEnvironment = resolvePath(resolved.snapshotEnvironment, resolved.root);
|
|
9422
9460
|
resolved.testNamePattern = resolved.testNamePattern ? resolved.testNamePattern instanceof RegExp ? resolved.testNamePattern : new RegExp(resolved.testNamePattern) : void 0;
|
|
9423
9461
|
if (resolved.snapshotFormat && "plugins" in resolved.snapshotFormat)
|
|
9424
9462
|
resolved.snapshotFormat.plugins = [];
|
|
@@ -9521,6 +9559,10 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
9521
9559
|
resolved.benchmark.reporters = ["default"];
|
|
9522
9560
|
if (options.outputFile)
|
|
9523
9561
|
resolved.benchmark.outputFile = options.outputFile;
|
|
9562
|
+
if (options.compare)
|
|
9563
|
+
resolved.benchmark.compare = options.compare;
|
|
9564
|
+
if (options.outputJson)
|
|
9565
|
+
resolved.benchmark.outputJson = options.outputJson;
|
|
9524
9566
|
}
|
|
9525
9567
|
resolved.setupFiles = toArray(resolved.setupFiles || []).map(
|
|
9526
9568
|
(file) => resolvePath(file, resolved.root)
|
|
@@ -10250,10 +10292,16 @@ function WorkspaceVitestPlugin(project, options) {
|
|
|
10250
10292
|
const root = testConfig.root || viteConfig.root || options.root;
|
|
10251
10293
|
let name = testConfig.name;
|
|
10252
10294
|
if (!name) {
|
|
10253
|
-
if (typeof options.workspacePath === "string")
|
|
10254
|
-
|
|
10255
|
-
|
|
10295
|
+
if (typeof options.workspacePath === "string") {
|
|
10296
|
+
const dir = options.workspacePath.endsWith("/") ? options.workspacePath.slice(0, -1) : dirname(options.workspacePath);
|
|
10297
|
+
const pkgJsonPath = resolve(dir, "package.json");
|
|
10298
|
+
if (existsSync(pkgJsonPath))
|
|
10299
|
+
name = JSON.parse(readFileSync(pkgJsonPath, "utf-8")).name;
|
|
10300
|
+
if (typeof name !== "string" || !name)
|
|
10301
|
+
name = basename(dir);
|
|
10302
|
+
} else {
|
|
10256
10303
|
name = options.workspacePath.toString();
|
|
10304
|
+
}
|
|
10257
10305
|
}
|
|
10258
10306
|
const config = {
|
|
10259
10307
|
root,
|
|
@@ -10408,6 +10456,8 @@ class WorkspaceProject {
|
|
|
10408
10456
|
browserProvider;
|
|
10409
10457
|
browserState;
|
|
10410
10458
|
testFilesList = null;
|
|
10459
|
+
id = nanoid();
|
|
10460
|
+
tmpDir = join(tmpdir(), this.id);
|
|
10411
10461
|
_globalSetups;
|
|
10412
10462
|
_provided = {};
|
|
10413
10463
|
getName() {
|
|
@@ -10512,7 +10562,7 @@ ${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
|
|
|
10512
10562
|
const files = await this.globFiles(includeSource, exclude, cwd);
|
|
10513
10563
|
await Promise.all(files.map(async (file) => {
|
|
10514
10564
|
try {
|
|
10515
|
-
const code = await promises.readFile(file, "utf-8");
|
|
10565
|
+
const code = await promises$1.readFile(file, "utf-8");
|
|
10516
10566
|
if (this.isInSourceTestFile(code))
|
|
10517
10567
|
testFiles.push(file);
|
|
10518
10568
|
} catch {
|
|
@@ -10543,7 +10593,7 @@ ${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
|
|
|
10543
10593
|
if (mm.isMatch(relativeId, this.config.include))
|
|
10544
10594
|
return true;
|
|
10545
10595
|
if (((_a = this.config.includeSource) == null ? void 0 : _a.length) && mm.isMatch(relativeId, this.config.includeSource)) {
|
|
10546
|
-
source = source || await promises.readFile(id, "utf-8");
|
|
10596
|
+
source = source || await promises$1.readFile(id, "utf-8");
|
|
10547
10597
|
return this.isInSourceTestFile(source);
|
|
10548
10598
|
}
|
|
10549
10599
|
return false;
|
|
@@ -10679,11 +10729,18 @@ ${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
|
|
|
10679
10729
|
this.closingPromise = Promise.all([
|
|
10680
10730
|
this.server.close(),
|
|
10681
10731
|
(_a = this.typechecker) == null ? void 0 : _a.stop(),
|
|
10682
|
-
(_b = this.browser) == null ? void 0 : _b.close()
|
|
10732
|
+
(_b = this.browser) == null ? void 0 : _b.close(),
|
|
10733
|
+
this.clearTmpDir()
|
|
10683
10734
|
].filter(Boolean)).then(() => this._provided = {});
|
|
10684
10735
|
}
|
|
10685
10736
|
return this.closingPromise;
|
|
10686
10737
|
}
|
|
10738
|
+
async clearTmpDir() {
|
|
10739
|
+
try {
|
|
10740
|
+
await rm(this.tmpDir, { force: true, recursive: true });
|
|
10741
|
+
} catch {
|
|
10742
|
+
}
|
|
10743
|
+
}
|
|
10687
10744
|
async initBrowserProvider() {
|
|
10688
10745
|
if (!this.isBrowserEnabled())
|
|
10689
10746
|
return;
|
|
@@ -10788,6 +10845,7 @@ class Vitest {
|
|
|
10788
10845
|
this.pool = void 0;
|
|
10789
10846
|
this.coverageProvider = void 0;
|
|
10790
10847
|
this.runningPromise = void 0;
|
|
10848
|
+
this.distPath = void 0;
|
|
10791
10849
|
this.projectsTestFiles.clear();
|
|
10792
10850
|
const resolved = resolveConfig(this.mode, options, server.config, this.logger);
|
|
10793
10851
|
this.server = server;
|
|
@@ -10798,9 +10856,6 @@ class Vitest {
|
|
|
10798
10856
|
if (this.config.watch)
|
|
10799
10857
|
this.registerWatcher();
|
|
10800
10858
|
this.vitenode = new ViteNodeServer(server, this.config.server);
|
|
10801
|
-
const projectVitestPath = await this.vitenode.resolveId("vitest");
|
|
10802
|
-
const vitestDir = projectVitestPath ? resolve(projectVitestPath.id, "../..") : rootDir;
|
|
10803
|
-
this.distPath = join(vitestDir, "dist");
|
|
10804
10859
|
const node = this.vitenode;
|
|
10805
10860
|
this.runner = new ViteNodeRunner({
|
|
10806
10861
|
root: server.config.root,
|
|
@@ -10869,7 +10924,7 @@ class Vitest {
|
|
|
10869
10924
|
if (this.config.workspace)
|
|
10870
10925
|
return this.config.workspace;
|
|
10871
10926
|
const configDir = this.server.config.configFile ? dirname(this.server.config.configFile) : this.config.root;
|
|
10872
|
-
const rootFiles = await promises.readdir(configDir);
|
|
10927
|
+
const rootFiles = await promises$1.readdir(configDir);
|
|
10873
10928
|
const workspaceConfigName = workspacesFiles.find((configFile) => {
|
|
10874
10929
|
return rootFiles.includes(configFile);
|
|
10875
10930
|
});
|
|
@@ -10920,7 +10975,7 @@ class Vitest {
|
|
|
10920
10975
|
return CONFIG_NAMES.some((configName) => filename.startsWith(configName));
|
|
10921
10976
|
}).map(async (filepath) => {
|
|
10922
10977
|
if (filepath.endsWith("/")) {
|
|
10923
|
-
const filesInside = await promises.readdir(filepath);
|
|
10978
|
+
const filesInside = await promises$1.readdir(filepath);
|
|
10924
10979
|
const configFile = configFiles.find((config) => filesInside.includes(config));
|
|
10925
10980
|
return configFile ? join(filepath, configFile) : filepath;
|
|
10926
10981
|
}
|
|
@@ -11039,6 +11094,20 @@ class Vitest {
|
|
|
11039
11094
|
if (this.config.watch)
|
|
11040
11095
|
await this.report("onWatcherStart");
|
|
11041
11096
|
}
|
|
11097
|
+
async init() {
|
|
11098
|
+
var _a;
|
|
11099
|
+
this._onClose = [];
|
|
11100
|
+
try {
|
|
11101
|
+
await this.initCoverageProvider();
|
|
11102
|
+
await ((_a = this.coverageProvider) == null ? void 0 : _a.clean(this.config.coverage.clean));
|
|
11103
|
+
await this.initBrowserProviders();
|
|
11104
|
+
} finally {
|
|
11105
|
+
await this.report("onInit", this);
|
|
11106
|
+
}
|
|
11107
|
+
await this.globTestFiles();
|
|
11108
|
+
if (this.config.watch)
|
|
11109
|
+
await this.report("onWatcherStart");
|
|
11110
|
+
}
|
|
11042
11111
|
async getTestDependencies(filepath, deps = /* @__PURE__ */ new Set()) {
|
|
11043
11112
|
const addImports = async ([project, filepath2]) => {
|
|
11044
11113
|
if (deps.has(filepath2))
|
|
@@ -11108,7 +11177,15 @@ class Vitest {
|
|
|
11108
11177
|
for await (const project of projects)
|
|
11109
11178
|
await project.initializeGlobalSetup();
|
|
11110
11179
|
}
|
|
11180
|
+
async initializeDistPath() {
|
|
11181
|
+
if (this.distPath)
|
|
11182
|
+
return;
|
|
11183
|
+
const projectVitestPath = await this.vitenode.resolveId("vitest");
|
|
11184
|
+
const vitestDir = projectVitestPath ? resolve(projectVitestPath.id, "../..") : rootDir;
|
|
11185
|
+
this.distPath = join(vitestDir, "dist");
|
|
11186
|
+
}
|
|
11111
11187
|
async runFiles(paths, allTestsRun) {
|
|
11188
|
+
await this.initializeDistPath();
|
|
11112
11189
|
const filepaths = paths.map(([, file]) => file);
|
|
11113
11190
|
this.state.collectPaths(filepaths);
|
|
11114
11191
|
await this.report("onPathsCollected", filepaths);
|
|
@@ -11172,12 +11249,21 @@ class Vitest {
|
|
|
11172
11249
|
async changeNamePattern(pattern, files = this.state.getFilepaths(), trigger) {
|
|
11173
11250
|
if (pattern === "")
|
|
11174
11251
|
this.filenamePattern = void 0;
|
|
11175
|
-
|
|
11252
|
+
const testNamePattern = pattern ? new RegExp(pattern) : void 0;
|
|
11253
|
+
this.configOverride.testNamePattern = testNamePattern;
|
|
11254
|
+
if (testNamePattern) {
|
|
11255
|
+
files = files.filter((filepath) => {
|
|
11256
|
+
const files2 = this.state.getFiles([filepath]);
|
|
11257
|
+
return !files2.length || files2.some((file) => {
|
|
11258
|
+
const tasks = getTasks(file);
|
|
11259
|
+
return !tasks.length || tasks.some((task) => testNamePattern.test(task.name));
|
|
11260
|
+
});
|
|
11261
|
+
});
|
|
11262
|
+
}
|
|
11176
11263
|
await this.rerunFiles(files, trigger);
|
|
11177
11264
|
}
|
|
11178
|
-
async changeFilenamePattern(pattern) {
|
|
11265
|
+
async changeFilenamePattern(pattern, files = this.state.getFilepaths()) {
|
|
11179
11266
|
this.filenamePattern = pattern;
|
|
11180
|
-
const files = this.state.getFilepaths();
|
|
11181
11267
|
const trigger = this.filenamePattern ? "change filename pattern" : "reset filename pattern";
|
|
11182
11268
|
await this.rerunFiles(files, trigger);
|
|
11183
11269
|
}
|
|
@@ -11289,8 +11375,11 @@ class Vitest {
|
|
|
11289
11375
|
updateLastChanged(id);
|
|
11290
11376
|
const matchingProjects = [];
|
|
11291
11377
|
await Promise.all(this.projects.map(async (project) => {
|
|
11292
|
-
|
|
11378
|
+
var _a;
|
|
11379
|
+
if (await project.isTargetFile(id)) {
|
|
11293
11380
|
matchingProjects.push(project);
|
|
11381
|
+
(_a = project.testFilesList) == null ? void 0 : _a.push(id);
|
|
11382
|
+
}
|
|
11294
11383
|
}));
|
|
11295
11384
|
if (matchingProjects.length > 0) {
|
|
11296
11385
|
this.projectsTestFiles.set(id, new Set(matchingProjects));
|
|
@@ -11434,6 +11523,9 @@ class Vitest {
|
|
|
11434
11523
|
);
|
|
11435
11524
|
}));
|
|
11436
11525
|
}
|
|
11526
|
+
async getTestFilepaths() {
|
|
11527
|
+
return this.globTestFiles().then((files) => files.map(([, file]) => file));
|
|
11528
|
+
}
|
|
11437
11529
|
async globTestFiles(filters = []) {
|
|
11438
11530
|
const files = [];
|
|
11439
11531
|
await Promise.all(this.projects.map(async (project) => {
|
|
@@ -18062,6 +18154,9 @@ ${resultBody}`;
|
|
|
18062
18154
|
write(data) {
|
|
18063
18155
|
this.stdout.write(data);
|
|
18064
18156
|
}
|
|
18157
|
+
getLastResults() {
|
|
18158
|
+
return this.results;
|
|
18159
|
+
}
|
|
18065
18160
|
}
|
|
18066
18161
|
|
|
18067
18162
|
const keys = [
|
|
@@ -18113,8 +18208,10 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
|
|
|
18113
18208
|
return printShortcutsHelp();
|
|
18114
18209
|
if (name === "u")
|
|
18115
18210
|
return ctx.updateSnapshot();
|
|
18116
|
-
if (name === "a" || name === "return")
|
|
18117
|
-
|
|
18211
|
+
if (name === "a" || name === "return") {
|
|
18212
|
+
const files = await ctx.getTestFilepaths();
|
|
18213
|
+
return ctx.changeNamePattern("", files, "rerun all tests");
|
|
18214
|
+
}
|
|
18118
18215
|
if (name === "r")
|
|
18119
18216
|
return ctx.rerunFiles();
|
|
18120
18217
|
if (name === "f")
|
|
@@ -18133,8 +18230,8 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
|
|
|
18133
18230
|
off();
|
|
18134
18231
|
const watchFilter = new WatchFilter("Input test name pattern (RegExp)", stdin, stdout2);
|
|
18135
18232
|
const filter = await watchFilter.filter((str) => {
|
|
18136
|
-
const
|
|
18137
|
-
const tests = getTests(
|
|
18233
|
+
const files2 = ctx.state.getFiles();
|
|
18234
|
+
const tests = getTests(files2);
|
|
18138
18235
|
try {
|
|
18139
18236
|
const reg = new RegExp(str);
|
|
18140
18237
|
return tests.map((test) => test.name).filter((testName) => testName.match(reg));
|
|
@@ -18143,7 +18240,9 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
|
|
|
18143
18240
|
}
|
|
18144
18241
|
});
|
|
18145
18242
|
on();
|
|
18146
|
-
|
|
18243
|
+
const files = ctx.state.getFilepaths();
|
|
18244
|
+
const cliFiles = ctx.config.standalone && !files.length ? await ctx.getTestFilepaths() : void 0;
|
|
18245
|
+
await ctx.changeNamePattern((filter == null ? void 0 : filter.trim()) || "", cliFiles, "change pattern");
|
|
18147
18246
|
}
|
|
18148
18247
|
async function inputProjectName() {
|
|
18149
18248
|
off();
|
|
@@ -18167,7 +18266,11 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
|
|
|
18167
18266
|
});
|
|
18168
18267
|
on();
|
|
18169
18268
|
latestFilename = (filter == null ? void 0 : filter.trim()) || "";
|
|
18170
|
-
|
|
18269
|
+
const lastResults = watchFilter.getLastResults();
|
|
18270
|
+
await ctx.changeFilenamePattern(
|
|
18271
|
+
latestFilename,
|
|
18272
|
+
filter && lastResults.length ? lastResults.map((i) => resolve(ctx.config.root, i)) : void 0
|
|
18273
|
+
);
|
|
18171
18274
|
}
|
|
18172
18275
|
let rl;
|
|
18173
18276
|
function on() {
|
|
@@ -18230,10 +18333,16 @@ async function startVitest(mode, cliFilters = [], options = {}, viteOverrides, v
|
|
|
18230
18333
|
process.exit(EXIT_CODE_RESTART);
|
|
18231
18334
|
});
|
|
18232
18335
|
ctx.onAfterSetServer(() => {
|
|
18233
|
-
ctx.
|
|
18336
|
+
if (ctx.config.standalone)
|
|
18337
|
+
ctx.init();
|
|
18338
|
+
else
|
|
18339
|
+
ctx.start(cliFilters);
|
|
18234
18340
|
});
|
|
18235
18341
|
try {
|
|
18236
|
-
|
|
18342
|
+
if (ctx.config.standalone)
|
|
18343
|
+
await ctx.init();
|
|
18344
|
+
else
|
|
18345
|
+
await ctx.start(cliFilters);
|
|
18237
18346
|
} catch (e) {
|
|
18238
18347
|
process.exitCode = 1;
|
|
18239
18348
|
await ctx.logger.printError(e, { fullStack: true, type: "Unhandled Error" });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import 'std-env';
|
|
2
|
+
|
|
3
|
+
var _a;
|
|
4
|
+
const isNode = typeof process < "u" && typeof process.stdout < "u" && !((_a = process.versions) == null ? void 0 : _a.deno) && !globalThis.window;
|
|
5
|
+
const isWindows = isNode && process.platform === "win32";
|
|
6
|
+
|
|
7
|
+
export { isWindows as a, isNode as i };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import vm from 'node:vm';
|
|
2
2
|
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
3
4
|
import { ViteNodeRunner, DEFAULT_REQUEST_STUBS } from 'vite-node/client';
|
|
4
5
|
import { isNodeBuiltin, isInternalRequest, toFilePath, isPrimitive } from 'vite-node/utils';
|
|
5
6
|
import { resolve, isAbsolute, dirname, join, basename, extname, normalize, relative } from 'pathe';
|
|
6
7
|
import { processError } from '@vitest/utils/error';
|
|
7
8
|
import { distDir } from '../path.js';
|
|
8
|
-
import { existsSync, readdirSync } from 'node:fs';
|
|
9
9
|
import { highlight, getType } from '@vitest/utils';
|
|
10
|
-
import { g as getAllMockableProperties } from './base.
|
|
10
|
+
import { g as getAllMockableProperties } from './base.5NT-gWu5.js';
|
|
11
11
|
|
|
12
12
|
const spyModulePath = resolve(distDir, "spy.js");
|
|
13
13
|
class RefTracker {
|
|
@@ -418,7 +418,12 @@ async function startVitestExecutor(options) {
|
|
|
418
418
|
externalizeMap.set(id, id);
|
|
419
419
|
return { externalize: id };
|
|
420
420
|
}
|
|
421
|
-
|
|
421
|
+
const result = await rpc().fetch(id, getTransformMode());
|
|
422
|
+
if (result.id && !result.externalize) {
|
|
423
|
+
const code = readFileSync(result.id, "utf-8");
|
|
424
|
+
return { code };
|
|
425
|
+
}
|
|
426
|
+
return result;
|
|
422
427
|
},
|
|
423
428
|
resolveId(id, importer) {
|
|
424
429
|
return rpc().resolveId(id, importer, getTransformMode());
|
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
import * as chai from 'chai';
|
|
2
|
-
import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
|
|
3
2
|
import { resolve } from 'pathe';
|
|
4
3
|
import { distDir } from '../path.js';
|
|
5
4
|
import { g as getWorkerState } from './global.CkGT_TMy.js';
|
|
6
5
|
import { r as rpc } from './rpc.joBhAkyK.js';
|
|
7
6
|
import { t as takeCoverageInsideWorker } from './coverage.E7sG1b3r.js';
|
|
8
|
-
import { l as loadDiffConfig, a as loadSnapshotSerializers } from './setup-common.
|
|
7
|
+
import { l as loadDiffConfig, a as loadSnapshotSerializers } from './setup-common.8nJLd4ay.js';
|
|
9
8
|
|
|
10
9
|
function setupChaiConfig(config) {
|
|
11
10
|
Object.assign(chai.config, config);
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
getHeader() {
|
|
20
|
-
return `// Vitest Snapshot v${this.getVersion()}, https://vitest.dev/guide/snapshot.html`;
|
|
21
|
-
}
|
|
22
|
-
resolvePath(filepath) {
|
|
23
|
-
return this.rpc.resolveSnapshotPath(filepath);
|
|
13
|
+
async function resolveSnapshotEnvironment(config, executor) {
|
|
14
|
+
if (!config.snapshotEnvironment) {
|
|
15
|
+
const { VitestNodeSnapshotEnvironment } = await import('../chunks/environments-node.vcoXCoKs.js');
|
|
16
|
+
return new VitestNodeSnapshotEnvironment();
|
|
24
17
|
}
|
|
18
|
+
const mod = await executor.executeId(config.snapshotEnvironment);
|
|
19
|
+
if (typeof mod.default !== "object" || !mod.default)
|
|
20
|
+
throw new Error("Snapshot environment module must have a default export object with a shape of `SnapshotEnvironment`");
|
|
21
|
+
return mod.default;
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
const runnersFile = resolve(distDir, "runners.js");
|
|
@@ -74,11 +71,13 @@ async function resolveTestRunner(config, executor) {
|
|
|
74
71
|
testRunner.onAfterRunFiles = async (files) => {
|
|
75
72
|
const state = getWorkerState();
|
|
76
73
|
const coverage = await takeCoverageInsideWorker(config.coverage, executor);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
if (coverage) {
|
|
75
|
+
rpc().onAfterSuiteRun({
|
|
76
|
+
coverage,
|
|
77
|
+
transformMode: state.environment.transformMode,
|
|
78
|
+
projectName: state.ctx.projectName
|
|
79
|
+
});
|
|
80
|
+
}
|
|
82
81
|
await (originalOnAfterRun == null ? void 0 : originalOnAfterRun.call(testRunner, files));
|
|
83
82
|
};
|
|
84
83
|
const originalOnAfterRunTask = testRunner.onAfterRunTask;
|
|
@@ -97,4 +96,4 @@ async function resolveTestRunner(config, executor) {
|
|
|
97
96
|
return testRunner;
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
export {
|
|
99
|
+
export { resolveSnapshotEnvironment as a, resolveTestRunner as r, setupChaiConfig as s };
|