vitest 0.18.0 → 0.19.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 (36) hide show
  1. package/LICENSE.md +6 -6
  2. package/dist/browser.d.ts +1850 -0
  3. package/dist/browser.mjs +20 -0
  4. package/dist/{chunk-api-setup.63babd7c.mjs → chunk-api-setup.0cf2c96a.mjs} +37 -11
  5. package/dist/{chunk-constants.8eb2ed35.mjs → chunk-constants.38b43a44.mjs} +3 -3
  6. package/dist/{chunk-env-node.26c72624.mjs → chunk-defaults.ed196a9a.mjs} +458 -455
  7. package/dist/{chunk-install-pkg.2dcb2c04.mjs → chunk-install-pkg.6c6dc0c2.mjs} +11 -10
  8. package/dist/chunk-integrations-globals.1018e651.mjs +24 -0
  9. package/dist/chunk-node-git.9058b82a.mjs +1139 -0
  10. package/dist/chunk-runtime-chain.f2e00f4c.mjs +2039 -0
  11. package/dist/{vendor-entry.78de67ab.mjs → chunk-runtime-error.606e0393.mjs} +167 -183
  12. package/dist/{chunk-runtime-chain.eb764dff.mjs → chunk-runtime-hooks.d4cadf47.mjs} +33 -2012
  13. package/dist/{chunk-runtime-mocker.79ccc3de.mjs → chunk-runtime-mocker.dfdfd57b.mjs} +70 -22
  14. package/dist/{chunk-runtime-rpc.cc6a06a2.mjs → chunk-runtime-rpc.45d8ee19.mjs} +1 -1
  15. package/dist/{chunk-utils-global.1b22c4fd.mjs → chunk-utils-global.2aa95025.mjs} +11 -6
  16. package/dist/{chunk-utils-source-map.957e7756.mjs → chunk-utils-source-map.8b066ce2.mjs} +2 -2
  17. package/dist/{chunk-vite-node-externalize.0791f2ed.mjs → chunk-vite-node-externalize.e9af6472.mjs} +105 -1174
  18. package/dist/chunk-vite-node-utils.ad73f2ab.mjs +1433 -0
  19. package/dist/cli.mjs +9 -11
  20. package/dist/config.cjs +4 -1
  21. package/dist/config.d.ts +1 -0
  22. package/dist/config.mjs +4 -1
  23. package/dist/entry.mjs +54 -10
  24. package/dist/index.d.ts +56 -27
  25. package/dist/index.mjs +12 -9
  26. package/dist/node.d.ts +37 -18
  27. package/dist/node.mjs +10 -12
  28. package/dist/spy.mjs +102 -2
  29. package/dist/suite.mjs +13 -0
  30. package/dist/vendor-index.61438b77.mjs +335 -0
  31. package/dist/{vendor-index.4bf9c627.mjs → vendor-index.62ce5c33.mjs} +11 -343
  32. package/dist/worker.mjs +6 -6
  33. package/package.json +20 -12
  34. package/dist/chunk-integrations-globals.61e4d6ae.mjs +0 -26
  35. package/dist/chunk-integrations-spy.674b628e.mjs +0 -102
  36. package/dist/chunk-vite-node-utils.af8ead96.mjs +0 -9195
@@ -1,9 +1,30 @@
1
- import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.af8ead96.mjs';
1
+ import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.ad73f2ab.mjs';
2
2
  import { normalizePath } from 'vite';
3
- import { a as getWorkerState, M as isWindows, N as mergeSlashes, d as dirname, j as join, o as basename, q as resolve, O as getType, P as getAllProperties, s as slash } from './chunk-utils-global.1b22c4fd.mjs';
3
+ import { g as getWorkerState, T as isWindows, U as mergeSlashes, d as dirname, j as join, D as basename, C as resolve, c as slash, q as getType, V as getAllProperties } from './chunk-utils-global.2aa95025.mjs';
4
4
  import { existsSync, readdirSync } from 'fs';
5
- import { d as distDir } from './chunk-constants.8eb2ed35.mjs';
5
+ import { d as distDir } from './chunk-constants.38b43a44.mjs';
6
6
 
7
+ class RefTracker {
8
+ constructor() {
9
+ this.idMap = /* @__PURE__ */ new Map();
10
+ this.mockedValueMap = /* @__PURE__ */ new Map();
11
+ }
12
+ getId(value) {
13
+ return this.idMap.get(value);
14
+ }
15
+ getMockedValue(id) {
16
+ return this.mockedValueMap.get(id);
17
+ }
18
+ track(originalValue, mockedValue) {
19
+ const newId = this.idMap.size;
20
+ this.idMap.set(originalValue, newId);
21
+ this.mockedValueMap.set(newId, mockedValue);
22
+ return newId;
23
+ }
24
+ }
25
+ function isSpecialProp(prop, parentType) {
26
+ return parentType.includes("Function") && typeof prop === "string" && ["arguments", "callee", "caller", "length", "name"].includes(prop);
27
+ }
7
28
  const _VitestMocker = class {
8
29
  constructor(options, moduleCache, request) {
9
30
  this.options = options;
@@ -91,27 +112,54 @@ const _VitestMocker = class {
91
112
  const fullPath = resolve(dir, "__mocks__", baseId);
92
113
  return existsSync(fullPath) ? fullPath : null;
93
114
  }
94
- mockValue(value) {
115
+ mockObject(object) {
95
116
  if (!_VitestMocker.spyModule) {
96
117
  throw new Error("Error: Spy module is not defined. This is likely an internal bug in Vitest. Please report it to https://github.com/vitest-dev/vitest/issues");
97
118
  }
98
- const type = getType(value);
99
- if (Array.isArray(value))
100
- return [];
101
- else if (type !== "Object" && type !== "Module")
102
- return value;
103
- const newObj = {};
104
- const properties = getAllProperties(value);
105
- for (const k of properties) {
106
- newObj[k] = this.mockValue(value[k]);
107
- const type2 = getType(value[k]);
108
- if (type2.includes("Function") && !value[k]._isMockFunction) {
109
- _VitestMocker.spyModule.spyOn(newObj, k).mockImplementation(() => void 0);
110
- Object.defineProperty(newObj[k], "length", { value: 0 });
119
+ const spyModule = _VitestMocker.spyModule;
120
+ const finalizers = new Array();
121
+ const refs = new RefTracker();
122
+ const mockPropertiesOf = (container, newContainer) => {
123
+ const containerType = getType(container);
124
+ const isModule = containerType === "Module" || !!container.__esModule;
125
+ for (const property of getAllProperties(container)) {
126
+ if (!isModule) {
127
+ const descriptor = Object.getOwnPropertyDescriptor(container, property);
128
+ if ((descriptor == null ? void 0 : descriptor.get) || (descriptor == null ? void 0 : descriptor.set))
129
+ continue;
130
+ }
131
+ if (isSpecialProp(property, containerType))
132
+ continue;
133
+ const value = container[property];
134
+ const refId = refs.getId(value);
135
+ if (refId) {
136
+ finalizers.push(() => newContainer[property] = refs.getMockedValue(refId));
137
+ continue;
138
+ }
139
+ const type = getType(value);
140
+ if (Array.isArray(value)) {
141
+ newContainer[property] = [];
142
+ continue;
143
+ }
144
+ const isFunction = type.includes("Function") && typeof value === "function";
145
+ if ((!isFunction || value.__isMockFunction) && type !== "Object" && type !== "Module") {
146
+ newContainer[property] = value;
147
+ continue;
148
+ }
149
+ newContainer[property] = isFunction ? value : {};
150
+ if (isFunction) {
151
+ spyModule.spyOn(newContainer, property).mockImplementation(() => void 0);
152
+ Object.defineProperty(newContainer[property], "length", { value: 0 });
153
+ }
154
+ refs.track(value, newContainer[property]);
155
+ mockPropertiesOf(value, newContainer[property]);
111
156
  }
112
- }
113
- Object.setPrototypeOf(newObj, Object.getPrototypeOf(value));
114
- return newObj;
157
+ };
158
+ const mockedObject = {};
159
+ mockPropertiesOf(object, mockedObject);
160
+ for (const finalizer of finalizers)
161
+ finalizer();
162
+ return mockedObject;
115
163
  }
116
164
  unmockPath(path) {
117
165
  const suitefile = this.getSuiteFilepath();
@@ -142,7 +190,7 @@ const _VitestMocker = class {
142
190
  if (mock === null) {
143
191
  await this.ensureSpy();
144
192
  const mod = await this.request(fsPath);
145
- return this.mockValue(mod);
193
+ return this.mockObject(mod);
146
194
  }
147
195
  if (typeof mock === "function")
148
196
  return this.callFunctionMock(fsPath, mock);
@@ -168,7 +216,7 @@ const _VitestMocker = class {
168
216
  return cache.exports;
169
217
  const cacheKey = toFilePath(dep, this.root);
170
218
  const mod = ((_a = this.moduleCache.get(cacheKey)) == null ? void 0 : _a.exports) || await this.request(dep);
171
- const exports = this.mockValue(mod);
219
+ const exports = this.mockObject(mod);
172
220
  this.moduleCache.set(cacheName, { exports });
173
221
  return exports;
174
222
  }
@@ -1,4 +1,4 @@
1
- import { a as getWorkerState, w as withSafeTimers } from './chunk-utils-global.1b22c4fd.mjs';
1
+ import { g as getWorkerState, w as withSafeTimers } from './chunk-utils-global.2aa95025.mjs';
2
2
 
3
3
  const rpc = () => {
4
4
  const { rpc: rpc2 } = getWorkerState();
@@ -1,6 +1,6 @@
1
+ import path, { relative as relative$1 } from 'path';
1
2
  import require$$0 from 'tty';
2
3
  import { isPackageExists } from 'local-pkg';
3
- import path from 'path';
4
4
 
5
5
  var picocolors = {exports: {}};
6
6
 
@@ -482,8 +482,11 @@ function withSafeTimers(fn) {
482
482
  }
483
483
  }
484
484
 
485
- const isNode = typeof process !== "undefined" && typeof process.platform !== "undefined";
485
+ var _a;
486
+ const isNode = typeof process < "u" && typeof process.stdout < "u" && !((_a = process.versions) == null ? void 0 : _a.deno) && !globalThis.window;
487
+ const isBrowser = typeof window !== "undefined";
486
488
  const isWindows = isNode && process.platform === "win32";
489
+ const relativePath = isBrowser ? relative$1 : relative;
487
490
  function partitionSuiteChildren(suite) {
488
491
  let tasksGroup = [];
489
492
  const tasksGroups = [];
@@ -515,9 +518,10 @@ function resetModules() {
515
518
  function getFullName(task) {
516
519
  return getNames(task).join(picocolors.exports.dim(" > "));
517
520
  }
518
- async function ensurePackageInstalled(dependency, promptInstall = !process.env.CI && process.stdout.isTTY) {
519
- if (isPackageExists(dependency))
521
+ async function ensurePackageInstalled(dependency, root) {
522
+ if (isPackageExists(dependency, { paths: [root] }))
520
523
  return true;
524
+ const promptInstall = !process.env.CI && process.stdout.isTTY;
521
525
  process.stderr.write(picocolors.exports.red(`${picocolors.exports.inverse(picocolors.exports.red(" MISSING DEP "))} Can not find dependency '${dependency}'
522
526
 
523
527
  `));
@@ -530,7 +534,7 @@ async function ensurePackageInstalled(dependency, promptInstall = !process.env.C
530
534
  message: picocolors.exports.reset(`Do you want to install ${picocolors.exports.green(dependency)}?`)
531
535
  });
532
536
  if (install) {
533
- await (await import('./chunk-install-pkg.2dcb2c04.mjs')).installPackage(dependency, { dev: true });
537
+ await (await import('./chunk-install-pkg.6c6dc0c2.mjs')).installPackage(dependency, { dev: true });
534
538
  process.stderr.write(picocolors.exports.yellow(`
535
539
  Package ${dependency} installed, re-run the command to start.
536
540
  `));
@@ -567,6 +571,7 @@ function getCallLastIndex(code) {
567
571
  }
568
572
  return null;
569
573
  }
574
+ isNode ? relative : relative$1;
570
575
  class AggregateErrorPonyfill extends Error {
571
576
  constructor(errors, message = "") {
572
577
  super(message);
@@ -574,4 +579,4 @@ class AggregateErrorPonyfill extends Error {
574
579
  }
575
580
  }
576
581
 
577
- export { AggregateErrorPonyfill as A, safeSetInterval as B, safeClearInterval as C, getSuites as D, shuffle as E, toArray as F, normalize as G, deepMerge as H, toNamespacedPath as I, ensurePackageInstalled as J, stdout as K, extname as L, isWindows as M, mergeSlashes as N, getType as O, getAllProperties as P, deepClone as Q, RealDate as R, partitionSuiteChildren as S, hasTests as T, getWorkerState as a, getNames as b, assertTypes as c, dirname as d, getFullName as e, safeSetTimeout as f, getCallLastIndex as g, safeClearTimeout as h, isObject as i, join as j, resetModules as k, notNullish as l, mockDate as m, noop as n, basename as o, picocolors as p, resolve as q, resetDate as r, slash as s, isAbsolute as t, relative as u, isNode as v, withSafeTimers as w, getTests as x, hasFailed as y, hasFailedSnapshot as z };
582
+ export { hasTests as A, hasFailed as B, resolve as C, basename as D, AggregateErrorPonyfill as E, isAbsolute as F, relative as G, getTests as H, hasFailedSnapshot as I, safeSetInterval as J, safeClearInterval as K, getSuites as L, normalize as M, deepMerge as N, toNamespacedPath as O, ensurePackageInstalled as P, stdout as Q, RealDate as R, extname as S, isWindows as T, mergeSlashes as U, getAllProperties as V, resetModules as a, getCallLastIndex as b, slash as c, dirname as d, getNames as e, assertTypes as f, getWorkerState as g, getFullName as h, isObject as i, join as j, safeClearTimeout as k, notNullish as l, mockDate as m, noop as n, deepClone as o, picocolors as p, getType as q, resetDate as r, safeSetTimeout as s, isNode as t, toArray as u, relativePath as v, withSafeTimers as w, isBrowser as x, partitionSuiteChildren as y, shuffle as z };
@@ -1,4 +1,4 @@
1
- import { s as slash, l as notNullish, p as picocolors } from './chunk-utils-global.1b22c4fd.mjs';
1
+ import { c as slash, l as notNullish, p as picocolors } from './chunk-utils-global.2aa95025.mjs';
2
2
 
3
3
  var build = {};
4
4
 
@@ -7435,4 +7435,4 @@ var matcherUtils = /*#__PURE__*/Object.freeze({
7435
7435
  diff: diff
7436
7436
  });
7437
7437
 
7438
- export { posToNumber as a, parseStacktrace as b, stripAnsi as c, cliTruncate as d, stringWidth as e, format_1 as f, getOriginalPos as g, ansiStyles as h, sliceAnsi as i, interpretSourcePos as j, lineSplitRE as l, matcherUtils as m, numberToPos as n, plugins_1 as p, stringify as s, unifiedDiff as u };
7438
+ export { plugins_1 as a, posToNumber as b, stripAnsi as c, cliTruncate as d, stringWidth as e, format_1 as f, getOriginalPos as g, ansiStyles as h, sliceAnsi as i, interpretSourcePos as j, lineSplitRE as l, matcherUtils as m, numberToPos as n, parseStacktrace as p, stringify as s, unifiedDiff as u };