vitest 0.33.0 → 0.34.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.
Files changed (49) hide show
  1. package/LICENSE.md +0 -83
  2. package/dist/browser.d.ts +3 -2
  3. package/dist/browser.js +4 -8
  4. package/dist/child.js +43 -29
  5. package/dist/{chunk-api-setup.8f785c4a.js → chunk-api-setup.644415c3.js} +13 -7
  6. package/dist/{chunk-install-pkg.23da664c.js → chunk-install-pkg.dd70081b.js} +14 -13
  7. package/dist/{chunk-integrations-globals.0093e2ed.js → chunk-integrations-globals.877c84db.js} +7 -6
  8. package/dist/chunk-runtime-console.ea222ffb.js +108 -0
  9. package/dist/cli.js +14 -15
  10. package/dist/config.cjs +4 -3
  11. package/dist/config.d.ts +15 -19
  12. package/dist/config.js +4 -3
  13. package/dist/coverage.d.ts +3 -2
  14. package/dist/entry-vm.js +60 -0
  15. package/dist/entry.js +34 -213
  16. package/dist/environments.d.ts +3 -2
  17. package/dist/environments.js +4 -2
  18. package/dist/execute.js +15 -0
  19. package/dist/index.d.ts +12 -7
  20. package/dist/index.js +8 -7
  21. package/dist/loader.js +6 -4
  22. package/dist/node.d.ts +6 -53
  23. package/dist/node.js +16 -19
  24. package/dist/runners.d.ts +3 -2
  25. package/dist/runners.js +6 -5
  26. package/dist/{types-198fd1d9.d.ts → types-3c7dbfa5.d.ts} +139 -121
  27. package/dist/vendor-base.9c08bbd0.js +96 -0
  28. package/dist/{vendor-coverage.2e41927a.js → vendor-coverage.78040316.js} +1 -2
  29. package/dist/vendor-date.6e993429.js +50 -0
  30. package/dist/{vendor-environments.392ddf08.js → vendor-environments.443ecd82.js} +199 -3
  31. package/dist/vendor-execute.9ab1c1a7.js +978 -0
  32. package/dist/{vendor-global.6795f91f.js → vendor-global.97e4527c.js} +2 -1
  33. package/dist/{vendor-index.23ac4e13.js → vendor-index.087d1af7.js} +2 -20
  34. package/dist/vendor-index.9378c9a4.js +89 -0
  35. package/dist/vendor-index.b271ebe4.js +92 -0
  36. package/dist/{vendor-index.2af39fbb.js → vendor-index.eff408fd.js} +2 -3
  37. package/dist/{vendor-cli-api.bf4b62a8.js → vendor-node.00226ab1.js} +538 -836
  38. package/dist/{vendor-rpc.ad5b08c7.js → vendor-rpc.cbd8e972.js} +7 -4
  39. package/dist/{vendor-run-once.1fa85ba7.js → vendor-run-once.3e5ef7d7.js} +1 -2
  40. package/dist/vendor-source-map.e6c1997b.js +747 -0
  41. package/dist/{vendor-vi.dd6706cb.js → vendor-vi.271667ef.js} +26 -59
  42. package/dist/vm.js +114 -0
  43. package/dist/worker.js +39 -27
  44. package/execute.d.ts +1 -0
  45. package/package.json +12 -9
  46. package/suppress-warnings.cjs +2 -0
  47. package/dist/vendor-execute.3576af13.js +0 -421
  48. package/dist/vendor-index.cc463d9e.js +0 -189
  49. package/dist/vendor-tasks.f9d75aed.js +0 -14
package/dist/config.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { UserConfig as UserConfig$1, ConfigEnv } from 'vite';
2
2
  export { ConfigEnv, UserConfig, mergeConfig } from 'vite';
3
- import { c as ResolvedCoverageOptions, U as UserConfig, d as CoverageV8Options, e as CoverageC8Options, f as CustomProviderOptions, g as CoverageIstanbulOptions, H as HtmlOptions, F as FileOptions, h as CloverOptions, i as CoberturaOptions, j as HtmlSpaOptions, L as LcovOptions, k as LcovOnlyOptions, T as TeamcityOptions, l as TextOptions, P as ProjectOptions, m as FakeTimerInstallOpts, n as ProjectConfig } from './types-198fd1d9.js';
3
+ import { c as ResolvedCoverageOptions, U as UserConfig, d as CoverageV8Options, P as ProjectConfig } from './types-3c7dbfa5.js';
4
4
  import '@vitest/snapshot';
5
5
  import '@vitest/expect';
6
6
  import '@vitest/runner';
7
+ import 'vite-node';
7
8
  import '@vitest/runner/utils';
8
9
  import '@vitest/utils';
9
10
  import 'tinybench';
@@ -11,7 +12,7 @@ import 'vite-node/client';
11
12
  import '@vitest/snapshot/manager';
12
13
  import 'vite-node/server';
13
14
  import 'node:worker_threads';
14
- import 'vite-node';
15
+ import 'rollup';
15
16
  import 'node:fs';
16
17
  import 'chai';
17
18
 
@@ -46,22 +47,12 @@ declare const config: {
46
47
  css: {
47
48
  include: never[];
48
49
  };
49
- coverage: {
50
- provider: "v8";
51
- } & CoverageV8Options & Required<Pick<({
52
- provider?: undefined;
53
- } & CoverageC8Options) | ({
54
- provider: "custom";
55
- } & CustomProviderOptions) | ({
56
- provider: "c8";
57
- } & CoverageC8Options) | ({
58
- provider: "v8";
59
- } & CoverageV8Options) | ({
60
- provider: "istanbul";
61
- } & CoverageIstanbulOptions), "exclude" | "enabled" | "clean" | "cleanOnRerun" | "reportsDirectory" | "extension" | "reportOnFailure">> & {
62
- reporter: (["html", Partial<HtmlOptions>] | ["none", {}] | ["json", Partial<FileOptions>] | ["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>])[];
50
+ coverage: CoverageV8Options;
51
+ fakeTimers: {
52
+ loopLimit: number;
53
+ shouldClearNativeTimers: true;
54
+ toFake: ("setTimeout" | "setInterval" | "clearInterval" | "clearTimeout" | "setImmediate" | "clearImmediate" | "Date")[];
63
55
  };
64
- fakeTimers: FakeTimerInstallOpts;
65
56
  maxConcurrency: number;
66
57
  dangerouslyIgnoreUnhandledErrors: boolean;
67
58
  typecheck: {
@@ -77,10 +68,15 @@ interface UserWorkspaceConfig extends UserConfig$1 {
77
68
  test?: ProjectConfig;
78
69
  }
79
70
 
71
+ type UserConfigFnObject = (env: ConfigEnv) => UserConfig$1;
72
+ type UserConfigFnPromise = (env: ConfigEnv) => Promise<UserConfig$1>;
80
73
  type UserConfigFn = (env: ConfigEnv) => UserConfig$1 | Promise<UserConfig$1>;
81
- type UserConfigExport = UserConfig$1 | Promise<UserConfig$1> | UserConfigFn;
74
+ type UserConfigExport = UserConfig$1 | Promise<UserConfig$1> | UserConfigFnObject | UserConfigFnPromise | UserConfigFn;
82
75
  type UserProjectConfigFn = (env: ConfigEnv) => UserWorkspaceConfig | Promise<UserWorkspaceConfig>;
83
76
  type UserProjectConfigExport = UserWorkspaceConfig | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
77
+ declare function defineConfig(config: UserConfig$1): UserConfig$1;
78
+ declare function defineConfig(config: Promise<UserConfig$1>): Promise<UserConfig$1>;
79
+ declare function defineConfig(config: UserConfigFnObject): UserConfigFnObject;
84
80
  declare function defineConfig(config: UserConfigExport): UserConfigExport;
85
81
  declare function defineProject(config: UserProjectConfigExport): UserProjectConfigExport;
86
82
  declare function defineWorkspace(config: (string | (UserProjectConfigExport & {
@@ -89,4 +85,4 @@ declare function defineWorkspace(config: (string | (UserProjectConfigExport & {
89
85
  extends?: string | undefined;
90
86
  }))[];
91
87
 
92
- export { UserConfigExport, UserConfigFn, UserProjectConfigExport, UserProjectConfigFn, UserWorkspaceConfig, configDefaults, coverageConfigDefaults, defaultExclude, defaultInclude, defineConfig, defineProject, defineWorkspace };
88
+ export { UserConfigExport, UserConfigFn, UserConfigFnObject, UserConfigFnPromise, UserProjectConfigExport, UserProjectConfigFn, UserWorkspaceConfig, configDefaults, coverageConfigDefaults, defaultExclude, defaultInclude, defineConfig, defineProject, defineWorkspace };
package/dist/config.js CHANGED
@@ -11,6 +11,9 @@ const defaultCoverageExcludes = [
11
11
  "dist/**",
12
12
  "packages/*/test?(s)/**",
13
13
  "**/*.d.ts",
14
+ "**/virtual:*",
15
+ "**/__x00__*",
16
+ "**/\0*",
14
17
  "cypress/**",
15
18
  "test?(s)/**",
16
19
  "test?(-*).?(c|m)[jt]s?(x)",
@@ -26,10 +29,8 @@ const coverageConfigDefaults = {
26
29
  cleanOnRerun: true,
27
30
  reportsDirectory: "./coverage",
28
31
  exclude: defaultCoverageExcludes,
29
- reportOnFailure: true,
32
+ reportOnFailure: false,
30
33
  reporter: [["text", {}], ["html", {}], ["clover", {}], ["json", {}]],
31
- // default extensions used by c8, plus '.vue' and '.svelte'
32
- // see https://github.com/istanbuljs/schema/blob/master/default-extension.js
33
34
  extension: [".js", ".cjs", ".mjs", ".ts", ".mts", ".cts", ".tsx", ".jsx", ".vue", ".svelte"]
34
35
  };
35
36
  const fakeTimersDefaults = {
@@ -1,8 +1,9 @@
1
- import { B as BaseCoverageOptions, c as ResolvedCoverageOptions } from './types-198fd1d9.js';
1
+ import { B as BaseCoverageOptions, c as ResolvedCoverageOptions } from './types-3c7dbfa5.js';
2
2
  import '@vitest/snapshot';
3
3
  import '@vitest/expect';
4
4
  import 'vite';
5
5
  import '@vitest/runner';
6
+ import 'vite-node';
6
7
  import '@vitest/runner/utils';
7
8
  import '@vitest/utils';
8
9
  import 'tinybench';
@@ -10,7 +11,7 @@ import 'vite-node/client';
10
11
  import '@vitest/snapshot/manager';
11
12
  import 'vite-node/server';
12
13
  import 'node:worker_threads';
13
- import 'vite-node';
14
+ import 'rollup';
14
15
  import 'node:fs';
15
16
  import 'chai';
16
17
 
@@ -0,0 +1,60 @@
1
+ import { isatty } from 'node:tty';
2
+ import { createRequire } from 'node:module';
3
+ import { performance } from 'node:perf_hooks';
4
+ import { startTests } from '@vitest/runner';
5
+ import { setupColors, createColors } from '@vitest/utils';
6
+ import { V as VitestSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './vendor-index.9378c9a4.js';
7
+ import { s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './vendor-coverage.78040316.js';
8
+ import { g as getWorkerState } from './vendor-global.97e4527c.js';
9
+ import { i as index } from './vendor-index.eff408fd.js';
10
+ import { setupCommonEnv } from './browser.js';
11
+ import 'chai';
12
+ import '@vitest/snapshot/environment';
13
+ import 'pathe';
14
+ import './vendor-paths.84fc7a99.js';
15
+ import 'node:url';
16
+ import './vendor-rpc.cbd8e972.js';
17
+ import './vendor-vi.271667ef.js';
18
+ import '@vitest/runner/utils';
19
+ import './vendor-index.087d1af7.js';
20
+ import 'std-env';
21
+ import './vendor-_commonjsHelpers.7d1333e8.js';
22
+ import '@vitest/expect';
23
+ import '@vitest/snapshot';
24
+ import '@vitest/utils/error';
25
+ import './vendor-source-map.e6c1997b.js';
26
+ import 'util';
27
+ import './vendor-date.6e993429.js';
28
+ import '@vitest/spy';
29
+ import './vendor-run-once.3e5ef7d7.js';
30
+
31
+ async function run(files, config, executor) {
32
+ const workerState = getWorkerState();
33
+ await setupCommonEnv(config);
34
+ Object.defineProperty(globalThis, "__vitest_index__", {
35
+ value: index,
36
+ enumerable: false
37
+ });
38
+ config.snapshotOptions.snapshotEnvironment = new VitestSnapshotEnvironment(workerState.rpc);
39
+ setupColors(createColors(isatty(1)));
40
+ if (workerState.environment.transformMode === "web") {
41
+ const _require = createRequire(import.meta.url);
42
+ _require.extensions[".css"] = () => ({});
43
+ _require.extensions[".scss"] = () => ({});
44
+ _require.extensions[".sass"] = () => ({});
45
+ _require.extensions[".less"] = () => ({});
46
+ }
47
+ await startCoverageInsideWorker(config.coverage, executor);
48
+ if (config.chaiConfig)
49
+ setupChaiConfig(config.chaiConfig);
50
+ const runner = await resolveTestRunner(config, executor);
51
+ workerState.durations.prepare = performance.now() - workerState.durations.prepare;
52
+ for (const file of files) {
53
+ workerState.filepath = file;
54
+ await startTests([file], runner);
55
+ workerState.filepath = void 0;
56
+ }
57
+ await stopCoverageInsideWorker(config.coverage, executor);
58
+ }
59
+
60
+ export { run };
package/dist/entry.js CHANGED
@@ -1,20 +1,17 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { startTests } from '@vitest/runner';
3
- import { resolve } from 'pathe';
4
- import { r as resetModules } from './vendor-index.23ac4e13.js';
5
- import { R as RealDate, d as globalExpect, s as setupChaiConfig, v as vi } from './vendor-vi.dd6706cb.js';
6
- import { d as distDir } from './vendor-paths.84fc7a99.js';
7
- import { s as startCoverageInsideWorker, t as takeCoverageInsideWorker, a as stopCoverageInsideWorker } from './vendor-coverage.2e41927a.js';
3
+ import './vendor-index.087d1af7.js';
4
+ import { d as globalExpect, r as resetModules, v as vi } from './vendor-vi.271667ef.js';
5
+ import { s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './vendor-coverage.78040316.js';
6
+ import { V as VitestSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './vendor-index.9378c9a4.js';
8
7
  import { createRequire } from 'node:module';
9
8
  import { isatty } from 'node:tty';
10
9
  import { installSourcemapsSupport } from 'vite-node/source-map';
11
10
  import { setupColors, createColors, getSafeTimers } from '@vitest/utils';
12
- import { e as environments } from './vendor-environments.392ddf08.js';
13
- import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
14
- import { a as rpc } from './vendor-rpc.ad5b08c7.js';
15
- import { i as index } from './vendor-index.2af39fbb.js';
11
+ import { i as index } from './vendor-index.eff408fd.js';
16
12
  import { setupCommonEnv } from './browser.js';
17
- import { g as getWorkerState } from './vendor-global.6795f91f.js';
13
+ import { g as getWorkerState } from './vendor-global.97e4527c.js';
14
+ import 'pathe';
18
15
  import 'std-env';
19
16
  import '@vitest/runner/utils';
20
17
  import 'chai';
@@ -22,25 +19,18 @@ import './vendor-_commonjsHelpers.7d1333e8.js';
22
19
  import '@vitest/expect';
23
20
  import '@vitest/snapshot';
24
21
  import '@vitest/utils/error';
25
- import './vendor-tasks.f9d75aed.js';
22
+ import './vendor-source-map.e6c1997b.js';
26
23
  import 'util';
24
+ import './vendor-date.6e993429.js';
27
25
  import '@vitest/spy';
26
+ import '@vitest/snapshot/environment';
27
+ import './vendor-paths.84fc7a99.js';
28
28
  import 'node:url';
29
- import 'node:console';
30
- import 'local-pkg';
31
- import './vendor-run-once.1fa85ba7.js';
32
-
33
- class VitestSnapshotEnvironment extends NodeSnapshotEnvironment {
34
- getHeader() {
35
- return `// Vitest Snapshot v${this.getVersion()}, https://vitest.dev/guide/snapshot.html`;
36
- }
37
- resolvePath(filepath) {
38
- return rpc().resolveSnapshotPath(filepath);
39
- }
40
- }
29
+ import './vendor-rpc.cbd8e972.js';
30
+ import './vendor-run-once.3e5ef7d7.js';
41
31
 
42
32
  let globalSetup = false;
43
- async function setupGlobalEnv(config) {
33
+ async function setupGlobalEnv(config, { environment }) {
44
34
  await setupCommonEnv(config);
45
35
  Object.defineProperty(globalThis, "__vitest_index__", {
46
36
  value: index,
@@ -48,140 +38,33 @@ async function setupGlobalEnv(config) {
48
38
  });
49
39
  const state = getWorkerState();
50
40
  if (!state.config.snapshotOptions.snapshotEnvironment)
51
- state.config.snapshotOptions.snapshotEnvironment = new VitestSnapshotEnvironment();
41
+ state.config.snapshotOptions.snapshotEnvironment = new VitestSnapshotEnvironment(state.rpc);
52
42
  if (globalSetup)
53
43
  return;
54
44
  globalSetup = true;
55
45
  setupColors(createColors(isatty(1)));
56
- const _require = createRequire(import.meta.url);
57
- _require.extensions[".css"] = () => ({});
58
- _require.extensions[".scss"] = () => ({});
59
- _require.extensions[".sass"] = () => ({});
60
- _require.extensions[".less"] = () => ({});
46
+ if (environment.transformMode === "web") {
47
+ const _require = createRequire(import.meta.url);
48
+ _require.extensions[".css"] = () => ({});
49
+ _require.extensions[".scss"] = () => ({});
50
+ _require.extensions[".sass"] = () => ({});
51
+ _require.extensions[".less"] = () => ({});
52
+ }
61
53
  installSourcemapsSupport({
62
54
  getSourceMap: (source) => state.moduleCache.getSourceMap(source)
63
55
  });
64
- await setupConsoleLogSpy();
65
- }
66
- async function setupConsoleLogSpy() {
67
- const stdoutBuffer = /* @__PURE__ */ new Map();
68
- const stderrBuffer = /* @__PURE__ */ new Map();
69
- const timers = /* @__PURE__ */ new Map();
70
- const unknownTestId = "__vitest__unknown_test__";
71
- const { Writable } = await import('node:stream');
72
- const { Console } = await import('node:console');
73
- const { setTimeout, clearTimeout } = getSafeTimers();
74
- function schedule(taskId) {
75
- const timer = timers.get(taskId);
76
- const { stdoutTime, stderrTime } = timer;
77
- clearTimeout(timer.timer);
78
- timer.timer = setTimeout(() => {
79
- if (stderrTime < stdoutTime) {
80
- sendStderr(taskId);
81
- sendStdout(taskId);
82
- } else {
83
- sendStdout(taskId);
84
- sendStderr(taskId);
85
- }
86
- });
87
- }
88
- function sendStdout(taskId) {
89
- const buffer = stdoutBuffer.get(taskId);
90
- if (!buffer)
91
- return;
92
- const content = buffer.map((i) => String(i)).join("");
93
- const timer = timers.get(taskId);
94
- rpc().onUserConsoleLog({
95
- type: "stdout",
96
- content: content || "<empty line>",
97
- taskId,
98
- time: timer.stdoutTime || RealDate.now(),
99
- size: buffer.length
100
- });
101
- stdoutBuffer.set(taskId, []);
102
- timer.stdoutTime = 0;
103
- }
104
- function sendStderr(taskId) {
105
- const buffer = stderrBuffer.get(taskId);
106
- if (!buffer)
107
- return;
108
- const content = buffer.map((i) => String(i)).join("");
109
- const timer = timers.get(taskId);
110
- rpc().onUserConsoleLog({
111
- type: "stderr",
112
- content: content || "<empty line>",
113
- taskId,
114
- time: timer.stderrTime || RealDate.now(),
115
- size: buffer.length
116
- });
117
- stderrBuffer.set(taskId, []);
118
- timer.stderrTime = 0;
119
- }
120
- const stdout = new Writable({
121
- write(data, encoding, callback) {
122
- var _a, _b;
123
- const id = ((_b = (_a = getWorkerState()) == null ? void 0 : _a.current) == null ? void 0 : _b.id) ?? unknownTestId;
124
- let timer = timers.get(id);
125
- if (timer) {
126
- timer.stdoutTime = timer.stdoutTime || RealDate.now();
127
- } else {
128
- timer = { stdoutTime: RealDate.now(), stderrTime: RealDate.now(), timer: 0 };
129
- timers.set(id, timer);
130
- }
131
- let buffer = stdoutBuffer.get(id);
132
- if (!buffer) {
133
- buffer = [];
134
- stdoutBuffer.set(id, buffer);
135
- }
136
- buffer.push(data);
137
- schedule(id);
138
- callback();
139
- }
140
- });
141
- const stderr = new Writable({
142
- write(data, encoding, callback) {
143
- var _a, _b;
144
- const id = ((_b = (_a = getWorkerState()) == null ? void 0 : _a.current) == null ? void 0 : _b.id) ?? unknownTestId;
145
- let timer = timers.get(id);
146
- if (timer) {
147
- timer.stderrTime = timer.stderrTime || RealDate.now();
148
- } else {
149
- timer = { stderrTime: RealDate.now(), stdoutTime: RealDate.now(), timer: 0 };
150
- timers.set(id, timer);
151
- }
152
- let buffer = stderrBuffer.get(id);
153
- if (!buffer) {
154
- buffer = [];
155
- stderrBuffer.set(id, buffer);
156
- }
157
- buffer.push(data);
158
- schedule(id);
159
- callback();
160
- }
161
- });
162
- globalThis.console = new Console({
163
- stdout,
164
- stderr,
165
- colorMode: true,
166
- groupIndentation: 2
167
- });
56
+ await setupConsoleLogSpy(state);
168
57
  }
169
- async function loadEnvironment(name, executor) {
170
- const pkg = await executor.executeId(`vitest-environment-${name}`);
171
- if (!pkg || !pkg.default || typeof pkg.default !== "object" || typeof pkg.default.setup !== "function") {
172
- throw new Error(
173
- `Environment "${name}" is not a valid environment. Package "vitest-environment-${name}" should have default export with "setup" method.`
174
- );
175
- }
176
- return pkg.default;
58
+ async function setupConsoleLogSpy(state) {
59
+ const { createCustomConsole } = await import('./chunk-runtime-console.ea222ffb.js');
60
+ globalThis.console = createCustomConsole(state);
177
61
  }
178
- async function withEnv(name, options, executor, fn) {
179
- const config = environments[name] || await loadEnvironment(name, executor);
180
- globalThis.__vitest_environment__ = config.name || name;
62
+ async function withEnv({ environment }, options, fn) {
63
+ globalThis.__vitest_environment__ = environment.name;
181
64
  globalExpect.setState({
182
- environment: config.name || name || "node"
65
+ environment: environment.name
183
66
  });
184
- const env = await config.setup(globalThis, options);
67
+ const env = await environment.setup(globalThis, options);
185
68
  try {
186
69
  await fn();
187
70
  } finally {
@@ -191,83 +74,21 @@ async function withEnv(name, options, executor, fn) {
191
74
  }
192
75
  }
193
76
 
194
- const runnersFile = resolve(distDir, "runners.js");
195
- async function getTestRunnerConstructor(config, executor) {
196
- if (!config.runner) {
197
- const { VitestTestRunner, NodeBenchmarkRunner } = await executor.executeFile(runnersFile);
198
- return config.mode === "test" ? VitestTestRunner : NodeBenchmarkRunner;
199
- }
200
- const mod = await executor.executeId(config.runner);
201
- if (!mod.default && typeof mod.default !== "function")
202
- throw new Error(`Runner must export a default function, but got ${typeof mod.default} imported from ${config.runner}`);
203
- return mod.default;
204
- }
205
- async function getTestRunner(config, executor) {
206
- const TestRunner = await getTestRunnerConstructor(config, executor);
207
- const testRunner = new TestRunner(config);
208
- Object.defineProperty(testRunner, "__vitest_executor", {
209
- value: executor,
210
- enumerable: false,
211
- configurable: false
212
- });
213
- if (!testRunner.config)
214
- testRunner.config = config;
215
- if (!testRunner.importFile)
216
- throw new Error('Runner must implement "importFile" method.');
217
- const originalOnTaskUpdate = testRunner.onTaskUpdate;
218
- testRunner.onTaskUpdate = async (task) => {
219
- const p = rpc().onTaskUpdate(task);
220
- await (originalOnTaskUpdate == null ? void 0 : originalOnTaskUpdate.call(testRunner, task));
221
- return p;
222
- };
223
- const originalOnCollected = testRunner.onCollected;
224
- testRunner.onCollected = async (files) => {
225
- const state = getWorkerState();
226
- files.forEach((file) => {
227
- file.prepareDuration = state.durations.prepare;
228
- file.environmentLoad = state.durations.environment;
229
- state.durations.prepare = 0;
230
- state.durations.environment = 0;
231
- });
232
- rpc().onCollected(files);
233
- await (originalOnCollected == null ? void 0 : originalOnCollected.call(testRunner, files));
234
- };
235
- const originalOnAfterRun = testRunner.onAfterRun;
236
- testRunner.onAfterRun = async (files) => {
237
- const coverage = await takeCoverageInsideWorker(config.coverage, executor);
238
- rpc().onAfterSuiteRun({ coverage });
239
- await (originalOnAfterRun == null ? void 0 : originalOnAfterRun.call(testRunner, files));
240
- };
241
- const originalOnAfterRunTest = testRunner.onAfterRunTest;
242
- testRunner.onAfterRunTest = async (test) => {
243
- var _a, _b;
244
- if (config.bail && ((_a = test.result) == null ? void 0 : _a.state) === "fail") {
245
- const previousFailures = await rpc().getCountOfFailedTests();
246
- const currentFailures = 1 + previousFailures;
247
- if (currentFailures >= config.bail) {
248
- rpc().onCancel("test-failure");
249
- (_b = testRunner.onCancel) == null ? void 0 : _b.call(testRunner, "test-failure");
250
- }
251
- }
252
- await (originalOnAfterRunTest == null ? void 0 : originalOnAfterRunTest.call(testRunner, test));
253
- };
254
- return testRunner;
255
- }
256
77
  async function run(files, config, environment, executor) {
257
78
  const workerState = getWorkerState();
258
- await setupGlobalEnv(config);
79
+ await setupGlobalEnv(config, environment);
259
80
  await startCoverageInsideWorker(config.coverage, executor);
260
81
  if (config.chaiConfig)
261
82
  setupChaiConfig(config.chaiConfig);
262
- const runner = await getTestRunner(config, executor);
83
+ const runner = await resolveTestRunner(config, executor);
263
84
  workerState.onCancel.then((reason) => {
264
85
  var _a;
265
86
  return (_a = runner.onCancel) == null ? void 0 : _a.call(runner, reason);
266
87
  });
267
88
  workerState.durations.prepare = performance.now() - workerState.durations.prepare;
268
- globalThis.__vitest_environment__ = environment;
89
+ workerState.environment = environment.environment;
269
90
  workerState.durations.environment = performance.now();
270
- await withEnv(environment.name, environment.options || config.environmentOptions || {}, executor, async () => {
91
+ await withEnv(environment, environment.options || config.environmentOptions || {}, async () => {
271
92
  workerState.durations.environment = performance.now() - workerState.durations.environment;
272
93
  for (const file of files) {
273
94
  if (config.isolate) {
@@ -1,8 +1,9 @@
1
- import { E as Environment } from './types-198fd1d9.js';
1
+ import { E as Environment } from './types-3c7dbfa5.js';
2
2
  import '@vitest/snapshot';
3
3
  import '@vitest/expect';
4
4
  import 'vite';
5
5
  import '@vitest/runner';
6
+ import 'vite-node';
6
7
  import '@vitest/runner/utils';
7
8
  import '@vitest/utils';
8
9
  import 'tinybench';
@@ -10,7 +11,7 @@ import 'vite-node/client';
10
11
  import '@vitest/snapshot/manager';
11
12
  import 'vite-node/server';
12
13
  import 'node:worker_threads';
13
- import 'vite-node';
14
+ import 'rollup';
14
15
  import 'node:fs';
15
16
  import 'chai';
16
17
 
@@ -1,3 +1,5 @@
1
- export { e as builtinEnvironments, p as populateGlobal } from './vendor-environments.392ddf08.js';
2
- import 'node:console';
1
+ export { e as builtinEnvironments, p as populateGlobal } from './vendor-environments.443ecd82.js';
2
+ import 'node:url';
3
+ import 'pathe';
3
4
  import 'local-pkg';
5
+ import 'node:console';
@@ -0,0 +1,15 @@
1
+ export { V as VitestExecutor } from './vendor-execute.9ab1c1a7.js';
2
+ import 'node:url';
3
+ import 'node:vm';
4
+ import 'vite-node/client';
5
+ import 'vite-node/utils';
6
+ import 'pathe';
7
+ import '@vitest/utils/error';
8
+ import './vendor-paths.84fc7a99.js';
9
+ import './vendor-global.97e4527c.js';
10
+ import 'node:fs';
11
+ import '@vitest/utils';
12
+ import './vendor-base.9c08bbd0.js';
13
+ import 'node:path';
14
+ import 'node:module';
15
+ import 'vite-node/constants';
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
- import { File, TaskResultPack, CancelReason } from '@vitest/runner';
1
+ import { Test, File, TaskResultPack, CancelReason } from '@vitest/runner';
2
2
  export { DoneCallback, File, HookCleanupCallback, HookListener, OnTestFailedHandler, RunMode, RuntimeContext, SequenceHooks, SequenceSetupFiles, Suite, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, Task, TaskBase, TaskMeta, TaskResult, TaskResultPack, TaskState, Test, TestAPI, TestContext, TestFunction, TestOptions, afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
3
- import { v as BenchmarkAPI, m as FakeTimerInstallOpts, w as MockFactoryWithHelper, x as RuntimeConfig, A as AfterSuiteRunMeta, y as UserConsoleLog, R as ResolvedConfig, z as ModuleGraphData, D as Reporter } from './types-198fd1d9.js';
4
- export { a2 as ApiConfig, ah as ArgumentsType, ag as Arrayable, ae as Awaitable, B as BaseCoverageOptions, as as BenchFunction, aq as Benchmark, ar as BenchmarkResult, ap as BenchmarkUserOptions, _ as BuiltinEnvironment, a1 as CSSModuleScopeStrategy, K as ChaiConfig, Q as CollectLineNumbers, S as CollectLines, aj as Constructable, Y as Context, aa as ContextRPC, a9 as ContextTestEnvironment, e as CoverageC8Options, g as CoverageIstanbulOptions, C as CoverageOptions, a as CoverageProvider, b as CoverageProviderModule, ao as CoverageReporter, d as CoverageV8Options, f as CustomProviderOptions, a4 as DepsOptimizationOptions, E as Environment, a3 as EnvironmentOptions, al as EnvironmentReturn, a5 as InlineConfig, Z as JSDOMOptions, ak as ModuleCache, ai as MutableArray, af as Nullable, am as OnServerRestartHandler, n as ProjectConfig, N as RawErrsMap, an as ReportContext, ac as ResolveIdFunction, c as ResolvedCoverageOptions, X as RootAndTarget, a8 as RunnerRPC, a7 as RuntimeRPC, O as TscErrorInfo, a6 as TypecheckConfig, U as UserConfig, o as Vitest, $ as VitestEnvironment, a0 as VitestPool, V as VitestRunMode, ab as WorkerContext, ad as WorkerGlobalState, I as createExpect, G as expect, J as setupChaiConfig } from './types-198fd1d9.js';
3
+ import { h as BenchmarkAPI, F as FakeTimerInstallOpts, M as MockFactoryWithHelper, i as RuntimeConfig, A as AfterSuiteRunMeta, j as UserConsoleLog, R as ResolvedConfig, k as ModuleGraphData, l as Reporter } from './types-3c7dbfa5.js';
4
+ export { x as ApiConfig, a0 as ArgumentsType, $ as Arrayable, Z as Awaitable, B as BaseCoverageOptions, ae as BenchFunction, ac as Benchmark, ad as BenchmarkResult, ab as BenchmarkUserOptions, t as BuiltinEnvironment, w as CSSModuleScopeStrategy, o as CollectLineNumbers, p as CollectLines, a2 as Constructable, r as Context, O as ContextRPC, L as ContextTestEnvironment, a9 as CoverageIstanbulOptions, C as CoverageOptions, a as CoverageProvider, b as CoverageProviderModule, a8 as CoverageReporter, d as CoverageV8Options, aa as CustomProviderOptions, D as DepsOptimizationOptions, E as Environment, y as EnvironmentOptions, a4 as EnvironmentReturn, I as InlineConfig, J as JSDOMOptions, a3 as ModuleCache, a1 as MutableArray, _ as Nullable, a6 as OnServerRestartHandler, P as ProjectConfig, m as RawErrsMap, a7 as ReportContext, S as ResolveIdFunction, c as ResolvedCoverageOptions, N as ResolvedTestEnvironment, q as RootAndTarget, K as RunnerRPC, H as RuntimeRPC, z as TransformModePatterns, n as TscErrorInfo, G as TypecheckConfig, U as UserConfig, e as Vitest, u as VitestEnvironment, v as VitestPool, V as VitestRunMode, a5 as VmEnvironmentReturn, Q as WorkerContext, Y as WorkerGlobalState, X as WorkerRPC } from './types-3c7dbfa5.js';
5
+ import { ExpectStatic } from '@vitest/expect';
6
+ export { Assertion, AsymmetricMatchersContaining, ExpectStatic, JestAssertion } from '@vitest/expect';
5
7
  import { spyOn, fn, MaybeMockedDeep, MaybeMocked, MaybePartiallyMocked, MaybePartiallyMockedDeep, EnhancedSpy } from '@vitest/spy';
6
8
  export { EnhancedSpy, Mock, MockContext, MockInstance, Mocked, MockedClass, MockedFunction, MockedObject, SpyInstance } from '@vitest/spy';
7
9
  export { SnapshotEnvironment } from '@vitest/snapshot/environment';
8
10
  import { SnapshotResult } from '@vitest/snapshot';
9
11
  export { SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, UncheckedSnapshot } from '@vitest/snapshot';
10
- export { Assertion, AsymmetricMatchersContaining, ExpectStatic, JestAssertion } from '@vitest/expect';
11
12
  import { TransformResult } from 'vite';
12
13
  import * as chai from 'chai';
13
14
  export { chai };
@@ -15,12 +16,13 @@ export { assert, should } from 'chai';
15
16
  export { UserWorkspaceConfig } from './config.js';
16
17
  export { ErrorWithDiff, ParsedStack } from '@vitest/utils';
17
18
  export { Bench as BenchFactory, Options as BenchOptions, Task as BenchTask, TaskResult as BenchTaskResult } from 'tinybench';
19
+ import 'vite-node';
18
20
  import '@vitest/runner/utils';
19
21
  import 'vite-node/client';
20
22
  import '@vitest/snapshot/manager';
21
23
  import 'vite-node/server';
22
24
  import 'node:worker_threads';
23
- import 'vite-node';
25
+ import 'rollup';
24
26
  import 'node:fs';
25
27
 
26
28
  declare type Not<T extends boolean> = T extends true ? false : true;
@@ -202,6 +204,9 @@ declare function runOnce<T>(fn: (() => T), key?: string): T;
202
204
  */
203
205
  declare function isFirstRun(): boolean;
204
206
 
207
+ declare function createExpect(test?: Test): ExpectStatic;
208
+ declare const globalExpect: ExpectStatic;
209
+
205
210
  interface VitestUtils {
206
211
  useFakeTimers(config?: FakeTimerInstallOpts): this;
207
212
  useRealTimers(): this;
@@ -346,7 +351,7 @@ interface VitestUtils {
346
351
  declare const vitest: VitestUtils;
347
352
  declare const vi: VitestUtils;
348
353
 
349
- declare function getRunningMode(): "run" | "watch";
354
+ declare function getRunningMode(): "watch" | "run";
350
355
  declare function isWatchMode(): boolean;
351
356
 
352
357
  interface TransformResultWithSource extends TransformResult {
@@ -379,4 +384,4 @@ interface WebSocketEvents extends Pick<Reporter, 'onCollected' | 'onFinished' |
379
384
  onCancel(reason: CancelReason): void;
380
385
  }
381
386
 
382
- export { AfterSuiteRunMeta, AssertType, BenchmarkAPI, ExpectTypeOf, ModuleGraphData, Reporter, ResolvedConfig, RuntimeConfig, TransformResultWithSource, UserConsoleLog, WebSocketEvents, WebSocketHandlers, assertType, bench, expectTypeOf, getRunningMode, isFirstRun, isWatchMode, runOnce, vi, vitest };
387
+ export { AfterSuiteRunMeta, AssertType, BenchmarkAPI, ExpectTypeOf, ModuleGraphData, Reporter, ResolvedConfig, RuntimeConfig, TransformResultWithSource, UserConsoleLog, WebSocketEvents, WebSocketHandlers, assertType, bench, createExpect, globalExpect as expect, expectTypeOf, getRunningMode, isFirstRun, isWatchMode, runOnce, vi, vitest };
package/dist/index.js CHANGED
@@ -1,23 +1,24 @@
1
1
  export { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
2
- export { e as bench, c as createExpect, d as expect, s as setupChaiConfig, v as vi, f as vitest } from './vendor-vi.dd6706cb.js';
3
- export { i as isFirstRun, r as runOnce } from './vendor-run-once.1fa85ba7.js';
4
- import { d as dist } from './vendor-index.2af39fbb.js';
5
- export { b as assertType, g as getRunningMode, a as isWatchMode } from './vendor-index.2af39fbb.js';
2
+ export { e as bench, c as createExpect, d as expect, v as vi, f as vitest } from './vendor-vi.271667ef.js';
3
+ export { i as isFirstRun, r as runOnce } from './vendor-run-once.3e5ef7d7.js';
4
+ import { d as dist } from './vendor-index.eff408fd.js';
5
+ export { b as assertType, g as getRunningMode, a as isWatchMode } from './vendor-index.eff408fd.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 './vendor-index.23ac4e13.js';
11
+ import './vendor-index.087d1af7.js';
12
12
  import 'pathe';
13
13
  import 'std-env';
14
- import './vendor-global.6795f91f.js';
14
+ import './vendor-global.97e4527c.js';
15
15
  import './vendor-_commonjsHelpers.7d1333e8.js';
16
16
  import '@vitest/expect';
17
17
  import '@vitest/snapshot';
18
18
  import '@vitest/utils/error';
19
- import './vendor-tasks.f9d75aed.js';
19
+ import './vendor-source-map.e6c1997b.js';
20
20
  import 'util';
21
+ import './vendor-date.6e993429.js';
21
22
  import '@vitest/spy';
22
23
 
23
24
 
package/dist/loader.js CHANGED
@@ -10,8 +10,8 @@ import 'node:path';
10
10
  import v8 from 'node:v8';
11
11
  import { format, inspect } from 'node:util';
12
12
  import { normalizeModuleId } from 'vite-node/utils';
13
- import './vendor-index.23ac4e13.js';
14
- import { g as getWorkerState } from './vendor-global.6795f91f.js';
13
+ import './vendor-index.087d1af7.js';
14
+ import { g as getWorkerState } from './vendor-global.97e4527c.js';
15
15
  import 'std-env';
16
16
  import '@vitest/runner/utils';
17
17
  import '@vitest/utils';
@@ -568,14 +568,16 @@ function detectESM(url, source) {
568
568
  return hasESMSyntax(source) && !hasCJSSyntax(source);
569
569
  }
570
570
  const resolve = async (url, context, next) => {
571
+ var _a;
571
572
  const { parentURL } = context;
572
573
  const state = getWorkerState();
573
574
  const resolver = state == null ? void 0 : state.rpc.resolveId;
574
- if (!parentURL || isNodeBuiltin(url) || !resolver)
575
+ const environment = state == null ? void 0 : state.ctx.environment;
576
+ if (!parentURL || isNodeBuiltin(url) || !resolver || !environment)
575
577
  return next(url, context, next);
576
578
  const id = normalizeModuleId(url);
577
579
  const importer = normalizeModuleId(parentURL);
578
- const resolved = await resolver(id, importer, state.ctx.environment.name);
580
+ const resolved = await resolver(id, importer, environment.transformMode ?? ((_a = environment.environment) == null ? void 0 : _a.transformMode) ?? "ssr");
579
581
  let result;
580
582
  let filepath;
581
583
  if (resolved) {