vitest 4.0.0-beta.5 → 4.0.0-beta.7

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 (64) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/{base.DMfOuRWD.js → base.BXI97p6t.js} +7 -16
  5. package/dist/chunks/{benchmark.CtuRzf-i.js → benchmark.UW6Ezvxy.js} +4 -9
  6. package/dist/chunks/{browser.d.Cawq_X_N.d.ts → browser.d.DOMmqJQx.d.ts} +1 -1
  7. package/dist/chunks/{cac.CKnbxhn2.js → cac.Dsn7ixFt.js} +38 -113
  8. package/dist/chunks/{cli-api.COn58yrl.js → cli-api.DfGJyldU.js} +829 -1232
  9. package/dist/chunks/{config.d.CKNVOKm0.d.ts → config.d._GBBbReY.d.ts} +1 -0
  10. package/dist/chunks/{console.Duv2dVIC.js → console.B0quX7yH.js} +32 -68
  11. package/dist/chunks/{coverage.B6cReEn1.js → coverage.Dvxug1RM.js} +210 -579
  12. package/dist/chunks/{creator.DUVZ6rfm.js → creator.KEg6n5IC.js} +28 -74
  13. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  14. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  15. package/dist/chunks/{globals.CJQ63oO0.js → globals.lgsmH00r.js} +5 -5
  16. package/dist/chunks/{index.QZr3S3vQ.js → index.AR8aAkCC.js} +2 -2
  17. package/dist/chunks/{index.DQhAfQQU.js → index.C3EbxYwt.js} +276 -607
  18. package/dist/chunks/{index.oWRWx-nj.js → index.CsFXYRkW.js} +17 -36
  19. package/dist/chunks/{index.DgN0Zk9a.js → index.D2B6d2vv.js} +14 -24
  20. package/dist/chunks/{index.BRtIe7r8.js → index.DfviD7lX.js} +55 -110
  21. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  22. package/dist/chunks/{moduleRunner.d.mmOmOGrW.d.ts → moduleRunner.d.CX4DuqOx.d.ts} +2 -2
  23. package/dist/chunks/{node.4JV5OXkt.js → node.BOqcT2jW.js} +1 -1
  24. package/dist/chunks/{plugin.d.CvOlgjxK.d.ts → plugin.d.vcD4xbMS.d.ts} +1 -1
  25. package/dist/chunks/{reporters.d.CYE9sT5z.d.ts → reporters.d.BC86JJdB.d.ts} +799 -758
  26. package/dist/chunks/{resolver.D5bG4zy5.js → resolver.Bx6lE0iq.js} +21 -64
  27. package/dist/chunks/{rpc.DGoW_Vl-.js → rpc.RpPylpp0.js} +7 -21
  28. package/dist/chunks/{runBaseTests.B3KcKqlF.js → runBaseTests.D6sfuWBM.js} +25 -54
  29. package/dist/chunks/{setup-common.lgPs-bYv.js → setup-common.hLGRxhC8.js} +9 -22
  30. package/dist/chunks/{startModuleRunner.C8FtT_BY.js → startModuleRunner.C8TW8zTN.js} +83 -205
  31. package/dist/chunks/{typechecker.BgoW4nTA.js → typechecker.DSo_maXz.js} +97 -209
  32. package/dist/chunks/{utils.CcGm2cd1.js → utils.C2YI6McM.js} +4 -13
  33. package/dist/chunks/{utils.B9FY3b73.js → utils.C7__0Iv5.js} +5 -14
  34. package/dist/chunks/{vi.DGAfBY4R.js → vi.BfdOiD4j.js} +110 -267
  35. package/dist/chunks/{vm.BKfKvaKl.js → vm.BHBje7cC.js} +73 -177
  36. package/dist/chunks/{worker.d.Db-UVmXc.d.ts → worker.d.BKu8cnnX.d.ts} +1 -1
  37. package/dist/chunks/{worker.d.D9QWnzAe.d.ts → worker.d.DYlqbejz.d.ts} +1 -1
  38. package/dist/cli.js +3 -3
  39. package/dist/config.d.ts +7 -7
  40. package/dist/coverage.d.ts +4 -4
  41. package/dist/coverage.js +2 -2
  42. package/dist/environments.js +1 -1
  43. package/dist/index.d.ts +6 -6
  44. package/dist/index.js +5 -5
  45. package/dist/module-evaluator.d.ts +3 -3
  46. package/dist/module-evaluator.js +33 -84
  47. package/dist/module-runner.js +2 -2
  48. package/dist/node.d.ts +11 -9
  49. package/dist/node.js +16 -27
  50. package/dist/reporters.d.ts +5 -5
  51. package/dist/reporters.js +3 -3
  52. package/dist/runners.d.ts +1 -1
  53. package/dist/runners.js +23 -51
  54. package/dist/snapshot.js +2 -2
  55. package/dist/suite.js +2 -2
  56. package/dist/worker.js +18 -34
  57. package/dist/workers/forks.js +4 -4
  58. package/dist/workers/runVmTests.js +19 -37
  59. package/dist/workers/threads.js +4 -4
  60. package/dist/workers/vmForks.js +7 -7
  61. package/dist/workers/vmThreads.js +7 -7
  62. package/dist/workers.d.ts +3 -3
  63. package/dist/workers.js +11 -11
  64. package/package.json +11 -11
@@ -2,39 +2,22 @@ import fs from 'node:fs';
2
2
 
3
3
  const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
4
4
  function normalizeWindowsPath(input = "") {
5
- if (!input) return input;
6
- return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
5
+ return input && input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
7
6
  }
8
- const _UNC_REGEX = /^[/\\]{2}/;
9
- const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
10
- const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
11
- const normalize = function(path) {
7
+ const _UNC_REGEX = /^[/\\]{2}/, _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/, _DRIVE_LETTER_RE = /^[A-Za-z]:$/, normalize = function(path) {
12
8
  if (path.length === 0) return ".";
13
9
  path = normalizeWindowsPath(path);
14
- const isUNCPath = path.match(_UNC_REGEX);
15
- const isPathAbsolute = isAbsolute(path);
16
- const trailingSeparator = path[path.length - 1] === "/";
17
- path = normalizeString(path, !isPathAbsolute);
18
- if (path.length === 0) {
19
- if (isPathAbsolute) return "/";
20
- return trailingSeparator ? "./" : ".";
21
- }
10
+ const isUNCPath = path.match(_UNC_REGEX), isPathAbsolute = isAbsolute(path), trailingSeparator = path[path.length - 1] === "/";
11
+ if (path = normalizeString(path, !isPathAbsolute), path.length === 0) return isPathAbsolute ? "/" : trailingSeparator ? "./" : ".";
22
12
  if (trailingSeparator) path += "/";
23
13
  if (_DRIVE_LETTER_RE.test(path)) path += "/";
24
- if (isUNCPath) {
25
- if (!isPathAbsolute) return `//./${path}`;
26
- return `//${path}`;
27
- }
28
- return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
29
- };
30
- const join = function(...segments) {
14
+ return isUNCPath ? isPathAbsolute ? `//${path}` : `//./${path}` : isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
15
+ }, join = function(...segments) {
31
16
  let path = "";
32
17
  for (const seg of segments) {
33
18
  if (!seg) continue;
34
19
  if (path.length > 0) {
35
- const pathTrailing = path[path.length - 1] === "/";
36
- const segLeading = seg[0] === "/";
37
- const both = pathTrailing && segLeading;
20
+ const pathTrailing = path[path.length - 1] === "/", segLeading = seg[0] === "/", both = pathTrailing && segLeading;
38
21
  if (both) path += seg.slice(1);
39
22
  else path += pathTrailing || segLeading ? seg : `/${seg}`;
40
23
  } else path += seg;
@@ -42,11 +25,7 @@ const join = function(...segments) {
42
25
  return normalize(path);
43
26
  };
44
27
  function normalizeString(path, allowAboveRoot) {
45
- let res = "";
46
- let lastSegmentLength = 0;
47
- let lastSlash = -1;
48
- let dots = 0;
49
- let char = null;
28
+ let res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, char = null;
50
29
  for (let index = 0; index <= path.length; ++index) {
51
30
  if (index < path.length) char = path[index];
52
31
  else if (char === "/") break;
@@ -57,35 +36,22 @@ function normalizeString(path, allowAboveRoot) {
57
36
  if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
58
37
  if (res.length > 2) {
59
38
  const lastSlashIndex = res.lastIndexOf("/");
60
- if (lastSlashIndex === -1) {
61
- res = "";
62
- lastSegmentLength = 0;
63
- } else {
64
- res = res.slice(0, lastSlashIndex);
65
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
66
- }
67
- lastSlash = index;
68
- dots = 0;
39
+ if (lastSlashIndex === -1) res = "", lastSegmentLength = 0;
40
+ else res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
41
+ lastSlash = index, dots = 0;
69
42
  continue;
70
43
  } else if (res.length > 0) {
71
- res = "";
72
- lastSegmentLength = 0;
73
- lastSlash = index;
74
- dots = 0;
44
+ res = "", lastSegmentLength = 0, lastSlash = index, dots = 0;
75
45
  continue;
76
46
  }
77
47
  }
78
- if (allowAboveRoot) {
79
- res += res.length > 0 ? "/.." : "..";
80
- lastSegmentLength = 2;
81
- }
48
+ if (allowAboveRoot) res += res.length > 0 ? "/.." : "..", lastSegmentLength = 2;
82
49
  } else {
83
50
  if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
84
51
  else res = path.slice(lastSlash + 1, index);
85
52
  lastSegmentLength = index - lastSlash - 1;
86
53
  }
87
- lastSlash = index;
88
- dots = 0;
54
+ lastSlash = index, dots = 0;
89
55
  } else if (char === "." && dots !== -1) ++dots;
90
56
  else dots = -1;
91
57
  }
@@ -93,8 +59,7 @@ function normalizeString(path, allowAboveRoot) {
93
59
  }
94
60
  const isAbsolute = function(p) {
95
61
  return _IS_ABSOLUTE_RE.test(p);
96
- };
97
- const dirname = function(p) {
62
+ }, dirname = function(p) {
98
63
  const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
99
64
  if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
100
65
  return segments.join("/") || (isAbsolute(p) ? "/" : ".");
@@ -120,8 +85,7 @@ function findNearestPackageData(basedir) {
120
85
  return {};
121
86
  }
122
87
  function stripBomTag(content) {
123
- if (content.charCodeAt(0) === 65279) return content.slice(1);
124
- return content;
88
+ return content.charCodeAt(0) === 65279 ? content.slice(1) : content;
125
89
  }
126
90
  function tryStatSync(file) {
127
91
  try {
@@ -131,16 +95,12 @@ function tryStatSync(file) {
131
95
  }
132
96
  function getCachedData(cache, basedir, originalBasedir) {
133
97
  const pkgData = cache.get(getFnpdCacheKey(basedir));
134
- if (pkgData) {
135
- traverseBetweenDirs(originalBasedir, basedir, (dir) => {
136
- cache.set(getFnpdCacheKey(dir), pkgData);
137
- });
138
- return pkgData;
139
- }
98
+ if (pkgData) return traverseBetweenDirs(originalBasedir, basedir, (dir) => {
99
+ cache.set(getFnpdCacheKey(dir), pkgData);
100
+ }), pkgData;
140
101
  }
141
102
  function setCacheData(cache, data, basedir, originalBasedir) {
142
- cache.set(getFnpdCacheKey(basedir), data);
143
- traverseBetweenDirs(originalBasedir, basedir, (dir) => {
103
+ cache.set(getFnpdCacheKey(basedir), data), traverseBetweenDirs(originalBasedir, basedir, (dir) => {
144
104
  cache.set(getFnpdCacheKey(dir), data);
145
105
  });
146
106
  }
@@ -153,10 +113,7 @@ function getFnpdCacheKey(basedir) {
153
113
  * @param shorterDir Shorter dir path, e.g. `/User/foo`
154
114
  */
155
115
  function traverseBetweenDirs(longerDir, shorterDir, cb) {
156
- while (longerDir !== shorterDir) {
157
- cb(longerDir);
158
- longerDir = dirname(longerDir);
159
- }
116
+ while (longerDir !== shorterDir) cb(longerDir), longerDir = dirname(longerDir);
160
117
  }
161
118
 
162
119
  export { findNearestPackageData as f };
@@ -1,29 +1,18 @@
1
1
  import { getSafeTimers } from '@vitest/utils';
2
2
  import { c as createBirpc } from './index.Bgo3tNWt.js';
3
- import { g as getWorkerState } from './utils.B9FY3b73.js';
3
+ import { g as getWorkerState } from './utils.C7__0Iv5.js';
4
4
 
5
5
  const { get } = Reflect;
6
6
  function withSafeTimers(fn) {
7
- const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers();
8
- const currentSetTimeout = globalThis.setTimeout;
9
- const currentClearTimeout = globalThis.clearTimeout;
10
- const currentSetImmediate = globalThis.setImmediate;
11
- const currentClearImmediate = globalThis.clearImmediate;
12
- const currentNextTick = globalThis.process?.nextTick;
7
+ const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers(), currentSetTimeout = globalThis.setTimeout, currentClearTimeout = globalThis.clearTimeout, currentSetImmediate = globalThis.setImmediate, currentClearImmediate = globalThis.clearImmediate, currentNextTick = globalThis.process?.nextTick;
13
8
  try {
14
- globalThis.setTimeout = setTimeout;
15
- globalThis.clearTimeout = clearTimeout;
16
- if (setImmediate) globalThis.setImmediate = setImmediate;
9
+ if (globalThis.setTimeout = setTimeout, globalThis.clearTimeout = clearTimeout, setImmediate) globalThis.setImmediate = setImmediate;
17
10
  if (clearImmediate) globalThis.clearImmediate = clearImmediate;
18
11
  if (globalThis.process && nextTick) globalThis.process.nextTick = nextTick;
19
12
  const result = fn();
20
13
  return result;
21
14
  } finally {
22
- globalThis.setTimeout = currentSetTimeout;
23
- globalThis.clearTimeout = currentClearTimeout;
24
- globalThis.setImmediate = currentSetImmediate;
25
- globalThis.clearImmediate = currentClearImmediate;
26
- if (globalThis.process && nextTick) nextTick(() => {
15
+ if (globalThis.setTimeout = currentSetTimeout, globalThis.clearTimeout = currentClearTimeout, globalThis.setImmediate = currentSetImmediate, globalThis.clearImmediate = currentClearImmediate, globalThis.process && nextTick) nextTick(() => {
27
16
  globalThis.process.nextTick = currentNextTick;
28
17
  });
29
18
  }
@@ -38,8 +27,7 @@ function createRuntimeRpc(options) {
38
27
  let setCancel = (_reason) => {};
39
28
  const onCancel = new Promise((resolve) => {
40
29
  setCancel = resolve;
41
- });
42
- const rpc = createSafeRpc(createBirpc({ onCancel: setCancel }, {
30
+ }), rpc = createSafeRpc(createBirpc({ onCancel: setCancel }, {
43
31
  eventNames: [
44
32
  "onUserConsoleLog",
45
33
  "onCollected",
@@ -57,8 +45,7 @@ function createSafeRpc(rpc) {
57
45
  return new Proxy(rpc, { get(target, p, handler) {
58
46
  // keep $rejectPendingCalls as sync function
59
47
  if (p === "$rejectPendingCalls") return rpc.$rejectPendingCalls;
60
- const sendCall = get(target, p, handler);
61
- const safeSendCall = (...args) => withSafeTimers(async () => {
48
+ const sendCall = get(target, p, handler), safeSendCall = (...args) => withSafeTimers(async () => {
62
49
  const result = sendCall(...args);
63
50
  promises.add(result);
64
51
  try {
@@ -67,8 +54,7 @@ function createSafeRpc(rpc) {
67
54
  promises.delete(result);
68
55
  }
69
56
  });
70
- safeSendCall.asEvent = sendCall.asEvent;
71
- return safeSendCall;
57
+ return safeSendCall.asEvent = sendCall.asEvent, safeSendCall;
72
58
  } });
73
59
  }
74
60
  function rpc() {
@@ -1,21 +1,21 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { startTests, collectTests } from '@vitest/runner';
3
- import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.oWRWx-nj.js';
4
- import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.lgPs-bYv.js';
5
- import { a as globalExpect, v as vi } from './vi.DGAfBY4R.js';
6
- import { c as closeInspector } from './inspector.C914Efll.js';
3
+ import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.CsFXYRkW.js';
4
+ import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.hLGRxhC8.js';
5
+ import { a as globalExpect, v as vi } from './vi.BfdOiD4j.js';
6
+ import { c as closeInspector } from './inspector.CvQD-Nie.js';
7
7
  import { createRequire } from 'node:module';
8
8
  import timers from 'node:timers';
9
9
  import timersPromises from 'node:timers/promises';
10
10
  import util from 'node:util';
11
11
  import { KNOWN_ASSET_TYPES, getSafeTimers } from '@vitest/utils';
12
- import { V as VitestIndex } from './index.QZr3S3vQ.js';
13
- import { g as getWorkerState, r as resetModules } from './utils.B9FY3b73.js';
12
+ import { V as VitestIndex } from './index.AR8aAkCC.js';
13
+ import { g as getWorkerState, r as resetModules } from './utils.C7__0Iv5.js';
14
14
  import 'chai';
15
15
  import 'node:path';
16
16
  import '../path.js';
17
17
  import 'node:url';
18
- import './rpc.DGoW_Vl-.js';
18
+ import './rpc.RpPylpp0.js';
19
19
  import './index.Bgo3tNWt.js';
20
20
  import './coverage.D_JHT54q.js';
21
21
  import '@vitest/snapshot';
@@ -25,16 +25,15 @@ import './_commonjsHelpers.BFTU3MAI.js';
25
25
  import '@vitest/utils/error';
26
26
  import '@vitest/spy';
27
27
  import '@vitest/utils/source-map';
28
- import './date.Bq6ZW5rf.js';
29
- import './benchmark.CtuRzf-i.js';
28
+ import './date.-jtEtIeV.js';
29
+ import './benchmark.UW6Ezvxy.js';
30
30
  import 'expect-type';
31
31
  import 'vite/module-runner';
32
32
 
33
33
  // this should only be used in Node
34
34
  let globalSetup = false;
35
35
  async function setupGlobalEnv(config, { environment }, moduleRunner) {
36
- await setupCommonEnv(config);
37
- Object.defineProperty(globalThis, "__vitest_index__", {
36
+ await setupCommonEnv(config), Object.defineProperty(globalThis, "__vitest_index__", {
38
37
  value: VitestIndex,
39
38
  enumerable: false
40
39
  });
@@ -45,24 +44,15 @@ async function setupGlobalEnv(config, { environment }, moduleRunner) {
45
44
  const viteEnvironment = environment.viteEnvironment || environment.name;
46
45
  if (viteEnvironment === "client") {
47
46
  const _require = createRequire(import.meta.url);
48
- // always mock "required" `css` files, because we cannot process them
49
- _require.extensions[".css"] = resolveCss;
50
- _require.extensions[".scss"] = resolveCss;
51
- _require.extensions[".sass"] = resolveCss;
52
- _require.extensions[".less"] = resolveCss;
53
- // since we are using Vite, we can assume how these will be resolved
54
- KNOWN_ASSET_TYPES.forEach((type) => {
47
+ _require.extensions[".css"] = resolveCss, _require.extensions[".scss"] = resolveCss, _require.extensions[".sass"] = resolveCss, _require.extensions[".less"] = resolveCss, KNOWN_ASSET_TYPES.forEach((type) => {
55
48
  _require.extensions[`.${type}`] = resolveAsset;
56
- });
57
- process.env.SSR = "";
49
+ }), process.env.SSR = "";
58
50
  } else process.env.SSR = "1";
59
- // @ts-expect-error not typed global for patched timers
60
- globalThis.__vitest_required__ = {
51
+ if (globalThis.__vitest_required__ = {
61
52
  util,
62
53
  timers,
63
54
  timersPromises
64
- };
65
- if (!config.disableConsoleIntercept) await setupConsoleLogSpy();
55
+ }, !config.disableConsoleIntercept) await setupConsoleLogSpy();
66
56
  }
67
57
  function resolveCss(mod) {
68
58
  mod.exports = "";
@@ -71,58 +61,39 @@ function resolveAsset(mod, url) {
71
61
  mod.exports = url;
72
62
  }
73
63
  async function setupConsoleLogSpy() {
74
- const { createCustomConsole } = await import('./console.Duv2dVIC.js');
64
+ const { createCustomConsole } = await import('./console.B0quX7yH.js');
75
65
  globalThis.console = createCustomConsole();
76
66
  }
77
67
  async function withEnv({ environment }, options, fn) {
78
- // @ts-expect-error untyped global
79
- globalThis.__vitest_environment__ = environment.name;
80
- globalExpect.setState({ environment: environment.name });
68
+ globalThis.__vitest_environment__ = environment.name, globalExpect.setState({ environment: environment.name });
81
69
  const env = await environment.setup(globalThis, options);
82
70
  try {
83
71
  await fn();
84
72
  } finally {
85
73
  // Run possible setTimeouts, e.g. the onces used by ConsoleLogSpy
86
74
  const { setTimeout } = getSafeTimers();
87
- await new Promise((resolve) => setTimeout(resolve));
88
- await env.teardown(globalThis);
75
+ await new Promise((resolve) => setTimeout(resolve)), await env.teardown(globalThis);
89
76
  }
90
77
  }
91
78
 
92
79
  // browser shouldn't call this!
93
80
  async function run(method, files, config, environment, moduleRunner) {
94
- const workerState = getWorkerState();
95
- const isIsolatedThreads = config.pool === "threads" && (config.poolOptions?.threads?.isolate ?? true);
96
- const isIsolatedForks = config.pool === "forks" && (config.poolOptions?.forks?.isolate ?? true);
97
- const isolate = isIsolatedThreads || isIsolatedForks;
98
- await setupGlobalEnv(config, environment, moduleRunner);
99
- await startCoverageInsideWorker(config.coverage, moduleRunner, { isolate });
100
- if (config.chaiConfig) setupChaiConfig(config.chaiConfig);
81
+ const workerState = getWorkerState(), isIsolatedThreads = config.pool === "threads" && (config.poolOptions?.threads?.isolate ?? true), isIsolatedForks = config.pool === "forks" && (config.poolOptions?.forks?.isolate ?? true), isolate = isIsolatedThreads || isIsolatedForks;
82
+ if (await setupGlobalEnv(config, environment, moduleRunner), await startCoverageInsideWorker(config.coverage, moduleRunner, { isolate }), config.chaiConfig) setupChaiConfig(config.chaiConfig);
101
83
  const runner = await resolveTestRunner(config, moduleRunner);
102
84
  workerState.onCancel.then((reason) => {
103
- closeInspector(config);
104
- runner.cancel?.(reason);
105
- });
106
- workerState.durations.prepare = performance.now() - workerState.durations.prepare;
107
- workerState.durations.environment = performance.now();
108
- await withEnv(environment, environment.options || config.environmentOptions || {}, async () => {
85
+ closeInspector(config), runner.cancel?.(reason);
86
+ }), workerState.durations.prepare = performance.now() - workerState.durations.prepare, workerState.durations.environment = performance.now(), await withEnv(environment, environment.options || config.environmentOptions || {}, async () => {
109
87
  workerState.durations.environment = performance.now() - workerState.durations.environment;
110
88
  for (const file of files) {
111
- if (isolate) {
112
- moduleRunner.mocker.reset();
113
- resetModules(workerState.evaluatedModules, true);
114
- }
115
- workerState.filepath = file.filepath;
116
- if (method === "run") await startTests([file], runner);
89
+ if (isolate) moduleRunner.mocker.reset(), resetModules(workerState.evaluatedModules, true);
90
+ if (workerState.filepath = file.filepath, method === "run") await startTests([file], runner);
117
91
  else await collectTests([file], runner);
118
- // reset after tests, because user might call `vi.setConfig` in setupFile
119
- vi.resetConfig();
120
92
  // mocks should not affect different files
121
- vi.restoreAllMocks();
93
+ vi.resetConfig(), vi.restoreAllMocks();
122
94
  }
123
95
  await stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate });
124
- });
125
- workerState.environmentTeardownRun = true;
96
+ }), workerState.environmentTeardownRun = true;
126
97
  }
127
98
 
128
99
  export { run };
@@ -1,54 +1,41 @@
1
1
  import { r as resolveCoverageProviderModule } from './coverage.D_JHT54q.js';
2
2
  import { addSerializer } from '@vitest/snapshot';
3
3
  import { setSafeTimers } from '@vitest/utils';
4
- import { g as getWorkerState } from './utils.B9FY3b73.js';
4
+ import { g as getWorkerState } from './utils.C7__0Iv5.js';
5
5
 
6
6
  async function startCoverageInsideWorker(options, loader, runtimeOptions) {
7
7
  const coverageModule = await resolveCoverageProviderModule(options, loader);
8
- if (coverageModule) return coverageModule.startCoverage?.(runtimeOptions);
9
- return null;
8
+ return coverageModule ? coverageModule.startCoverage?.(runtimeOptions) : null;
10
9
  }
11
10
  async function takeCoverageInsideWorker(options, loader) {
12
11
  const coverageModule = await resolveCoverageProviderModule(options, loader);
13
- if (coverageModule) return coverageModule.takeCoverage?.({ moduleExecutionInfo: loader.moduleExecutionInfo });
14
- return null;
12
+ return coverageModule ? coverageModule.takeCoverage?.({ moduleExecutionInfo: loader.moduleExecutionInfo }) : null;
15
13
  }
16
14
  async function stopCoverageInsideWorker(options, loader, runtimeOptions) {
17
15
  const coverageModule = await resolveCoverageProviderModule(options, loader);
18
- if (coverageModule) return coverageModule.stopCoverage?.(runtimeOptions);
19
- return null;
16
+ return coverageModule ? coverageModule.stopCoverage?.(runtimeOptions) : null;
20
17
  }
21
18
 
22
19
  let globalSetup = false;
23
20
  async function setupCommonEnv(config) {
24
- setupDefines(config.defines);
25
- setupEnv(config.env);
26
- if (globalSetup) return;
27
- globalSetup = true;
28
- setSafeTimers();
29
- if (config.globals) (await import('./globals.CJQ63oO0.js')).registerApiGlobally();
21
+ if (setupDefines(config.defines), setupEnv(config.env), !globalSetup && (globalSetup = true, setSafeTimers(), config.globals)) (await import('./globals.lgsmH00r.js')).registerApiGlobally();
30
22
  }
31
23
  function setupDefines(defines) {
32
24
  for (const key in defines) globalThis[key] = defines[key];
33
25
  }
34
26
  function setupEnv(env) {
35
- const state = getWorkerState();
36
- // same boolean-to-string assignment as VitestPlugin.configResolved
37
- const { PROD, DEV,...restEnvs } = env;
38
- state.metaEnv.PROD = PROD;
39
- state.metaEnv.DEV = DEV;
40
- for (const key in restEnvs) state.metaEnv[key] = env[key];
27
+ const state = getWorkerState(), { PROD, DEV,...restEnvs } = env;
28
+ for (const key in state.metaEnv.PROD = PROD, state.metaEnv.DEV = DEV, restEnvs) state.metaEnv[key] = env[key];
41
29
  }
42
30
  async function loadDiffConfig(config, moduleRunner) {
43
31
  if (typeof config.diff === "object") return config.diff;
44
32
  if (typeof config.diff !== "string") return;
45
33
  const diffModule = await moduleRunner.import(config.diff);
46
34
  if (diffModule && typeof diffModule.default === "object" && diffModule.default != null) return diffModule.default;
47
- else throw new Error(`invalid diff config file ${config.diff}. Must have a default export with config object`);
35
+ throw new Error(`invalid diff config file ${config.diff}. Must have a default export with config object`);
48
36
  }
49
37
  async function loadSnapshotSerializers(config, moduleRunner) {
50
- const files = config.snapshotSerializers;
51
- const snapshotSerializers = await Promise.all(files.map(async (file) => {
38
+ const files = config.snapshotSerializers, snapshotSerializers = await Promise.all(files.map(async (file) => {
52
39
  const mo = await moduleRunner.import(file);
53
40
  if (!mo || typeof mo.default !== "object" || mo.default === null) throw new Error(`invalid snapshot serializer file ${file}. Must export a default object`);
54
41
  const config = mo.default;