vitest 0.21.1 → 0.23.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 (50) hide show
  1. package/LICENSE.md +61 -33
  2. package/dist/browser.d.ts +5 -5
  3. package/dist/browser.mjs +12 -10
  4. package/dist/{chunk-api-setup.7a6ba7fb.mjs → chunk-api-setup.5fc06d1d.mjs} +94 -91
  5. package/dist/chunk-constants.6196597b.mjs +284 -0
  6. package/dist/chunk-env-node.ceb43f1c.mjs +403 -0
  7. package/dist/{chunk-install-pkg.6c6dc0c2.mjs → chunk-install-pkg.e081fc1b.mjs} +2 -1
  8. package/dist/chunk-integrations-coverage.99c020eb.mjs +166 -0
  9. package/dist/{chunk-integrations-globals.44a8f047.mjs → chunk-integrations-globals.ef598c23.mjs} +8 -9
  10. package/dist/{chunk-magic-string.efe26975.mjs → chunk-magic-string.56b2b543.mjs} +30 -10
  11. package/dist/chunk-mock-date.0d86eaa5.mjs +332 -0
  12. package/dist/chunk-node-git.6f289b0a.mjs +84 -0
  13. package/dist/{chunk-runtime-chain.98d42d89.mjs → chunk-runtime-chain.2af36ddf.mjs} +507 -172
  14. package/dist/{chunk-runtime-error.87a2b5a2.mjs → chunk-runtime-error.ed9b4f70.mjs} +208 -76
  15. package/dist/{chunk-runtime-hooks.453f8858.mjs → chunk-runtime-hooks.75ce0575.mjs} +18 -12
  16. package/dist/{chunk-runtime-mocker.23b62bfa.mjs → chunk-runtime-mocker.fc76f21d.mjs} +18 -11
  17. package/dist/{chunk-runtime-rpc.b50ab560.mjs → chunk-runtime-rpc.3fe371e9.mjs} +1 -2
  18. package/dist/{chunk-utils-source-map.94107ee8.mjs → chunk-utils-source-map.70ee97e1.mjs} +11 -4
  19. package/dist/{chunk-vite-node-client.fdd9592c.mjs → chunk-vite-node-client.74ebe3d5.mjs} +97 -31
  20. package/dist/{chunk-vite-node-debug.09afb76f.mjs → chunk-vite-node-debug.2d8a1dc3.mjs} +3 -3
  21. package/dist/{chunk-vite-node-externalize.27aee038.mjs → chunk-vite-node-externalize.41bf722e.mjs} +644 -222
  22. package/dist/{chunk-vite-node-utils.f34df9d3.mjs → chunk-vite-node-utils.68573626.mjs} +60 -42
  23. package/dist/cli-wrapper.mjs +128 -0
  24. package/dist/cli.mjs +29 -20
  25. package/dist/config.cjs +5 -2
  26. package/dist/config.d.ts +8 -4
  27. package/dist/config.mjs +4 -3
  28. package/dist/entry.mjs +20 -15
  29. package/dist/environments.d.ts +23 -0
  30. package/dist/environments.mjs +3 -0
  31. package/dist/{global-60f880c6.d.ts → global-ea084c9f.d.ts} +627 -178
  32. package/dist/{index-4a906fa4.d.ts → index-5f09f4d0.d.ts} +3 -50
  33. package/dist/index.d.ts +6 -6
  34. package/dist/index.mjs +7 -6
  35. package/dist/loader.mjs +3 -3
  36. package/dist/node.d.ts +5 -4
  37. package/dist/node.mjs +19 -16
  38. package/dist/suite.mjs +6 -5
  39. package/dist/vendor-index.0557b03a.mjs +147 -0
  40. package/dist/vendor-index.13e3bda3.mjs +61 -0
  41. package/dist/{chunk-node-git.c2be9c49.mjs → vendor-index.4aeeb598.mjs} +4 -72
  42. package/dist/{vendor-index.61438b77.mjs → vendor-index.731a22f2.mjs} +1 -61
  43. package/dist/worker.mjs +20 -18
  44. package/package.json +19 -16
  45. package/vitest.mjs +1 -1
  46. package/dist/chunk-constants.26dc9f85.mjs +0 -38
  47. package/dist/chunk-defaults.02abff90.mjs +0 -680
  48. package/dist/chunk-mock-date.bc81a3ac.mjs +0 -555
  49. package/dist/chunk-utils-global.fa20c2f6.mjs +0 -5
  50. package/dist/mocker-5e2a8e41.d.ts +0 -3
@@ -1,8 +1,8 @@
1
1
  import { createRequire } from 'module';
2
2
  import { pathToFileURL, fileURLToPath } from 'url';
3
3
  import vm from 'vm';
4
- import { y as resolve, d as dirname, B as isAbsolute, L as extname } from './chunk-mock-date.bc81a3ac.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.f34df9d3.mjs';
4
+ import { a as resolve, d as dirname, i as isAbsolute, h as extname } from './chunk-constants.6196597b.mjs';
5
+ import { s as slash, n as normalizeRequestId, b as toFilePath, i as isNodeBuiltin, c as isPrimitive, g as getType, d as normalizeModuleId, m as mergeSlashes } from './chunk-vite-node-utils.68573626.mjs';
6
6
  import createDebug from 'debug';
7
7
 
8
8
  const debugExecute = createDebug("vite-node:client:execute");
@@ -45,7 +45,7 @@ class ModuleCacheMap extends Map {
45
45
  normalizePath(fsPath) {
46
46
  return normalizeModuleId(fsPath);
47
47
  }
48
- set(fsPath, mod) {
48
+ update(fsPath, mod) {
49
49
  fsPath = this.normalizePath(fsPath);
50
50
  if (!super.has(fsPath))
51
51
  super.set(fsPath, mod);
@@ -53,14 +53,48 @@ class ModuleCacheMap extends Map {
53
53
  Object.assign(super.get(fsPath), mod);
54
54
  return this;
55
55
  }
56
+ set(fsPath, mod) {
57
+ fsPath = this.normalizePath(fsPath);
58
+ return super.set(fsPath, mod);
59
+ }
56
60
  get(fsPath) {
57
61
  fsPath = this.normalizePath(fsPath);
62
+ if (!super.has(fsPath))
63
+ super.set(fsPath, {});
58
64
  return super.get(fsPath);
59
65
  }
60
66
  delete(fsPath) {
61
67
  fsPath = this.normalizePath(fsPath);
62
68
  return super.delete(fsPath);
63
69
  }
70
+ invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
71
+ for (const _id of ids) {
72
+ const id = this.normalizePath(_id);
73
+ if (invalidated.has(id))
74
+ continue;
75
+ invalidated.add(id);
76
+ const mod = super.get(id);
77
+ if (mod == null ? void 0 : mod.importers)
78
+ this.invalidateDepTree(mod.importers, invalidated);
79
+ super.delete(id);
80
+ }
81
+ return invalidated;
82
+ }
83
+ invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
84
+ for (const _id of ids) {
85
+ const id = this.normalizePath(_id);
86
+ if (invalidated.has(id))
87
+ continue;
88
+ invalidated.add(id);
89
+ const subIds = Array.from(super.entries()).filter(([, mod]) => {
90
+ var _a;
91
+ return (_a = mod.importers) == null ? void 0 : _a.has(id);
92
+ }).map(([key]) => key);
93
+ subIds.length && this.invalidateSubDepTree(subIds, invalidated);
94
+ super.delete(id);
95
+ }
96
+ return invalidated;
97
+ }
64
98
  }
65
99
  class ViteNodeRunner {
66
100
  constructor(options) {
@@ -76,39 +110,44 @@ class ViteNodeRunner {
76
110
  return await this.cachedRequest(id, []);
77
111
  }
78
112
  async cachedRequest(rawId, callstack) {
79
- var _a, _b, _c, _d;
80
113
  const id = normalizeRequestId(rawId, this.options.base);
81
114
  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;
115
+ const mod = this.moduleCache.get(fsPath);
116
+ const importee = callstack[callstack.length - 1];
117
+ if (!mod.importers)
118
+ mod.importers = /* @__PURE__ */ new Set();
119
+ if (importee)
120
+ mod.importers.add(importee);
121
+ if (callstack.includes(fsPath) && mod.exports)
122
+ return mod.exports;
123
+ if (mod.promise)
124
+ return mod.promise;
86
125
  const promise = this.directRequest(id, fsPath, callstack);
87
- this.moduleCache.set(fsPath, { promise });
126
+ Object.assign(mod, { promise });
88
127
  return await promise;
89
128
  }
90
129
  async directRequest(id, fsPath, _callstack) {
91
130
  const callstack = [..._callstack, fsPath];
131
+ const mod = this.moduleCache.get(fsPath);
92
132
  const request = async (dep) => {
93
133
  var _a;
94
- const fsPath2 = toFilePath(normalizeRequestId(dep, this.options.base), this.root);
134
+ const depFsPath = toFilePath(normalizeRequestId(dep, this.options.base), this.root);
95
135
  const getStack = () => {
96
136
  return `stack:
97
- ${[...callstack, fsPath2].reverse().map((p) => `- ${p}`).join("\n")}`;
137
+ ${[...callstack, depFsPath].reverse().map((p) => `- ${p}`).join("\n")}`;
98
138
  };
99
139
  let debugTimer;
100
140
  if (this.debug)
101
- debugTimer = setTimeout(() => console.warn(() => `module ${fsPath2} takes over 2s to load.
141
+ debugTimer = setTimeout(() => console.warn(() => `module ${depFsPath} takes over 2s to load.
102
142
  ${getStack()}`), 2e3);
103
143
  try {
104
- if (callstack.includes(fsPath2)) {
105
- const depExports = (_a = this.moduleCache.get(fsPath2)) == null ? void 0 : _a.exports;
144
+ if (callstack.includes(depFsPath)) {
145
+ const depExports = (_a = this.moduleCache.get(depFsPath)) == null ? void 0 : _a.exports;
106
146
  if (depExports)
107
147
  return depExports;
108
148
  throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
109
149
  }
110
- const mod = await this.cachedRequest(dep, callstack);
111
- return mod;
150
+ return await this.cachedRequest(dep, callstack);
112
151
  } finally {
113
152
  if (debugTimer)
114
153
  clearTimeout(debugTimer);
@@ -132,9 +171,9 @@ ${getStack()}`), 2e3);
132
171
  let { code: transformed, externalize } = await this.options.fetchModule(id);
133
172
  if (externalize) {
134
173
  debugNative(externalize);
135
- const mod = await this.interopedImport(externalize);
136
- this.moduleCache.set(fsPath, { exports: mod });
137
- return mod;
174
+ const exports2 = await this.interopedImport(externalize);
175
+ mod.exports = exports2;
176
+ return exports2;
138
177
  }
139
178
  if (transformed == null)
140
179
  throw new Error(`[vite-node] Failed to load ${id}`);
@@ -146,15 +185,34 @@ ${getStack()}`), 2e3);
146
185
  enumerable: false,
147
186
  configurable: false
148
187
  });
149
- this.moduleCache.set(fsPath, { code: transformed, exports });
188
+ const cjsExports = new Proxy(exports, {
189
+ get(_, p, receiver) {
190
+ return Reflect.get(exports, p, receiver);
191
+ },
192
+ set(_, p, value) {
193
+ if (p !== "default") {
194
+ if (!Reflect.has(exports, "default"))
195
+ exports.default = {};
196
+ if (exports.default === null || typeof exports.default !== "object") {
197
+ defineExport(exports, p, () => void 0);
198
+ return true;
199
+ }
200
+ exports.default[p] = value;
201
+ defineExport(exports, p, () => value);
202
+ return true;
203
+ }
204
+ return Reflect.set(exports, p, value);
205
+ }
206
+ });
207
+ Object.assign(mod, { code: transformed, exports });
150
208
  const __filename = fileURLToPath(url);
151
209
  const moduleProxy = {
152
210
  set exports(value) {
153
- exportAll(exports, value);
154
- exports.default = value;
211
+ exportAll(cjsExports, value);
212
+ cjsExports.default = value;
155
213
  },
156
214
  get exports() {
157
- return exports;
215
+ return cjsExports;
158
216
  }
159
217
  };
160
218
  let hotContext;
@@ -176,7 +234,7 @@ ${getStack()}`), 2e3);
176
234
  __vite_ssr_import_meta__: meta,
177
235
  __vitest_resolve_id__: resolveId,
178
236
  require: createRequire(url),
179
- exports,
237
+ exports: cjsExports,
180
238
  module: moduleProxy,
181
239
  __filename,
182
240
  __dirname: dirname(__filename)
@@ -232,19 +290,27 @@ function proxyMethod(name, tryDefault) {
232
290
  return result;
233
291
  };
234
292
  }
293
+ function defineExport(exports, key, value) {
294
+ Object.defineProperty(exports, key, {
295
+ enumerable: true,
296
+ configurable: true,
297
+ get: value
298
+ });
299
+ }
235
300
  function exportAll(exports, sourceModule) {
301
+ var _a;
236
302
  if (exports === sourceModule)
237
303
  return;
304
+ const type = getType(sourceModule);
305
+ if (type !== "Object" && type !== "Module")
306
+ return;
307
+ const constructor = (_a = sourceModule.constructor) == null ? void 0 : _a.name;
308
+ if (constructor && constructor !== "Object")
309
+ return;
238
310
  for (const key in sourceModule) {
239
311
  if (key !== "default") {
240
312
  try {
241
- Object.defineProperty(exports, key, {
242
- enumerable: true,
243
- configurable: true,
244
- get() {
245
- return sourceModule[key];
246
- }
247
- });
313
+ defineExport(exports, key, () => sourceModule[key]);
248
314
  } catch (_err) {
249
315
  }
250
316
  }
@@ -1,8 +1,8 @@
1
1
  import { existsSync, promises } from 'fs';
2
- import { y as resolve, p as picocolors, j as join } from './chunk-mock-date.bc81a3ac.mjs';
3
- import 'path';
2
+ import { a as resolve, p as picocolors, j as join } from './chunk-constants.6196597b.mjs';
4
3
  import 'tty';
5
- import 'local-pkg';
4
+ import 'url';
5
+ import 'path';
6
6
 
7
7
  function hashCode(s) {
8
8
  return s.split("").reduce((a, b) => {