vitest 0.28.4 → 0.29.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/LICENSE.md +1 -1
- package/coverage.d.ts +1 -0
- package/dist/browser.d.ts +2 -1
- package/dist/browser.js +4 -4
- package/dist/child.js +89 -0
- package/dist/{chunk-api-setup.ec61b167.js → chunk-api-setup.d9eccaeb.js} +5 -5
- package/dist/{chunk-env-node.ffd1183b.js → chunk-env-node.affdd278.js} +1 -2
- package/dist/{chunk-install-pkg.13d8e7be.js → chunk-install-pkg.ea1a5ef4.js} +9 -8
- package/dist/chunk-integrations-coverage.e0a6acd2.js +51 -0
- package/dist/{chunk-integrations-globals.aacbac4d.js → chunk-integrations-globals.b56fcb06.js} +8 -8
- package/dist/{chunk-integrations-run-once.38756e30.js → chunk-integrations-run-once.9012f759.js} +1 -1
- package/dist/{chunk-integrations-utils.dae69d89.js → chunk-integrations-utils.233d6a3b.js} +2 -2
- package/dist/{chunk-node-git.d9ad64ab.js → chunk-node-git.ed5bded8.js} +1 -2
- package/dist/{chunk-node-pkg.94145502.js → chunk-node-pkg.88e7e848.js} +4423 -270
- package/dist/{chunk-runtime-mocker.eb0c265c.js → chunk-runtime-mocker.a048e92d.js} +83 -47
- package/dist/chunk-runtime-rpc.971b3848.js +61 -0
- package/dist/{chunk-runtime-setup.7dfc1a6a.js → chunk-runtime-setup.992bb661.js} +2 -2
- package/dist/{chunk-snapshot-env.6457638e.js → chunk-snapshot-env.a347d647.js} +2 -2
- package/dist/{chunk-utils-base.904102a8.js → chunk-utils-base.81f83dbd.js} +15 -1
- package/dist/{chunk-utils-global.442d1d33.js → chunk-utils-global.727b6d25.js} +1 -7
- package/dist/{chunk-utils-import.0402c9db.js → chunk-utils-import.ec15dcad.js} +18 -29
- package/dist/{chunk-utils-tasks.a9a8d8e1.js → chunk-utils-tasks.b41c8284.js} +14 -10
- package/dist/cli-wrapper.js +1 -2
- package/dist/cli.js +12 -11
- package/dist/config.cjs +1 -1
- package/dist/config.d.ts +8 -7
- package/dist/config.js +1 -1
- package/dist/coverage.d.ts +142 -0
- package/dist/coverage.js +49 -0
- package/dist/entry.js +51 -84
- package/dist/environments.d.ts +2 -1
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +9 -9
- package/dist/loader.js +2 -2
- package/dist/node.d.ts +9 -10
- package/dist/node.js +14 -12
- package/dist/runners.d.ts +4 -1
- package/dist/runners.js +221 -13
- package/dist/{types-aac763a5.d.ts → types-7cd96283.d.ts} +164 -39
- package/dist/{vendor-index.618ca5a1.js → vendor-index.2cbcdd1e.js} +18 -13
- package/dist/worker.js +14 -56
- package/package.json +16 -10
- package/dist/chunk-integrations-coverage.48e6286b.js +0 -3993
- package/dist/chunk-runtime-rpc.9c0386cc.js +0 -31
- package/dist/runners-chunk.js +0 -215
package/dist/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UserConfig as UserConfig$2, ConfigEnv } from 'vite';
|
|
2
2
|
export { ConfigEnv } from 'vite';
|
|
3
|
-
import {
|
|
3
|
+
import { a3 as ResolvedCoverageOptions, U as UserConfig$1, a6 as CoverageC8Options, a7 as CustomProviderOptions, a5 as CoverageIstanbulOptions, ah as HtmlOptions, ai as FileOptions, aj as CloverOptions, ak as CoberturaOptions, al as HtmlSpaOptions, am as LcovOptions, an as LcovOnlyOptions, ao as TeamcityOptions, ap as TextOptions, aq as ProjectOptions, F as FakeTimerInstallOpts } from './types-7cd96283.js';
|
|
4
4
|
import '@vitest/expect';
|
|
5
5
|
import '@vitest/runner/types';
|
|
6
6
|
import '@vitest/runner';
|
|
@@ -11,6 +11,7 @@ import 'vite-node/client';
|
|
|
11
11
|
import 'vite-node/server';
|
|
12
12
|
import 'node:worker_threads';
|
|
13
13
|
import 'vite-node';
|
|
14
|
+
import 'source-map';
|
|
14
15
|
import 'node:fs';
|
|
15
16
|
|
|
16
17
|
declare const defaultInclude: string[];
|
|
@@ -44,17 +45,17 @@ declare const config: {
|
|
|
44
45
|
include: never[];
|
|
45
46
|
};
|
|
46
47
|
coverage: {
|
|
47
|
-
provider
|
|
48
|
+
provider: "c8";
|
|
48
49
|
} & CoverageC8Options & Required<Pick<({
|
|
49
50
|
provider?: undefined;
|
|
50
51
|
} & CoverageC8Options) | ({
|
|
51
|
-
provider:
|
|
52
|
-
} &
|
|
53
|
-
provider
|
|
52
|
+
provider: "custom";
|
|
53
|
+
} & CustomProviderOptions) | ({
|
|
54
|
+
provider: "c8";
|
|
54
55
|
} & CoverageC8Options) | ({
|
|
55
56
|
provider: "istanbul";
|
|
56
|
-
} & CoverageIstanbulOptions), "exclude" | "enabled" | "clean" | "cleanOnRerun" | "reportsDirectory" | "extension"
|
|
57
|
-
reporter:
|
|
57
|
+
} & CoverageIstanbulOptions), "exclude" | "enabled" | "clean" | "cleanOnRerun" | "reportsDirectory" | "extension">> & {
|
|
58
|
+
reporter: (["html", Partial<HtmlOptions>] | ["json", Partial<FileOptions>] | ["none", {}] | ["clover", Partial<CloverOptions>] | ["cobertura", Partial<CoberturaOptions>] | ["html-spa", Partial<HtmlSpaOptions>] | ["json-summary", Partial<FileOptions>] | ["lcov", Partial<LcovOptions>] | ["lcovonly", Partial<LcovOnlyOptions>] | ["teamcity", Partial<TeamcityOptions>] | ["text", Partial<TextOptions>] | ["text-lcov", Partial<ProjectOptions>] | ["text-summary", Partial<FileOptions>])[];
|
|
58
59
|
};
|
|
59
60
|
fakeTimers: FakeTimerInstallOpts;
|
|
60
61
|
maxConcurrency: number;
|
package/dist/config.js
CHANGED
|
@@ -26,7 +26,7 @@ const coverageConfigDefaults = {
|
|
|
26
26
|
cleanOnRerun: true,
|
|
27
27
|
reportsDirectory: "./coverage",
|
|
28
28
|
exclude: defaultCoverageExcludes,
|
|
29
|
-
reporter: ["text", "html", "clover", "json"],
|
|
29
|
+
reporter: [["text", {}], ["html", {}], ["clover", {}], ["json", {}]],
|
|
30
30
|
extension: [".js", ".cjs", ".mjs", ".ts", ".mts", ".cts", ".tsx", ".jsx", ".vue", ".svelte"]
|
|
31
31
|
};
|
|
32
32
|
const fakeTimersDefaults = {
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { a4 as BaseCoverageOptions, a3 as ResolvedCoverageOptions } from './types-7cd96283.js';
|
|
2
|
+
import '@vitest/expect';
|
|
3
|
+
import 'vite';
|
|
4
|
+
import '@vitest/runner/types';
|
|
5
|
+
import '@vitest/runner';
|
|
6
|
+
import '@vitest/runner/utils';
|
|
7
|
+
import '@vitest/utils';
|
|
8
|
+
import 'tinybench';
|
|
9
|
+
import 'vite-node/client';
|
|
10
|
+
import 'vite-node/server';
|
|
11
|
+
import 'node:worker_threads';
|
|
12
|
+
import 'vite-node';
|
|
13
|
+
import 'source-map';
|
|
14
|
+
import 'node:fs';
|
|
15
|
+
|
|
16
|
+
// Type definitions for istanbul-lib-coverage 2.0
|
|
17
|
+
// Project: https://istanbul.js.org, https://github.com/istanbuljs/istanbuljs
|
|
18
|
+
// Definitions by: Jason Cheatham <https://github.com/jason0x43>
|
|
19
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
20
|
+
// TypeScript Version: 2.4
|
|
21
|
+
|
|
22
|
+
interface CoverageSummaryData {
|
|
23
|
+
lines: Totals;
|
|
24
|
+
statements: Totals;
|
|
25
|
+
branches: Totals;
|
|
26
|
+
functions: Totals;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare class CoverageSummary {
|
|
30
|
+
constructor(data: CoverageSummary | CoverageSummaryData);
|
|
31
|
+
merge(obj: CoverageSummary): CoverageSummary;
|
|
32
|
+
toJSON(): CoverageSummaryData;
|
|
33
|
+
isEmpty(): boolean;
|
|
34
|
+
data: CoverageSummaryData;
|
|
35
|
+
lines: Totals;
|
|
36
|
+
statements: Totals;
|
|
37
|
+
branches: Totals;
|
|
38
|
+
functions: Totals;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface CoverageMapData {
|
|
42
|
+
[key: string]: FileCoverage | FileCoverageData;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare class CoverageMap {
|
|
46
|
+
constructor(data: CoverageMapData | CoverageMap);
|
|
47
|
+
addFileCoverage(pathOrObject: string | FileCoverage | FileCoverageData): void;
|
|
48
|
+
files(): string[];
|
|
49
|
+
fileCoverageFor(filename: string): FileCoverage;
|
|
50
|
+
filter(callback: (key: string) => boolean): void;
|
|
51
|
+
getCoverageSummary(): CoverageSummary;
|
|
52
|
+
merge(data: CoverageMapData | CoverageMap): void;
|
|
53
|
+
toJSON(): CoverageMapData;
|
|
54
|
+
data: CoverageMapData;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface Location {
|
|
58
|
+
line: number;
|
|
59
|
+
column: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface Range {
|
|
63
|
+
start: Location;
|
|
64
|
+
end: Location;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface BranchMapping {
|
|
68
|
+
loc: Range;
|
|
69
|
+
type: string;
|
|
70
|
+
locations: Range[];
|
|
71
|
+
line: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface FunctionMapping {
|
|
75
|
+
name: string;
|
|
76
|
+
decl: Range;
|
|
77
|
+
loc: Range;
|
|
78
|
+
line: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface FileCoverageData {
|
|
82
|
+
path: string;
|
|
83
|
+
statementMap: { [key: string]: Range };
|
|
84
|
+
fnMap: { [key: string]: FunctionMapping };
|
|
85
|
+
branchMap: { [key: string]: BranchMapping };
|
|
86
|
+
s: { [key: string]: number };
|
|
87
|
+
f: { [key: string]: number };
|
|
88
|
+
b: { [key: string]: number[] };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface Totals {
|
|
92
|
+
total: number;
|
|
93
|
+
covered: number;
|
|
94
|
+
skipped: number;
|
|
95
|
+
pct: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface Coverage {
|
|
99
|
+
covered: number;
|
|
100
|
+
total: number;
|
|
101
|
+
coverage: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
declare class FileCoverage implements FileCoverageData {
|
|
105
|
+
constructor(data: string | FileCoverage | FileCoverageData);
|
|
106
|
+
merge(other: FileCoverageData): void;
|
|
107
|
+
getBranchCoverageByLine(): { [line: number]: Coverage };
|
|
108
|
+
getLineCoverage(): { [line: number]: number };
|
|
109
|
+
getUncoveredLines(): number[];
|
|
110
|
+
resetHits(): void;
|
|
111
|
+
computeBranchTotals(): Totals;
|
|
112
|
+
computeSimpleTotals(): Totals;
|
|
113
|
+
toSummary(): CoverageSummary;
|
|
114
|
+
toJSON(): object;
|
|
115
|
+
|
|
116
|
+
data: FileCoverageData;
|
|
117
|
+
path: string;
|
|
118
|
+
statementMap: { [key: string]: Range };
|
|
119
|
+
fnMap: { [key: string]: FunctionMapping };
|
|
120
|
+
branchMap: { [key: string]: BranchMapping };
|
|
121
|
+
s: { [key: string]: number };
|
|
122
|
+
f: { [key: string]: number };
|
|
123
|
+
b: { [key: string]: number[] };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
type Threshold = 'lines' | 'functions' | 'statements' | 'branches';
|
|
127
|
+
declare class BaseCoverageProvider {
|
|
128
|
+
/**
|
|
129
|
+
* Check if current coverage is above configured thresholds and bump the thresholds if needed
|
|
130
|
+
*/
|
|
131
|
+
updateThresholds({ configurationFile, coverageMap, thresholds }: {
|
|
132
|
+
coverageMap: CoverageMap;
|
|
133
|
+
thresholds: Record<Threshold, number | undefined>;
|
|
134
|
+
configurationFile?: string;
|
|
135
|
+
}): void;
|
|
136
|
+
/**
|
|
137
|
+
* Resolve reporters from various configuration options
|
|
138
|
+
*/
|
|
139
|
+
resolveReporters(configReporters: NonNullable<BaseCoverageOptions['reporter']>): ResolvedCoverageOptions['reporter'];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { BaseCoverageProvider };
|
package/dist/coverage.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
|
|
3
|
+
const THRESHOLD_KEYS = ["lines", "functions", "statements", "branches"];
|
|
4
|
+
class BaseCoverageProvider {
|
|
5
|
+
updateThresholds({ configurationFile, coverageMap, thresholds }) {
|
|
6
|
+
if (!configurationFile)
|
|
7
|
+
throw new Error('Missing configurationFile. The "coverage.thresholdAutoUpdate" can only be enabled when configuration file is used.');
|
|
8
|
+
const summary = coverageMap.getCoverageSummary();
|
|
9
|
+
const thresholdsToUpdate = [];
|
|
10
|
+
for (const key of THRESHOLD_KEYS) {
|
|
11
|
+
const threshold = thresholds[key] || 100;
|
|
12
|
+
const actual = summary[key].pct;
|
|
13
|
+
if (actual > threshold)
|
|
14
|
+
thresholdsToUpdate.push(key);
|
|
15
|
+
}
|
|
16
|
+
if (thresholdsToUpdate.length === 0)
|
|
17
|
+
return;
|
|
18
|
+
const originalConfig = readFileSync(configurationFile, "utf8");
|
|
19
|
+
let updatedConfig = originalConfig;
|
|
20
|
+
for (const threshold of thresholdsToUpdate) {
|
|
21
|
+
const previousThreshold = (thresholds[threshold] || 100).toString();
|
|
22
|
+
const pattern = new RegExp(`(${threshold}\\s*:\\s*)${previousThreshold.replace(".", "\\.")}`);
|
|
23
|
+
const matches = originalConfig.match(pattern);
|
|
24
|
+
if (matches)
|
|
25
|
+
updatedConfig = updatedConfig.replace(matches[0], matches[1] + summary[threshold].pct);
|
|
26
|
+
else
|
|
27
|
+
console.error(`Unable to update coverage threshold ${threshold}. No threshold found using pattern ${pattern}`);
|
|
28
|
+
}
|
|
29
|
+
if (updatedConfig !== originalConfig) {
|
|
30
|
+
console.log("Updating thresholds to configuration file. You may want to push with updated coverage thresholds.");
|
|
31
|
+
writeFileSync(configurationFile, updatedConfig, "utf-8");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
resolveReporters(configReporters) {
|
|
35
|
+
if (!Array.isArray(configReporters))
|
|
36
|
+
return [[configReporters, {}]];
|
|
37
|
+
const resolvedReporters = [];
|
|
38
|
+
for (const reporter of configReporters) {
|
|
39
|
+
if (Array.isArray(reporter)) {
|
|
40
|
+
resolvedReporters.push([reporter[0], reporter[1] || {}]);
|
|
41
|
+
} else {
|
|
42
|
+
resolvedReporters.push([reporter, {}]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return resolvedReporters;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { BaseCoverageProvider };
|
package/dist/entry.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { promises, existsSync } from 'node:fs';
|
|
2
|
-
import { m as micromatch_1, t as takeCoverageInsideWorker } from './chunk-integrations-coverage.48e6286b.js';
|
|
3
1
|
import { startTests } from '@vitest/runner';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { resolve } from 'pathe';
|
|
3
|
+
import { g as getWorkerState, r as resetModules } from './chunk-utils-global.727b6d25.js';
|
|
4
|
+
import { R as RealDate, g as globalExpect, a as vi } from './chunk-utils-import.ec15dcad.js';
|
|
5
|
+
import { d as distDir } from './chunk-constants.797d3ebf.js';
|
|
6
|
+
import { s as startCoverageInsideWorker, t as takeCoverageInsideWorker, a as stopCoverageInsideWorker } from './chunk-integrations-coverage.e0a6acd2.js';
|
|
7
7
|
import { createRequire } from 'node:module';
|
|
8
8
|
import c from 'picocolors';
|
|
9
9
|
import { installSourcemapsSupport } from 'vite-node/source-map';
|
|
10
10
|
import { setColors, getSafeTimers } from '@vitest/utils';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import '
|
|
17
|
-
import 'util';
|
|
18
|
-
import 'path';
|
|
19
|
-
import 'pathe';
|
|
11
|
+
import { e as environments } from './chunk-env-node.affdd278.js';
|
|
12
|
+
import { i as index } from './chunk-integrations-utils.233d6a3b.js';
|
|
13
|
+
import { s as setupSnapshotEnvironment } from './chunk-snapshot-env.a347d647.js';
|
|
14
|
+
import { promises, existsSync } from 'node:fs';
|
|
15
|
+
import { r as rpc } from './chunk-runtime-rpc.971b3848.js';
|
|
16
|
+
import { s as setupCommonEnv } from './chunk-runtime-setup.992bb661.js';
|
|
20
17
|
import './chunk-utils-env.860d90c2.js';
|
|
21
18
|
import 'std-env';
|
|
22
19
|
import '@vitest/runner/utils';
|
|
23
20
|
import 'chai';
|
|
24
21
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
25
22
|
import '@vitest/expect';
|
|
26
|
-
import './chunk-utils-base.
|
|
27
|
-
import './chunk-utils-tasks.
|
|
23
|
+
import './chunk-utils-base.81f83dbd.js';
|
|
24
|
+
import './chunk-utils-tasks.b41c8284.js';
|
|
25
|
+
import 'util';
|
|
28
26
|
import '@vitest/spy';
|
|
27
|
+
import 'node:url';
|
|
28
|
+
import 'local-pkg';
|
|
29
29
|
import 'node:console';
|
|
30
|
-
import './chunk-integrations-run-once.
|
|
30
|
+
import './chunk-integrations-run-once.9012f759.js';
|
|
31
31
|
|
|
32
32
|
class NodeSnapshotEnvironment {
|
|
33
33
|
resolvePath(filepath) {
|
|
@@ -175,8 +175,8 @@ async function setupConsoleLogSpy() {
|
|
|
175
175
|
groupIndentation: 2
|
|
176
176
|
});
|
|
177
177
|
}
|
|
178
|
-
async function loadEnvironment(name) {
|
|
179
|
-
const pkg = await
|
|
178
|
+
async function loadEnvironment(name, executor) {
|
|
179
|
+
const pkg = await executor.executeId(`vitest-environment-${name}`);
|
|
180
180
|
if (!pkg || !pkg.default || typeof pkg.default !== "object" || typeof pkg.default.setup !== "function") {
|
|
181
181
|
throw new Error(
|
|
182
182
|
`Environment "${name}" is not a valid environment. Package "vitest-environment-${name}" should have default export with "setup" method.`
|
|
@@ -184,8 +184,8 @@ async function loadEnvironment(name) {
|
|
|
184
184
|
}
|
|
185
185
|
return pkg.default;
|
|
186
186
|
}
|
|
187
|
-
async function withEnv(name, options, fn) {
|
|
188
|
-
const config = environments[name] || await loadEnvironment(name);
|
|
187
|
+
async function withEnv(name, options, executor, fn) {
|
|
188
|
+
const config = environments[name] || await loadEnvironment(name, executor);
|
|
189
189
|
globalThis.__vitest_environment__ = config.name || name;
|
|
190
190
|
globalExpect.setState({
|
|
191
191
|
environment: config.name || name || "node"
|
|
@@ -198,25 +198,25 @@ async function withEnv(name, options, fn) {
|
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
acc[key].push(item);
|
|
206
|
-
return acc;
|
|
207
|
-
}, {});
|
|
208
|
-
}
|
|
209
|
-
async function getTestRunnerConstructor(config) {
|
|
210
|
-
if (!config.runner)
|
|
201
|
+
const runnersFile = resolve(distDir, "runners.js");
|
|
202
|
+
async function getTestRunnerConstructor(config, executor) {
|
|
203
|
+
if (!config.runner) {
|
|
204
|
+
const { VitestTestRunner, NodeBenchmarkRunner } = await executor.executeFile(runnersFile);
|
|
211
205
|
return config.mode === "test" ? VitestTestRunner : NodeBenchmarkRunner;
|
|
212
|
-
|
|
206
|
+
}
|
|
207
|
+
const mod = await executor.executeId(config.runner);
|
|
213
208
|
if (!mod.default && typeof mod.default !== "function")
|
|
214
209
|
throw new Error(`Runner must export a default function, but got ${typeof mod.default} imported from ${config.runner}`);
|
|
215
210
|
return mod.default;
|
|
216
211
|
}
|
|
217
|
-
async function getTestRunner(config) {
|
|
218
|
-
const TestRunner = await getTestRunnerConstructor(config);
|
|
212
|
+
async function getTestRunner(config, executor) {
|
|
213
|
+
const TestRunner = await getTestRunnerConstructor(config, executor);
|
|
219
214
|
const testRunner = new TestRunner(config);
|
|
215
|
+
Object.defineProperty(testRunner, "__vitest_executor", {
|
|
216
|
+
value: executor,
|
|
217
|
+
enumerable: false,
|
|
218
|
+
configurable: false
|
|
219
|
+
});
|
|
220
220
|
if (!testRunner.config)
|
|
221
221
|
testRunner.config = config;
|
|
222
222
|
if (!testRunner.importFile)
|
|
@@ -234,65 +234,32 @@ async function getTestRunner(config) {
|
|
|
234
234
|
};
|
|
235
235
|
const originalOnAfterRun = testRunner.onAfterRun;
|
|
236
236
|
testRunner.onAfterRun = async (files) => {
|
|
237
|
-
const coverage = await takeCoverageInsideWorker(config.coverage);
|
|
237
|
+
const coverage = await takeCoverageInsideWorker(config.coverage, executor);
|
|
238
238
|
rpc().onAfterSuiteRun({ coverage });
|
|
239
239
|
await (originalOnAfterRun == null ? void 0 : originalOnAfterRun.call(testRunner, files));
|
|
240
240
|
};
|
|
241
241
|
return testRunner;
|
|
242
242
|
}
|
|
243
|
-
async function run(files, config) {
|
|
243
|
+
async function run(files, config, environment, executor) {
|
|
244
244
|
await setupGlobalEnv(config);
|
|
245
|
+
await startCoverageInsideWorker(config.coverage, executor);
|
|
245
246
|
const workerState = getWorkerState();
|
|
246
|
-
const runner = await getTestRunner(config);
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if (micromatch_1.isMatch(file, glob)) {
|
|
254
|
-
env = target;
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
247
|
+
const runner = await getTestRunner(config, executor);
|
|
248
|
+
globalThis.__vitest_environment__ = environment;
|
|
249
|
+
await withEnv(environment.name, environment.options || config.environmentOptions || {}, executor, async () => {
|
|
250
|
+
for (const file of files) {
|
|
251
|
+
if (config.isolate) {
|
|
252
|
+
workerState.mockMap.clear();
|
|
253
|
+
resetModules(workerState.moduleCache, true);
|
|
257
254
|
}
|
|
255
|
+
workerState.filepath = file;
|
|
256
|
+
await startTests([file], runner);
|
|
257
|
+
workerState.filepath = void 0;
|
|
258
|
+
vi.resetConfig();
|
|
259
|
+
vi.restoreAllMocks();
|
|
258
260
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return {
|
|
262
|
-
file,
|
|
263
|
-
env,
|
|
264
|
-
envOptions: envOptions ? { [env]: envOptions } : null
|
|
265
|
-
};
|
|
266
|
-
}));
|
|
267
|
-
const filesByEnv = groupBy(filesWithEnv, ({ env }) => env);
|
|
268
|
-
const orderedEnvs = envs.concat(
|
|
269
|
-
Object.keys(filesByEnv).filter((env) => !envs.includes(env))
|
|
270
|
-
);
|
|
271
|
-
for (const env of orderedEnvs) {
|
|
272
|
-
const environment = env;
|
|
273
|
-
const files2 = filesByEnv[environment];
|
|
274
|
-
if (!files2 || !files2.length)
|
|
275
|
-
continue;
|
|
276
|
-
globalThis.__vitest_environment__ = environment;
|
|
277
|
-
const filesByOptions = groupBy(files2, ({ envOptions }) => JSON.stringify(envOptions));
|
|
278
|
-
for (const options of Object.keys(filesByOptions)) {
|
|
279
|
-
const files3 = filesByOptions[options];
|
|
280
|
-
if (!files3 || !files3.length)
|
|
281
|
-
continue;
|
|
282
|
-
await withEnv(environment, files3[0].envOptions || config.environmentOptions || {}, async () => {
|
|
283
|
-
for (const { file } of files3) {
|
|
284
|
-
if (config.isolate) {
|
|
285
|
-
workerState.mockMap.clear();
|
|
286
|
-
resetModules(workerState.moduleCache, true);
|
|
287
|
-
}
|
|
288
|
-
workerState.filepath = file;
|
|
289
|
-
await startTests([file], runner);
|
|
290
|
-
workerState.filepath = void 0;
|
|
291
|
-
vi.resetConfig();
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
}
|
|
261
|
+
await stopCoverageInsideWorker(config.coverage, executor);
|
|
262
|
+
});
|
|
296
263
|
}
|
|
297
264
|
|
|
298
265
|
export { run };
|
package/dist/environments.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { X as Environment } from './types-7cd96283.js';
|
|
2
2
|
import '@vitest/expect';
|
|
3
3
|
import 'vite';
|
|
4
4
|
import '@vitest/runner/types';
|
|
@@ -10,6 +10,7 @@ import 'vite-node/client';
|
|
|
10
10
|
import 'vite-node/server';
|
|
11
11
|
import 'node:worker_threads';
|
|
12
12
|
import 'vite-node';
|
|
13
|
+
import 'source-map';
|
|
13
14
|
import 'node:fs';
|
|
14
15
|
|
|
15
16
|
declare const environments: {
|
package/dist/environments.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Test } from '@vitest/runner';
|
|
2
2
|
export { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
|
|
3
|
-
import { B as BenchmarkAPI, F as FakeTimerInstallOpts, M as MockFactoryWithHelper, R as RuntimeConfig, a as ResolvedConfig, b as ModuleGraphData, S as SnapshotResult, c as Reporter } from './types-
|
|
4
|
-
export {
|
|
3
|
+
import { B as BenchmarkAPI, F as FakeTimerInstallOpts, M as MockFactoryWithHelper, R as RuntimeConfig, a as ResolvedConfig, b as ModuleGraphData, S as SnapshotResult, c as Reporter } from './types-7cd96283.js';
|
|
4
|
+
export { x as AfterSuiteRunMeta, A as ApiConfig, G as ArgumentsType, D as Arrayable, z as Awaitable, a4 as BaseCoverageOptions, ab as BenchFunction, a9 as Benchmark, B as BenchmarkAPI, aa as BenchmarkResult, a8 as BenchmarkUserOptions, h as BuiltinEnvironment, i as CSSModuleScopeStrategy, C as CollectLineNumbers, e as CollectLines, O as Constructable, g as Context, o as ContextRPC, n as ContextTestEnvironment, a6 as CoverageC8Options, a5 as CoverageIstanbulOptions, a2 as CoverageOptions, _ as CoverageProvider, a0 as CoverageProviderModule, a1 as CoverageReporter, a7 as CustomProviderOptions, K as DeepMerge, X as Environment, E as EnvironmentOptions, Q as EnvironmentReturn, I as InlineConfig, J as JSDOMOptions, H as MergeInsertions, P as ModuleCache, b as ModuleGraphData, L as MutableArray, N as Nullable, Z as OnServerRestartHandler, d as RawErrsMap, $ as ReportContext, c as Reporter, w as ResolveIdFunction, a as ResolvedConfig, a3 as ResolvedCoverageOptions, f as RootAndTarget, R as RuntimeConfig, m as RuntimeRPC, j as SequenceHooks, q as SnapshotData, t as SnapshotMatchOptions, S as SnapshotResult, s as SnapshotStateOptions, v as SnapshotSummary, r as SnapshotUpdateState, T as TscErrorInfo, l as TypecheckConfig, u as UncheckedSnapshot, U as UserConfig, Y as UserConsoleLog, p as Vitest, V as VitestEnvironment, k as VitestRunMode, W as WorkerContext, y as WorkerGlobalState } from './types-7cd96283.js';
|
|
5
5
|
import { spyOn, fn, MaybeMockedDeep, MaybeMocked, MaybePartiallyMocked, MaybePartiallyMockedDeep, EnhancedSpy } from '@vitest/spy';
|
|
6
6
|
export { EnhancedSpy, Mock, MockContext, MockInstance, Mocked, MockedClass, MockedFunction, MockedObject, SpyInstance } from '@vitest/spy';
|
|
7
7
|
export { S as SnapshotEnvironment } from './env-afee91f0.js';
|
|
@@ -19,6 +19,7 @@ import 'vite-node/client';
|
|
|
19
19
|
import 'vite-node/server';
|
|
20
20
|
import 'node:worker_threads';
|
|
21
21
|
import 'vite-node';
|
|
22
|
+
import 'source-map';
|
|
22
23
|
import 'node:fs';
|
|
23
24
|
|
|
24
25
|
declare type Not<T extends boolean> = T extends true ? false : true;
|
|
@@ -306,7 +307,7 @@ declare class VitestUtils {
|
|
|
306
307
|
*/
|
|
307
308
|
unstubAllGlobals(): this;
|
|
308
309
|
/**
|
|
309
|
-
* Reset
|
|
310
|
+
* Reset environmental variables to the ones that were available before first `vi.stubEnv` was called.
|
|
310
311
|
*/
|
|
311
312
|
unstubAllEnvs(): this;
|
|
312
313
|
resetModules(): this;
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
export { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
|
|
2
|
-
export { b as bench, c as createExpect, g as expect, a as vi, v as vitest } from './chunk-utils-import.
|
|
3
|
-
export { i as isFirstRun, r as runOnce } from './chunk-integrations-run-once.
|
|
4
|
-
import { d as dist } from './chunk-integrations-utils.
|
|
5
|
-
export { b as assertType, g as getRunningMode, a as isWatchMode } from './chunk-integrations-utils.
|
|
2
|
+
export { b as bench, c as createExpect, g as expect, a as vi, v as vitest } from './chunk-utils-import.ec15dcad.js';
|
|
3
|
+
export { i as isFirstRun, r as runOnce } from './chunk-integrations-run-once.9012f759.js';
|
|
4
|
+
import { d as dist } from './chunk-integrations-utils.233d6a3b.js';
|
|
5
|
+
export { b as assertType, g as getRunningMode, a as isWatchMode } from './chunk-integrations-utils.233d6a3b.js';
|
|
6
6
|
import * as chai from 'chai';
|
|
7
7
|
export { chai };
|
|
8
8
|
export { assert, should } from 'chai';
|
|
9
9
|
import '@vitest/runner/utils';
|
|
10
10
|
import '@vitest/utils';
|
|
11
|
-
import './chunk-utils-global.
|
|
11
|
+
import './chunk-utils-global.727b6d25.js';
|
|
12
12
|
import 'pathe';
|
|
13
13
|
import './chunk-utils-env.860d90c2.js';
|
|
14
14
|
import 'std-env';
|
|
15
15
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
16
16
|
import '@vitest/expect';
|
|
17
|
-
import './chunk-runtime-rpc.
|
|
18
|
-
import './chunk-snapshot-env.
|
|
19
|
-
import './chunk-utils-base.
|
|
20
|
-
import './chunk-utils-tasks.
|
|
17
|
+
import './chunk-runtime-rpc.971b3848.js';
|
|
18
|
+
import './chunk-snapshot-env.a347d647.js';
|
|
19
|
+
import './chunk-utils-base.81f83dbd.js';
|
|
20
|
+
import './chunk-utils-tasks.b41c8284.js';
|
|
21
21
|
import 'util';
|
|
22
22
|
import '@vitest/spy';
|
|
23
23
|
|
package/dist/loader.js
CHANGED
|
@@ -2,7 +2,7 @@ import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { i as isNodeBuiltin, h as hasCJSSyntax } from './vendor-index.bdee400f.js';
|
|
4
4
|
import { normalizeModuleId } from 'vite-node/utils';
|
|
5
|
-
import { g as getWorkerState } from './chunk-utils-global.
|
|
5
|
+
import { g as getWorkerState } from './chunk-utils-global.727b6d25.js';
|
|
6
6
|
import 'acorn';
|
|
7
7
|
import 'node:module';
|
|
8
8
|
import 'node:fs';
|
|
@@ -56,7 +56,7 @@ const resolve = async (url, context, next) => {
|
|
|
56
56
|
return next(url, context, next);
|
|
57
57
|
const id = normalizeModuleId(url);
|
|
58
58
|
const importer = normalizeModuleId(parentURL);
|
|
59
|
-
const resolved = await resolver(id, importer);
|
|
59
|
+
const resolved = await resolver(id, importer, state.ctx.environment.name);
|
|
60
60
|
let result;
|
|
61
61
|
let filepath;
|
|
62
62
|
if (resolved) {
|
package/dist/node.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { k as VitestRunMode, U as UserConfig,
|
|
2
|
-
export {
|
|
1
|
+
import { k as VitestRunMode, U as UserConfig, p as Vitest, ac as MockFactory, ad as MockMap, ae as TestSequencer } from './types-7cd96283.js';
|
|
2
|
+
export { ae as TestSequencer, ag as TestSequencerConstructor, p as Vitest, af as startVitest } from './types-7cd96283.js';
|
|
3
3
|
import { UserConfig as UserConfig$1, Plugin } from 'vite';
|
|
4
4
|
import { ViteNodeRunner } from 'vite-node/client';
|
|
5
5
|
import { ViteNodeRunnerOptions } from 'vite-node';
|
|
@@ -11,6 +11,7 @@ import '@vitest/utils';
|
|
|
11
11
|
import 'tinybench';
|
|
12
12
|
import 'vite-node/server';
|
|
13
13
|
import 'node:worker_threads';
|
|
14
|
+
import 'source-map';
|
|
14
15
|
import 'node:fs';
|
|
15
16
|
|
|
16
17
|
declare function createVitest(mode: VitestRunMode, options: UserConfig, viteOverrides?: UserConfig$1): Promise<Vitest>;
|
|
@@ -19,16 +20,15 @@ declare function VitestPlugin(options?: UserConfig, ctx?: Vitest): Promise<Plugi
|
|
|
19
20
|
|
|
20
21
|
type Key = string | symbol;
|
|
21
22
|
declare class VitestMocker {
|
|
22
|
-
|
|
23
|
+
executor: VitestExecutor;
|
|
23
24
|
private static pendingIds;
|
|
24
|
-
private static spyModulePath;
|
|
25
|
-
private static spyModule?;
|
|
26
25
|
private resolveCache;
|
|
27
|
-
constructor(
|
|
26
|
+
constructor(executor: VitestExecutor);
|
|
28
27
|
private get root();
|
|
29
28
|
private get base();
|
|
30
29
|
private get mockMap();
|
|
31
30
|
private get moduleCache();
|
|
31
|
+
private deleteCachedItem;
|
|
32
32
|
getSuiteFilepath(): string;
|
|
33
33
|
getMocks(): {
|
|
34
34
|
[x: string]: string | MockFactory | null;
|
|
@@ -45,7 +45,6 @@ declare class VitestMocker {
|
|
|
45
45
|
mockPath(originalId: string, path: string, external: string | null, factory?: MockFactory): void;
|
|
46
46
|
importActual<T>(rawId: string, importee: string): Promise<T>;
|
|
47
47
|
importMock(rawId: string, importee: string): Promise<any>;
|
|
48
|
-
initializeSpyModule(): Promise<void>;
|
|
49
48
|
requestWithMock(url: string, callstack: string[]): Promise<any>;
|
|
50
49
|
queueMock(id: string, importer: string, factory?: MockFactory): void;
|
|
51
50
|
queueUnmock(id: string, importer: string): void;
|
|
@@ -54,12 +53,12 @@ declare class VitestMocker {
|
|
|
54
53
|
interface ExecuteOptions extends ViteNodeRunnerOptions {
|
|
55
54
|
mockMap: MockMap;
|
|
56
55
|
}
|
|
57
|
-
declare class
|
|
56
|
+
declare class VitestExecutor extends ViteNodeRunner {
|
|
58
57
|
options: ExecuteOptions;
|
|
59
58
|
mocker: VitestMocker;
|
|
60
59
|
constructor(options: ExecuteOptions);
|
|
61
60
|
shouldResolveId(id: string, _importee?: string | undefined): boolean;
|
|
62
|
-
resolveUrl(id: string,
|
|
61
|
+
resolveUrl(id: string, importer?: string): Promise<[url: string, fsPath: string]>;
|
|
63
62
|
dependencyRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
|
|
64
63
|
prepareContext(context: Record<string, any>): Record<string, any>;
|
|
65
64
|
}
|
|
@@ -71,4 +70,4 @@ declare class BaseSequencer implements TestSequencer {
|
|
|
71
70
|
sort(files: string[]): Promise<string[]>;
|
|
72
71
|
}
|
|
73
72
|
|
|
74
|
-
export { BaseSequencer, ExecuteOptions,
|
|
73
|
+
export { BaseSequencer, ExecuteOptions, VitestExecutor, VitestPlugin, createVitest };
|