vitest 0.27.2 → 0.28.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 (64) hide show
  1. package/LICENSE.md +4 -93
  2. package/browser.d.ts +1 -1
  3. package/dist/browser.d.ts +11 -13
  4. package/dist/browser.js +10 -34
  5. package/dist/{chunk-api-setup.029198e3.js → chunk-api-setup.52751a38.js} +27 -12
  6. package/dist/chunk-constants.797d3ebf.js +42 -0
  7. package/dist/{chunk-env-node.787e9561.js → chunk-env-node.ffd1183b.js} +26 -0
  8. package/dist/{chunk-install-pkg.7b006b3e.js → chunk-install-pkg.cfd23146.js} +51 -11
  9. package/dist/chunk-integrations-coverage.48e6286b.js +3993 -0
  10. package/dist/chunk-integrations-globals.0d5f50f0.js +29 -0
  11. package/dist/chunk-integrations-run-once.38756e30.js +27 -0
  12. package/dist/chunk-integrations-utils.f1f6f1ed.js +118 -0
  13. package/dist/{chunk-node-git.125c9008.js → chunk-node-git.d9ad64ab.js} +6 -7
  14. package/dist/{chunk-snapshot-manager.ce714e21.js → chunk-node-pkg.dcdf4369.js} +12653 -9324
  15. package/dist/{chunk-runtime-mocker.58511c38.js → chunk-runtime-mocker.03017e8c.js} +14 -13
  16. package/dist/{chunk-runtime-rpc.d709e91b.js → chunk-runtime-rpc.9c0386cc.js} +3 -2
  17. package/dist/chunk-runtime-setup.d9302cfd.js +20 -0
  18. package/dist/chunk-snapshot-env.6457638e.js +11 -0
  19. package/dist/chunk-utils-base.977ae74f.js +77 -0
  20. package/dist/chunk-utils-env.860d90c2.js +6 -0
  21. package/dist/chunk-utils-global.442d1d33.js +73 -0
  22. package/dist/{chunk-utils-import.054ab315.js → chunk-utils-import.9911c99d.js} +3289 -169
  23. package/dist/chunk-utils-tasks.1b603032.js +103 -0
  24. package/dist/cli-wrapper.js +8 -6
  25. package/dist/cli.js +18 -15
  26. package/dist/config.cjs +10 -7
  27. package/dist/config.d.ts +22 -4
  28. package/dist/config.js +10 -8
  29. package/dist/entry.js +244 -28
  30. package/dist/env-afee91f0.d.ts +10 -0
  31. package/dist/environments.d.ts +7 -2
  32. package/dist/environments.js +1 -1
  33. package/dist/index.d.ts +160 -11
  34. package/dist/index.js +18 -18
  35. package/dist/loader.js +9 -8
  36. package/dist/node.d.ts +9 -7
  37. package/dist/node.js +20 -17
  38. package/dist/runners-chunk.js +215 -0
  39. package/dist/runners.d.ts +39 -0
  40. package/dist/runners.js +18 -0
  41. package/dist/spy.js +1 -2
  42. package/dist/suite.d.ts +2 -0
  43. package/dist/suite.js +2 -18
  44. package/dist/{types-d97c72c7.d.ts → types-c800444e.d.ts} +196 -437
  45. package/dist/{vendor-index.e6c27006.js → vendor-index.618ca5a1.js} +1078 -10
  46. package/dist/{vendor-index.b0346fe4.js → vendor-index.bdee400f.js} +1 -0
  47. package/dist/worker.js +17 -16
  48. package/package.json +22 -12
  49. package/runners.d.ts +1 -0
  50. package/suite.d.ts +1 -0
  51. package/dist/chunk-integrations-coverage.44413252.js +0 -240
  52. package/dist/chunk-integrations-globals.0024ce21.js +0 -27
  53. package/dist/chunk-mock-date.c543fa3e.js +0 -349
  54. package/dist/chunk-runtime-chain.2da9e75c.js +0 -2595
  55. package/dist/chunk-runtime-error.de671af0.js +0 -144
  56. package/dist/chunk-runtime-setup.35da9209.js +0 -649
  57. package/dist/chunk-utils-env.f4a39d2c.js +0 -228
  58. package/dist/chunk-utils-source-map.5f5d12cf.js +0 -408
  59. package/dist/chunk-utils-timers.52534f96.js +0 -3573
  60. package/dist/index-50755efe.d.ts +0 -258
  61. package/dist/vendor-index.451e37bc.js +0 -1071
  62. package/dist/vendor-index.723a074f.js +0 -102
  63. package/dist/vendor-index.9c919048.js +0 -61
  64. package/dist/vendor-index.9f20a9be.js +0 -6291
@@ -1,11 +1,13 @@
1
1
  import { ViteNodeRunner } from 'vite-node/client';
2
2
  import { isInternalRequest } from 'vite-node/utils';
3
3
  import { normalizePath } from 'vite';
4
- import { i as isNodeBuiltin } from './vendor-index.b0346fe4.js';
5
- import { g as getWorkerState, x as getType, I as getAllMockableProperties, d as getCurrentEnvironment } from './chunk-mock-date.c543fa3e.js';
4
+ import { i as isNodeBuiltin } from './vendor-index.bdee400f.js';
5
+ import { g as getWorkerState, b as getCurrentEnvironment } from './chunk-utils-global.442d1d33.js';
6
6
  import { existsSync, readdirSync } from 'node:fs';
7
- import { b as resolve, f as distDir, h as isAbsolute, d as dirname, j as join, c as basename, e as extname } from './chunk-utils-env.f4a39d2c.js';
8
- import c from 'picocolors';
7
+ import { resolve, isAbsolute, dirname, join, basename, extname } from 'pathe';
8
+ import { getColors } from '@vitest/utils';
9
+ import { d as distDir } from './chunk-constants.797d3ebf.js';
10
+ import { g as getType, c as getAllMockableProperties } from './chunk-utils-base.977ae74f.js';
9
11
 
10
12
  class RefTracker {
11
13
  constructor() {
@@ -102,6 +104,7 @@ const _VitestMocker = class {
102
104
  if (target instanceof Promise)
103
105
  return target.then.bind(target);
104
106
  } else if (!(prop in target)) {
107
+ const c = getColors();
105
108
  throw new Error(
106
109
  `[vitest] No "${String(prop)}" export is defined on the "${mockpath}" mock. Did you forget to return it from "vi.mock"?
107
110
  If you need to partially mock a module, you can use "vi.importActual" inside:
@@ -309,12 +312,17 @@ class VitestRunner extends ViteNodeRunner {
309
312
  super(options);
310
313
  this.options = options;
311
314
  this.mocker = new VitestMocker(this);
315
+ Object.defineProperty(globalThis, "__vitest_mocker__", {
316
+ value: this.mocker,
317
+ writable: true,
318
+ configurable: true
319
+ });
312
320
  }
313
321
  shouldResolveId(id, _importee) {
314
322
  if (isInternalRequest(id))
315
323
  return false;
316
324
  const environment = getCurrentEnvironment();
317
- return environment === "node" ? !isNodeBuiltin(id) : true;
325
+ return environment === "node" ? !isNodeBuiltin(id) : !id.startsWith("node:");
318
326
  }
319
327
  async resolveUrl(id, importee) {
320
328
  if (importee && importee.startsWith("mock:"))
@@ -334,14 +342,7 @@ class VitestRunner extends ViteNodeRunner {
334
342
  if (workerState.filepath && normalizePath(workerState.filepath) === normalizePath(context.__filename)) {
335
343
  Object.defineProperty(context.__vite_ssr_import_meta__, "vitest", { get: () => globalThis.__vitest_index__ });
336
344
  }
337
- return Object.assign(context, {
338
- __vitest_mocker__: this.mocker
339
- });
340
- }
341
- shouldInterop(path, mod) {
342
- if (this.options.interopDefault === false)
343
- return false;
344
- return (this.options.interopDefault || getCurrentEnvironment() !== "node") && super.shouldInterop(path, mod);
345
+ return context;
345
346
  }
346
347
  }
347
348
 
@@ -1,8 +1,9 @@
1
- import { g as getWorkerState } from './chunk-mock-date.c543fa3e.js';
2
- import { s as safeSetTimeout } from './chunk-utils-timers.52534f96.js';
1
+ import { getSafeTimers } from '@vitest/utils';
2
+ import { g as getWorkerState } from './chunk-utils-global.442d1d33.js';
3
3
 
4
4
  const safeRandom = Math.random;
5
5
  function withSafeTimers(fn) {
6
+ const { setTimeout: safeSetTimeout } = getSafeTimers();
6
7
  const currentSetTimeout = globalThis.setTimeout;
7
8
  const currentRandom = globalThis.Math.random;
8
9
  try {
@@ -0,0 +1,20 @@
1
+ import { setSafeTimers } from '@vitest/utils';
2
+ import { a as resetRunOnceCounter } from './chunk-integrations-run-once.38756e30.js';
3
+
4
+ let globalSetup = false;
5
+ async function setupCommonEnv(config) {
6
+ resetRunOnceCounter();
7
+ setupDefines(config.defines);
8
+ if (globalSetup)
9
+ return;
10
+ globalSetup = true;
11
+ setSafeTimers();
12
+ if (config.globals)
13
+ (await import('./chunk-integrations-globals.0d5f50f0.js')).registerApiGlobally();
14
+ }
15
+ function setupDefines(defines) {
16
+ for (const key in defines)
17
+ globalThis[key] = defines[key];
18
+ }
19
+
20
+ export { setupCommonEnv as s };
@@ -0,0 +1,11 @@
1
+ let _snapshotEnvironment;
2
+ function setupSnapshotEnvironment(environment) {
3
+ _snapshotEnvironment = environment;
4
+ }
5
+ function getSnapshotEnironment() {
6
+ if (!_snapshotEnvironment)
7
+ throw new Error("Snapshot environment is not setup");
8
+ return _snapshotEnvironment;
9
+ }
10
+
11
+ export { getSnapshotEnironment as g, setupSnapshotEnvironment as s };
@@ -0,0 +1,77 @@
1
+ function isFinalObj(obj) {
2
+ return obj === Object.prototype || obj === Function.prototype || obj === RegExp.prototype;
3
+ }
4
+ function collectOwnProperties(obj, collector) {
5
+ const collect = typeof collector === "function" ? collector : (key) => collector.add(key);
6
+ Object.getOwnPropertyNames(obj).forEach(collect);
7
+ Object.getOwnPropertySymbols(obj).forEach(collect);
8
+ }
9
+ function getAllMockableProperties(obj, isModule) {
10
+ const allProps = /* @__PURE__ */ new Map();
11
+ let curr = obj;
12
+ do {
13
+ if (isFinalObj(curr))
14
+ break;
15
+ collectOwnProperties(curr, (key) => {
16
+ const descriptor = Object.getOwnPropertyDescriptor(curr, key);
17
+ if (descriptor)
18
+ allProps.set(key, { key, descriptor });
19
+ });
20
+ } while (curr = Object.getPrototypeOf(curr));
21
+ if (isModule && !allProps.has("default") && "default" in obj) {
22
+ const descriptor = Object.getOwnPropertyDescriptor(obj, "default");
23
+ if (descriptor)
24
+ allProps.set("default", { key: "default", descriptor });
25
+ }
26
+ return Array.from(allProps.values());
27
+ }
28
+ function notNullish(v) {
29
+ return v != null;
30
+ }
31
+ function slash(str) {
32
+ return str.replace(/\\/g, "/");
33
+ }
34
+ const noop = () => {
35
+ };
36
+ function getType(value) {
37
+ return Object.prototype.toString.apply(value).slice(8, -1);
38
+ }
39
+ function toArray(array) {
40
+ if (array === null || array === void 0)
41
+ array = [];
42
+ if (Array.isArray(array))
43
+ return array;
44
+ return [array];
45
+ }
46
+ const toString = (v) => Object.prototype.toString.call(v);
47
+ const isPlainObject = (val) => toString(val) === "[object Object]" && (!val.constructor || val.constructor.name === "Object");
48
+ function isObject(item) {
49
+ return item != null && typeof item === "object" && !Array.isArray(item);
50
+ }
51
+ function deepMerge(target, ...sources) {
52
+ if (!sources.length)
53
+ return target;
54
+ const source = sources.shift();
55
+ if (source === void 0)
56
+ return target;
57
+ if (isMergeableObject(target) && isMergeableObject(source)) {
58
+ Object.keys(source).forEach((key) => {
59
+ if (isMergeableObject(source[key])) {
60
+ if (!target[key])
61
+ target[key] = {};
62
+ deepMerge(target[key], source[key]);
63
+ } else {
64
+ target[key] = source[key];
65
+ }
66
+ });
67
+ }
68
+ return deepMerge(target, ...sources);
69
+ }
70
+ function isMergeableObject(item) {
71
+ return isPlainObject(item) && !Array.isArray(item);
72
+ }
73
+ function stdout() {
74
+ return console._stdout || process.stdout;
75
+ }
76
+
77
+ export { noop as a, stdout as b, getAllMockableProperties as c, deepMerge as d, getType as g, isObject as i, notNullish as n, slash as s, toArray as t };
@@ -0,0 +1,6 @@
1
+ import 'std-env';
2
+
3
+ var _a;
4
+ const isNode = typeof process < "u" && typeof process.stdout < "u" && !((_a = process.versions) == null ? void 0 : _a.deno) && !globalThis.window;
5
+
6
+ export { isNode as i };
@@ -0,0 +1,73 @@
1
+ import { relative } from 'pathe';
2
+ import { i as isNode } from './chunk-utils-env.860d90c2.js';
3
+ import '@vitest/runner/utils';
4
+ import '@vitest/utils';
5
+
6
+ function getWorkerState() {
7
+ return globalThis.__vitest_worker__;
8
+ }
9
+ function getCurrentEnvironment() {
10
+ return globalThis.__vitest_environment__;
11
+ }
12
+
13
+ const isWindows = isNode && process.platform === "win32";
14
+ const getRunMode = () => getWorkerState().config.mode;
15
+ const isRunningInBenchmark = () => getRunMode() === "benchmark";
16
+ const relativePath = relative;
17
+ function resetModules(modules, resetMocks = false) {
18
+ const skipPaths = [
19
+ /\/vitest\/dist\//,
20
+ /\/vite-node\/dist\//,
21
+ /vitest-virtual-\w+\/dist/,
22
+ /@vitest\/dist/,
23
+ ...!resetMocks ? [/^mock:/] : []
24
+ ];
25
+ modules.forEach((_, path) => {
26
+ if (skipPaths.some((re) => re.test(path)))
27
+ return;
28
+ modules.delete(path);
29
+ });
30
+ }
31
+ function removeUndefinedValues(obj) {
32
+ for (const key in Object.keys(obj)) {
33
+ if (obj[key] === void 0)
34
+ delete obj[key];
35
+ }
36
+ return obj;
37
+ }
38
+ function getCallLastIndex(code) {
39
+ let charIndex = -1;
40
+ let inString = null;
41
+ let startedBracers = 0;
42
+ let endedBracers = 0;
43
+ let beforeChar = null;
44
+ while (charIndex <= code.length) {
45
+ beforeChar = code[charIndex];
46
+ charIndex++;
47
+ const char = code[charIndex];
48
+ const isCharString = char === '"' || char === "'" || char === "`";
49
+ if (isCharString && beforeChar !== "\\") {
50
+ if (inString === char)
51
+ inString = null;
52
+ else if (!inString)
53
+ inString = char;
54
+ }
55
+ if (!inString) {
56
+ if (char === "(")
57
+ startedBracers++;
58
+ if (char === ")")
59
+ endedBracers++;
60
+ }
61
+ if (startedBracers && endedBracers && startedBracers === endedBracers)
62
+ return charIndex;
63
+ }
64
+ return null;
65
+ }
66
+ class AggregateErrorPonyfill extends Error {
67
+ constructor(errors, message = "") {
68
+ super(message);
69
+ this.errors = [...errors];
70
+ }
71
+ }
72
+
73
+ export { AggregateErrorPonyfill as A, getCallLastIndex as a, getCurrentEnvironment as b, relativePath as c, removeUndefinedValues as d, isWindows as e, getWorkerState as g, isRunningInBenchmark as i, resetModules as r };