vitest 3.2.0-beta.3 → 3.2.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 (65) hide show
  1. package/LICENSE.md +29 -0
  2. package/dist/browser.d.ts +1 -1
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/{base.D4119yLM.js → base.Cg0miDlQ.js} +10 -14
  5. package/dist/chunks/{benchmark.Cf_PACH1.js → benchmark.CYdenmiT.js} +4 -6
  6. package/dist/chunks/{cac.DWaWHIIE.js → cac.6rXCxFY1.js} +66 -136
  7. package/dist/chunks/{cli-api.CnmEXkxs.js → cli-api.Cej3MBjA.js} +1250 -1335
  8. package/dist/chunks/{console.Cwr-MFPV.js → console.CtFJOzRO.js} +24 -45
  9. package/dist/chunks/{coverage.0iPg4Wrz.js → coverage.DVF1vEu8.js} +4 -12
  10. package/dist/chunks/{coverage.C73DaDgS.js → coverage.EIiagJJP.js} +484 -1003
  11. package/dist/chunks/{creator.C8WKy2eW.js → creator.GK6I-cL4.js} +29 -76
  12. package/dist/chunks/{date.ByMsSlOr.js → date.Bq6ZW5rf.js} +3 -8
  13. package/dist/chunks/{defaults.DpVH7vbg.js → defaults.B7q_naMc.js} +1 -1
  14. package/dist/chunks/{env.Dq0hM4Xv.js → env.D4Lgay0q.js} +1 -1
  15. package/dist/chunks/{execute.B3q-2LPV.js → execute.B7h3T_Hc.js} +104 -220
  16. package/dist/chunks/{git.DXfdBEfR.js → git.BVQ8w_Sw.js} +1 -3
  17. package/dist/chunks/{global.d.BNLIi6yo.d.ts → global.d.MAmajcmJ.d.ts} +2 -0
  18. package/dist/chunks/{globals.CI21aWXF.js → globals.DEHgCU4V.js} +5 -5
  19. package/dist/chunks/{index.Bter3jj9.js → index.BZ0g1JD2.js} +366 -628
  20. package/dist/chunks/{index.CbT4iuwc.js → index.BbB8_kAK.js} +22 -24
  21. package/dist/chunks/{index.JOzufsrU.js → index.CIyJn3t1.js} +37 -82
  22. package/dist/chunks/{index.DNgLEKsQ.js → index.CdQS2e2Q.js} +2 -2
  23. package/dist/chunks/{index.2jgTs_Q5.js → index.CmSc2RE5.js} +69 -107
  24. package/dist/chunks/{inspector.BFsh5KO0.js → inspector.C914Efll.js} +1 -1
  25. package/dist/chunks/{node.Be-ntJnD.js → node.fjCdwEIl.js} +1 -1
  26. package/dist/chunks/{reporters.d.Bt4IGtsa.d.ts → reporters.d.C1ogPriE.d.ts} +24 -4
  27. package/dist/chunks/{rpc.BKExFSRG.js → rpc.Iovn4oWe.js} +9 -19
  28. package/dist/chunks/{runBaseTests.B_M1TTsK.js → runBaseTests.Dd85QTll.js} +18 -31
  29. package/dist/chunks/{setup-common.CF-O-dZX.js → setup-common.Dd054P77.js} +15 -42
  30. package/dist/chunks/{typechecker.BgzF-6iO.js → typechecker.DRKU1-1g.js} +106 -186
  31. package/dist/chunks/{utils.DPCq3gzW.js → utils.CAioKnHs.js} +6 -14
  32. package/dist/chunks/{utils.BlI4TC7Y.js → utils.XdZDrNZV.js} +5 -13
  33. package/dist/chunks/{vi.pkoYCV6A.js → vi.bdSIJ99Y.js} +118 -267
  34. package/dist/chunks/{vite.d.B-Kx3KCF.d.ts → vite.d.DqE4-hhK.d.ts} +1 -1
  35. package/dist/chunks/{vm.DPYem2so.js → vm.BThCzidc.js} +98 -214
  36. package/dist/chunks/{worker.d.Bl1O4kuf.d.ts → worker.d.DvqK5Vmu.d.ts} +1 -1
  37. package/dist/chunks/{worker.d.BKbBp2ga.d.ts → worker.d.tQu2eJQy.d.ts} +3 -1
  38. package/dist/cli.js +4 -4
  39. package/dist/config.cjs +1 -1
  40. package/dist/config.d.ts +4 -4
  41. package/dist/config.js +2 -2
  42. package/dist/coverage.d.ts +2 -2
  43. package/dist/coverage.js +5 -5
  44. package/dist/environments.js +1 -1
  45. package/dist/execute.d.ts +1 -1
  46. package/dist/execute.js +1 -1
  47. package/dist/index.d.ts +11 -10
  48. package/dist/index.js +5 -5
  49. package/dist/node.d.ts +7 -7
  50. package/dist/node.js +12 -14
  51. package/dist/reporters.d.ts +2 -2
  52. package/dist/reporters.js +4 -4
  53. package/dist/runners.d.ts +5 -2
  54. package/dist/runners.js +51 -80
  55. package/dist/snapshot.js +2 -2
  56. package/dist/suite.js +2 -2
  57. package/dist/worker.js +36 -42
  58. package/dist/workers/forks.js +4 -4
  59. package/dist/workers/runVmTests.js +15 -21
  60. package/dist/workers/threads.js +4 -4
  61. package/dist/workers/vmForks.js +6 -6
  62. package/dist/workers/vmThreads.js +6 -6
  63. package/dist/workers.d.ts +2 -2
  64. package/dist/workers.js +10 -10
  65. package/package.json +16 -14
@@ -1,9 +1,9 @@
1
1
  import * as chai from 'chai';
2
2
  import { resolve } from 'node:path';
3
- import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.CF-O-dZX.js';
3
+ import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.Dd054P77.js';
4
4
  import { distDir } from '../path.js';
5
- import { r as rpc } from './rpc.BKExFSRG.js';
6
- import { g as getWorkerState } from './utils.BlI4TC7Y.js';
5
+ import { r as rpc } from './rpc.Iovn4oWe.js';
6
+ import { g as getWorkerState } from './utils.XdZDrNZV.js';
7
7
 
8
8
  function setupChaiConfig(config) {
9
9
  Object.assign(chai.config, config);
@@ -11,13 +11,11 @@ function setupChaiConfig(config) {
11
11
 
12
12
  async function resolveSnapshotEnvironment(config, executor) {
13
13
  if (!config.snapshotEnvironment) {
14
- const { VitestNodeSnapshotEnvironment } = await import('./node.Be-ntJnD.js');
14
+ const { VitestNodeSnapshotEnvironment } = await import('./node.fjCdwEIl.js');
15
15
  return new VitestNodeSnapshotEnvironment();
16
16
  }
17
17
  const mod = await executor.executeId(config.snapshotEnvironment);
18
- if (typeof mod.default !== "object" || !mod.default) {
19
- throw new Error("Snapshot environment module must have a default export object with a shape of `SnapshotEnvironment`");
20
- }
18
+ if (typeof mod.default !== "object" || !mod.default) throw new Error("Snapshot environment module must have a default export object with a shape of `SnapshotEnvironment`");
21
19
  return mod.default;
22
20
  }
23
21
 
@@ -28,9 +26,7 @@ async function getTestRunnerConstructor(config, executor) {
28
26
  return config.mode === "test" ? VitestTestRunner : NodeBenchmarkRunner;
29
27
  }
30
28
  const mod = await executor.executeId(config.runner);
31
- if (!mod.default && typeof mod.default !== "function") {
32
- throw new Error(`Runner must export a default function, but got ${typeof mod.default} imported from ${config.runner}`);
33
- }
29
+ if (!mod.default && typeof mod.default !== "function") throw new Error(`Runner must export a default function, but got ${typeof mod.default} imported from ${config.runner}`);
34
30
  return mod.default;
35
31
  }
36
32
  async function resolveTestRunner(config, executor) {
@@ -42,12 +38,8 @@ async function resolveTestRunner(config, executor) {
42
38
  enumerable: false,
43
39
  configurable: false
44
40
  });
45
- if (!testRunner.config) {
46
- testRunner.config = config;
47
- }
48
- if (!testRunner.importFile) {
49
- throw new Error("Runner must implement \"importFile\" method.");
50
- }
41
+ if (!testRunner.config) testRunner.config = config;
42
+ if (!testRunner.importFile) throw new Error("Runner must implement \"importFile\" method.");
51
43
  const [diffOptions] = await Promise.all([loadDiffConfig(config, executor), loadSnapshotSerializers(config, executor)]);
52
44
  testRunner.config.diffOptions = diffOptions;
53
45
  // patch some methods, so custom runners don't need to call RPC
@@ -57,6 +49,14 @@ async function resolveTestRunner(config, executor) {
57
49
  await originalOnTaskUpdate?.call(testRunner, task, events);
58
50
  return p;
59
51
  };
52
+ // patch some methods, so custom runners don't need to call RPC
53
+ const originalOnTestAnnotate = testRunner.onTestAnnotate;
54
+ testRunner.onTestAnnotate = async (test, annotation) => {
55
+ const p = rpc().onTaskAnnotate(test.id, annotation);
56
+ const overridenResult = await originalOnTestAnnotate?.call(testRunner, test, annotation);
57
+ const vitestResult = await p;
58
+ return overridenResult || vitestResult;
59
+ };
60
60
  const originalOnCollectStart = testRunner.onCollectStart;
61
61
  testRunner.onCollectStart = async (file) => {
62
62
  await rpc().onQueued(file);
@@ -79,14 +79,12 @@ async function resolveTestRunner(config, executor) {
79
79
  testRunner.onAfterRunFiles = async (files) => {
80
80
  const state = getWorkerState();
81
81
  const coverage = await takeCoverageInsideWorker(config.coverage, executor);
82
- if (coverage) {
83
- rpc().onAfterSuiteRun({
84
- coverage,
85
- testFiles: files.map((file) => file.name).sort(),
86
- transformMode: state.environment.transformMode,
87
- projectName: state.ctx.projectName
88
- });
89
- }
82
+ if (coverage) rpc().onAfterSuiteRun({
83
+ coverage,
84
+ testFiles: files.map((file) => file.name).sort(),
85
+ transformMode: state.environment.transformMode,
86
+ projectName: state.ctx.projectName
87
+ });
90
88
  await originalOnAfterRun?.call(testRunner, files);
91
89
  };
92
90
  const originalOnAfterRunTask = testRunner.onAfterRunTask;
@@ -2,7 +2,7 @@ import fs from 'node:fs';
2
2
  import { getTasks, getFullName, getTests } from '@vitest/runner/utils';
3
3
  import * as pathe from 'pathe';
4
4
  import c from 'tinyrainbow';
5
- import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName } from './index.Bter3jj9.js';
5
+ import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName } from './index.BZ0g1JD2.js';
6
6
  import { stripVTControlCharacters } from 'node:util';
7
7
  import { notNullish } from '@vitest/utils';
8
8
 
@@ -10,26 +10,20 @@ function createBenchmarkJsonReport(files) {
10
10
  const report = { files: [] };
11
11
  for (const file of files) {
12
12
  const groups = [];
13
- for (const task of getTasks(file)) {
14
- if (task?.type === "suite") {
15
- const benchmarks = [];
16
- for (const t of task.tasks) {
17
- const benchmark = t.meta.benchmark && t.result?.benchmark;
18
- if (benchmark) {
19
- benchmarks.push({
20
- id: t.id,
21
- ...benchmark,
22
- samples: []
23
- });
24
- }
25
- }
26
- if (benchmarks.length) {
27
- groups.push({
28
- fullName: getFullName(task, " > "),
29
- benchmarks
30
- });
31
- }
13
+ for (const task of getTasks(file)) if (task?.type === "suite") {
14
+ const benchmarks = [];
15
+ for (const t of task.tasks) {
16
+ const benchmark = t.meta.benchmark && t.result?.benchmark;
17
+ if (benchmark) benchmarks.push({
18
+ id: t.id,
19
+ ...benchmark,
20
+ samples: []
21
+ });
32
22
  }
23
+ if (benchmarks.length) groups.push({
24
+ fullName: getFullName(task, " > "),
25
+ benchmarks
26
+ });
33
27
  }
34
28
  report.files.push({
35
29
  filepath: file.filepath,
@@ -40,17 +34,11 @@ function createBenchmarkJsonReport(files) {
40
34
  }
41
35
  function flattenFormattedBenchmarkReport(report) {
42
36
  const flat = {};
43
- for (const file of report.files) {
44
- for (const group of file.groups) {
45
- for (const t of group.benchmarks) {
46
- flat[t.id] = t;
47
- }
48
- }
49
- }
37
+ for (const file of report.files) for (const group of file.groups) for (const t of group.benchmarks) flat[t.id] = t;
50
38
  return flat;
51
39
  }
52
40
 
53
- const outputMap = new WeakMap();
41
+ const outputMap = /* @__PURE__ */ new WeakMap();
54
42
  function formatNumber(number) {
55
43
  const res = String(number.toFixed(number < 100 ? 4 : 2)).split(".");
56
44
  return res[0].replace(/(?=(?:\d{3})+$)\B/g, ",") + (res[1] ? `.${res[1]}` : "");
@@ -112,14 +100,10 @@ function renderBenchmark(result, widths) {
112
100
  function renderTable(options) {
113
101
  const output = [];
114
102
  const benchMap = {};
115
- for (const task of options.tasks) {
116
- if (task.meta.benchmark && task.result?.benchmark) {
117
- benchMap[task.id] = {
118
- current: task.result.benchmark,
119
- baseline: options.compare?.[task.id]
120
- };
121
- }
122
- }
103
+ for (const task of options.tasks) if (task.meta.benchmark && task.result?.benchmark) benchMap[task.id] = {
104
+ current: task.result.benchmark,
105
+ baseline: options.compare?.[task.id]
106
+ };
123
107
  const benchCount = Object.entries(benchMap).length;
124
108
  const columnWidths = computeColumnWidths(Object.values(benchMap).flatMap((v) => [v.current, v.baseline]).filter(notNullish));
125
109
  let idx = 0;
@@ -128,61 +112,40 @@ function renderTable(options) {
128
112
  const duration = task.result?.duration;
129
113
  const bench = benchMap[task.id];
130
114
  let prefix = "";
131
- if (idx === 0 && task.meta?.benchmark) {
132
- prefix += `${renderTableHead(columnWidths)}\n${padding}`;
133
- }
115
+ if (idx === 0 && task.meta?.benchmark) prefix += `${renderTableHead(columnWidths)}\n${padding}`;
134
116
  prefix += ` ${getStateSymbol(task)} `;
135
117
  let suffix = "";
136
- if (task.type === "suite") {
137
- suffix += c.dim(` (${getTests(task).length})`);
138
- }
139
- if (task.mode === "skip" || task.mode === "todo") {
140
- suffix += c.dim(c.gray(" [skipped]"));
141
- }
118
+ if (task.type === "suite") suffix += c.dim(` (${getTests(task).length})`);
119
+ if (task.mode === "skip" || task.mode === "todo") suffix += c.dim(c.gray(" [skipped]"));
142
120
  if (duration != null) {
143
121
  const color = duration > options.slowTestThreshold ? c.yellow : c.green;
144
122
  suffix += color(` ${Math.round(duration)}${c.dim("ms")}`);
145
123
  }
146
- if (options.showHeap && task.result?.heap != null) {
147
- suffix += c.magenta(` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`);
148
- }
124
+ if (options.showHeap && task.result?.heap != null) suffix += c.magenta(` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`);
149
125
  if (bench) {
150
126
  let body = renderBenchmark(bench.current, columnWidths);
151
127
  if (options.compare && bench.baseline) {
152
128
  if (bench.current.hz) {
153
129
  const diff = bench.current.hz / bench.baseline.hz;
154
130
  const diffFixed = diff.toFixed(2);
155
- if (diffFixed === "1.0.0") {
156
- body += c.gray(` [${diffFixed}x]`);
157
- }
158
- if (diff > 1) {
159
- body += c.blue(` [${diffFixed}x] ⇑`);
160
- } else {
161
- body += c.red(` [${diffFixed}x] ⇓`);
162
- }
131
+ if (diffFixed === "1.0.0") body += c.gray(` [${diffFixed}x]`);
132
+ if (diff > 1) body += c.blue(` [${diffFixed}x] ⇑`);
133
+ else body += c.red(` [${diffFixed}x] ⇓`);
163
134
  }
164
135
  output.push(padding + prefix + body + suffix);
165
136
  const bodyBaseline = renderBenchmark(bench.baseline, columnWidths);
166
137
  output.push(`${padding} ${bodyBaseline} ${c.dim("(baseline)")}`);
167
138
  } else {
168
- if (bench.current.rank === 1 && benchCount > 1) {
169
- body += c.bold(c.green(" fastest"));
170
- }
171
- if (bench.current.rank === benchCount && benchCount > 2) {
172
- body += c.bold(c.gray(" slowest"));
173
- }
139
+ if (bench.current.rank === 1 && benchCount > 1) body += c.bold(c.green(" fastest"));
140
+ if (bench.current.rank === benchCount && benchCount > 2) body += c.bold(c.gray(" slowest"));
174
141
  output.push(padding + prefix + body + suffix);
175
142
  }
176
- } else {
177
- output.push(padding + prefix + task.name + suffix);
178
- }
143
+ } else output.push(padding + prefix + task.name + suffix);
179
144
  if (task.result?.state !== "pass" && outputMap.get(task) != null) {
180
145
  let data = outputMap.get(task);
181
146
  if (typeof data === "string") {
182
147
  data = stripVTControlCharacters(data.trim().split("\n").filter(Boolean).pop());
183
- if (data === "") {
184
- data = undefined;
185
- }
148
+ if (data === "") data = void 0;
186
149
  }
187
150
  if (data != null) {
188
151
  const out = ` ${" ".repeat(options.level)}${F_RIGHT} ${data}`;
@@ -210,11 +173,9 @@ class BenchmarkReporter extends DefaultReporter {
210
173
  onTaskUpdate(packs) {
211
174
  for (const pack of packs) {
212
175
  const task = this.ctx.state.idMap.get(pack[0]);
213
- if (task?.type === "suite" && task.result?.state !== "run") {
214
- task.tasks.filter((task) => task.result?.benchmark).sort((benchA, benchB) => benchA.result.benchmark.mean - benchB.result.benchmark.mean).forEach((bench, idx) => {
215
- bench.result.benchmark.rank = Number(idx) + 1;
216
- });
217
- }
176
+ if (task?.type === "suite" && task.result?.state !== "run") task.tasks.filter((task) => task.result?.benchmark).sort((benchA, benchB) => benchA.result.benchmark.mean - benchB.result.benchmark.mean).forEach((bench, idx) => {
177
+ bench.result.benchmark.rank = Number(idx) + 1;
178
+ });
218
179
  }
219
180
  }
220
181
  onTestSuiteResult(testSuite) {
@@ -226,16 +187,12 @@ class BenchmarkReporter extends DefaultReporter {
226
187
  }
227
188
  printSuiteTable(testTask) {
228
189
  const state = testTask.state();
229
- if (state === "pending" || state === "queued") {
230
- return;
231
- }
190
+ if (state === "pending" || state === "queued") return;
232
191
  const benches = testTask.task.tasks.filter((t) => t.meta.benchmark);
233
192
  const duration = testTask.task.result?.duration || 0;
234
193
  if (benches.length > 0 && benches.every((t) => t.result?.state !== "run" && t.result?.state !== "queued")) {
235
194
  let title = `\n ${getStateSymbol(testTask.task)} ${formatProjectName(testTask.project)}${getFullName(testTask.task, c.dim(" > "))}`;
236
- if (duration != null && duration > this.ctx.config.slowTestThreshold) {
237
- title += c.yellow(` ${Math.round(duration)}${c.dim("ms")}`);
238
- }
195
+ if (duration != null && duration > this.ctx.config.slowTestThreshold) title += c.yellow(` ${Math.round(duration)}${c.dim("ms")}`);
239
196
  this.log(title);
240
197
  this.log(renderTable({
241
198
  tasks: benches,
@@ -254,9 +211,7 @@ class BenchmarkReporter extends DefaultReporter {
254
211
  if (outputFile) {
255
212
  outputFile = pathe.resolve(this.ctx.config.root, outputFile);
256
213
  const outputDirectory = pathe.dirname(outputFile);
257
- if (!fs.existsSync(outputDirectory)) {
258
- await fs.promises.mkdir(outputDirectory, { recursive: true });
259
- }
214
+ if (!fs.existsSync(outputDirectory)) await fs.promises.mkdir(outputDirectory, { recursive: true });
260
215
  const output = createBenchmarkJsonReport(files);
261
216
  await fs.promises.writeFile(outputFile, JSON.stringify(output, null, 2));
262
217
  this.log(`Benchmark report written to ${outputFile}`);
@@ -1,5 +1,5 @@
1
- import { c as createExpect, a as globalExpect, i as inject, v as vi, b as vitest } from './vi.pkoYCV6A.js';
2
- import { b as bench } from './benchmark.Cf_PACH1.js';
1
+ import { c as createExpect, a as globalExpect, i as inject, v as vi, b as vitest } from './vi.bdSIJ99Y.js';
2
+ import { b as bench } from './benchmark.CYdenmiT.js';
3
3
  import { expectTypeOf } from 'expect-type';
4
4
  import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
5
5
  import * as chai from 'chai';
@@ -246,12 +246,8 @@ const skipKeys = [
246
246
  function getWindowKeys(global, win, additionalKeys = []) {
247
247
  const keysArray = [...additionalKeys, ...KEYS];
248
248
  const keys = new Set(keysArray.concat(Object.getOwnPropertyNames(win)).filter((k) => {
249
- if (skipKeys.includes(k)) {
250
- return false;
251
- }
252
- if (k in global) {
253
- return keysArray.includes(k);
254
- }
249
+ if (skipKeys.includes(k)) return false;
250
+ if (k in global) return keysArray.includes(k);
255
251
  return true;
256
252
  }));
257
253
  return keys;
@@ -262,21 +258,15 @@ function isClassLikeName(name) {
262
258
  function populateGlobal(global, win, options = {}) {
263
259
  const { bindFunctions = false } = options;
264
260
  const keys = getWindowKeys(global, win, options.additionalKeys);
265
- const originals = new Map();
266
- const overrideObject = new Map();
261
+ const originals = /* @__PURE__ */ new Map();
262
+ const overrideObject = /* @__PURE__ */ new Map();
267
263
  for (const key of keys) {
268
264
  const boundFunction = bindFunctions && typeof win[key] === "function" && !isClassLikeName(key) && win[key].bind(win);
269
- if (KEYS.includes(key) && key in global) {
270
- originals.set(key, global[key]);
271
- }
265
+ if (KEYS.includes(key) && key in global) originals.set(key, global[key]);
272
266
  Object.defineProperty(global, key, {
273
267
  get() {
274
- if (overrideObject.has(key)) {
275
- return overrideObject.get(key);
276
- }
277
- if (boundFunction) {
278
- return boundFunction;
279
- }
268
+ if (overrideObject.has(key)) return overrideObject.get(key);
269
+ if (boundFunction) return boundFunction;
280
270
  return win[key];
281
271
  },
282
272
  set(v) {
@@ -289,17 +279,13 @@ function populateGlobal(global, win, options = {}) {
289
279
  global.self = global;
290
280
  global.top = global;
291
281
  global.parent = global;
292
- if (global.global) {
293
- global.global = global;
294
- }
282
+ if (global.global) global.global = global;
295
283
  // rewrite defaultView to reference the same global context
296
- if (global.document && global.document.defaultView) {
297
- Object.defineProperty(global.document, "defaultView", {
298
- get: () => global,
299
- enumerable: true,
300
- configurable: true
301
- });
302
- }
284
+ if (global.document && global.document.defaultView) Object.defineProperty(global.document, "defaultView", {
285
+ get: () => global,
286
+ enumerable: true,
287
+ configurable: true
288
+ });
303
289
  skipKeys.forEach((k) => keys.add(k));
304
290
  return {
305
291
  keys,
@@ -333,9 +319,7 @@ var edge = {
333
319
  context.global = context;
334
320
  context.Buffer = Buffer;
335
321
  KEYS.forEach((key) => {
336
- if (key in global) {
337
- context[key] = global[key];
338
- }
322
+ if (key in global) context[key] = global[key];
339
323
  });
340
324
  return context;
341
325
  } });
@@ -351,9 +335,7 @@ async function teardownWindow(win) {
351
335
  if (win.close && win.happyDOM.abort) {
352
336
  await win.happyDOM.abort();
353
337
  win.close();
354
- } else {
355
- win.happyDOM.cancelAsync();
356
- }
338
+ } else win.happyDOM.cancelAsync();
357
339
  }
358
340
  var happy = {
359
341
  name: "happy-dom",
@@ -362,7 +344,7 @@ var happy = {
362
344
  const { Window } = await import('happy-dom');
363
345
  let win = new Window({
364
346
  ...happyDOM,
365
- console: console && globalThis.console ? globalThis.console : undefined,
347
+ console: console && globalThis.console ? globalThis.console : void 0,
366
348
  url: happyDOM.url || "http://localhost:3000",
367
349
  settings: {
368
350
  ...happyDOM.settings,
@@ -372,16 +354,14 @@ var happy = {
372
354
  // TODO: browser doesn't expose Buffer, but a lot of dependencies use it
373
355
  win.Buffer = Buffer;
374
356
  // inject structuredClone if it exists
375
- if (typeof structuredClone !== "undefined" && !win.structuredClone) {
376
- win.structuredClone = structuredClone;
377
- }
357
+ if (typeof structuredClone !== "undefined" && !win.structuredClone) win.structuredClone = structuredClone;
378
358
  return {
379
359
  getVmContext() {
380
360
  return win;
381
361
  },
382
362
  async teardown() {
383
363
  await teardownWindow(win);
384
- win = undefined;
364
+ win = void 0;
385
365
  }
386
366
  };
387
367
  },
@@ -391,7 +371,7 @@ var happy = {
391
371
  const { Window, GlobalWindow } = await import('happy-dom');
392
372
  const win = new (GlobalWindow || Window)({
393
373
  ...happyDOM,
394
- console: console && global.console ? global.console : undefined,
374
+ console: console && global.console ? global.console : void 0,
395
375
  url: happyDOM.url || "http://localhost:3000",
396
376
  settings: {
397
377
  ...happyDOM.settings,
@@ -418,23 +398,17 @@ var happy = {
418
398
  function catchWindowErrors(window) {
419
399
  let userErrorListenerCount = 0;
420
400
  function throwUnhandlerError(e) {
421
- if (userErrorListenerCount === 0 && e.error != null) {
422
- process.emit("uncaughtException", e.error);
423
- }
401
+ if (userErrorListenerCount === 0 && e.error != null) process.emit("uncaughtException", e.error);
424
402
  }
425
403
  const addEventListener = window.addEventListener.bind(window);
426
404
  const removeEventListener = window.removeEventListener.bind(window);
427
405
  window.addEventListener("error", throwUnhandlerError);
428
406
  window.addEventListener = function(...args) {
429
- if (args[0] === "error") {
430
- userErrorListenerCount++;
431
- }
407
+ if (args[0] === "error") userErrorListenerCount++;
432
408
  return addEventListener.apply(this, args);
433
409
  };
434
410
  window.removeEventListener = function(...args) {
435
- if (args[0] === "error" && userErrorListenerCount) {
436
- userErrorListenerCount--;
437
- }
411
+ if (args[0] === "error" && userErrorListenerCount) userErrorListenerCount--;
438
412
  return removeEventListener.apply(this, args);
439
413
  };
440
414
  return function clearErrorHandlers() {
@@ -449,11 +423,11 @@ var jsdom = {
449
423
  const { html = "<!DOCTYPE html>", userAgent, url = "http://localhost:3000", contentType = "text/html", pretendToBeVisual = true, includeNodeLocations = false, runScripts = "dangerously", resources, console = false, cookieJar = false,...restOptions } = jsdom;
450
424
  let dom = new JSDOM(html, {
451
425
  pretendToBeVisual,
452
- resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : undefined),
426
+ resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
453
427
  runScripts,
454
428
  url,
455
- virtualConsole: console && globalThis.console ? new VirtualConsole().sendTo(globalThis.console) : undefined,
456
- cookieJar: cookieJar ? new CookieJar() : undefined,
429
+ virtualConsole: console && globalThis.console ? new VirtualConsole().sendTo(globalThis.console) : void 0,
430
+ cookieJar: cookieJar ? new CookieJar() : void 0,
457
431
  includeNodeLocations,
458
432
  contentType,
459
433
  userAgent,
@@ -478,9 +452,7 @@ var jsdom = {
478
452
  ];
479
453
  for (const name of globalNames) {
480
454
  const value = globalThis[name];
481
- if (typeof value !== "undefined" && typeof dom.window[name] === "undefined") {
482
- dom.window[name] = value;
483
- }
455
+ if (typeof value !== "undefined" && typeof dom.window[name] === "undefined") dom.window[name] = value;
484
456
  }
485
457
  return {
486
458
  getVmContext() {
@@ -489,7 +461,7 @@ var jsdom = {
489
461
  teardown() {
490
462
  clearWindowErrors();
491
463
  dom.window.close();
492
- dom = undefined;
464
+ dom = void 0;
493
465
  }
494
466
  };
495
467
  },
@@ -498,11 +470,11 @@ var jsdom = {
498
470
  const { html = "<!DOCTYPE html>", userAgent, url = "http://localhost:3000", contentType = "text/html", pretendToBeVisual = true, includeNodeLocations = false, runScripts = "dangerously", resources, console = false, cookieJar = false,...restOptions } = jsdom;
499
471
  const dom = new JSDOM(html, {
500
472
  pretendToBeVisual,
501
- resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : undefined),
473
+ resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
502
474
  runScripts,
503
475
  url,
504
- virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : undefined,
505
- cookieJar: cookieJar ? new CookieJar() : undefined,
476
+ virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : void 0,
477
+ cookieJar: cookieJar ? new CookieJar() : void 0,
506
478
  includeNodeLocations,
507
479
  contentType,
508
480
  userAgent,
@@ -532,9 +504,7 @@ const denyList = new Set([
532
504
  ]);
533
505
  const nodeGlobals = new Map(Object.getOwnPropertyNames(globalThis).filter((global) => !denyList.has(global)).map((nodeGlobalsKey) => {
534
506
  const descriptor = Object.getOwnPropertyDescriptor(globalThis, nodeGlobalsKey);
535
- if (!descriptor) {
536
- throw new Error(`No property descriptor for ${nodeGlobalsKey}, this is a bug in Vitest.`);
537
- }
507
+ if (!descriptor) throw new Error(`No property descriptor for ${nodeGlobalsKey}, this is a bug in Vitest.`);
538
508
  return [nodeGlobalsKey, descriptor];
539
509
  }));
540
510
  var node = {
@@ -545,51 +515,43 @@ var node = {
545
515
  let context = vm.createContext();
546
516
  let global = vm.runInContext("this", context);
547
517
  const contextGlobals = new Set(Object.getOwnPropertyNames(global));
548
- for (const [nodeGlobalsKey, descriptor] of nodeGlobals) {
549
- if (!contextGlobals.has(nodeGlobalsKey)) {
550
- if (descriptor.configurable) {
551
- Object.defineProperty(global, nodeGlobalsKey, {
552
- configurable: true,
553
- enumerable: descriptor.enumerable,
554
- get() {
555
- // @ts-expect-error: no index signature
556
- const val = globalThis[nodeGlobalsKey];
557
- // override lazy getter
558
- Object.defineProperty(global, nodeGlobalsKey, {
559
- configurable: true,
560
- enumerable: descriptor.enumerable,
561
- value: val,
562
- writable: descriptor.writable === true || nodeGlobalsKey === "performance"
563
- });
564
- return val;
565
- },
566
- set(val) {
567
- // override lazy getter
568
- Object.defineProperty(global, nodeGlobalsKey, {
569
- configurable: true,
570
- enumerable: descriptor.enumerable,
571
- value: val,
572
- writable: true
573
- });
574
- }
575
- });
576
- } else if ("value" in descriptor) {
577
- Object.defineProperty(global, nodeGlobalsKey, {
578
- configurable: false,
579
- enumerable: descriptor.enumerable,
580
- value: descriptor.value,
581
- writable: descriptor.writable
582
- });
583
- } else {
584
- Object.defineProperty(global, nodeGlobalsKey, {
585
- configurable: false,
586
- enumerable: descriptor.enumerable,
587
- get: descriptor.get,
588
- set: descriptor.set
589
- });
590
- }
518
+ for (const [nodeGlobalsKey, descriptor] of nodeGlobals) if (!contextGlobals.has(nodeGlobalsKey)) if (descriptor.configurable) Object.defineProperty(global, nodeGlobalsKey, {
519
+ configurable: true,
520
+ enumerable: descriptor.enumerable,
521
+ get() {
522
+ // @ts-expect-error: no index signature
523
+ const val = globalThis[nodeGlobalsKey];
524
+ // override lazy getter
525
+ Object.defineProperty(global, nodeGlobalsKey, {
526
+ configurable: true,
527
+ enumerable: descriptor.enumerable,
528
+ value: val,
529
+ writable: descriptor.writable === true || nodeGlobalsKey === "performance"
530
+ });
531
+ return val;
532
+ },
533
+ set(val) {
534
+ // override lazy getter
535
+ Object.defineProperty(global, nodeGlobalsKey, {
536
+ configurable: true,
537
+ enumerable: descriptor.enumerable,
538
+ value: val,
539
+ writable: true
540
+ });
591
541
  }
592
- }
542
+ });
543
+ else if ("value" in descriptor) Object.defineProperty(global, nodeGlobalsKey, {
544
+ configurable: false,
545
+ enumerable: descriptor.enumerable,
546
+ value: descriptor.value,
547
+ writable: descriptor.writable
548
+ });
549
+ else Object.defineProperty(global, nodeGlobalsKey, {
550
+ configurable: false,
551
+ enumerable: descriptor.enumerable,
552
+ get: descriptor.get,
553
+ set: descriptor.set
554
+ });
593
555
  global.global = global;
594
556
  global.Buffer = Buffer;
595
557
  global.ArrayBuffer = ArrayBuffer;
@@ -602,8 +564,8 @@ var node = {
602
564
  return context;
603
565
  },
604
566
  teardown() {
605
- context = undefined;
606
- global = undefined;
567
+ context = void 0;
568
+ global = void 0;
607
569
  }
608
570
  };
609
571
  },
@@ -14,7 +14,7 @@ function setupInspect(ctx) {
14
14
  if (isEnabled) {
15
15
  inspector = __require("node:inspector");
16
16
  // Inspector may be open already if "isolate: false" is used
17
- const isOpen = inspector.url() !== undefined;
17
+ const isOpen = inspector.url() !== void 0;
18
18
  if (!isOpen) {
19
19
  inspector.open(config.inspector.port, config.inspector.host, config.inspector.waitForDebugger);
20
20
  if (config.inspectBrk) {
@@ -1,5 +1,5 @@
1
1
  import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
2
- import { g as getWorkerState } from './utils.BlI4TC7Y.js';
2
+ import { g as getWorkerState } from './utils.XdZDrNZV.js';
3
3
  import '@vitest/utils';
4
4
 
5
5
  class VitestNodeSnapshotEnvironment extends NodeSnapshotEnvironment {