vitest 1.5.3 → 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.Hr6znn-f.js → integrations-globals.kw4co3rx.js} +3 -3
- package/dist/chunks/{runtime-runBaseTests.l6qXp5eU.js → runtime-runBaseTests.oAvMKtQC.js} +8 -9
- package/dist/cli.js +2 -2
- package/dist/config.cjs +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- 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 +4 -4
- package/dist/node.d.ts +2 -2
- package/dist/node.js +7 -7
- package/dist/{reporters-BXNXFKfg.d.ts → reporters-yx5ZTtEV.d.ts} +100 -24
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +5 -5
- package/dist/runners.d.ts +1 -1
- package/dist/runners.js +2 -2
- package/dist/snapshot.d.ts +9 -0
- package/dist/snapshot.js +8 -0
- package/dist/{suite-KPWE530F.d.ts → suite-IbNSsUWN.d.ts} +1 -1
- package/dist/suite.d.ts +2 -2
- package/dist/vendor/{base.Xt0Omgh7.js → base.5NT-gWu5.js} +9 -1
- package/dist/vendor/{base.oIzAvGLe.js → base.Ybri3C14.js} +2 -2
- package/dist/vendor/{cac.RDd_SGOd.js → cac.EdDItJD-.js} +38 -15
- package/dist/vendor/{cli-api.AmIc1Dmz.js → cli-api.E07AF1Yq.js} +139 -41
- package/dist/vendor/{execute.2_yoIC01.js → execute.fL3szUAI.js} +8 -3
- package/dist/vendor/{index.Fm6OikHU.js → index.DpVgvm2P.js} +17 -18
- package/dist/vendor/{index.X7lgIMc_.js → index.Q04MCqDO.js} +177 -122
- package/dist/vendor/{index.QVcwRDVW.js → index.dI9lHwVn.js} +1 -1
- package/dist/vendor/{setup-common.5nUd4r76.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.i4FO5N37.js → vm.QEE48c0T.js} +131 -41
- package/dist/worker.js +8 -2
- package/dist/workers/forks.js +4 -4
- package/dist/workers/runVmTests.js +10 -8
- package/dist/workers/threads.js +4 -4
- package/dist/workers/vmForks.js +4 -4
- package/dist/workers/vmThreads.js +4 -4
- package/dist/workers.d.ts +1 -1
- package/dist/workers.js +5 -5
- 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, readFileSync } 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,8 +19,8 @@ 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 { hasFailed, 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, w as wildcardPatternToRegExp,
|
|
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
24
|
import { createDefer, toArray as toArray$1, notNullish } from '@vitest/utils';
|
|
25
25
|
import { a as isWindows } from './env.AtSIuHFg.js';
|
|
26
26
|
import { rootDir } from '../path.js';
|
|
@@ -36,20 +36,21 @@ import require$$7 from 'url';
|
|
|
36
36
|
import { parseErrorStacktrace } from '@vitest/utils/source-map';
|
|
37
37
|
import v8 from 'node:v8';
|
|
38
38
|
import * as nodeos from 'node:os';
|
|
39
|
-
import nodeos__default from 'node:os';
|
|
39
|
+
import nodeos__default, { tmpdir } from 'node:os';
|
|
40
40
|
import EventEmitter$2 from 'node:events';
|
|
41
41
|
import Tinypool$1, { Tinypool } from 'tinypool';
|
|
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.
|
|
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.RDd_SGOd.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';
|
|
54
55
|
import { a as removeUndefinedValues } from './index.SMVOaj7F.js';
|
|
55
56
|
import readline from 'node:readline';
|
|
@@ -329,7 +330,7 @@ async function locatePath(
|
|
|
329
330
|
checkType(type);
|
|
330
331
|
cwd = toPath$1(cwd);
|
|
331
332
|
|
|
332
|
-
const statFunction = allowSymlinks ? promises.stat : promises.lstat;
|
|
333
|
+
const statFunction = allowSymlinks ? promises$1.stat : promises$1.lstat;
|
|
333
334
|
|
|
334
335
|
return pLocate(paths, async path_ => {
|
|
335
336
|
try {
|
|
@@ -7682,28 +7683,28 @@ function setup(vitestOrWorkspace, _server) {
|
|
|
7682
7683
|
checkFileAccess(snapshotPath);
|
|
7683
7684
|
if (!existsSync(snapshotPath))
|
|
7684
7685
|
return null;
|
|
7685
|
-
return promises.readFile(snapshotPath, "utf-8");
|
|
7686
|
+
return promises$1.readFile(snapshotPath, "utf-8");
|
|
7686
7687
|
},
|
|
7687
7688
|
async readTestFile(id) {
|
|
7688
7689
|
if (!ctx.state.filesMap.has(id) || !existsSync(id))
|
|
7689
7690
|
return null;
|
|
7690
|
-
return promises.readFile(id, "utf-8");
|
|
7691
|
+
return promises$1.readFile(id, "utf-8");
|
|
7691
7692
|
},
|
|
7692
7693
|
async saveTestFile(id, content) {
|
|
7693
7694
|
if (!ctx.state.filesMap.has(id) || !existsSync(id))
|
|
7694
7695
|
throw new Error(`Test file "${id}" was not registered, so it cannot be updated using the API.`);
|
|
7695
|
-
return promises.writeFile(id, content, "utf-8");
|
|
7696
|
+
return promises$1.writeFile(id, content, "utf-8");
|
|
7696
7697
|
},
|
|
7697
7698
|
async saveSnapshotFile(id, content) {
|
|
7698
7699
|
checkFileAccess(id);
|
|
7699
|
-
await promises.mkdir(dirname(id), { recursive: true });
|
|
7700
|
-
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");
|
|
7701
7702
|
},
|
|
7702
7703
|
async removeSnapshotFile(id) {
|
|
7703
7704
|
checkFileAccess(id);
|
|
7704
7705
|
if (!existsSync(id))
|
|
7705
7706
|
throw new Error(`Snapshot file "${id}" does not exist.`);
|
|
7706
|
-
return promises.unlink(id);
|
|
7707
|
+
return promises$1.unlink(id);
|
|
7707
7708
|
},
|
|
7708
7709
|
snapshotSaved(snapshot) {
|
|
7709
7710
|
ctx.snapshot.add(snapshot);
|
|
@@ -7725,7 +7726,7 @@ function setup(vitestOrWorkspace, _server) {
|
|
|
7725
7726
|
const result = await ctx.vitenode.transformRequest(id);
|
|
7726
7727
|
if (result) {
|
|
7727
7728
|
try {
|
|
7728
|
-
result.source = result.source || await promises.readFile(id, "utf-8");
|
|
7729
|
+
result.source = result.source || await promises$1.readFile(id, "utf-8");
|
|
7729
7730
|
} catch {
|
|
7730
7731
|
}
|
|
7731
7732
|
return result;
|
|
@@ -7766,6 +7767,10 @@ function setup(vitestOrWorkspace, _server) {
|
|
|
7766
7767
|
},
|
|
7767
7768
|
getProvidedContext() {
|
|
7768
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]);
|
|
7769
7774
|
}
|
|
7770
7775
|
},
|
|
7771
7776
|
{
|
|
@@ -7862,7 +7867,7 @@ function getTransformMode(patterns, filename) {
|
|
|
7862
7867
|
async function groupFilesByEnv(files) {
|
|
7863
7868
|
const filesWithEnv = await Promise.all(files.map(async ([project, file]) => {
|
|
7864
7869
|
var _a, _b;
|
|
7865
|
-
const code = await promises.readFile(file, "utf-8");
|
|
7870
|
+
const code = await promises$1.readFile(file, "utf-8");
|
|
7866
7871
|
let env = (_a = code.match(/@(?:vitest|jest)-environment\s+?([\w-]+)\b/)) == null ? void 0 : _a[1];
|
|
7867
7872
|
if (!env) {
|
|
7868
7873
|
for (const [glob, target] of project.config.environmentMatchGlobs || []) {
|
|
@@ -7890,6 +7895,8 @@ async function groupFilesByEnv(files) {
|
|
|
7890
7895
|
return groupBy(filesWithEnv, ({ environment }) => environment.name);
|
|
7891
7896
|
}
|
|
7892
7897
|
|
|
7898
|
+
const created = /* @__PURE__ */ new Set();
|
|
7899
|
+
const promises = /* @__PURE__ */ new Map();
|
|
7893
7900
|
function createMethodsRPC(project) {
|
|
7894
7901
|
const ctx = project.ctx;
|
|
7895
7902
|
return {
|
|
@@ -7908,8 +7915,30 @@ function createMethodsRPC(project) {
|
|
|
7908
7915
|
const r = await project.vitenode.transformRequest(id);
|
|
7909
7916
|
return r == null ? void 0 : r.map;
|
|
7910
7917
|
},
|
|
7911
|
-
fetch(id, transformMode) {
|
|
7912
|
-
|
|
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 };
|
|
7913
7942
|
},
|
|
7914
7943
|
resolveId(id, importer, transformMode) {
|
|
7915
7944
|
return project.vitenode.resolveId(id, importer, transformMode);
|
|
@@ -9068,7 +9097,7 @@ const defaultCoverageExcludes = [
|
|
|
9068
9097
|
"cypress/**",
|
|
9069
9098
|
"test?(s)/**",
|
|
9070
9099
|
"test?(-*).?(c|m)[jt]s?(x)",
|
|
9071
|
-
"**/*{.,-}{test,spec}.?(c|m)[jt]s?(x)",
|
|
9100
|
+
"**/*{.,-}{test,spec}?(-d).?(c|m)[jt]s?(x)",
|
|
9072
9101
|
"**/__tests__/**",
|
|
9073
9102
|
"**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*",
|
|
9074
9103
|
"**/vitest.{workspace,projects}.[jt]s?(on)",
|
|
@@ -9342,6 +9371,8 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
9342
9371
|
throw new Error("--shard <index> must be a positive number less then <count>");
|
|
9343
9372
|
resolved.shard = { index, count };
|
|
9344
9373
|
}
|
|
9374
|
+
if (resolved.standalone && !resolved.watch)
|
|
9375
|
+
throw new Error(`Vitest standalone mode requires --watch`);
|
|
9345
9376
|
if (resolved.maxWorkers)
|
|
9346
9377
|
resolved.maxWorkers = Number(resolved.maxWorkers);
|
|
9347
9378
|
if (resolved.minWorkers)
|
|
@@ -9424,6 +9455,8 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
9424
9455
|
resolved.server.deps.moduleDirectories.push(...resolved.deps.moduleDirectories);
|
|
9425
9456
|
if (resolved.runner)
|
|
9426
9457
|
resolved.runner = resolvePath(resolved.runner, resolved.root);
|
|
9458
|
+
if (resolved.snapshotEnvironment)
|
|
9459
|
+
resolved.snapshotEnvironment = resolvePath(resolved.snapshotEnvironment, resolved.root);
|
|
9427
9460
|
resolved.testNamePattern = resolved.testNamePattern ? resolved.testNamePattern instanceof RegExp ? resolved.testNamePattern : new RegExp(resolved.testNamePattern) : void 0;
|
|
9428
9461
|
if (resolved.snapshotFormat && "plugins" in resolved.snapshotFormat)
|
|
9429
9462
|
resolved.snapshotFormat.plugins = [];
|
|
@@ -9526,6 +9559,10 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
9526
9559
|
resolved.benchmark.reporters = ["default"];
|
|
9527
9560
|
if (options.outputFile)
|
|
9528
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;
|
|
9529
9566
|
}
|
|
9530
9567
|
resolved.setupFiles = toArray(resolved.setupFiles || []).map(
|
|
9531
9568
|
(file) => resolvePath(file, resolved.root)
|
|
@@ -10419,6 +10456,8 @@ class WorkspaceProject {
|
|
|
10419
10456
|
browserProvider;
|
|
10420
10457
|
browserState;
|
|
10421
10458
|
testFilesList = null;
|
|
10459
|
+
id = nanoid();
|
|
10460
|
+
tmpDir = join(tmpdir(), this.id);
|
|
10422
10461
|
_globalSetups;
|
|
10423
10462
|
_provided = {};
|
|
10424
10463
|
getName() {
|
|
@@ -10523,7 +10562,7 @@ ${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
|
|
|
10523
10562
|
const files = await this.globFiles(includeSource, exclude, cwd);
|
|
10524
10563
|
await Promise.all(files.map(async (file) => {
|
|
10525
10564
|
try {
|
|
10526
|
-
const code = await promises.readFile(file, "utf-8");
|
|
10565
|
+
const code = await promises$1.readFile(file, "utf-8");
|
|
10527
10566
|
if (this.isInSourceTestFile(code))
|
|
10528
10567
|
testFiles.push(file);
|
|
10529
10568
|
} catch {
|
|
@@ -10554,7 +10593,7 @@ ${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
|
|
|
10554
10593
|
if (mm.isMatch(relativeId, this.config.include))
|
|
10555
10594
|
return true;
|
|
10556
10595
|
if (((_a = this.config.includeSource) == null ? void 0 : _a.length) && mm.isMatch(relativeId, this.config.includeSource)) {
|
|
10557
|
-
source = source || await promises.readFile(id, "utf-8");
|
|
10596
|
+
source = source || await promises$1.readFile(id, "utf-8");
|
|
10558
10597
|
return this.isInSourceTestFile(source);
|
|
10559
10598
|
}
|
|
10560
10599
|
return false;
|
|
@@ -10690,11 +10729,18 @@ ${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
|
|
|
10690
10729
|
this.closingPromise = Promise.all([
|
|
10691
10730
|
this.server.close(),
|
|
10692
10731
|
(_a = this.typechecker) == null ? void 0 : _a.stop(),
|
|
10693
|
-
(_b = this.browser) == null ? void 0 : _b.close()
|
|
10732
|
+
(_b = this.browser) == null ? void 0 : _b.close(),
|
|
10733
|
+
this.clearTmpDir()
|
|
10694
10734
|
].filter(Boolean)).then(() => this._provided = {});
|
|
10695
10735
|
}
|
|
10696
10736
|
return this.closingPromise;
|
|
10697
10737
|
}
|
|
10738
|
+
async clearTmpDir() {
|
|
10739
|
+
try {
|
|
10740
|
+
await rm(this.tmpDir, { force: true, recursive: true });
|
|
10741
|
+
} catch {
|
|
10742
|
+
}
|
|
10743
|
+
}
|
|
10698
10744
|
async initBrowserProvider() {
|
|
10699
10745
|
if (!this.isBrowserEnabled())
|
|
10700
10746
|
return;
|
|
@@ -10799,6 +10845,7 @@ class Vitest {
|
|
|
10799
10845
|
this.pool = void 0;
|
|
10800
10846
|
this.coverageProvider = void 0;
|
|
10801
10847
|
this.runningPromise = void 0;
|
|
10848
|
+
this.distPath = void 0;
|
|
10802
10849
|
this.projectsTestFiles.clear();
|
|
10803
10850
|
const resolved = resolveConfig(this.mode, options, server.config, this.logger);
|
|
10804
10851
|
this.server = server;
|
|
@@ -10809,9 +10856,6 @@ class Vitest {
|
|
|
10809
10856
|
if (this.config.watch)
|
|
10810
10857
|
this.registerWatcher();
|
|
10811
10858
|
this.vitenode = new ViteNodeServer(server, this.config.server);
|
|
10812
|
-
const projectVitestPath = await this.vitenode.resolveId("vitest");
|
|
10813
|
-
const vitestDir = projectVitestPath ? resolve(projectVitestPath.id, "../..") : rootDir;
|
|
10814
|
-
this.distPath = join(vitestDir, "dist");
|
|
10815
10859
|
const node = this.vitenode;
|
|
10816
10860
|
this.runner = new ViteNodeRunner({
|
|
10817
10861
|
root: server.config.root,
|
|
@@ -10880,7 +10924,7 @@ class Vitest {
|
|
|
10880
10924
|
if (this.config.workspace)
|
|
10881
10925
|
return this.config.workspace;
|
|
10882
10926
|
const configDir = this.server.config.configFile ? dirname(this.server.config.configFile) : this.config.root;
|
|
10883
|
-
const rootFiles = await promises.readdir(configDir);
|
|
10927
|
+
const rootFiles = await promises$1.readdir(configDir);
|
|
10884
10928
|
const workspaceConfigName = workspacesFiles.find((configFile) => {
|
|
10885
10929
|
return rootFiles.includes(configFile);
|
|
10886
10930
|
});
|
|
@@ -10931,7 +10975,7 @@ class Vitest {
|
|
|
10931
10975
|
return CONFIG_NAMES.some((configName) => filename.startsWith(configName));
|
|
10932
10976
|
}).map(async (filepath) => {
|
|
10933
10977
|
if (filepath.endsWith("/")) {
|
|
10934
|
-
const filesInside = await promises.readdir(filepath);
|
|
10978
|
+
const filesInside = await promises$1.readdir(filepath);
|
|
10935
10979
|
const configFile = configFiles.find((config) => filesInside.includes(config));
|
|
10936
10980
|
return configFile ? join(filepath, configFile) : filepath;
|
|
10937
10981
|
}
|
|
@@ -11050,6 +11094,20 @@ class Vitest {
|
|
|
11050
11094
|
if (this.config.watch)
|
|
11051
11095
|
await this.report("onWatcherStart");
|
|
11052
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
|
+
}
|
|
11053
11111
|
async getTestDependencies(filepath, deps = /* @__PURE__ */ new Set()) {
|
|
11054
11112
|
const addImports = async ([project, filepath2]) => {
|
|
11055
11113
|
if (deps.has(filepath2))
|
|
@@ -11119,7 +11177,15 @@ class Vitest {
|
|
|
11119
11177
|
for await (const project of projects)
|
|
11120
11178
|
await project.initializeGlobalSetup();
|
|
11121
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
|
+
}
|
|
11122
11187
|
async runFiles(paths, allTestsRun) {
|
|
11188
|
+
await this.initializeDistPath();
|
|
11123
11189
|
const filepaths = paths.map(([, file]) => file);
|
|
11124
11190
|
this.state.collectPaths(filepaths);
|
|
11125
11191
|
await this.report("onPathsCollected", filepaths);
|
|
@@ -11183,12 +11249,21 @@ class Vitest {
|
|
|
11183
11249
|
async changeNamePattern(pattern, files = this.state.getFilepaths(), trigger) {
|
|
11184
11250
|
if (pattern === "")
|
|
11185
11251
|
this.filenamePattern = void 0;
|
|
11186
|
-
|
|
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
|
+
}
|
|
11187
11263
|
await this.rerunFiles(files, trigger);
|
|
11188
11264
|
}
|
|
11189
|
-
async changeFilenamePattern(pattern) {
|
|
11265
|
+
async changeFilenamePattern(pattern, files = this.state.getFilepaths()) {
|
|
11190
11266
|
this.filenamePattern = pattern;
|
|
11191
|
-
const files = this.state.getFilepaths();
|
|
11192
11267
|
const trigger = this.filenamePattern ? "change filename pattern" : "reset filename pattern";
|
|
11193
11268
|
await this.rerunFiles(files, trigger);
|
|
11194
11269
|
}
|
|
@@ -11300,8 +11375,11 @@ class Vitest {
|
|
|
11300
11375
|
updateLastChanged(id);
|
|
11301
11376
|
const matchingProjects = [];
|
|
11302
11377
|
await Promise.all(this.projects.map(async (project) => {
|
|
11303
|
-
|
|
11378
|
+
var _a;
|
|
11379
|
+
if (await project.isTargetFile(id)) {
|
|
11304
11380
|
matchingProjects.push(project);
|
|
11381
|
+
(_a = project.testFilesList) == null ? void 0 : _a.push(id);
|
|
11382
|
+
}
|
|
11305
11383
|
}));
|
|
11306
11384
|
if (matchingProjects.length > 0) {
|
|
11307
11385
|
this.projectsTestFiles.set(id, new Set(matchingProjects));
|
|
@@ -11445,6 +11523,9 @@ class Vitest {
|
|
|
11445
11523
|
);
|
|
11446
11524
|
}));
|
|
11447
11525
|
}
|
|
11526
|
+
async getTestFilepaths() {
|
|
11527
|
+
return this.globTestFiles().then((files) => files.map(([, file]) => file));
|
|
11528
|
+
}
|
|
11448
11529
|
async globTestFiles(filters = []) {
|
|
11449
11530
|
const files = [];
|
|
11450
11531
|
await Promise.all(this.projects.map(async (project) => {
|
|
@@ -18073,6 +18154,9 @@ ${resultBody}`;
|
|
|
18073
18154
|
write(data) {
|
|
18074
18155
|
this.stdout.write(data);
|
|
18075
18156
|
}
|
|
18157
|
+
getLastResults() {
|
|
18158
|
+
return this.results;
|
|
18159
|
+
}
|
|
18076
18160
|
}
|
|
18077
18161
|
|
|
18078
18162
|
const keys = [
|
|
@@ -18124,8 +18208,10 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
|
|
|
18124
18208
|
return printShortcutsHelp();
|
|
18125
18209
|
if (name === "u")
|
|
18126
18210
|
return ctx.updateSnapshot();
|
|
18127
|
-
if (name === "a" || name === "return")
|
|
18128
|
-
|
|
18211
|
+
if (name === "a" || name === "return") {
|
|
18212
|
+
const files = await ctx.getTestFilepaths();
|
|
18213
|
+
return ctx.changeNamePattern("", files, "rerun all tests");
|
|
18214
|
+
}
|
|
18129
18215
|
if (name === "r")
|
|
18130
18216
|
return ctx.rerunFiles();
|
|
18131
18217
|
if (name === "f")
|
|
@@ -18144,8 +18230,8 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
|
|
|
18144
18230
|
off();
|
|
18145
18231
|
const watchFilter = new WatchFilter("Input test name pattern (RegExp)", stdin, stdout2);
|
|
18146
18232
|
const filter = await watchFilter.filter((str) => {
|
|
18147
|
-
const
|
|
18148
|
-
const tests = getTests(
|
|
18233
|
+
const files2 = ctx.state.getFiles();
|
|
18234
|
+
const tests = getTests(files2);
|
|
18149
18235
|
try {
|
|
18150
18236
|
const reg = new RegExp(str);
|
|
18151
18237
|
return tests.map((test) => test.name).filter((testName) => testName.match(reg));
|
|
@@ -18154,7 +18240,9 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
|
|
|
18154
18240
|
}
|
|
18155
18241
|
});
|
|
18156
18242
|
on();
|
|
18157
|
-
|
|
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");
|
|
18158
18246
|
}
|
|
18159
18247
|
async function inputProjectName() {
|
|
18160
18248
|
off();
|
|
@@ -18178,7 +18266,11 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
|
|
|
18178
18266
|
});
|
|
18179
18267
|
on();
|
|
18180
18268
|
latestFilename = (filter == null ? void 0 : filter.trim()) || "";
|
|
18181
|
-
|
|
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
|
+
);
|
|
18182
18274
|
}
|
|
18183
18275
|
let rl;
|
|
18184
18276
|
function on() {
|
|
@@ -18241,10 +18333,16 @@ async function startVitest(mode, cliFilters = [], options = {}, viteOverrides, v
|
|
|
18241
18333
|
process.exit(EXIT_CODE_RESTART);
|
|
18242
18334
|
});
|
|
18243
18335
|
ctx.onAfterSetServer(() => {
|
|
18244
|
-
ctx.
|
|
18336
|
+
if (ctx.config.standalone)
|
|
18337
|
+
ctx.init();
|
|
18338
|
+
else
|
|
18339
|
+
ctx.start(cliFilters);
|
|
18245
18340
|
});
|
|
18246
18341
|
try {
|
|
18247
|
-
|
|
18342
|
+
if (ctx.config.standalone)
|
|
18343
|
+
await ctx.init();
|
|
18344
|
+
else
|
|
18345
|
+
await ctx.start(cliFilters);
|
|
18248
18346
|
} catch (e) {
|
|
18249
18347
|
process.exitCode = 1;
|
|
18250
18348
|
await ctx.logger.printError(e, { fullStack: true, type: "Unhandled Error" });
|
|
@@ -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 };
|