vitest 0.21.0 → 0.22.1

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 (45) hide show
  1. package/LICENSE.md +61 -4
  2. package/dist/browser.d.ts +4 -5
  3. package/dist/browser.mjs +9 -9
  4. package/dist/{chunk-api-setup.89eb0e7a.mjs → chunk-api-setup.377c28aa.mjs} +9 -9
  5. package/dist/chunk-constants.71e8a211.mjs +284 -0
  6. package/dist/{chunk-install-pkg.6c6dc0c2.mjs → chunk-install-pkg.3aa3eae6.mjs} +3 -2
  7. package/dist/{chunk-defaults.8390340d.mjs → chunk-integrations-coverage.d205bd87.mjs} +23 -152
  8. package/dist/{chunk-integrations-globals.a798d352.mjs → chunk-integrations-globals.60af7da3.mjs} +8 -8
  9. package/dist/{chunk-mock-date.ea3b3121.mjs → chunk-mock-date.304e29b1.mjs} +11 -255
  10. package/dist/chunk-node-git.9a7e3153.mjs +78 -0
  11. package/dist/{chunk-runtime-chain.44b4224d.mjs → chunk-runtime-chain.be610650.mjs} +4 -3
  12. package/dist/{chunk-runtime-error.95e53764.mjs → chunk-runtime-error.1104e45a.mjs} +13 -12
  13. package/dist/{chunk-runtime-hooks.291644ec.mjs → chunk-runtime-hooks.5d7073db.mjs} +3 -3
  14. package/dist/{chunk-runtime-mocker.6190d6a3.mjs → chunk-runtime-mocker.49d21aa6.mjs} +19 -5
  15. package/dist/{chunk-runtime-rpc.fc50dcc0.mjs → chunk-runtime-rpc.57586b73.mjs} +1 -1
  16. package/dist/{chunk-utils-source-map.d307e4ea.mjs → chunk-utils-source-map.bbf3ad19.mjs} +2 -1
  17. package/dist/{chunk-vite-node-client.b59ba135.mjs → chunk-vite-node-client.cddda63d.mjs} +49 -21
  18. package/dist/{chunk-vite-node-debug.dbce2e1f.mjs → chunk-vite-node-debug.536c4c5b.mjs} +3 -3
  19. package/dist/{chunk-vite-node-externalize.80bed9b3.mjs → chunk-vite-node-externalize.c843f497.mjs} +186 -50
  20. package/dist/chunk-vite-node-utils.b432150c.mjs +6921 -0
  21. package/dist/cli-wrapper.mjs +124 -0
  22. package/dist/cli.mjs +16 -15
  23. package/dist/config.cjs +3 -0
  24. package/dist/config.d.ts +6 -3
  25. package/dist/config.mjs +2 -1
  26. package/dist/entry.mjs +9 -9
  27. package/dist/{global-644546f7.d.ts → global-fe52f84b.d.ts} +512 -177
  28. package/dist/{index-3f764034.d.ts → index-ea17aa0c.d.ts} +4 -52
  29. package/dist/index.d.ts +5 -6
  30. package/dist/index.mjs +7 -5
  31. package/dist/loader.mjs +4 -3
  32. package/dist/node.d.ts +3 -3
  33. package/dist/node.mjs +16 -15
  34. package/dist/suite.mjs +6 -4
  35. package/dist/{vendor-index.61438b77.mjs → vendor-index.29636037.mjs} +1 -61
  36. package/dist/{vendor-index.62ce5c33.mjs → vendor-index.2ae8040a.mjs} +0 -0
  37. package/dist/vendor-index.9d9196cc.mjs +61 -0
  38. package/dist/{vendor-index.de788b6a.mjs → vendor-index.ae96af6e.mjs} +14 -14
  39. package/dist/{chunk-node-git.e0dc0a7e.mjs → vendor-index.fbec8a81.mjs} +5 -73
  40. package/dist/worker.mjs +9 -9
  41. package/package.json +9 -13
  42. package/vitest.mjs +1 -1
  43. package/dist/chunk-constants.9da1ef26.mjs +0 -38
  44. package/dist/chunk-vite-node-utils.96438e82.mjs +0 -1114
  45. package/dist/mocker-5e2a8e41.d.ts +0 -3
@@ -1,11 +1,11 @@
1
- import { e as environments, t as takeCoverage, p as pLimit } from './chunk-defaults.8390340d.mjs';
2
- import { r as resetRunOnceCounter, i as index, v as vi } from './chunk-runtime-hooks.291644ec.mjs';
3
- import { h as deepClone, k as getType, l as isNode, R as RealDate, t as toArray, o as relativePath, q as isBrowser, u as partitionSuiteChildren, v as shuffle, w as hasTests, x as hasFailed, e as getFullName } from './chunk-mock-date.ea3b3121.mjs';
4
- import { e as clearCollectorContext, f as defaultSuite, h as setHooks, j as getHooks, k as collectorContext, l as setState, G as GLOBAL_EXPECT, m as getFn, n as getState } from './chunk-runtime-chain.44b4224d.mjs';
5
- import { r as rpc } from './chunk-runtime-rpc.fc50dcc0.mjs';
1
+ import { e as environments, t as takeCoverageInsideWorker, p as pLimit } from './chunk-integrations-coverage.d205bd87.mjs';
2
+ import { r as resetRunOnceCounter, i as index, v as vi } from './chunk-runtime-hooks.5d7073db.mjs';
3
+ import { f as deepClone, h as getType, j as isNode, R as RealDate, t as toArray, k as relativePath, l as isBrowser, p as partitionSuiteChildren, o as shuffle, q as hasTests, u as hasFailed, d as getFullName } from './chunk-mock-date.304e29b1.mjs';
4
+ import { e as clearCollectorContext, f as defaultSuite, h as setHooks, j as getHooks, k as collectorContext, l as setState, G as GLOBAL_EXPECT, m as getFn, n as getState } from './chunk-runtime-chain.be610650.mjs';
5
+ import { r as rpc } from './chunk-runtime-rpc.57586b73.mjs';
6
6
  import util$1 from 'util';
7
7
  import { util } from 'chai';
8
- import { s as stringify } from './chunk-utils-source-map.d307e4ea.mjs';
8
+ import { s as stringify } from './chunk-utils-source-map.bbf3ad19.mjs';
9
9
  import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
10
10
  import { a as safeClearTimeout, s as safeSetTimeout } from './chunk-utils-timers.b48455ed.mjs';
11
11
 
@@ -131,7 +131,7 @@ async function setupGlobalEnv(config) {
131
131
  if (isNode)
132
132
  await setupConsoleLogSpy();
133
133
  if (config.globals)
134
- (await import('./chunk-integrations-globals.a798d352.mjs')).registerApiGlobally();
134
+ (await import('./chunk-integrations-globals.60af7da3.mjs')).registerApiGlobally();
135
135
  }
136
136
  function setupDefines(defines) {
137
137
  for (const key in defines)
@@ -442,7 +442,7 @@ async function sendTasksUpdate() {
442
442
  async function runTest(test) {
443
443
  var _a, _b;
444
444
  if (test.mode !== "run") {
445
- const { getSnapshotClient } = await import('./chunk-runtime-chain.44b4224d.mjs').then(function (n) { return n.p; });
445
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.be610650.mjs').then(function (n) { return n.p; });
446
446
  getSnapshotClient().skipTestSnapshots(test);
447
447
  return;
448
448
  }
@@ -458,7 +458,7 @@ async function runTest(test) {
458
458
  updateTask(test);
459
459
  clearModuleMocks();
460
460
  if (isNode) {
461
- const { getSnapshotClient } = await import('./chunk-runtime-chain.44b4224d.mjs').then(function (n) { return n.p; });
461
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.be610650.mjs').then(function (n) { return n.p; });
462
462
  await getSnapshotClient().setTest(test);
463
463
  }
464
464
  const workerState = getWorkerState();
@@ -511,7 +511,7 @@ async function runTest(test) {
511
511
  if (isBrowser && test.result.error)
512
512
  console.error(test.result.error.message, test.result.error.stackStr);
513
513
  if (isNode) {
514
- const { getSnapshotClient } = await import('./chunk-runtime-chain.44b4224d.mjs').then(function (n) { return n.p; });
514
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.be610650.mjs').then(function (n) { return n.p; });
515
515
  getSnapshotClient().clearTest();
516
516
  }
517
517
  test.result.duration = now() - start;
@@ -623,10 +623,11 @@ async function startTestsBrowser(paths, config) {
623
623
  async function startTestsNode(paths, config) {
624
624
  const files = await collectTests(paths, config);
625
625
  rpc().onCollected(files);
626
- const { getSnapshotClient } = await import('./chunk-runtime-chain.44b4224d.mjs').then(function (n) { return n.p; });
626
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.be610650.mjs').then(function (n) { return n.p; });
627
627
  getSnapshotClient().clear();
628
628
  await runFiles(files, config);
629
- takeCoverage();
629
+ const coverage = await takeCoverageInsideWorker(config.coverage);
630
+ rpc().onAfterSuiteRun({ coverage });
630
631
  await getSnapshotClient().saveCurrent();
631
632
  await sendTasksUpdate();
632
633
  }
@@ -1,7 +1,7 @@
1
- import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, c as createExpect, b as globalExpect } from './chunk-runtime-chain.44b4224d.mjs';
2
- import { R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-mock-date.ea3b3121.mjs';
1
+ import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, c as createExpect, b as globalExpect } from './chunk-runtime-chain.be610650.mjs';
2
+ import { R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-mock-date.304e29b1.mjs';
3
3
  import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
4
- import { p as parseStacktrace } from './chunk-utils-source-map.d307e4ea.mjs';
4
+ import { p as parseStacktrace } from './chunk-utils-source-map.bbf3ad19.mjs';
5
5
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
6
6
  import util from 'util';
7
7
  import { spyOn, fn, isMockFunction, spies } from './spy.mjs';
@@ -1,9 +1,9 @@
1
- import { V as ViteNodeRunner } from './chunk-vite-node-client.b59ba135.mjs';
1
+ import { V as ViteNodeRunner } from './chunk-vite-node-client.cddda63d.mjs';
2
2
  import { normalizePath } from 'vite';
3
- import { M as isWindows, N as mergeSlashes, d as dirname, j as join, z as basename, y as resolve, s as slash, k as getType, O as getAllMockableProperties } from './chunk-mock-date.ea3b3121.mjs';
3
+ import { C as isWindows, D as mergeSlashes, s as slash, h as getType, E as getAllMockableProperties } from './chunk-mock-date.304e29b1.mjs';
4
4
  import { existsSync, readdirSync } from 'fs';
5
- import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.96438e82.mjs';
6
- import { d as distDir } from './chunk-constants.9da1ef26.mjs';
5
+ import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.b432150c.mjs';
6
+ import { d as dirname, j as join, b as basename, a as resolve, c as distDir } from './chunk-constants.71e8a211.mjs';
7
7
  import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
8
8
 
9
9
  class RefTracker {
@@ -78,8 +78,22 @@ const _VitestMocker = class {
78
78
  if (cached)
79
79
  return cached;
80
80
  const exports = await mock();
81
+ if (exports === null || typeof exports !== "object")
82
+ throw new Error('[vitest] vi.mock(path: string, factory?: () => unknown) is not returning an object. Did you mean to return an object with a "default" key?');
81
83
  this.moduleCache.set(dep, { exports });
82
- return exports;
84
+ const exportHandler = {
85
+ get(target, prop) {
86
+ const val = target[prop];
87
+ if (prop === "then") {
88
+ if (target instanceof Promise)
89
+ return target.then.bind(target);
90
+ } else if (!(prop in target)) {
91
+ throw new Error(`[vitest] No "${prop}" export is defined on the "${dep}"`);
92
+ }
93
+ return val;
94
+ }
95
+ };
96
+ return new Proxy(exports, exportHandler);
83
97
  }
84
98
  getMockPath(dep) {
85
99
  return `mock:${dep}`;
@@ -1,4 +1,4 @@
1
- import './chunk-mock-date.ea3b3121.mjs';
1
+ import './chunk-mock-date.304e29b1.mjs';
2
2
  import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
3
3
  import { w as withSafeTimers } from './chunk-utils-timers.b48455ed.mjs';
4
4
 
@@ -1,4 +1,5 @@
1
- import { s as slash, f as notNullish, p as picocolors } from './chunk-mock-date.ea3b3121.mjs';
1
+ import { s as slash, e as notNullish } from './chunk-mock-date.304e29b1.mjs';
2
+ import { p as picocolors } from './chunk-constants.71e8a211.mjs';
2
3
 
3
4
  var build = {};
4
5
 
@@ -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.ea3b3121.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.96438e82.mjs';
4
+ import { a as resolve, d as dirname, i as isAbsolute, h as extname } from './chunk-constants.71e8a211.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.b432150c.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,33 @@ 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
+ }
64
83
  }
65
84
  class ViteNodeRunner {
66
85
  constructor(options) {
@@ -76,39 +95,44 @@ class ViteNodeRunner {
76
95
  return await this.cachedRequest(id, []);
77
96
  }
78
97
  async cachedRequest(rawId, callstack) {
79
- var _a, _b, _c, _d;
80
98
  const id = normalizeRequestId(rawId, this.options.base);
81
99
  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;
100
+ const mod = this.moduleCache.get(fsPath);
101
+ const importee = callstack[callstack.length - 1];
102
+ if (!mod.importers)
103
+ mod.importers = /* @__PURE__ */ new Set();
104
+ if (importee)
105
+ mod.importers.add(importee);
106
+ if (callstack.includes(fsPath) && mod.exports)
107
+ return mod.exports;
108
+ if (mod.promise)
109
+ return mod.promise;
86
110
  const promise = this.directRequest(id, fsPath, callstack);
87
- this.moduleCache.set(fsPath, { promise });
111
+ Object.assign(mod, { promise });
88
112
  return await promise;
89
113
  }
90
114
  async directRequest(id, fsPath, _callstack) {
91
115
  const callstack = [..._callstack, fsPath];
116
+ const mod = this.moduleCache.get(fsPath);
92
117
  const request = async (dep) => {
93
118
  var _a;
94
- const fsPath2 = toFilePath(normalizeRequestId(dep, this.options.base), this.root);
119
+ const depFsPath = toFilePath(normalizeRequestId(dep, this.options.base), this.root);
95
120
  const getStack = () => {
96
121
  return `stack:
97
- ${[...callstack, fsPath2].reverse().map((p) => `- ${p}`).join("\n")}`;
122
+ ${[...callstack, depFsPath].reverse().map((p) => `- ${p}`).join("\n")}`;
98
123
  };
99
124
  let debugTimer;
100
125
  if (this.debug)
101
- debugTimer = setTimeout(() => console.warn(() => `module ${fsPath2} takes over 2s to load.
126
+ debugTimer = setTimeout(() => console.warn(() => `module ${depFsPath} takes over 2s to load.
102
127
  ${getStack()}`), 2e3);
103
128
  try {
104
- if (callstack.includes(fsPath2)) {
105
- const depExports = (_a = this.moduleCache.get(fsPath2)) == null ? void 0 : _a.exports;
129
+ if (callstack.includes(depFsPath)) {
130
+ const depExports = (_a = this.moduleCache.get(depFsPath)) == null ? void 0 : _a.exports;
106
131
  if (depExports)
107
132
  return depExports;
108
133
  throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
109
134
  }
110
- const mod = await this.cachedRequest(dep, callstack);
111
- return mod;
135
+ return await this.cachedRequest(dep, callstack);
112
136
  } finally {
113
137
  if (debugTimer)
114
138
  clearTimeout(debugTimer);
@@ -132,17 +156,21 @@ ${getStack()}`), 2e3);
132
156
  let { code: transformed, externalize } = await this.options.fetchModule(id);
133
157
  if (externalize) {
134
158
  debugNative(externalize);
135
- const mod = await this.interopedImport(externalize);
136
- this.moduleCache.set(fsPath, { exports: mod });
137
- return mod;
159
+ const exports2 = await this.interopedImport(externalize);
160
+ mod.exports = exports2;
161
+ return exports2;
138
162
  }
139
163
  if (transformed == null)
140
164
  throw new Error(`[vite-node] Failed to load ${id}`);
141
165
  const url = pathToFileURL(fsPath).href;
142
166
  const meta = { url };
143
167
  const exports = /* @__PURE__ */ Object.create(null);
144
- exports[Symbol.toStringTag] = "Module";
145
- this.moduleCache.set(fsPath, { code: transformed, exports });
168
+ Object.defineProperty(exports, Symbol.toStringTag, {
169
+ value: "Module",
170
+ enumerable: false,
171
+ configurable: false
172
+ });
173
+ Object.assign(mod, { code: transformed, exports });
146
174
  const __filename = fileURLToPath(url);
147
175
  const moduleProxy = {
148
176
  set exports(value) {
@@ -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.ea3b3121.mjs';
3
- import 'path';
2
+ import { a as resolve, p as picocolors, j as join } from './chunk-constants.71e8a211.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) => {