vitest 0.29.7 → 0.30.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 +3 -266
  2. package/dist/browser.d.ts +16 -4
  3. package/dist/browser.js +5 -4
  4. package/dist/child.js +12 -17
  5. package/dist/{chunk-api-setup.ac7748ac.js → chunk-api-setup.6662587e.js} +65 -51
  6. package/dist/{chunk-install-pkg.863031f2.js → chunk-install-pkg.6450b372.js} +33 -32
  7. package/dist/chunk-integrations-globals.d419838f.js +26 -0
  8. package/dist/{chunk-node-git.ed5bded8.js → chunk-node-git.4c43bd73.js} +4 -2
  9. package/dist/cli-wrapper.js +6 -5
  10. package/dist/cli.js +27 -26
  11. package/dist/config.cjs +15 -7
  12. package/dist/config.d.ts +15 -8
  13. package/dist/config.js +10 -6
  14. package/dist/coverage.d.ts +5 -2
  15. package/dist/coverage.js +6 -0
  16. package/dist/entry.js +35 -34
  17. package/dist/environments.d.ts +5 -2
  18. package/dist/environments.js +1 -1
  19. package/dist/index.d.ts +17 -21
  20. package/dist/index.js +9 -10
  21. package/dist/loader.js +396 -12
  22. package/dist/node.d.ts +9 -7
  23. package/dist/node.js +28 -30
  24. package/dist/runners.d.ts +5 -2
  25. package/dist/runners.js +34 -30
  26. package/dist/{types-fafda418.d.ts → types-f03c83c4.d.ts} +243 -317
  27. package/dist/utils.d.ts +1 -0
  28. package/dist/utils.js +1 -0
  29. package/dist/{chunk-node-pkg.f9696901.js → vendor-cli-api.c04eaa34.js} +3858 -5514
  30. package/dist/vendor-constants.538d9b49.js +54 -0
  31. package/dist/{chunk-integrations-coverage.e0a6acd2.js → vendor-coverage.a585b712.js} +5 -5
  32. package/dist/{chunk-runtime-mocker.344fec90.js → vendor-execute.8eaab47b.js} +9 -12
  33. package/dist/vendor-global.6795f91f.js +8 -0
  34. package/dist/vendor-index.4f82d248.js +161 -0
  35. package/dist/{chunk-env-node.affdd278.js → vendor-index.75f2b63d.js} +9 -2
  36. package/dist/{chunk-integrations-utils.d7c85bd9.js → vendor-index.81b9e499.js} +22 -21
  37. package/dist/{vendor-index.2cbcdd1e.js → vendor-index.c1e09929.js} +458 -373
  38. package/dist/vendor-index.fad2598b.js +44 -0
  39. package/dist/{vendor-index.534e612c.js → vendor-index.fc98d30f.js} +2 -2
  40. package/dist/{chunk-runtime-inspector.b1427a10.js → vendor-inspector.47fc8cbb.js} +5 -2
  41. package/dist/{chunk-runtime-rpc.1b5714dc.js → vendor-rpc.4d3d7a54.js} +5 -5
  42. package/dist/{chunk-integrations-run-once.a2b4758b.js → vendor-run-once.69ce7172.js} +3 -2
  43. package/dist/{chunk-runtime-setup.a49dc2f9.js → vendor-setup.common.cef38f4e.js} +2 -2
  44. package/dist/vendor-tasks.042d6084.js +14 -0
  45. package/dist/{chunk-utils-import.39ffe9c5.js → vendor-vi.a3ff54b1.js} +262 -3147
  46. package/dist/worker.js +13 -19
  47. package/package.json +40 -34
  48. package/utils.d.ts +1 -0
  49. package/dist/chunk-constants.bc18a549.js +0 -36
  50. package/dist/chunk-integrations-globals.a473e88a.js +0 -27
  51. package/dist/chunk-snapshot-env.a347d647.js +0 -11
  52. package/dist/chunk-utils-base.81f83dbd.js +0 -88
  53. package/dist/chunk-utils-env.04ffbef7.js +0 -70
  54. package/dist/chunk-utils-tasks.b41c8284.js +0 -107
  55. package/dist/env-afee91f0.d.ts +0 -10
  56. package/dist/vendor-index.783e7f3e.js +0 -71
  57. package/dist/vendor-index.bdee400f.js +0 -396
  58. package/dist/vendor-magic-string.es.b3bc5745.js +0 -1591
  59. /package/dist/{vendor-_commonjsHelpers.addc3445.js → vendor-_commonjsHelpers.76cdd49e.js} +0 -0
  60. /package/dist/{chunk-paths.e36446b4.js → vendor-paths.84fc7a99.js} +0 -0
@@ -0,0 +1,54 @@
1
+ const defaultPort = 51204;
2
+ const defaultBrowserPort = 63315;
3
+ const EXIT_CODE_RESTART = 43;
4
+ const API_PATH = "/__vitest_api__";
5
+ const CONFIG_NAMES = [
6
+ "vitest.config",
7
+ "vite.config"
8
+ ];
9
+ const WORKSPACES_NAMES = [
10
+ "vitest.workspace",
11
+ "vitest.projects"
12
+ ];
13
+ const CONFIG_EXTENSIONS = [
14
+ ".ts",
15
+ ".mts",
16
+ ".cts",
17
+ ".js",
18
+ ".mjs",
19
+ ".cjs"
20
+ ];
21
+ const configFiles = CONFIG_NAMES.flatMap(
22
+ (name) => CONFIG_EXTENSIONS.map((ext) => name + ext)
23
+ );
24
+ const WORKSPACES_EXTENSIONS = [
25
+ ...CONFIG_EXTENSIONS,
26
+ ".json"
27
+ ];
28
+ const workspacesFiles = WORKSPACES_NAMES.flatMap(
29
+ (name) => WORKSPACES_EXTENSIONS.map((ext) => name + ext)
30
+ );
31
+ const globalApis = [
32
+ // suite
33
+ "suite",
34
+ "test",
35
+ "describe",
36
+ "it",
37
+ // chai
38
+ "chai",
39
+ "expect",
40
+ "assert",
41
+ // typecheck
42
+ "expectTypeOf",
43
+ "assertType",
44
+ // utils
45
+ "vitest",
46
+ "vi",
47
+ // hooks
48
+ "beforeAll",
49
+ "afterAll",
50
+ "beforeEach",
51
+ "afterEach"
52
+ ];
53
+
54
+ export { API_PATH as A, CONFIG_NAMES as C, EXIT_CODE_RESTART as E, defaultBrowserPort as a, configFiles as c, defaultPort as d, globalApis as g, workspacesFiles as w };
@@ -1,5 +1,3 @@
1
- import { importModule } from 'local-pkg';
2
-
3
1
  const CoverageProviderMap = {
4
2
  c8: "@vitest/coverage-c8",
5
3
  istanbul: "@vitest/coverage-istanbul"
@@ -8,8 +6,10 @@ async function resolveCoverageProviderModule(options, loader) {
8
6
  if (!(options == null ? void 0 : options.enabled) || !options.provider)
9
7
  return null;
10
8
  const provider = options.provider;
11
- if (provider === "c8" || provider === "istanbul")
12
- return await importModule(CoverageProviderMap[provider]);
9
+ if (provider === "c8" || provider === "istanbul") {
10
+ const { default: coverageModule } = await loader.executeId(CoverageProviderMap[provider]);
11
+ return coverageModule;
12
+ }
13
13
  let customProviderModule;
14
14
  try {
15
15
  customProviderModule = await loader.executeId(options.customProviderModule);
@@ -48,4 +48,4 @@ async function stopCoverageInsideWorker(options, loader) {
48
48
  return null;
49
49
  }
50
50
 
51
- export { CoverageProviderMap as C, stopCoverageInsideWorker as a, getCoverageProvider as g, startCoverageInsideWorker as s, takeCoverageInsideWorker as t };
51
+ export { CoverageProviderMap as C, startCoverageInsideWorker as a, getCoverageProvider as g, stopCoverageInsideWorker as s, takeCoverageInsideWorker as t };
@@ -1,16 +1,15 @@
1
1
  import { pathToFileURL } from 'node:url';
2
2
  import { ModuleCacheMap, ViteNodeRunner } from 'vite-node/client';
3
- import { isInternalRequest, isPrimitive } from 'vite-node/utils';
3
+ import { isNodeBuiltin, isInternalRequest, isPrimitive } from 'vite-node/utils';
4
4
  import { isAbsolute, dirname, join, basename, extname, resolve, normalize, relative } from 'pathe';
5
- import { i as isNodeBuiltin } from './vendor-index.bdee400f.js';
6
5
  import { processError } from '@vitest/runner/utils';
7
- import { g as getWorkerState, b as getCurrentEnvironment } from './chunk-utils-env.04ffbef7.js';
8
- import { d as distDir } from './chunk-paths.e36446b4.js';
6
+ import { g as getWorkerState, a as getCurrentEnvironment } from './vendor-global.6795f91f.js';
7
+ import { d as distDir } from './vendor-paths.84fc7a99.js';
9
8
  import { existsSync, readdirSync } from 'node:fs';
10
9
  import { getColors, getType } from '@vitest/utils';
11
- import { e as getAllMockableProperties } from './chunk-utils-base.81f83dbd.js';
10
+ import { e as getAllMockableProperties } from './vendor-index.4f82d248.js';
12
11
  import { spyOn } from '@vitest/spy';
13
- import { r as rpc } from './chunk-runtime-rpc.1b5714dc.js';
12
+ import { r as rpc } from './vendor-rpc.4d3d7a54.js';
14
13
 
15
14
  const filterPublicKeys = ["__esModule", Symbol.asyncIterator, Symbol.hasInstance, Symbol.isConcatSpreadable, Symbol.iterator, Symbol.match, Symbol.matchAll, Symbol.replace, Symbol.search, Symbol.split, Symbol.species, Symbol.toPrimitive, Symbol.toStringTag, Symbol.unscopables];
16
15
  class RefTracker {
@@ -42,9 +41,6 @@ const _VitestMocker = class {
42
41
  get root() {
43
42
  return this.executor.options.root;
44
43
  }
45
- get base() {
46
- return this.executor.options.base;
47
- }
48
44
  get mockMap() {
49
45
  return this.executor.options.mockMap;
50
46
  }
@@ -318,11 +314,12 @@ async function startViteNode(ctx) {
318
314
  var _a;
319
315
  const worker = getWorkerState();
320
316
  const error = processError(err);
321
- if (worker.filepath && !isPrimitive(error)) {
317
+ if (!isPrimitive(error)) {
322
318
  error.VITEST_TEST_NAME = (_a = worker.current) == null ? void 0 : _a.name;
323
- error.VITEST_TEST_PATH = relative(config.root, worker.filepath);
319
+ if (worker.filepath)
320
+ error.VITEST_TEST_PATH = relative(config.root, worker.filepath);
321
+ error.VITEST_AFTER_ENV_TEARDOWN = worker.environmentTeardownRun;
324
322
  }
325
- error.VITEST_AFTER_ENV_TEARDOWN = worker.environmentTeardownRun;
326
323
  rpc().onUnhandledError(error, type);
327
324
  }
328
325
  process.on("uncaughtException", (e) => catchError(e, "Uncaught Exception"));
@@ -0,0 +1,8 @@
1
+ function getWorkerState() {
2
+ return globalThis.__vitest_worker__;
3
+ }
4
+ function getCurrentEnvironment() {
5
+ return globalThis.__vitest_environment__;
6
+ }
7
+
8
+ export { getCurrentEnvironment as a, getWorkerState as g };
@@ -0,0 +1,161 @@
1
+ import '@vitest/utils';
2
+
3
+ function isFinalObj(obj) {
4
+ return obj === Object.prototype || obj === Function.prototype || obj === RegExp.prototype;
5
+ }
6
+ function collectOwnProperties(obj, collector) {
7
+ const collect = typeof collector === "function" ? collector : (key) => collector.add(key);
8
+ Object.getOwnPropertyNames(obj).forEach(collect);
9
+ Object.getOwnPropertySymbols(obj).forEach(collect);
10
+ }
11
+ function groupBy(collection, iteratee) {
12
+ return collection.reduce((acc, item) => {
13
+ const key = iteratee(item);
14
+ acc[key] || (acc[key] = []);
15
+ acc[key].push(item);
16
+ return acc;
17
+ }, {});
18
+ }
19
+ function isPrimitive(value) {
20
+ return value === null || typeof value !== "function" && typeof value !== "object";
21
+ }
22
+ function getAllMockableProperties(obj, isModule) {
23
+ const allProps = /* @__PURE__ */ new Map();
24
+ let curr = obj;
25
+ do {
26
+ if (isFinalObj(curr))
27
+ break;
28
+ collectOwnProperties(curr, (key) => {
29
+ const descriptor = Object.getOwnPropertyDescriptor(curr, key);
30
+ if (descriptor)
31
+ allProps.set(key, { key, descriptor });
32
+ });
33
+ } while (curr = Object.getPrototypeOf(curr));
34
+ if (isModule && !allProps.has("default") && "default" in obj) {
35
+ const descriptor = Object.getOwnPropertyDescriptor(obj, "default");
36
+ if (descriptor)
37
+ allProps.set("default", { key: "default", descriptor });
38
+ }
39
+ return Array.from(allProps.values());
40
+ }
41
+ function slash(str) {
42
+ return str.replace(/\\/g, "/");
43
+ }
44
+ function noop() {
45
+ }
46
+ function toArray(array) {
47
+ if (array === null || array === void 0)
48
+ array = [];
49
+ if (Array.isArray(array))
50
+ return array;
51
+ return [array];
52
+ }
53
+ function toString(v) {
54
+ return Object.prototype.toString.call(v);
55
+ }
56
+ function isPlainObject(val) {
57
+ return toString(val) === "[object Object]" && (!val.constructor || val.constructor.name === "Object");
58
+ }
59
+ function deepMerge(target, ...sources) {
60
+ if (!sources.length)
61
+ return target;
62
+ const source = sources.shift();
63
+ if (source === void 0)
64
+ return target;
65
+ if (isMergeableObject(target) && isMergeableObject(source)) {
66
+ Object.keys(source).forEach((key) => {
67
+ if (isMergeableObject(source[key])) {
68
+ if (!target[key])
69
+ target[key] = {};
70
+ deepMerge(target[key], source[key]);
71
+ } else {
72
+ target[key] = source[key];
73
+ }
74
+ });
75
+ }
76
+ return deepMerge(target, ...sources);
77
+ }
78
+ function isMergeableObject(item) {
79
+ return isPlainObject(item) && !Array.isArray(item);
80
+ }
81
+ function stdout() {
82
+ return console._stdout || process.stdout;
83
+ }
84
+ function getEnvironmentTransformMode(config, environment) {
85
+ var _a, _b;
86
+ if (!((_b = (_a = config.deps) == null ? void 0 : _a.experimentalOptimizer) == null ? void 0 : _b.enabled))
87
+ return void 0;
88
+ return environment === "happy-dom" || environment === "jsdom" ? "web" : "ssr";
89
+ }
90
+
91
+ const DEFAULT_TIMEOUT = 6e4;
92
+ function createBirpc(functions, options) {
93
+ const {
94
+ post,
95
+ on,
96
+ eventNames = [],
97
+ serialize = (i) => i,
98
+ deserialize = (i) => i,
99
+ timeout = DEFAULT_TIMEOUT
100
+ } = options;
101
+ const rpcPromiseMap = /* @__PURE__ */ new Map();
102
+ const rpc = new Proxy({}, {
103
+ get(_, method) {
104
+ const sendEvent = (...args) => {
105
+ post(serialize({ m: method, a: args, t: "q" }));
106
+ };
107
+ if (eventNames.includes(method)) {
108
+ sendEvent.asEvent = sendEvent;
109
+ return sendEvent;
110
+ }
111
+ const sendCall = (...args) => {
112
+ return new Promise((resolve, reject) => {
113
+ const id = nanoid();
114
+ rpcPromiseMap.set(id, { resolve, reject });
115
+ post(serialize({ m: method, a: args, i: id, t: "q" }));
116
+ if (timeout >= 0) {
117
+ setTimeout(() => {
118
+ reject(new Error(`[birpc] timeout on calling "${method}"`));
119
+ rpcPromiseMap.delete(id);
120
+ }, timeout);
121
+ }
122
+ });
123
+ };
124
+ sendCall.asEvent = sendEvent;
125
+ return sendCall;
126
+ }
127
+ });
128
+ on(async (data, ...extra) => {
129
+ const msg = deserialize(data);
130
+ if (msg.t === "q") {
131
+ const { m: method, a: args } = msg;
132
+ let result, error;
133
+ try {
134
+ result = await functions[method].apply(rpc, args);
135
+ } catch (e) {
136
+ error = e;
137
+ }
138
+ if (msg.i)
139
+ post(serialize({ t: "s", i: msg.i, r: result, e: error }), ...extra);
140
+ } else {
141
+ const { i: ack, r: result, e: error } = msg;
142
+ const promise = rpcPromiseMap.get(ack);
143
+ if (error)
144
+ promise?.reject(error);
145
+ else
146
+ promise?.resolve(result);
147
+ rpcPromiseMap.delete(ack);
148
+ }
149
+ });
150
+ return rpc;
151
+ }
152
+ const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
153
+ function nanoid(size = 21) {
154
+ let id = "";
155
+ let i = size;
156
+ while (i--)
157
+ id += urlAlphabet[Math.random() * 64 | 0];
158
+ return id;
159
+ }
160
+
161
+ export { getEnvironmentTransformMode as a, stdout as b, createBirpc as c, deepMerge as d, getAllMockableProperties as e, groupBy as g, isPrimitive as i, noop as n, slash as s, toArray as t };
@@ -176,6 +176,7 @@ const LIVING_KEYS = [
176
176
  "AbortController",
177
177
  "AbortSignal",
178
178
  "ArrayBuffer",
179
+ // not specified in docs, but is available
179
180
  "Image",
180
181
  "Audio",
181
182
  "Option"
@@ -187,8 +188,11 @@ const OTHER_KEYS = [
187
188
  "blur",
188
189
  "btoa",
189
190
  "cancelAnimationFrame",
191
+ /* 'clearInterval', */
192
+ /* 'clearTimeout', */
190
193
  "close",
191
194
  "confirm",
195
+ /* 'console', */
192
196
  "createPopup",
193
197
  "dispatchEvent",
194
198
  "document",
@@ -231,7 +235,10 @@ const OTHER_KEYS = [
231
235
  "scrollX",
232
236
  "scrollY",
233
237
  "self",
238
+ /* 'setInterval', */
239
+ /* 'setTimeout', */
234
240
  "stop",
241
+ /* 'toString', */
235
242
  "top",
236
243
  "Window",
237
244
  "window"
@@ -422,12 +429,12 @@ const envPackageNames = {
422
429
  "happy-dom": "happy-dom",
423
430
  "edge-runtime": "@edge-runtime/vm"
424
431
  };
425
- const getEnvPackageName = (env) => {
432
+ function getEnvPackageName(env) {
426
433
  if (env === "node")
427
434
  return null;
428
435
  if (env in envPackageNames)
429
436
  return envPackageNames[env];
430
437
  return `vitest-environment-${env}`;
431
- };
438
+ }
432
439
 
433
440
  export { environments as e, getEnvPackageName as g, populateGlobal as p };
@@ -1,6 +1,6 @@
1
- import { suite, test, describe, it, beforeAll, beforeEach, afterAll, afterEach, onTestFailed } from '@vitest/runner';
2
- import { b as bench, c as createExpect, g as globalExpect, v as vitest, a as vi } from './chunk-utils-import.39ffe9c5.js';
3
- import { r as runOnce, i as isFirstRun } from './chunk-integrations-run-once.a2b4758b.js';
1
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
2
+ import { e as bench, c as createExpect, d as globalExpect, s as setupChaiConfig, v as vi, f as vitest } from './vendor-vi.a3ff54b1.js';
3
+ import { i as isFirstRun, a as runOnce } from './vendor-run-once.69ce7172.js';
4
4
  import * as chai from 'chai';
5
5
  import { assert, should } from 'chai';
6
6
 
@@ -84,35 +84,36 @@ var dist = {};
84
84
  exports.expectTypeOf = expectTypeOf;
85
85
  } (dist));
86
86
 
87
- const noop = () => {
88
- };
87
+ function noop() {
88
+ }
89
89
  const assertType = noop;
90
90
 
91
91
  var index = /*#__PURE__*/Object.freeze({
92
92
  __proto__: null,
93
- suite: suite,
94
- test: test,
95
- describe: describe,
96
- it: it,
97
- beforeAll: beforeAll,
98
- beforeEach: beforeEach,
99
93
  afterAll: afterAll,
100
94
  afterEach: afterEach,
101
- onTestFailed: onTestFailed,
102
- bench: bench,
103
- runOnce: runOnce,
104
- isFirstRun: isFirstRun,
105
95
  assert: assert,
106
- should: should,
107
- createExpect: createExpect,
96
+ assertType: assertType,
97
+ beforeAll: beforeAll,
98
+ beforeEach: beforeEach,
99
+ bench: bench,
108
100
  chai: chai,
101
+ createExpect: createExpect,
102
+ describe: describe,
109
103
  expect: globalExpect,
110
- vitest: vitest,
111
- vi: vi,
104
+ expectTypeOf: dist.expectTypeOf,
112
105
  getRunningMode: getRunningMode,
106
+ isFirstRun: isFirstRun,
113
107
  isWatchMode: isWatchMode,
114
- expectTypeOf: dist.expectTypeOf,
115
- assertType: assertType
108
+ it: it,
109
+ onTestFailed: onTestFailed,
110
+ runOnce: runOnce,
111
+ setupChaiConfig: setupChaiConfig,
112
+ should: should,
113
+ suite: suite,
114
+ test: test,
115
+ vi: vi,
116
+ vitest: vitest
116
117
  });
117
118
 
118
119
  export { isWatchMode as a, assertType as b, dist as d, getRunningMode as g, index as i };