vitest 0.19.1 → 0.20.2

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 (35) hide show
  1. package/dist/browser.d.ts +48 -3
  2. package/dist/browser.mjs +9 -7
  3. package/dist/{chunk-api-setup.0cf2c96a.mjs → chunk-api-setup.7c4c8879.mjs} +7 -6
  4. package/dist/{chunk-constants.38b43a44.mjs → chunk-constants.16825f0c.mjs} +3 -2
  5. package/dist/{chunk-defaults.ed196a9a.mjs → chunk-defaults.1c51d585.mjs} +6 -4
  6. package/dist/chunk-integrations-globals.56a11010.mjs +26 -0
  7. package/dist/{chunk-utils-global.2aa95025.mjs → chunk-mock-date.9160e13b.mjs} +6 -36
  8. package/dist/{chunk-node-git.9058b82a.mjs → chunk-node-git.43dbdd42.mjs} +1 -1
  9. package/dist/{chunk-runtime-chain.f2e00f4c.mjs → chunk-runtime-chain.b6c2cdbc.mjs} +5 -3
  10. package/dist/{chunk-runtime-error.606e0393.mjs → chunk-runtime-error.0aa0dc06.mjs} +17 -13
  11. package/dist/{chunk-runtime-hooks.d4cadf47.mjs → chunk-runtime-hooks.3ee34848.mjs} +7 -4
  12. package/dist/{chunk-runtime-mocker.dfdfd57b.mjs → chunk-runtime-mocker.0a8f7c5e.mjs} +23 -17
  13. package/dist/{chunk-runtime-rpc.45d8ee19.mjs → chunk-runtime-rpc.dbf0b31d.mjs} +3 -1
  14. package/dist/chunk-utils-global.fa20c2f6.mjs +5 -0
  15. package/dist/{chunk-utils-source-map.8b066ce2.mjs → chunk-utils-source-map.8198ebd9.mjs} +1 -1
  16. package/dist/chunk-utils-timers.b48455ed.mjs +27 -0
  17. package/dist/chunk-vite-node-client.a247c2c2.mjs +320 -0
  18. package/dist/chunk-vite-node-debug.c5887932.mjs +76 -0
  19. package/dist/{chunk-vite-node-externalize.e9af6472.mjs → chunk-vite-node-externalize.45323563.mjs} +76 -22
  20. package/dist/{chunk-vite-node-utils.ad73f2ab.mjs → chunk-vite-node-utils.9dfd1e3f.mjs} +4 -323
  21. package/dist/cli.mjs +9 -7
  22. package/dist/config.cjs +3 -2
  23. package/dist/config.d.ts +1 -0
  24. package/dist/config.mjs +3 -2
  25. package/dist/entry.mjs +10 -8
  26. package/dist/index.d.ts +49 -4
  27. package/dist/index.mjs +7 -5
  28. package/dist/loader.mjs +36 -0
  29. package/dist/node.d.ts +49 -3
  30. package/dist/node.mjs +10 -7
  31. package/dist/suite.mjs +6 -4
  32. package/dist/worker.mjs +9 -6
  33. package/package.json +6 -5
  34. package/suppress-warnings.cjs +20 -0
  35. package/dist/chunk-integrations-globals.1018e651.mjs +0 -24
@@ -0,0 +1,320 @@
1
+ import { createRequire } from 'module';
2
+ import { pathToFileURL, fileURLToPath } from 'url';
3
+ import vm from 'vm';
4
+ import { y as resolve, d as dirname, B as isAbsolute, L as extname } from './chunk-mock-date.9160e13b.mjs';
5
+ import { s as slash, n as normalizeRequestId, b as toFilePath, i as isNodeBuiltin, c as isPrimitive, d as normalizeModuleId, m as mergeSlashes } from './chunk-vite-node-utils.9dfd1e3f.mjs';
6
+ import createDebug from 'debug';
7
+
8
+ const debugExecute = createDebug("vite-node:client:execute");
9
+ const debugNative = createDebug("vite-node:client:native");
10
+ const DEFAULT_REQUEST_STUBS = {
11
+ "/@vite/client": {
12
+ injectQuery: (id) => id,
13
+ createHotContext() {
14
+ return {
15
+ accept: () => {
16
+ },
17
+ prune: () => {
18
+ },
19
+ dispose: () => {
20
+ },
21
+ decline: () => {
22
+ },
23
+ invalidate: () => {
24
+ },
25
+ on: () => {
26
+ }
27
+ };
28
+ },
29
+ updateStyle(id, css) {
30
+ if (typeof document === "undefined")
31
+ return;
32
+ const element = document.getElementById(id);
33
+ if (element)
34
+ element.remove();
35
+ const head = document.querySelector("head");
36
+ const style = document.createElement("style");
37
+ style.setAttribute("type", "text/css");
38
+ style.id = id;
39
+ style.innerHTML = css;
40
+ head == null ? void 0 : head.appendChild(style);
41
+ }
42
+ }
43
+ };
44
+ class ModuleCacheMap extends Map {
45
+ normalizePath(fsPath) {
46
+ return normalizeModuleId(fsPath);
47
+ }
48
+ set(fsPath, mod) {
49
+ fsPath = this.normalizePath(fsPath);
50
+ if (!super.has(fsPath))
51
+ super.set(fsPath, mod);
52
+ else
53
+ Object.assign(super.get(fsPath), mod);
54
+ return this;
55
+ }
56
+ get(fsPath) {
57
+ fsPath = this.normalizePath(fsPath);
58
+ return super.get(fsPath);
59
+ }
60
+ delete(fsPath) {
61
+ fsPath = this.normalizePath(fsPath);
62
+ return super.delete(fsPath);
63
+ }
64
+ }
65
+ class ViteNodeRunner {
66
+ constructor(options) {
67
+ this.options = options;
68
+ this.root = options.root ?? process.cwd();
69
+ this.moduleCache = options.moduleCache ?? new ModuleCacheMap();
70
+ this.debug = options.debug ?? (typeof process !== "undefined" ? !!process.env.VITE_NODE_DEBUG_RUNNER : false);
71
+ }
72
+ async executeFile(file) {
73
+ return await this.cachedRequest(`/@fs/${slash(resolve(file))}`, []);
74
+ }
75
+ async executeId(id) {
76
+ return await this.cachedRequest(id, []);
77
+ }
78
+ async cachedRequest(rawId, callstack) {
79
+ var _a, _b, _c, _d;
80
+ const id = normalizeRequestId(rawId, this.options.base);
81
+ const fsPath = toFilePath(id, this.root);
82
+ if (callstack.includes(fsPath) && ((_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.exports))
83
+ return (_b = this.moduleCache.get(fsPath)) == null ? void 0 : _b.exports;
84
+ if ((_c = this.moduleCache.get(fsPath)) == null ? void 0 : _c.promise)
85
+ return (_d = this.moduleCache.get(fsPath)) == null ? void 0 : _d.promise;
86
+ const promise = this.directRequest(id, fsPath, callstack);
87
+ this.moduleCache.set(fsPath, { promise });
88
+ return await promise;
89
+ }
90
+ async directRequest(id, fsPath, _callstack) {
91
+ const callstack = [..._callstack, fsPath];
92
+ const request = async (dep) => {
93
+ var _a;
94
+ const fsPath2 = toFilePath(normalizeRequestId(dep, this.options.base), this.root);
95
+ const getStack = () => {
96
+ return `stack:
97
+ ${[...callstack, fsPath2].reverse().map((p) => `- ${p}`).join("\n")}`;
98
+ };
99
+ let debugTimer;
100
+ if (this.debug)
101
+ debugTimer = setTimeout(() => console.warn(() => `module ${fsPath2} takes over 2s to load.
102
+ ${getStack()}`), 2e3);
103
+ try {
104
+ if (callstack.includes(fsPath2)) {
105
+ const depExports = (_a = this.moduleCache.get(fsPath2)) == null ? void 0 : _a.exports;
106
+ if (depExports)
107
+ return depExports;
108
+ throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
109
+ }
110
+ const mod = await this.cachedRequest(dep, callstack);
111
+ return mod;
112
+ } finally {
113
+ if (debugTimer)
114
+ clearTimeout(debugTimer);
115
+ }
116
+ };
117
+ Object.defineProperty(request, "callstack", { get: () => callstack });
118
+ const resolveId = async (dep, callstackPosition = 1) => {
119
+ if (this.options.resolveId && this.shouldResolveId(dep)) {
120
+ let importer = callstack[callstack.length - callstackPosition];
121
+ if (importer && importer.startsWith("mock:"))
122
+ importer = importer.slice(5);
123
+ const { id: id2 } = await this.options.resolveId(dep, importer) || {};
124
+ dep = id2 && isAbsolute(id2) ? mergeSlashes(`/@fs/${id2}`) : id2 || dep;
125
+ }
126
+ return dep;
127
+ };
128
+ id = await resolveId(id, 2);
129
+ const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
130
+ if (id in requestStubs)
131
+ return requestStubs[id];
132
+ let { code: transformed, externalize } = await this.options.fetchModule(id);
133
+ if (externalize) {
134
+ debugNative(externalize);
135
+ const mod = await this.interopedImport(externalize);
136
+ this.moduleCache.set(fsPath, { exports: mod });
137
+ return mod;
138
+ }
139
+ if (transformed == null)
140
+ throw new Error(`[vite-node] Failed to load ${id}`);
141
+ const url = pathToFileURL(fsPath).href;
142
+ const meta = { url };
143
+ const exports = /* @__PURE__ */ Object.create(null);
144
+ exports[Symbol.toStringTag] = "Module";
145
+ this.moduleCache.set(fsPath, { code: transformed, exports });
146
+ const __filename = fileURLToPath(url);
147
+ const moduleProxy = {
148
+ set exports(value) {
149
+ exportAll(exports, value);
150
+ exports.default = value;
151
+ },
152
+ get exports() {
153
+ return exports;
154
+ }
155
+ };
156
+ let hotContext;
157
+ if (this.options.createHotContext) {
158
+ Object.defineProperty(meta, "hot", {
159
+ enumerable: true,
160
+ get: () => {
161
+ var _a, _b;
162
+ hotContext || (hotContext = (_b = (_a = this.options).createHotContext) == null ? void 0 : _b.call(_a, this, `/@fs/${fsPath}`));
163
+ return hotContext;
164
+ }
165
+ });
166
+ }
167
+ const context = this.prepareContext({
168
+ __vite_ssr_import__: request,
169
+ __vite_ssr_dynamic_import__: request,
170
+ __vite_ssr_exports__: exports,
171
+ __vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
172
+ __vite_ssr_import_meta__: meta,
173
+ __vitest_resolve_id__: resolveId,
174
+ require: createRequire(url),
175
+ exports,
176
+ module: moduleProxy,
177
+ __filename,
178
+ __dirname: dirname(__filename)
179
+ });
180
+ debugExecute(__filename);
181
+ if (transformed[0] === "#")
182
+ transformed = transformed.replace(/^\#\!.*/, (s) => " ".repeat(s.length));
183
+ const fn = vm.runInThisContext(`'use strict';async (${Object.keys(context).join(",")})=>{{${transformed}
184
+ }}`, {
185
+ filename: fsPath,
186
+ lineOffset: 0
187
+ });
188
+ await fn(...Object.values(context));
189
+ return exports;
190
+ }
191
+ prepareContext(context) {
192
+ return context;
193
+ }
194
+ shouldResolveId(dep) {
195
+ if (isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS) || dep.startsWith("/@vite"))
196
+ return false;
197
+ return !isAbsolute(dep) || !extname(dep);
198
+ }
199
+ shouldInterop(path, mod) {
200
+ if (this.options.interopDefault === false)
201
+ return false;
202
+ return !path.endsWith(".mjs") && "default" in mod;
203
+ }
204
+ async interopedImport(path) {
205
+ const mod = await import(path);
206
+ if (this.shouldInterop(path, mod)) {
207
+ const tryDefault = this.hasNestedDefault(mod);
208
+ return new Proxy(mod, {
209
+ get: proxyMethod("get", tryDefault),
210
+ set: proxyMethod("set", tryDefault),
211
+ has: proxyMethod("has", tryDefault),
212
+ deleteProperty: proxyMethod("deleteProperty", tryDefault)
213
+ });
214
+ }
215
+ return mod;
216
+ }
217
+ hasNestedDefault(target) {
218
+ return "__esModule" in target && target.__esModule && "default" in target.default;
219
+ }
220
+ }
221
+ function proxyMethod(name, tryDefault) {
222
+ return function(target, key, ...args) {
223
+ const result = Reflect[name](target, key, ...args);
224
+ if (isPrimitive(target.default))
225
+ return result;
226
+ if (tryDefault && key === "default" || typeof result === "undefined")
227
+ return Reflect[name](target.default, key, ...args);
228
+ return result;
229
+ };
230
+ }
231
+ function exportAll(exports, sourceModule) {
232
+ if (exports === sourceModule)
233
+ return;
234
+ for (const key in sourceModule) {
235
+ if (key !== "default") {
236
+ try {
237
+ Object.defineProperty(exports, key, {
238
+ enumerable: true,
239
+ configurable: true,
240
+ get() {
241
+ return sourceModule[key];
242
+ }
243
+ });
244
+ } catch (_err) {
245
+ }
246
+ }
247
+ }
248
+ }
249
+
250
+ const DEFAULT_TIMEOUT = 6e4;
251
+ function createBirpc(functions, options) {
252
+ const {
253
+ post,
254
+ on,
255
+ eventNames = [],
256
+ serialize = (i) => i,
257
+ deserialize = (i) => i,
258
+ timeout = DEFAULT_TIMEOUT
259
+ } = options;
260
+ const rpcPromiseMap = /* @__PURE__ */ new Map();
261
+ const rpc = new Proxy({}, {
262
+ get(_, method) {
263
+ const sendEvent = (...args) => {
264
+ post(serialize({ m: method, a: args, t: "q" }));
265
+ };
266
+ if (eventNames.includes(method)) {
267
+ sendEvent.asEvent = sendEvent;
268
+ return sendEvent;
269
+ }
270
+ const sendCall = (...args) => {
271
+ return new Promise((resolve, reject) => {
272
+ const id = nanoid();
273
+ rpcPromiseMap.set(id, { resolve, reject });
274
+ post(serialize({ m: method, a: args, i: id, t: "q" }));
275
+ if (timeout >= 0) {
276
+ setTimeout(() => {
277
+ reject(new Error(`[birpc] timeout on calling "${method}"`));
278
+ rpcPromiseMap.delete(id);
279
+ }, timeout);
280
+ }
281
+ });
282
+ };
283
+ sendCall.asEvent = sendEvent;
284
+ return sendCall;
285
+ }
286
+ });
287
+ on(async (data, ...extra) => {
288
+ const msg = deserialize(data);
289
+ if (msg.t === "q") {
290
+ const { m: method, a: args } = msg;
291
+ let result, error;
292
+ try {
293
+ result = await functions[method].apply(rpc, args);
294
+ } catch (e) {
295
+ error = e;
296
+ }
297
+ if (msg.i)
298
+ post(serialize({ t: "s", i: msg.i, r: result, e: error }), ...extra);
299
+ } else {
300
+ const { i: ack, r: result, e: error } = msg;
301
+ const promise = rpcPromiseMap.get(ack);
302
+ if (error)
303
+ promise?.reject(error);
304
+ else
305
+ promise?.resolve(result);
306
+ rpcPromiseMap.delete(ack);
307
+ }
308
+ });
309
+ return rpc;
310
+ }
311
+ const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
312
+ function nanoid(size = 21) {
313
+ let id = "";
314
+ let i = size;
315
+ while (i--)
316
+ id += urlAlphabet[Math.random() * 64 | 0];
317
+ return id;
318
+ }
319
+
320
+ export { ModuleCacheMap as M, ViteNodeRunner as V, createBirpc as c };
@@ -0,0 +1,76 @@
1
+ import { existsSync, promises } from 'fs';
2
+ import { y as resolve, p as picocolors, j as join } from './chunk-mock-date.9160e13b.mjs';
3
+ import 'path';
4
+ import 'tty';
5
+ import 'local-pkg';
6
+
7
+ function hashCode(s) {
8
+ return s.split("").reduce((a, b) => {
9
+ a = (a << 5) - a + b.charCodeAt(0);
10
+ return a & a;
11
+ }, 0);
12
+ }
13
+ class Debugger {
14
+ constructor(root, options) {
15
+ this.options = options;
16
+ this.externalizeMap = /* @__PURE__ */ new Map();
17
+ if (options.dumpModules)
18
+ this.dumpDir = resolve(root, options.dumpModules === true ? ".vite-node/dump" : options.dumpModules);
19
+ if (this.dumpDir) {
20
+ if (options.loadDumppedModules)
21
+ console.info(picocolors.exports.gray(`[vite-node] [debug] load modules from ${this.dumpDir}`));
22
+ else
23
+ console.info(picocolors.exports.gray(`[vite-node] [debug] dump modules to ${this.dumpDir}`));
24
+ }
25
+ this.initPromise = this.clearDump();
26
+ }
27
+ async clearDump() {
28
+ if (!this.dumpDir)
29
+ return;
30
+ if (!this.options.loadDumppedModules && existsSync(this.dumpDir))
31
+ await promises.rm(this.dumpDir, { recursive: true, force: true });
32
+ await promises.mkdir(this.dumpDir, { recursive: true });
33
+ }
34
+ encodeId(id) {
35
+ return `${id.replace(/[^\w@_-]/g, "_").replace(/_+/g, "_")}-${hashCode(id)}.js`;
36
+ }
37
+ async recordExternalize(id, path) {
38
+ if (!this.dumpDir)
39
+ return;
40
+ this.externalizeMap.set(id, path);
41
+ await this.writeInfo();
42
+ }
43
+ async dumpFile(id, result) {
44
+ if (!result || !this.dumpDir)
45
+ return;
46
+ await this.initPromise;
47
+ const name = this.encodeId(id);
48
+ return await promises.writeFile(join(this.dumpDir, name), `// ${id.replace(/\0/g, "\\0")}
49
+ ${result.code}`, "utf-8");
50
+ }
51
+ async loadDump(id) {
52
+ if (!this.dumpDir)
53
+ return null;
54
+ await this.initPromise;
55
+ const name = this.encodeId(id);
56
+ const path = join(this.dumpDir, name);
57
+ if (!existsSync(path))
58
+ return null;
59
+ const code = await promises.readFile(path, "utf-8");
60
+ return {
61
+ code: code.replace(/^\/\/.*?\n/, ""),
62
+ map: void 0
63
+ };
64
+ }
65
+ async writeInfo() {
66
+ if (!this.dumpDir)
67
+ return;
68
+ const info = JSON.stringify({
69
+ time: new Date().toLocaleString(),
70
+ externalize: Object.fromEntries(this.externalizeMap.entries())
71
+ }, null, 2);
72
+ return promises.writeFile(join(this.dumpDir, "info.json"), info, "utf-8");
73
+ }
74
+ }
75
+
76
+ export { Debugger };
@@ -1,22 +1,24 @@
1
- import { j as join, D as basename, d as dirname, C as resolve, E as AggregateErrorPonyfill, p as picocolors, F as isAbsolute, G as relative, c as slash$2, t as isNode, v as relativePath, H as getTests, h as getFullName, B as hasFailed, I as hasFailedSnapshot, J as safeSetInterval, K as safeClearInterval, L as getSuites, s as safeSetTimeout, z as shuffle, u as toArray$1, M as normalize, n as noop$1, k as safeClearTimeout, N as deepMerge, O as toNamespacedPath, b as getCallLastIndex, l as notNullish, P as ensurePackageInstalled, Q as stdout } from './chunk-utils-global.2aa95025.mjs';
2
- import { p as pLimit, c as configDefaults, r as resolveC8Options, a as cleanCoverage, b as reportCoverage, d as envPackageNames } from './chunk-defaults.ed196a9a.mjs';
1
+ import { j as join, z as basename, d as dirname, y as resolve, A as AggregateErrorPonyfill, p as picocolors, B as isAbsolute, C as relative, s as slash$2, l as isNode, o as relativePath, D as getTests, e as getFullName, x as hasFailed, E as hasFailedSnapshot, F as getSuites, v as shuffle, t as toArray$1, G as normalize, n as noop$1, H as deepMerge, I as toNamespacedPath, g as getCallLastIndex, f as notNullish, J as ensurePackageInstalled, K as stdout } from './chunk-mock-date.9160e13b.mjs';
2
+ import { p as pLimit, c as configDefaults, r as resolveC8Options, a as cleanCoverage, b as reportCoverage, d as envPackageNames } from './chunk-defaults.1c51d585.mjs';
3
3
  import { loadConfigFromFile, createServer, mergeConfig } from 'vite';
4
4
  import path$a from 'path';
5
5
  import _url, { fileURLToPath } from 'url';
6
6
  import process$1 from 'process';
7
7
  import fs$8, { promises, existsSync, readFileSync } from 'fs';
8
- import { d as distDir, c as configFiles, a as defaultPort } from './chunk-constants.38b43a44.mjs';
8
+ import { d as distDir, r as rootDir, c as configFiles, a as defaultPort } from './chunk-constants.16825f0c.mjs';
9
9
  import require$$0, { cpus, hostname } from 'os';
10
10
  import util$2 from 'util';
11
11
  import require$$0$1 from 'stream';
12
12
  import require$$2 from 'events';
13
13
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
14
- import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toArray, b as toFilePath, w as withInlineSourcemap, c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-utils.ad73f2ab.mjs';
14
+ import { c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-client.a247c2c2.mjs';
15
15
  import createDebug from 'debug';
16
+ import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toArray, b as toFilePath, w as withInlineSourcemap } from './chunk-vite-node-utils.9dfd1e3f.mjs';
16
17
  import { MessageChannel } from 'worker_threads';
17
18
  import { Tinypool } from 'tinypool';
18
19
  import { performance } from 'perf_hooks';
19
- import { c as stripAnsi, d as cliTruncate, p as parseStacktrace, e as stringWidth, h as ansiStyles, i as sliceAnsi, j as interpretSourcePos, s as stringify$5, u as unifiedDiff, b as posToNumber, l as lineSplitRE } from './chunk-utils-source-map.8b066ce2.mjs';
20
+ import { c as stripAnsi, d as cliTruncate, p as parseStacktrace, e as stringWidth, h as ansiStyles, i as sliceAnsi, j as interpretSourcePos, s as stringify$5, u as unifiedDiff, b as posToNumber, l as lineSplitRE } from './chunk-utils-source-map.8198ebd9.mjs';
21
+ import { b as safeSetInterval, c as safeClearInterval, s as safeSetTimeout, a as safeClearTimeout } from './chunk-utils-timers.b48455ed.mjs';
20
22
  import { resolveModule } from 'local-pkg';
21
23
  import { createHash } from 'crypto';
22
24
  import { o as onetime, s as signalExit } from './vendor-index.61438b77.mjs';
@@ -24,7 +26,7 @@ import MagicString from './chunk-magic-string.efe26975.mjs';
24
26
  import require$$0$2 from 'readline';
25
27
  import { p as prompts } from './vendor-index.de788b6a.mjs';
26
28
 
27
- var version$1 = "0.19.1";
29
+ var version$1 = "0.20.2";
28
30
 
29
31
  class EndError extends Error {
30
32
  constructor(value) {
@@ -6767,7 +6769,8 @@ function guessCJSversion(id) {
6767
6769
  }
6768
6770
  }
6769
6771
  }
6770
- async function shouldExternalize(id, options, cache = /* @__PURE__ */ new Map()) {
6772
+ const _defaultExternalizeCache = /* @__PURE__ */ new Map();
6773
+ async function shouldExternalize(id, options, cache = _defaultExternalizeCache) {
6771
6774
  if (!cache.has(id))
6772
6775
  cache.set(id, _shouldExternalize(id, options));
6773
6776
  return cache.get(id);
@@ -6828,6 +6831,7 @@ class ViteNodeServer {
6828
6831
  this.fetchPromiseMap = /* @__PURE__ */ new Map();
6829
6832
  this.transformPromiseMap = /* @__PURE__ */ new Map();
6830
6833
  this.fetchCache = /* @__PURE__ */ new Map();
6834
+ this.externalizeCache = /* @__PURE__ */ new Map();
6831
6835
  var _a, _b;
6832
6836
  const ssrOptions = server.config.ssr;
6833
6837
  if (ssrOptions) {
@@ -6839,9 +6843,17 @@ class ViteNodeServer {
6839
6843
  options.deps.inline.push(...toArray(ssrOptions.noExternal));
6840
6844
  }
6841
6845
  }
6846
+ if (process.env.VITE_NODE_DEBUG_DUMP) {
6847
+ options.debug = Object.assign({
6848
+ dumpModules: !!process.env.VITE_NODE_DEBUG_DUMP,
6849
+ loadDumppedModules: process.env.VITE_NODE_DEBUG_DUMP === "load"
6850
+ }, options.debug ?? {});
6851
+ }
6852
+ if (options.debug)
6853
+ import('./chunk-vite-node-debug.c5887932.mjs').then((r) => this.debugger = new r.Debugger(server.config.root, options.debug));
6842
6854
  }
6843
6855
  shouldExternalize(id) {
6844
- return shouldExternalize(id, this.options.deps);
6856
+ return shouldExternalize(id, this.options.deps, this.externalizeCache);
6845
6857
  }
6846
6858
  async resolveId(id, importer) {
6847
6859
  if (importer && !importer.startsWith(this.server.config.root))
@@ -6879,6 +6891,7 @@ class ViteNodeServer {
6879
6891
  return "web";
6880
6892
  }
6881
6893
  async _fetchModule(id) {
6894
+ var _a;
6882
6895
  let result;
6883
6896
  const filePath = toFilePath(id, this.server.config.root);
6884
6897
  const module = this.server.moduleGraph.getModuleById(id);
@@ -6889,6 +6902,7 @@ class ViteNodeServer {
6889
6902
  const externalize = await this.shouldExternalize(filePath);
6890
6903
  if (externalize) {
6891
6904
  result = { externalize };
6905
+ (_a = this.debugger) == null ? void 0 : _a.recordExternalize(id, externalize);
6892
6906
  } else {
6893
6907
  const r = await this._transformRequest(id);
6894
6908
  result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
@@ -6900,8 +6914,14 @@ class ViteNodeServer {
6900
6914
  return result;
6901
6915
  }
6902
6916
  async _transformRequest(id) {
6917
+ var _a, _b, _c, _d;
6903
6918
  debugRequest(id);
6904
6919
  let result = null;
6920
+ if ((_a = this.options.debug) == null ? void 0 : _a.loadDumppedModules) {
6921
+ result = await ((_b = this.debugger) == null ? void 0 : _b.loadDump(id)) ?? null;
6922
+ if (result)
6923
+ return result;
6924
+ }
6905
6925
  if (this.getTransformMode(id) === "web") {
6906
6926
  result = await this.server.transformRequest(id);
6907
6927
  if (result)
@@ -6912,6 +6932,8 @@ class ViteNodeServer {
6912
6932
  const sourcemap = this.options.sourcemap ?? "inline";
6913
6933
  if (sourcemap === "inline" && result && !id.includes("node_modules"))
6914
6934
  withInlineSourcemap(result);
6935
+ if ((_c = this.options.debug) == null ? void 0 : _c.dumpModules)
6936
+ await ((_d = this.debugger) == null ? void 0 : _d.dumpFile(id, result));
6915
6937
  return result;
6916
6938
  }
6917
6939
  }
@@ -6979,16 +7001,26 @@ function addSnapshotResult(summary, result) {
6979
7001
  }
6980
7002
 
6981
7003
  const workerPath = _url.pathToFileURL(resolve(distDir, "./worker.mjs")).href;
7004
+ const loaderPath = _url.pathToFileURL(resolve(distDir, "./loader.mjs")).href;
7005
+ const suppressLoaderWarningsPath = resolve(rootDir, "./suppress-warnings.cjs");
6982
7006
  function createPool(ctx) {
6983
- var _a;
7007
+ var _a, _b;
6984
7008
  const threadsCount = ctx.config.watch ? Math.max(Math.floor(cpus().length / 2), 1) : Math.max(cpus().length - 1, 1);
6985
7009
  const maxThreads = ctx.config.maxThreads ?? threadsCount;
6986
7010
  const minThreads = ctx.config.minThreads ?? threadsCount;
7011
+ const conditions = (_a = ctx.server.config.resolve.conditions) == null ? void 0 : _a.flatMap((c) => ["-C", c]);
6987
7012
  const options = {
6988
7013
  filename: workerPath,
6989
7014
  useAtomics: false,
6990
7015
  maxThreads,
6991
- minThreads
7016
+ minThreads,
7017
+ execArgv: ctx.config.deps.registerNodeLoader ? [
7018
+ "--require",
7019
+ suppressLoaderWarningsPath,
7020
+ "--experimental-loader",
7021
+ loaderPath,
7022
+ ...conditions || []
7023
+ ] : []
6992
7024
  };
6993
7025
  if (ctx.config.isolate) {
6994
7026
  options.isolateWorkers = true;
@@ -7000,7 +7032,7 @@ function createPool(ctx) {
7000
7032
  options.minThreads = 1;
7001
7033
  }
7002
7034
  if (ctx.config.coverage.enabled)
7003
- (_a = process.env).NODE_V8_COVERAGE || (_a.NODE_V8_COVERAGE = ctx.config.coverage.tempDirectory);
7035
+ (_b = process.env).NODE_V8_COVERAGE || (_b.NODE_V8_COVERAGE = ctx.config.coverage.tempDirectory);
7004
7036
  options.env = {
7005
7037
  TEST: "true",
7006
7038
  VITEST: "true",
@@ -7295,7 +7327,8 @@ class BaseReporter {
7295
7327
  this.end = performance.now();
7296
7328
  await this.reportSummary(files);
7297
7329
  if (errors.length) {
7298
- process.exitCode = 1;
7330
+ if (!this.ctx.config.dangerouslyIgnoreUnhandledErrors)
7331
+ process.exitCode = 1;
7299
7332
  this.ctx.logger.printUnhandledErrors(errors);
7300
7333
  }
7301
7334
  }
@@ -7442,10 +7475,13 @@ ${BADGE}${TRIGGER} ${picocolors.exports.blue(`x${rerun}`)}
7442
7475
  await this.printTaskErrors(failedTests, errorDivider);
7443
7476
  }
7444
7477
  const executionTime = this.end - this.start;
7445
- const threadTime = files.reduce((acc, test) => {
7478
+ const collectTime = files.reduce((acc, test) => acc + Math.max(0, test.collectDuration || 0), 0);
7479
+ const setupTime = files.reduce((acc, test) => acc + Math.max(0, test.setupDuration || 0), 0);
7480
+ const testsTime = files.reduce((acc, test) => {
7446
7481
  var _a2;
7447
- return acc + Math.max(0, ((_a2 = test.result) == null ? void 0 : _a2.duration) || 0) + Math.max(0, test.collectDuration || 0);
7482
+ return acc + Math.max(0, ((_a2 = test.result) == null ? void 0 : _a2.duration) || 0);
7448
7483
  }, 0);
7484
+ const threadTime = collectTime + testsTime + setupTime;
7449
7485
  const padTitle = (str) => picocolors.exports.dim(`${str.padStart(10)} `);
7450
7486
  const time = (time2) => {
7451
7487
  if (time2 > 1e3)
@@ -7463,7 +7499,7 @@ ${BADGE}${TRIGGER} ${picocolors.exports.blue(`x${rerun}`)}
7463
7499
  if (this.watchFilters)
7464
7500
  logger.log(padTitle("Time"), time(threadTime));
7465
7501
  else
7466
- logger.log(padTitle("Time"), time(executionTime) + picocolors.exports.gray(` (in thread ${time(threadTime)}, ${(executionTime / threadTime * 100).toFixed(2)}%)`));
7502
+ logger.log(padTitle("Time"), time(executionTime) + picocolors.exports.gray(` (setup ${time(setupTime)}, collect ${time(collectTime)}, tests ${time(testsTime)})`));
7467
7503
  logger.log();
7468
7504
  }
7469
7505
  async printTaskErrors(tasks, errorDivider) {
@@ -8212,6 +8248,7 @@ class StateManager {
8212
8248
  constructor() {
8213
8249
  this.filesMap = /* @__PURE__ */ new Map();
8214
8250
  this.pathsSet = /* @__PURE__ */ new Set();
8251
+ this.collectingPromise = void 0;
8215
8252
  this.idMap = /* @__PURE__ */ new Map();
8216
8253
  this.taskFileMap = /* @__PURE__ */ new WeakMap();
8217
8254
  this.errorsSet = /* @__PURE__ */ new Set();
@@ -8226,7 +8263,21 @@ class StateManager {
8226
8263
  getUnhandledErrors() {
8227
8264
  return Array.from(this.errorsSet.values());
8228
8265
  }
8229
- getPaths() {
8266
+ startCollectingPaths() {
8267
+ let _resolve;
8268
+ const promise = new Promise((resolve) => {
8269
+ _resolve = resolve;
8270
+ });
8271
+ this.collectingPromise = { promise, resolve: _resolve };
8272
+ }
8273
+ finishCollectingPaths() {
8274
+ var _a;
8275
+ (_a = this.collectingPromise) == null ? void 0 : _a.resolve();
8276
+ this.collectingPromise = void 0;
8277
+ }
8278
+ async getPaths() {
8279
+ var _a;
8280
+ await ((_a = this.collectingPromise) == null ? void 0 : _a.promise);
8230
8281
  return Array.from(this.pathsSet);
8231
8282
  }
8232
8283
  getFiles(keys) {
@@ -8479,7 +8530,7 @@ function resolveApiConfig(options) {
8479
8530
  return api;
8480
8531
  }
8481
8532
  function resolveConfig(options, viteConfig) {
8482
- var _a, _b, _c, _d;
8533
+ var _a, _b, _c, _d, _e;
8483
8534
  if (options.dom) {
8484
8535
  if (((_a = viteConfig.test) == null ? void 0 : _a.environment) != null && viteConfig.test.environment !== "happy-dom") {
8485
8536
  console.warn(picocolors.exports.yellow(`${picocolors.exports.inverse(picocolors.exports.yellow(" Vitest "))} Your config.test.environment ("${viteConfig.test.environment}") conflicts with --dom flag ("happy-dom"), ignoring "${viteConfig.test.environment}"`));
@@ -8516,6 +8567,7 @@ function resolveConfig(options, viteConfig) {
8516
8567
  resolved.deps.inline.push(...extraInlineDeps);
8517
8568
  }
8518
8569
  }
8570
+ (_c = resolved.deps).registerNodeLoader ?? (_c.registerNodeLoader = true);
8519
8571
  resolved.testNamePattern = resolved.testNamePattern ? resolved.testNamePattern instanceof RegExp ? resolved.testNamePattern : new RegExp(resolved.testNamePattern) : void 0;
8520
8572
  const CI = !!process.env.CI;
8521
8573
  const UPDATE_SNAPSHOT = resolved.update || process.env.UPDATE_SNAPSHOT;
@@ -8544,11 +8596,11 @@ function resolveConfig(options, viteConfig) {
8544
8596
  resolved.passWithNoTests ?? (resolved.passWithNoTests = true);
8545
8597
  resolved.css ?? (resolved.css = {});
8546
8598
  if (typeof resolved.css === "object")
8547
- (_c = resolved.css).include ?? (_c.include = [/\.module\./]);
8599
+ (_d = resolved.css).include ?? (_d.include = [/\.module\./]);
8548
8600
  resolved.cache ?? (resolved.cache = { dir: "" });
8549
8601
  if (resolved.cache)
8550
8602
  resolved.cache.dir = VitestCache.resolveCacheDir(resolved.root, resolved.cache.dir);
8551
- if (!((_d = resolved.sequence) == null ? void 0 : _d.sequencer)) {
8603
+ if (!((_e = resolved.sequence) == null ? void 0 : _e.sequencer)) {
8552
8604
  resolved.sequence ?? (resolved.sequence = {});
8553
8605
  resolved.sequence.sequencer = resolved.sequence.shuffle ? RandomSequencer : BaseSequencer;
8554
8606
  }
@@ -9041,7 +9093,7 @@ createLogUpdate(process$1.stdout);
9041
9093
 
9042
9094
  createLogUpdate(process$1.stderr);
9043
9095
 
9044
- var version = "0.19.1";
9096
+ var version = "0.20.2";
9045
9097
 
9046
9098
  function fileFromParsedStack(stack) {
9047
9099
  var _a, _b;
@@ -9408,7 +9460,7 @@ class Vitest {
9408
9460
  }
9409
9461
  async filterTestsBySource(tests) {
9410
9462
  if (this.config.changed && !this.config.related) {
9411
- const { VitestGit } = await import('./chunk-node-git.9058b82a.mjs');
9463
+ const { VitestGit } = await import('./chunk-node-git.43dbdd42.mjs');
9412
9464
  const vitestGit = new VitestGit(this.config.root);
9413
9465
  const related2 = await vitestGit.findChangedFiles({
9414
9466
  changedSince: this.config.changed
@@ -9440,6 +9492,7 @@ class Vitest {
9440
9492
  }
9441
9493
  async runFiles(paths) {
9442
9494
  await this.runningPromise;
9495
+ this.state.startCollectingPaths();
9443
9496
  this.runningPromise = (async () => {
9444
9497
  if (!this.pool)
9445
9498
  this.pool = createPool(this);
@@ -9461,6 +9514,7 @@ class Vitest {
9461
9514
  await this.cache.results.writeToCache();
9462
9515
  })().finally(() => {
9463
9516
  this.runningPromise = void 0;
9517
+ this.state.finishCollectingPaths();
9464
9518
  });
9465
9519
  return await this.runningPromise;
9466
9520
  }
@@ -9992,7 +10046,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
9992
10046
  await ctx.setServer(options, server);
9993
10047
  haveStarted = true;
9994
10048
  if (options.api && options.watch)
9995
- (await import('./chunk-api-setup.0cf2c96a.mjs')).setup(ctx);
10049
+ (await import('./chunk-api-setup.7c4c8879.mjs')).setup(ctx);
9996
10050
  } catch (err) {
9997
10051
  ctx.logger.printError(err, true);
9998
10052
  process.exit(1);