vitest 2.1.2 → 2.1.4

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 (74) hide show
  1. package/LICENSE.md +320 -238
  2. package/dist/browser.d.ts +21 -21
  3. package/dist/browser.js +7 -7
  4. package/dist/chunks/{RandomSequencer.Bh5-tlNJ.js → RandomSequencer.CMRlh2v4.js} +143 -142
  5. package/dist/chunks/{base.tiemDJX6.js → base.C3xNdjV6.js} +3 -3
  6. package/dist/chunks/{benchmark.C8CRJYG4.js → benchmark.Cdu9hjj4.js} +2 -2
  7. package/dist/chunks/{benchmark.JVlTzojj.d.ts → benchmark.geERunq4.d.ts} +1 -1
  8. package/dist/chunks/{cac.B9PaPYY1.js → cac.DrfPaMvZ.js} +11 -10
  9. package/dist/chunks/{cli-api.CHxC4-U8.js → cli-api.CKrRYkw8.js} +3573 -3353
  10. package/dist/chunks/{console.DI3gHgtH.js → console.BYGVloWk.js} +3 -7
  11. package/dist/chunks/{coverage.zlNdAMHK.js → coverage.BoMDb1ip.js} +1 -1
  12. package/dist/chunks/{creator.Cf-MKt9i.js → creator.IIqd8RWT.js} +8 -8
  13. package/dist/chunks/{execute._eQQfgI8.js → execute.2pr0rHgK.js} +8 -6
  14. package/dist/chunks/{globals.HsM2o-0O.js → globals.Bp645TTJ.js} +8 -13
  15. package/dist/chunks/{index.BpSiYbpB.js → index.68735LiX.js} +28 -5
  16. package/dist/chunks/{index.BpojBOif.js → index.BJDntFik.js} +10 -10
  17. package/dist/chunks/{index.FcPVJkIQ.js → index.Bn81VaWg.js} +3828 -3790
  18. package/dist/chunks/{index.CPD77dLA.js → index.CqYx2Nsr.js} +7 -7
  19. package/dist/chunks/{index.Ckn0Cw1h.js → index.D3d79vc8.js} +6 -6
  20. package/dist/chunks/index.Dqe5k2Rk.js +54 -0
  21. package/dist/chunks/{node.Bx4JZjMG.js → node.AKq966Jp.js} +1 -5
  22. package/dist/chunks/{reporters.DAfKSDh5.d.ts → reporters.anwo7Y6a.d.ts} +1159 -1144
  23. package/dist/chunks/{resolveConfig.D1DENLPF.js → resolveConfig.DPmbhVlP.js} +2610 -2574
  24. package/dist/chunks/{rpc.B7Mfb-Yf.js → rpc.C3q9uwRX.js} +2 -2
  25. package/dist/chunks/{run-once.Sxe67Wng.js → run-once.2ogXb3JV.js} +1 -1
  26. package/dist/chunks/{runBaseTests.D-Gcin7G.js → runBaseTests.Dm-659zB.js} +21 -25
  27. package/dist/chunks/{setup-common.DF96bIYE.js → setup-common.DDmVKp6O.js} +3 -3
  28. package/dist/chunks/{suite.BMWOKiTe.d.ts → suite.B2jumIFP.d.ts} +2 -2
  29. package/dist/chunks/{utils.CY6Spixo.js → utils.BB4zjzR8.js} +2 -2
  30. package/dist/chunks/utils.C8RiOc4B.js +77 -0
  31. package/dist/chunks/{vi.DUs2eKik.js → vi.JMQoNY_Z.js} +94 -139
  32. package/dist/chunks/{vite.8fk186v-.d.ts → vite.BdBj-UWY.d.ts} +1 -1
  33. package/dist/chunks/{vm.CPXwWp4C.js → vm.jpyrB0xy.js} +5 -8
  34. package/dist/chunks/{worker.Chrs-_NL.d.ts → worker.BAlI9hII.d.ts} +50 -27
  35. package/dist/chunks/{worker.Qtv8v5nL.d.ts → worker.DHnGaO2M.d.ts} +1 -1
  36. package/dist/cli.js +3 -4
  37. package/dist/config.cjs +4 -4
  38. package/dist/config.d.ts +24 -19
  39. package/dist/config.js +4 -4
  40. package/dist/coverage.d.ts +72 -35
  41. package/dist/coverage.js +256 -118
  42. package/dist/environments.d.ts +2 -2
  43. package/dist/environments.js +1 -1
  44. package/dist/execute.d.ts +53 -53
  45. package/dist/execute.js +7 -6
  46. package/dist/index.d.ts +92 -1099
  47. package/dist/index.js +7 -18
  48. package/dist/node.d.ts +43 -41
  49. package/dist/node.js +23 -28
  50. package/dist/path.js +1 -1
  51. package/dist/reporters.d.ts +10 -10
  52. package/dist/reporters.js +12 -18
  53. package/dist/runners.d.ts +12 -19
  54. package/dist/runners.js +142 -148
  55. package/dist/snapshot.js +2 -6
  56. package/dist/suite.d.ts +2 -2
  57. package/dist/suite.js +2 -6
  58. package/dist/worker.js +5 -6
  59. package/dist/workers/forks.js +9 -8
  60. package/dist/workers/runVmTests.js +16 -20
  61. package/dist/workers/threads.js +9 -8
  62. package/dist/workers/vmForks.js +9 -12
  63. package/dist/workers/vmThreads.js +9 -12
  64. package/dist/workers.d.ts +13 -13
  65. package/dist/workers.js +14 -18
  66. package/package.json +27 -27
  67. package/dist/chunks/base.DwXGwWst.js +0 -89
  68. package/dist/chunks/env.CmHVDJnw.js +0 -7
  69. package/dist/chunks/index.CxRxs566.js +0 -23
  70. package/dist/chunks/index.mAqbj9F9.js +0 -140
  71. package/dist/chunks/tasks.BZnCS9aT.js +0 -18
  72. package/dist/chunks/utils.Ck2hJTRs.js +0 -23
  73. package/dist/chunks/{environment.CzISCQ7o.d.ts → environment.LoooBwUu.d.ts} +24 -24
  74. package/dist/chunks/{index.lVXYBqEP.js → index.BMoXz_-n.js} +186 -186
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "2.1.2",
4
+ "version": "2.1.4",
5
5
  "description": "Next generation testing framework powered by Vite",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -122,8 +122,8 @@
122
122
  "@types/node": "^18.0.0 || >=20.0.0",
123
123
  "happy-dom": "*",
124
124
  "jsdom": "*",
125
- "@vitest/browser": "2.1.2",
126
- "@vitest/ui": "2.1.2"
125
+ "@vitest/browser": "2.1.4",
126
+ "@vitest/ui": "2.1.4"
127
127
  },
128
128
  "peerDependenciesMeta": {
129
129
  "@edge-runtime/vm": {
@@ -146,58 +146,58 @@
146
146
  }
147
147
  },
148
148
  "dependencies": {
149
- "chai": "^5.1.1",
150
- "debug": "^4.3.6",
151
- "magic-string": "^0.30.11",
149
+ "chai": "^5.1.2",
150
+ "debug": "^4.3.7",
151
+ "expect-type": "^1.1.0",
152
+ "magic-string": "^0.30.12",
152
153
  "pathe": "^1.1.2",
153
154
  "std-env": "^3.7.0",
154
155
  "tinybench": "^2.9.0",
155
- "tinyexec": "^0.3.0",
156
- "tinypool": "^1.0.0",
156
+ "tinyexec": "^0.3.1",
157
+ "tinypool": "^1.0.1",
157
158
  "tinyrainbow": "^1.2.0",
158
159
  "vite": "^5.0.0",
159
160
  "why-is-node-running": "^2.3.0",
160
- "@vitest/expect": "2.1.2",
161
- "@vitest/pretty-format": "^2.1.2",
162
- "@vitest/mocker": "2.1.2",
163
- "@vitest/snapshot": "2.1.2",
164
- "@vitest/runner": "2.1.2",
165
- "@vitest/utils": "2.1.2",
166
- "@vitest/spy": "2.1.2",
167
- "vite-node": "2.1.2"
161
+ "@vitest/expect": "2.1.4",
162
+ "@vitest/mocker": "2.1.4",
163
+ "@vitest/spy": "2.1.4",
164
+ "@vitest/pretty-format": "^2.1.4",
165
+ "@vitest/utils": "2.1.4",
166
+ "@vitest/snapshot": "2.1.4",
167
+ "@vitest/runner": "2.1.4",
168
+ "vite-node": "2.1.4"
168
169
  },
169
170
  "devDependencies": {
170
171
  "@ampproject/remapping": "^2.3.0",
171
172
  "@antfu/install-pkg": "^0.4.1",
172
- "@edge-runtime/vm": "^4.0.1",
173
+ "@edge-runtime/vm": "^4.0.3",
173
174
  "@sinonjs/fake-timers": "11.1.0",
174
175
  "@types/debug": "^4.1.12",
175
- "@types/estree": "^1.0.5",
176
+ "@types/estree": "^1.0.6",
176
177
  "@types/istanbul-lib-coverage": "^2.0.6",
177
178
  "@types/istanbul-reports": "^3.0.4",
178
179
  "@types/jsdom": "^21.1.7",
179
180
  "@types/micromatch": "^4.0.9",
180
- "@types/node": "^22.5.2",
181
+ "@types/node": "^22.7.9",
181
182
  "@types/prompts": "^2.4.9",
182
183
  "@types/sinonjs__fake-timers": "^8.1.5",
183
- "acorn-walk": "^8.3.3",
184
- "birpc": "0.2.17",
184
+ "acorn-walk": "^8.3.4",
185
+ "birpc": "0.2.19",
185
186
  "cac": "^6.7.14",
186
187
  "chai-subset": "^1.6.0",
187
188
  "cli-truncate": "^4.0.0",
188
- "expect-type": "^0.19.0",
189
+ "fast-glob": "3.3.2",
189
190
  "find-up": "^6.3.0",
190
191
  "flatted": "^3.3.1",
191
- "get-tsconfig": "^4.7.6",
192
- "happy-dom": "^15.7.3",
193
- "jsdom": "^25.0.0",
192
+ "get-tsconfig": "^4.8.1",
193
+ "happy-dom": "^15.7.4",
194
+ "jsdom": "^25.0.1",
194
195
  "local-pkg": "^0.5.0",
195
196
  "log-update": "^5.0.1",
196
- "micromatch": "^4.0.7",
197
+ "micromatch": "^4.0.8",
197
198
  "pretty-format": "^29.7.0",
198
199
  "prompts": "^2.4.2",
199
200
  "strip-literal": "^2.1.0",
200
- "tinyglobby": "^0.2.6",
201
201
  "ws": "^8.18.0"
202
202
  },
203
203
  "scripts": {
@@ -1,89 +0,0 @@
1
- import '@vitest/utils';
2
-
3
- function groupBy(collection, iteratee) {
4
- return collection.reduce((acc, item) => {
5
- const key = iteratee(item);
6
- acc[key] ||= [];
7
- acc[key].push(item);
8
- return acc;
9
- }, {});
10
- }
11
- function isPrimitive(value) {
12
- return value === null || typeof value !== "function" && typeof value !== "object";
13
- }
14
- function slash(str) {
15
- return str.replace(/\\/g, "/");
16
- }
17
- function noop() {
18
- }
19
- function toArray(array) {
20
- if (array === null || array === void 0) {
21
- array = [];
22
- }
23
- if (Array.isArray(array)) {
24
- return array;
25
- }
26
- return [array];
27
- }
28
- function toString(v) {
29
- return Object.prototype.toString.call(v);
30
- }
31
- function isPlainObject(val) {
32
- return toString(val) === "[object Object]" && (!val.constructor || val.constructor.name === "Object");
33
- }
34
- function deepMerge(target, ...sources) {
35
- if (!sources.length) {
36
- return target;
37
- }
38
- const source = sources.shift();
39
- if (source === void 0) {
40
- return target;
41
- }
42
- if (isMergeableObject(target) && isMergeableObject(source)) {
43
- Object.keys(source).forEach((key) => {
44
- const _source = source;
45
- if (isMergeableObject(_source[key])) {
46
- if (!target[key]) {
47
- target[key] = {};
48
- }
49
- deepMerge(target[key], _source[key]);
50
- } else {
51
- target[key] = _source[key];
52
- }
53
- });
54
- }
55
- return deepMerge(target, ...sources);
56
- }
57
- function isMergeableObject(item) {
58
- return isPlainObject(item) && !Array.isArray(item);
59
- }
60
- function stdout() {
61
- return console._stdout || process.stdout;
62
- }
63
- class AggregateErrorPonyfill extends Error {
64
- errors;
65
- constructor(errors, message = "") {
66
- super(message);
67
- this.errors = [...errors];
68
- }
69
- }
70
- function isChildProcess() {
71
- return typeof process !== "undefined" && !!process.send;
72
- }
73
- function setProcessTitle(title) {
74
- try {
75
- process.title = `node (${title})`;
76
- } catch {
77
- }
78
- }
79
- function escapeRegExp(s) {
80
- return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
81
- }
82
- function wildcardPatternToRegExp(pattern) {
83
- return new RegExp(
84
- `^${pattern.split("*").map(escapeRegExp).join(".*")}$`,
85
- "i"
86
- );
87
- }
88
-
89
- export { AggregateErrorPonyfill as A, slash as a, isPrimitive as b, stdout as c, deepMerge as d, groupBy as g, isChildProcess as i, noop as n, setProcessTitle as s, toArray as t, wildcardPatternToRegExp as w };
@@ -1,7 +0,0 @@
1
- import 'std-env';
2
-
3
- const isNode = typeof process < "u" && typeof process.stdout < "u" && !process.versions?.deno && !globalThis.window;
4
- const isDeno = typeof process < "u" && typeof process.stdout < "u" && process.versions?.deno !== void 0;
5
- const isWindows = (isNode || isDeno) && process.platform === "win32";
6
-
7
- export { isNode as a, isDeno as b, isWindows as i };
@@ -1,23 +0,0 @@
1
- import { relative } from 'pathe';
2
- import '@vitest/runner/utils';
3
- import '@vitest/utils';
4
- import { g as getWorkerState } from './utils.Ck2hJTRs.js';
5
- import './env.CmHVDJnw.js';
6
-
7
- function getRunMode() {
8
- return getWorkerState().config.mode;
9
- }
10
- function isRunningInBenchmark() {
11
- return getRunMode() === "benchmark";
12
- }
13
- const relativePath = relative;
14
- function removeUndefinedValues(obj) {
15
- for (const key in Object.keys(obj)) {
16
- if (obj[key] === void 0) {
17
- delete obj[key];
18
- }
19
- }
20
- return obj;
21
- }
22
-
23
- export { removeUndefinedValues as a, isRunningInBenchmark as i, relativePath as r };
@@ -1,140 +0,0 @@
1
- import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
2
- import { b as bench } from './benchmark.C8CRJYG4.js';
3
- import { i as isFirstRun, a as runOnce } from './run-once.Sxe67Wng.js';
4
- import { c as createExpect, a as globalExpect, v as vi, b as vitest } from './vi.DUs2eKik.js';
5
- import { g as getWorkerState } from './utils.Ck2hJTRs.js';
6
- import * as chai from 'chai';
7
- import { assert, should } from 'chai';
8
-
9
- var dist = {};
10
-
11
- var hasRequiredDist;
12
-
13
- function requireDist () {
14
- if (hasRequiredDist) return dist;
15
- hasRequiredDist = 1;
16
- (function (exports) {
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.expectTypeOf = void 0;
19
- const fn = () => true;
20
- /**
21
- * Similar to Jest's `expect`, but with type-awareness.
22
- * Gives you access to a number of type-matchers that let you make assertions about the
23
- * form of a reference or generic type parameter.
24
- *
25
- * @example
26
- * import {foo, bar} from '../foo'
27
- * import {expectTypeOf} from 'expect-type'
28
- *
29
- * test('foo types', () => {
30
- * // make sure `foo` has type {a: number}
31
- * expectTypeOf(foo).toMatchTypeOf({a: 1})
32
- * expectTypeOf(foo).toHaveProperty('a').toBeNumber()
33
- *
34
- * // make sure `bar` is a function taking a string:
35
- * expectTypeOf(bar).parameter(0).toBeString()
36
- * expectTypeOf(bar).returns.not.toBeAny()
37
- * })
38
- *
39
- * @description
40
- * See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples.
41
- */
42
- const expectTypeOf = (_actual) => {
43
- const nonFunctionProperties = [
44
- 'parameters',
45
- 'returns',
46
- 'resolves',
47
- 'not',
48
- 'items',
49
- 'constructorParameters',
50
- 'thisParameter',
51
- 'instance',
52
- 'guards',
53
- 'asserts',
54
- 'branded',
55
- ];
56
- const obj = {
57
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
58
- toBeAny: fn,
59
- toBeUnknown: fn,
60
- toBeNever: fn,
61
- toBeFunction: fn,
62
- toBeObject: fn,
63
- toBeArray: fn,
64
- toBeString: fn,
65
- toBeNumber: fn,
66
- toBeBoolean: fn,
67
- toBeVoid: fn,
68
- toBeSymbol: fn,
69
- toBeNull: fn,
70
- toBeUndefined: fn,
71
- toBeNullable: fn,
72
- toMatchTypeOf: fn,
73
- toEqualTypeOf: fn,
74
- toBeCallableWith: fn,
75
- toBeConstructibleWith: fn,
76
- /* eslint-enable @typescript-eslint/no-unsafe-assignment */
77
- extract: exports.expectTypeOf,
78
- exclude: exports.expectTypeOf,
79
- pick: exports.expectTypeOf,
80
- omit: exports.expectTypeOf,
81
- toHaveProperty: exports.expectTypeOf,
82
- parameter: exports.expectTypeOf,
83
- };
84
- const getterProperties = nonFunctionProperties;
85
- getterProperties.forEach((prop) => Object.defineProperty(obj, prop, { get: () => (0, exports.expectTypeOf)({}) }));
86
- return obj;
87
- };
88
- exports.expectTypeOf = expectTypeOf;
89
- } (dist));
90
- return dist;
91
- }
92
-
93
- var distExports = requireDist();
94
-
95
- function noop() {
96
- }
97
- const assertType = noop;
98
-
99
- function getRunningMode() {
100
- return process.env.VITEST_MODE === "WATCH" ? "watch" : "run";
101
- }
102
- function isWatchMode() {
103
- return getRunningMode() === "watch";
104
- }
105
-
106
- function inject(key) {
107
- const workerState = getWorkerState();
108
- return workerState.providedContext[key];
109
- }
110
-
111
- var VitestIndex = /*#__PURE__*/Object.freeze({
112
- __proto__: null,
113
- afterAll: afterAll,
114
- afterEach: afterEach,
115
- assert: assert,
116
- assertType: assertType,
117
- beforeAll: beforeAll,
118
- beforeEach: beforeEach,
119
- bench: bench,
120
- chai: chai,
121
- createExpect: createExpect,
122
- describe: describe,
123
- expect: globalExpect,
124
- expectTypeOf: distExports.expectTypeOf,
125
- getRunningMode: getRunningMode,
126
- inject: inject,
127
- isFirstRun: isFirstRun,
128
- isWatchMode: isWatchMode,
129
- it: it,
130
- onTestFailed: onTestFailed,
131
- onTestFinished: onTestFinished,
132
- runOnce: runOnce,
133
- should: should,
134
- suite: suite,
135
- test: test,
136
- vi: vi,
137
- vitest: vitest
138
- });
139
-
140
- export { VitestIndex as V, assertType as a, inject as b, distExports as d, getRunningMode as g, isWatchMode as i };
@@ -1,18 +0,0 @@
1
- import { getNames, getTests } from '@vitest/runner/utils';
2
- import '@vitest/utils';
3
-
4
- function hasFailedSnapshot(suite) {
5
- return getTests(suite).some((s) => {
6
- return s.result?.errors?.some(
7
- (e) => typeof e?.message === "string" && e.message.match(/Snapshot .* mismatched/)
8
- );
9
- });
10
- }
11
- function getFullName(task, separator = " > ") {
12
- return getNames(task).join(separator);
13
- }
14
- function getTestName(task, separator = " > ") {
15
- return getNames(task).slice(1).join(separator);
16
- }
17
-
18
- export { getFullName as a, getTestName as g, hasFailedSnapshot as h };
@@ -1,23 +0,0 @@
1
- function getWorkerState() {
2
- const workerState = globalThis.__vitest_worker__;
3
- if (!workerState) {
4
- const errorMsg = 'Vitest failed to access its internal state.\n\nOne of the following is possible:\n- "vitest" is imported directly without running "vitest" command\n- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n';
5
- throw new Error(errorMsg);
6
- }
7
- return workerState;
8
- }
9
- function provideWorkerState(context, state) {
10
- Object.defineProperty(context, "__vitest_worker__", {
11
- value: state,
12
- configurable: true,
13
- writable: true,
14
- enumerable: false
15
- });
16
- return state;
17
- }
18
- function getCurrentEnvironment() {
19
- const state = getWorkerState();
20
- return state?.environment.name;
21
- }
22
-
23
- export { getCurrentEnvironment as a, getWorkerState as g, provideWorkerState as p };
@@ -39,6 +39,30 @@ type OnServerRestartHandler = (reason?: string) => Promise<void> | void;
39
39
  interface ProvidedContext {
40
40
  }
41
41
 
42
+ /**
43
+ * Happy DOM options.
44
+ */
45
+ interface HappyDOMOptions {
46
+ width?: number;
47
+ height?: number;
48
+ url?: string;
49
+ settings?: {
50
+ disableJavaScriptEvaluation?: boolean;
51
+ disableJavaScriptFileLoading?: boolean;
52
+ disableCSSFileLoading?: boolean;
53
+ disableIframePageLoading?: boolean;
54
+ disableComputedStyleRendering?: boolean;
55
+ enableFileSystemHttpRequests?: boolean;
56
+ navigator?: {
57
+ userAgent?: string;
58
+ };
59
+ device?: {
60
+ prefersColorScheme?: string;
61
+ mediaType?: string;
62
+ };
63
+ };
64
+ }
65
+
42
66
  interface JSDOMOptions {
43
67
  /**
44
68
  * The html content for the test.
@@ -119,30 +143,6 @@ interface JSDOMOptions {
119
143
  resources?: 'usable';
120
144
  }
121
145
 
122
- /**
123
- * Happy DOM options.
124
- */
125
- interface HappyDOMOptions {
126
- width?: number;
127
- height?: number;
128
- url?: string;
129
- settings?: {
130
- disableJavaScriptEvaluation?: boolean;
131
- disableJavaScriptFileLoading?: boolean;
132
- disableCSSFileLoading?: boolean;
133
- disableIframePageLoading?: boolean;
134
- disableComputedStyleRendering?: boolean;
135
- enableFileSystemHttpRequests?: boolean;
136
- navigator?: {
137
- userAgent?: string;
138
- };
139
- device?: {
140
- prefersColorScheme?: string;
141
- mediaType?: string;
142
- };
143
- };
144
- }
145
-
146
146
  interface EnvironmentReturn {
147
147
  teardown: (global: any) => Awaitable<void>;
148
148
  }