vitest 0.27.3 → 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 (60) 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 +9 -34
  5. package/dist/{chunk-api-setup.0a2398d8.js → chunk-api-setup.52751a38.js} +26 -12
  6. package/dist/chunk-constants.797d3ebf.js +42 -0
  7. package/dist/{chunk-install-pkg.7b006b3e.js → chunk-install-pkg.cfd23146.js} +51 -11
  8. package/dist/{vendor-index.57682f0c.js → chunk-integrations-coverage.48e6286b.js} +33 -4
  9. package/dist/chunk-integrations-globals.0d5f50f0.js +29 -0
  10. package/dist/chunk-integrations-run-once.38756e30.js +27 -0
  11. package/dist/chunk-integrations-utils.f1f6f1ed.js +118 -0
  12. package/dist/{chunk-node-git.59caac18.js → chunk-node-git.d9ad64ab.js} +6 -8
  13. package/dist/{chunk-snapshot-manager.d16903ef.js → chunk-node-pkg.dcdf4369.js} +7440 -172
  14. package/dist/{chunk-runtime-mocker.66533d65.js → chunk-runtime-mocker.03017e8c.js} +13 -12
  15. package/dist/{chunk-runtime-rpc.e79efa9a.js → chunk-runtime-rpc.9c0386cc.js} +3 -2
  16. package/dist/chunk-runtime-setup.d9302cfd.js +20 -0
  17. package/dist/chunk-snapshot-env.6457638e.js +11 -0
  18. package/dist/chunk-utils-base.977ae74f.js +77 -0
  19. package/dist/chunk-utils-env.860d90c2.js +6 -0
  20. package/dist/chunk-utils-global.442d1d33.js +73 -0
  21. package/dist/{chunk-utils-import.eb63557e.js → chunk-utils-import.9911c99d.js} +3289 -169
  22. package/dist/chunk-utils-tasks.1b603032.js +103 -0
  23. package/dist/cli-wrapper.js +7 -6
  24. package/dist/cli.js +16 -15
  25. package/dist/config.d.ts +7 -2
  26. package/dist/entry.js +233 -28
  27. package/dist/env-afee91f0.d.ts +10 -0
  28. package/dist/environments.d.ts +7 -2
  29. package/dist/index.d.ts +160 -11
  30. package/dist/index.js +17 -18
  31. package/dist/loader.js +6 -6
  32. package/dist/node.d.ts +9 -7
  33. package/dist/node.js +18 -17
  34. package/dist/runners-chunk.js +215 -0
  35. package/dist/runners.d.ts +39 -0
  36. package/dist/runners.js +18 -0
  37. package/dist/spy.js +1 -2
  38. package/dist/suite.d.ts +2 -0
  39. package/dist/suite.js +2 -19
  40. package/dist/{types-c1386a7d.d.ts → types-c800444e.d.ts} +160 -425
  41. package/dist/{vendor-index.e6c27006.js → vendor-index.618ca5a1.js} +1078 -10
  42. package/dist/{vendor-index.b0346fe4.js → vendor-index.bdee400f.js} +1 -0
  43. package/dist/worker.js +11 -13
  44. package/package.json +21 -12
  45. package/runners.d.ts +1 -0
  46. package/suite.d.ts +1 -0
  47. package/dist/chunk-integrations-coverage.18366936.js +0 -242
  48. package/dist/chunk-integrations-globals.59b4d460.js +0 -28
  49. package/dist/chunk-mock-date.91595ccd.js +0 -350
  50. package/dist/chunk-runtime-chain.07d16eac.js +0 -2594
  51. package/dist/chunk-runtime-error.f2062967.js +0 -144
  52. package/dist/chunk-runtime-setup.8ca273cd.js +0 -653
  53. package/dist/chunk-utils-env.4ebb0106.js +0 -229
  54. package/dist/chunk-utils-source-map.832515f7.js +0 -408
  55. package/dist/chunk-utils-timers.52534f96.js +0 -3573
  56. package/dist/index-2dd51af4.d.ts +0 -258
  57. package/dist/vendor-index.451e37bc.js +0 -1071
  58. package/dist/vendor-index.723a074f.js +0 -102
  59. package/dist/vendor-index.9c919048.js +0 -61
  60. 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.91595ccd.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.4ebb0106.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,6 +312,11 @@ 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))
@@ -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.91595ccd.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 };