vitest 4.0.0-beta.1 → 4.0.0-beta.11

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 (90) hide show
  1. package/LICENSE.md +83 -2
  2. package/dist/browser.d.ts +19 -16
  3. package/dist/browser.js +11 -7
  4. package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.LXhJ0F0X.js} +7 -9
  5. package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
  6. package/dist/chunks/{browser.d.q8Z0P0q1.d.ts → browser.d.Dx7DO_Ce.d.ts} +5 -5
  7. package/dist/chunks/{cac.D3EzDDZd.js → cac.elvK37c9.js} +71 -153
  8. package/dist/chunks/{cli-api.Dn5gKePv.js → cli-api.C7plPyhs.js} +1376 -1693
  9. package/dist/chunks/{config.d.HJdfX-8k.d.ts → config.d.B_LthbQq.d.ts} +58 -63
  10. package/dist/chunks/{console.CtFJOzRO.js → console.CiTi59Jy.js} +35 -71
  11. package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
  12. package/dist/chunks/{coverage.Cwa-XhJt.js → coverage.CG6Uhorw.js} +522 -792
  13. package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
  14. package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
  15. package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
  16. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  17. package/dist/chunks/{environment.d.CUq4cUgQ.d.ts → environment.d.BsToaxti.d.ts} +27 -6
  18. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  19. package/dist/chunks/{global.d.CVbXEflG.d.ts → global.d.BK3X7FW1.d.ts} +2 -5
  20. package/dist/chunks/{globals.Cxal6MLI.js → globals.BjvYA-AD.js} +11 -9
  21. package/dist/chunks/{index.BWf_gE5n.js → index.AZOjjqWP.js} +7 -6
  22. package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
  23. package/dist/chunks/{index.TfbsX-3I.js → index.BhY64fF0.js} +16 -26
  24. package/dist/chunks/{index.CZI_8rVt.js → index.BwBttQPf.js} +340 -663
  25. package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
  26. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  27. package/dist/chunks/moduleRunner.d.BNa-CL9e.d.ts +201 -0
  28. package/dist/chunks/{node.fjCdwEIl.js → node.BsdMi6DV.js} +2 -2
  29. package/dist/chunks/{plugin.d.C2EcJUjo.d.ts → plugin.d.C5phQR6o.d.ts} +1 -1
  30. package/dist/chunks/{reporters.d.DxZg19fy.d.ts → reporters.d.CVzhsTvK.d.ts} +1233 -1293
  31. package/dist/chunks/resolveSnapshotEnvironment.DQVamkje.js +81 -0
  32. package/dist/chunks/rpc.jKGRSXIH.js +65 -0
  33. package/dist/chunks/{setup-common.D7ZqXFx-.js → setup-common.NAWRuMRP.js} +18 -30
  34. package/dist/chunks/startModuleRunner.oAuCu1yL.js +682 -0
  35. package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
  36. package/dist/chunks/test.KC5tH8hC.js +214 -0
  37. package/dist/chunks/typechecker.gXq-5P3n.js +1438 -0
  38. package/dist/chunks/{utils.XdZDrNZV.js → utils.DGKhod2J.js} +9 -28
  39. package/dist/chunks/{vi.bdSIJ99Y.js → vi.CiJ0Laa6.js} +159 -306
  40. package/dist/chunks/worker.d.B_Fd9M_w.d.ts +100 -0
  41. package/dist/chunks/worker.rPGLlbkW.js +200 -0
  42. package/dist/cli.js +8 -6
  43. package/dist/config.cjs +3 -9
  44. package/dist/config.d.ts +49 -54
  45. package/dist/config.js +1 -1
  46. package/dist/coverage.d.ts +27 -26
  47. package/dist/coverage.js +6 -8
  48. package/dist/environments.d.ts +9 -13
  49. package/dist/environments.js +1 -1
  50. package/dist/index.d.ts +38 -45
  51. package/dist/index.js +10 -10
  52. package/dist/module-evaluator.d.ts +13 -0
  53. package/dist/module-evaluator.js +276 -0
  54. package/dist/module-runner.js +15 -0
  55. package/dist/node.d.ts +44 -42
  56. package/dist/node.js +30 -36
  57. package/dist/reporters.d.ts +12 -13
  58. package/dist/reporters.js +7 -5
  59. package/dist/runners.d.ts +3 -3
  60. package/dist/runners.js +15 -232
  61. package/dist/snapshot.js +3 -3
  62. package/dist/suite.d.ts +2 -2
  63. package/dist/suite.js +4 -3
  64. package/dist/worker-base.js +203 -0
  65. package/dist/{chunks/vm.BThCzidc.js → worker-vm.js} +179 -228
  66. package/dist/workers/runVmTests.js +39 -56
  67. package/globals.d.ts +17 -17
  68. package/package.json +40 -38
  69. package/browser.d.ts +0 -1
  70. package/dist/chunks/base.Bj3pWTr1.js +0 -38
  71. package/dist/chunks/execute.B7h3T_Hc.js +0 -708
  72. package/dist/chunks/index.D-VkfKhf.js +0 -105
  73. package/dist/chunks/rpc.CsFtxqeq.js +0 -83
  74. package/dist/chunks/runBaseTests.BC7ZIH5L.js +0 -129
  75. package/dist/chunks/typechecker.CVytUJuF.js +0 -874
  76. package/dist/chunks/utils.CAioKnHs.js +0 -61
  77. package/dist/chunks/worker.d.CmvJfRGs.d.ts +0 -8
  78. package/dist/chunks/worker.d.DoNjFAiv.d.ts +0 -169
  79. package/dist/execute.d.ts +0 -148
  80. package/dist/execute.js +0 -13
  81. package/dist/worker.js +0 -124
  82. package/dist/workers/forks.js +0 -43
  83. package/dist/workers/threads.js +0 -31
  84. package/dist/workers/vmForks.js +0 -47
  85. package/dist/workers/vmThreads.js +0 -37
  86. package/dist/workers.d.ts +0 -37
  87. package/dist/workers.js +0 -30
  88. package/execute.d.ts +0 -1
  89. package/utils.d.ts +0 -1
  90. package/workers.d.ts +0 -1
@@ -93,73 +93,67 @@ interface SerializedConfig {
93
93
  restoreMocks: boolean;
94
94
  unstubGlobals: boolean;
95
95
  unstubEnvs: boolean;
96
- // TODO: make optional
97
96
  fakeTimers: FakeTimerInstallOpts;
98
97
  maxConcurrency: number;
99
98
  defines: Record<string, any>;
100
99
  expect: {
101
- requireAssertions?: boolean
100
+ requireAssertions?: boolean;
102
101
  poll?: {
103
- timeout?: number
104
- interval?: number
105
- }
102
+ timeout?: number;
103
+ interval?: number;
104
+ };
106
105
  };
107
106
  printConsoleTrace: boolean | undefined;
108
107
  sequence: {
109
- shuffle?: boolean
110
- concurrent?: boolean
111
- seed: number
112
- hooks: SequenceHooks
113
- setupFiles: SequenceSetupFiles
108
+ shuffle?: boolean;
109
+ concurrent?: boolean;
110
+ seed: number;
111
+ hooks: SequenceHooks;
112
+ setupFiles: SequenceSetupFiles;
114
113
  };
115
114
  poolOptions: {
116
115
  forks: {
117
- singleFork: boolean
118
- isolate: boolean
119
- }
116
+ singleFork: boolean;
117
+ isolate: boolean;
118
+ };
120
119
  threads: {
121
- singleThread: boolean
122
- isolate: boolean
123
- }
120
+ singleThread: boolean;
121
+ isolate: boolean;
122
+ };
124
123
  vmThreads: {
125
- singleThread: boolean
126
- }
124
+ singleThread: boolean;
125
+ };
127
126
  vmForks: {
128
- singleFork: boolean
129
- }
127
+ singleFork: boolean;
128
+ };
130
129
  };
131
130
  deps: {
132
131
  web: {
133
- transformAssets?: boolean
134
- transformCss?: boolean
135
- transformGlobPattern?: RegExp | RegExp[]
136
- }
137
- optimizer: {
138
- web: {
139
- enabled: boolean
140
- }
141
- ssr: {
142
- enabled: boolean
143
- }
144
- }
145
- interopDefault: boolean | undefined
146
- moduleDirectories: string[] | undefined
132
+ transformAssets?: boolean;
133
+ transformCss?: boolean;
134
+ transformGlobPattern?: RegExp | RegExp[];
135
+ };
136
+ optimizer: Record<string, {
137
+ enabled: boolean;
138
+ }>;
139
+ interopDefault: boolean | undefined;
140
+ moduleDirectories: string[] | undefined;
147
141
  };
148
142
  snapshotOptions: {
149
- updateSnapshot: SnapshotUpdateState
150
- expand: boolean | undefined
151
- snapshotFormat: PrettyFormatOptions | undefined
143
+ updateSnapshot: SnapshotUpdateState;
144
+ expand: boolean | undefined;
145
+ snapshotFormat: PrettyFormatOptions | undefined;
152
146
  /**
153
147
  * only exists for tests, not available in the main process
154
148
  */
155
- snapshotEnvironment: SnapshotEnvironment
149
+ snapshotEnvironment: SnapshotEnvironment;
156
150
  };
157
151
  pool: string;
158
152
  snapshotSerializers: string[];
159
153
  chaiConfig: {
160
- includeStack?: boolean
161
- showDiff?: boolean
162
- truncateThreshold?: number
154
+ includeStack?: boolean;
155
+ showDiff?: boolean;
156
+ truncateThreshold?: number;
163
157
  } | undefined;
164
158
  diff: string | SerializedDiffOptions | undefined;
165
159
  retry: number;
@@ -167,52 +161,53 @@ interface SerializedConfig {
167
161
  inspect: boolean | string | undefined;
168
162
  inspectBrk: boolean | string | undefined;
169
163
  inspector: {
170
- enabled?: boolean
171
- port?: number
172
- host?: string
173
- waitForDebugger?: boolean
164
+ enabled?: boolean;
165
+ port?: number;
166
+ host?: string;
167
+ waitForDebugger?: boolean;
174
168
  };
175
169
  watch: boolean;
176
170
  env: Record<string, any>;
177
171
  browser: {
178
- name: string
179
- headless: boolean
180
- isolate: boolean
181
- fileParallelism: boolean
182
- ui: boolean
172
+ name: string;
173
+ headless: boolean;
174
+ isolate: boolean;
175
+ fileParallelism: boolean;
176
+ ui: boolean;
183
177
  viewport: {
184
- width: number
185
- height: number
186
- }
178
+ width: number;
179
+ height: number;
180
+ };
187
181
  locators: {
188
- testIdAttribute: string
189
- }
190
- screenshotFailures: boolean
182
+ testIdAttribute: string;
183
+ };
184
+ screenshotFailures: boolean;
191
185
  providerOptions: {
192
- // for playwright
193
- actionTimeout?: number
194
- }
186
+ actionTimeout?: number;
187
+ };
188
+ trackUnhandledErrors: boolean;
195
189
  };
196
190
  standalone: boolean;
197
191
  logHeapUsage: boolean | undefined;
198
192
  coverage: SerializedCoverageConfig;
199
193
  benchmark: {
200
- includeSamples: boolean
194
+ includeSamples: boolean;
201
195
  } | undefined;
196
+ serializedDefines: string;
202
197
  }
203
198
  interface SerializedCoverageConfig {
204
199
  provider: "istanbul" | "v8" | "custom" | undefined;
205
200
  reportsDirectory: string;
206
201
  htmlReporter: {
207
- subdir: string | undefined
202
+ subdir: string | undefined;
208
203
  } | undefined;
209
204
  enabled: boolean;
210
205
  customProviderModule: string | undefined;
211
206
  }
212
207
  type RuntimeConfig = Pick<SerializedConfig, "allowOnly" | "testTimeout" | "hookTimeout" | "clearMocks" | "mockReset" | "restoreMocks" | "fakeTimers" | "maxConcurrency" | "expect" | "printConsoleTrace"> & {
213
208
  sequence?: {
214
- hooks?: SequenceHooks
215
- }
209
+ hooks?: SequenceHooks;
210
+ };
216
211
  };
217
212
  type RuntimeOptions = Partial<RuntimeConfig>;
218
213
 
@@ -1,50 +1,37 @@
1
1
  import { Console } from 'node:console';
2
2
  import { relative } from 'node:path';
3
3
  import { Writable } from 'node:stream';
4
- import { getSafeTimers } from '@vitest/utils';
4
+ import { getSafeTimers } from '@vitest/utils/timers';
5
5
  import c from 'tinyrainbow';
6
- import { R as RealDate } from './date.Bq6ZW5rf.js';
7
- import { g as getWorkerState } from './utils.XdZDrNZV.js';
6
+ import { R as RealDate } from './date.-jtEtIeV.js';
7
+ import { g as getWorkerState } from './utils.DGKhod2J.js';
8
8
 
9
9
  const UNKNOWN_TEST_ID = "__vitest__unknown_test__";
10
10
  function getTaskIdByStack(root) {
11
- const stack = new Error("STACK_TRACE_ERROR").stack?.split("\n");
11
+ const stack = (/* @__PURE__ */ new Error("STACK_TRACE_ERROR")).stack?.split("\n");
12
12
  if (!stack) return UNKNOWN_TEST_ID;
13
- const index = stack.findIndex((line) => line.includes("at Console.value"));
14
- const line = index === -1 ? null : stack[index + 2];
13
+ const index = stack.findIndex((line) => line.includes("at Console.value")), line = index === -1 ? null : stack[index + 2];
15
14
  if (!line) return UNKNOWN_TEST_ID;
16
15
  const filepath = line.match(/at\s(.*)\s?/)?.[1];
17
- if (filepath) return relative(root, filepath);
18
- return UNKNOWN_TEST_ID;
16
+ return filepath ? relative(root, filepath) : UNKNOWN_TEST_ID;
19
17
  }
20
18
  function createCustomConsole(defaultState) {
21
- const stdoutBuffer = /* @__PURE__ */ new Map();
22
- const stderrBuffer = /* @__PURE__ */ new Map();
23
- const timers = /* @__PURE__ */ new Map();
24
- const { queueMicrotask } = getSafeTimers();
19
+ const stdoutBuffer = /* @__PURE__ */ new Map(), stderrBuffer = /* @__PURE__ */ new Map(), timers = /* @__PURE__ */ new Map(), { queueMicrotask } = getSafeTimers();
25
20
  function queueCancelableMicrotask(callback) {
26
21
  let canceled = false;
27
- queueMicrotask(() => {
22
+ return queueMicrotask(() => {
28
23
  if (!canceled) callback();
29
- });
30
- return () => {
24
+ }), () => {
31
25
  canceled = true;
32
26
  };
33
27
  }
34
28
  const state = () => defaultState || getWorkerState();
35
29
  // group sync console.log calls with micro task
36
30
  function schedule(taskId) {
37
- const timer = timers.get(taskId);
38
- const { stdoutTime, stderrTime } = timer;
39
- timer.cancel?.();
40
- timer.cancel = queueCancelableMicrotask(() => {
41
- if (stderrTime < stdoutTime) {
42
- sendStderr(taskId);
43
- sendStdout(taskId);
44
- } else {
45
- sendStdout(taskId);
46
- sendStderr(taskId);
47
- }
31
+ const timer = timers.get(taskId), { stdoutTime, stderrTime } = timer;
32
+ timer.cancel?.(), timer.cancel = queueCancelableMicrotask(() => {
33
+ if (stderrTime < stdoutTime) sendStderr(taskId), sendStdout(taskId);
34
+ else sendStdout(taskId), sendStderr(taskId);
48
35
  });
49
36
  }
50
37
  function sendStdout(taskId) {
@@ -54,8 +41,7 @@ function createCustomConsole(defaultState) {
54
41
  sendBuffer("stderr", taskId);
55
42
  }
56
43
  function sendBuffer(type, taskId) {
57
- const buffers = type === "stdout" ? stdoutBuffer : stderrBuffer;
58
- const buffer = buffers.get(taskId);
44
+ const buffers = type === "stdout" ? stdoutBuffer : stderrBuffer, buffer = buffers.get(taskId);
59
45
  if (!buffer) return;
60
46
  if (state().config.printConsoleTrace) buffer.forEach(([buffer, origin]) => {
61
47
  sendLog(type, taskId, String(buffer), buffer.length, origin);
@@ -65,13 +51,11 @@ function createCustomConsole(defaultState) {
65
51
  sendLog(type, taskId, content, buffer.length);
66
52
  }
67
53
  const timer = timers.get(taskId);
68
- buffers.delete(taskId);
69
- if (type === "stderr") timer.stderrTime = 0;
54
+ if (buffers.delete(taskId), type === "stderr") timer.stderrTime = 0;
70
55
  else timer.stdoutTime = 0;
71
56
  }
72
57
  function sendLog(type, taskId, content, size, origin) {
73
- const timer = timers.get(taskId);
74
- const time = type === "stderr" ? timer.stderrTime : timer.stdoutTime;
58
+ const timer = timers.get(taskId), time = type === "stderr" ? timer.stderrTime : timer.stdoutTime;
75
59
  state().rpc.onUserConsoleLog({
76
60
  type,
77
61
  content: content || "<empty line>",
@@ -82,65 +66,45 @@ function createCustomConsole(defaultState) {
82
66
  });
83
67
  }
84
68
  const stdout = new Writable({ write(data, encoding, callback) {
85
- const s = state();
86
- const id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
69
+ const s = state(), id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
87
70
  let timer = timers.get(id);
88
71
  if (timer) timer.stdoutTime = timer.stdoutTime || RealDate.now();
89
- else {
90
- timer = {
91
- stdoutTime: RealDate.now(),
92
- stderrTime: RealDate.now()
93
- };
94
- timers.set(id, timer);
95
- }
72
+ else timer = {
73
+ stdoutTime: RealDate.now(),
74
+ stderrTime: RealDate.now()
75
+ }, timers.set(id, timer);
96
76
  let buffer = stdoutBuffer.get(id);
97
- if (!buffer) {
98
- buffer = [];
99
- stdoutBuffer.set(id, buffer);
100
- }
77
+ if (!buffer) buffer = [], stdoutBuffer.set(id, buffer);
101
78
  if (state().config.printConsoleTrace) {
102
79
  const limit = Error.stackTraceLimit;
103
80
  Error.stackTraceLimit = limit + 6;
104
- const stack = new Error("STACK_TRACE").stack;
105
- const trace = stack?.split("\n").slice(7).join("\n");
106
- Error.stackTraceLimit = limit;
107
- buffer.push([data, trace]);
81
+ const stack = (/* @__PURE__ */ new Error("STACK_TRACE")).stack, trace = stack?.split("\n").slice(7).join("\n");
82
+ Error.stackTraceLimit = limit, buffer.push([data, trace]);
108
83
  } else buffer.push([data, void 0]);
109
- schedule(id);
110
- callback();
111
- } });
112
- const stderr = new Writable({ write(data, encoding, callback) {
113
- const s = state();
114
- const id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
84
+ schedule(id), callback();
85
+ } }), stderr = new Writable({ write(data, encoding, callback) {
86
+ const s = state(), id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
115
87
  let timer = timers.get(id);
116
88
  if (timer) timer.stderrTime = timer.stderrTime || RealDate.now();
117
- else {
118
- timer = {
119
- stderrTime: RealDate.now(),
120
- stdoutTime: RealDate.now()
121
- };
122
- timers.set(id, timer);
123
- }
89
+ else timer = {
90
+ stderrTime: RealDate.now(),
91
+ stdoutTime: RealDate.now()
92
+ }, timers.set(id, timer);
124
93
  let buffer = stderrBuffer.get(id);
125
- if (!buffer) {
126
- buffer = [];
127
- stderrBuffer.set(id, buffer);
128
- }
94
+ if (!buffer) buffer = [], stderrBuffer.set(id, buffer);
129
95
  if (state().config.printConsoleTrace) {
130
96
  const limit = Error.stackTraceLimit;
131
97
  Error.stackTraceLimit = limit + 6;
132
- const stack = new Error("STACK_TRACE").stack?.split("\n");
98
+ const stack = (/* @__PURE__ */ new Error("STACK_TRACE")).stack?.split("\n");
133
99
  Error.stackTraceLimit = limit;
134
100
  const isTrace = stack?.some((line) => line.includes("at Console.trace"));
135
101
  if (isTrace) buffer.push([data, void 0]);
136
102
  else {
137
103
  const trace = stack?.slice(7).join("\n");
138
- Error.stackTraceLimit = limit;
139
- buffer.push([data, trace]);
104
+ Error.stackTraceLimit = limit, buffer.push([data, trace]);
140
105
  }
141
106
  } else buffer.push([data, void 0]);
142
- schedule(id);
143
- callback();
107
+ schedule(id), callback();
144
108
  } });
145
109
  return new Console({
146
110
  stdout,
@@ -3,13 +3,7 @@ const defaultPort = 51204;
3
3
  const defaultBrowserPort = 63315;
4
4
  const defaultInspectPort = 9229;
5
5
  const API_PATH = "/__vitest_api__";
6
- const extraInlineDeps = [
7
- /^(?!.*node_modules).*\.mjs$/,
8
- /^(?!.*node_modules).*\.cjs\.js$/,
9
- /vite\w*\/dist\/client\/env.mjs/
10
- ];
11
6
  const CONFIG_NAMES = ["vitest.config", "vite.config"];
12
- const WORKSPACES_NAMES = ["vitest.workspace", "vitest.projects"];
13
7
  const CONFIG_EXTENSIONS = [
14
8
  ".ts",
15
9
  ".mts",
@@ -19,8 +13,6 @@ const CONFIG_EXTENSIONS = [
19
13
  ".cjs"
20
14
  ];
21
15
  const configFiles = CONFIG_NAMES.flatMap((name) => CONFIG_EXTENSIONS.map((ext) => name + ext));
22
- const WORKSPACES_EXTENSIONS = [...CONFIG_EXTENSIONS, ".json"];
23
- const workspacesFiles = WORKSPACES_NAMES.flatMap((name) => WORKSPACES_EXTENSIONS.map((ext) => name + ext));
24
16
  const globalApis = [
25
17
  "suite",
26
18
  "test",
@@ -41,4 +33,4 @@ const globalApis = [
41
33
  "onTestFailed"
42
34
  ];
43
35
 
44
- export { API_PATH as A, defaultPort as a, defaultInspectPort as b, configFiles as c, defaultBrowserPort as d, extraInlineDeps as e, globalApis as g, workspacesFiles as w };
36
+ export { API_PATH as A, defaultPort as a, defaultInspectPort as b, configFiles as c, defaultBrowserPort as d, globalApis as g };