vitest 0.27.3 → 0.28.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.
- package/LICENSE.md +4 -93
- package/browser.d.ts +1 -1
- package/dist/browser.d.ts +11 -13
- package/dist/browser.js +9 -34
- package/dist/{chunk-api-setup.0a2398d8.js → chunk-api-setup.52751a38.js} +26 -12
- package/dist/chunk-constants.797d3ebf.js +42 -0
- package/dist/{chunk-install-pkg.7b006b3e.js → chunk-install-pkg.e816b731.js} +51 -11
- package/dist/{vendor-index.57682f0c.js → chunk-integrations-coverage.48e6286b.js} +33 -4
- package/dist/chunk-integrations-globals.0d5f50f0.js +29 -0
- package/dist/chunk-integrations-run-once.38756e30.js +27 -0
- package/dist/chunk-integrations-utils.f1f6f1ed.js +118 -0
- package/dist/{chunk-node-git.59caac18.js → chunk-node-git.d9ad64ab.js} +6 -8
- package/dist/{chunk-snapshot-manager.d16903ef.js → chunk-node-pkg.a7963c3f.js} +7440 -172
- package/dist/{chunk-runtime-mocker.66533d65.js → chunk-runtime-mocker.03017e8c.js} +13 -12
- package/dist/{chunk-runtime-rpc.e79efa9a.js → chunk-runtime-rpc.9c0386cc.js} +3 -2
- package/dist/chunk-runtime-setup.d9302cfd.js +20 -0
- package/dist/chunk-snapshot-env.6457638e.js +11 -0
- package/dist/chunk-utils-base.977ae74f.js +77 -0
- package/dist/chunk-utils-env.860d90c2.js +6 -0
- package/dist/chunk-utils-global.442d1d33.js +73 -0
- package/dist/{chunk-utils-import.eb63557e.js → chunk-utils-import.9911c99d.js} +3289 -169
- package/dist/chunk-utils-tasks.1b603032.js +103 -0
- package/dist/cli-wrapper.js +7 -6
- package/dist/cli.js +16 -15
- package/dist/config.d.ts +7 -2
- package/dist/entry.js +233 -28
- package/dist/env-afee91f0.d.ts +10 -0
- package/dist/environments.d.ts +7 -2
- package/dist/index.d.ts +160 -11
- package/dist/index.js +17 -18
- package/dist/loader.js +6 -6
- package/dist/node.d.ts +9 -7
- package/dist/node.js +18 -17
- package/dist/runners-chunk.js +215 -0
- package/dist/runners.d.ts +39 -0
- package/dist/runners.js +18 -0
- package/dist/spy.js +1 -2
- package/dist/suite.d.ts +2 -0
- package/dist/suite.js +2 -19
- package/dist/{types-c1386a7d.d.ts → types-c800444e.d.ts} +160 -425
- package/dist/{vendor-index.e6c27006.js → vendor-index.618ca5a1.js} +1078 -10
- package/dist/{vendor-index.b0346fe4.js → vendor-index.bdee400f.js} +1 -0
- package/dist/worker.js +11 -13
- package/package.json +20 -12
- package/runners.d.ts +1 -0
- package/suite.d.ts +1 -0
- package/dist/chunk-integrations-coverage.18366936.js +0 -242
- package/dist/chunk-integrations-globals.59b4d460.js +0 -28
- package/dist/chunk-mock-date.91595ccd.js +0 -350
- package/dist/chunk-runtime-chain.07d16eac.js +0 -2594
- package/dist/chunk-runtime-error.f2062967.js +0 -144
- package/dist/chunk-runtime-setup.8ca273cd.js +0 -653
- package/dist/chunk-utils-env.4ebb0106.js +0 -229
- package/dist/chunk-utils-source-map.832515f7.js +0 -408
- package/dist/chunk-utils-timers.52534f96.js +0 -3573
- package/dist/index-2dd51af4.d.ts +0 -258
- package/dist/vendor-index.451e37bc.js +0 -1071
- package/dist/vendor-index.723a074f.js +0 -102
- package/dist/vendor-index.9c919048.js +0 -61
- package/dist/vendor-index.9f20a9be.js +0 -6291
package/dist/worker.js
CHANGED
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolve, relative } from 'pathe';
|
|
2
2
|
import { c as createBirpc } from './vendor-index.783e7f3e.js';
|
|
3
3
|
import { workerId } from 'tinypool';
|
|
4
|
+
import { processError } from '@vitest/runner/utils';
|
|
4
5
|
import { ModuleCacheMap } from 'vite-node/client';
|
|
5
6
|
import { isPrimitive } from 'vite-node/utils';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import { d as distDir } from './chunk-constants.797d3ebf.js';
|
|
8
|
+
import { g as getWorkerState } from './chunk-utils-global.442d1d33.js';
|
|
9
|
+
import { e as executeInViteNode } from './chunk-runtime-mocker.03017e8c.js';
|
|
10
|
+
import { r as rpc } from './chunk-runtime-rpc.9c0386cc.js';
|
|
10
11
|
import 'node:url';
|
|
11
|
-
import '
|
|
12
|
+
import './chunk-utils-env.860d90c2.js';
|
|
12
13
|
import 'std-env';
|
|
13
|
-
import '
|
|
14
|
-
import 'picocolors';
|
|
15
|
-
import 'local-pkg';
|
|
14
|
+
import '@vitest/utils';
|
|
16
15
|
import 'vite';
|
|
17
|
-
import './vendor-index.
|
|
16
|
+
import './vendor-index.bdee400f.js';
|
|
18
17
|
import 'acorn';
|
|
19
18
|
import 'node:module';
|
|
20
19
|
import 'node:fs';
|
|
21
20
|
import 'node:assert';
|
|
22
21
|
import 'node:process';
|
|
22
|
+
import 'node:path';
|
|
23
23
|
import 'node:v8';
|
|
24
24
|
import 'node:util';
|
|
25
|
-
import './chunk-utils-
|
|
26
|
-
import 'util';
|
|
27
|
-
import 'chai';
|
|
25
|
+
import './chunk-utils-base.977ae74f.js';
|
|
28
26
|
|
|
29
27
|
let _viteNode;
|
|
30
28
|
const moduleCache = new ModuleCacheMap();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.28.1",
|
|
5
5
|
"description": "A blazing fast unit test framework powered by Vite",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -45,14 +45,22 @@
|
|
|
45
45
|
"types": "./dist/node.d.ts",
|
|
46
46
|
"import": "./dist/node.js"
|
|
47
47
|
},
|
|
48
|
-
"./environments": {
|
|
49
|
-
"types": "./dist/environments.d.ts",
|
|
50
|
-
"import": "./dist/environments.js"
|
|
51
|
-
},
|
|
52
48
|
"./browser": {
|
|
53
49
|
"types": "./dist/browser.d.ts",
|
|
54
50
|
"import": "./dist/browser.js"
|
|
55
51
|
},
|
|
52
|
+
"./runners": {
|
|
53
|
+
"types": "./dist/runners.d.ts",
|
|
54
|
+
"import": "./dist/runners.js"
|
|
55
|
+
},
|
|
56
|
+
"./suite": {
|
|
57
|
+
"types": "./dist/suite.d.ts",
|
|
58
|
+
"import": "./dist/suite.js"
|
|
59
|
+
},
|
|
60
|
+
"./environments": {
|
|
61
|
+
"types": "./dist/environments.d.ts",
|
|
62
|
+
"import": "./dist/environments.js"
|
|
63
|
+
},
|
|
56
64
|
"./config": {
|
|
57
65
|
"types": "./config.d.ts",
|
|
58
66
|
"require": "./dist/config.cjs",
|
|
@@ -110,6 +118,7 @@
|
|
|
110
118
|
"chai": "^4.3.7",
|
|
111
119
|
"debug": "^4.3.4",
|
|
112
120
|
"local-pkg": "^0.4.2",
|
|
121
|
+
"pathe": "^1.1.0",
|
|
113
122
|
"picocolors": "^1.0.0",
|
|
114
123
|
"source-map": "^0.6.1",
|
|
115
124
|
"std-env": "^3.3.1",
|
|
@@ -119,7 +128,11 @@
|
|
|
119
128
|
"tinyspy": "^1.0.2",
|
|
120
129
|
"vite": "^3.0.0 || ^4.0.0",
|
|
121
130
|
"why-is-node-running": "^2.2.2",
|
|
122
|
-
"
|
|
131
|
+
"@vitest/expect": "0.28.1",
|
|
132
|
+
"@vitest/runner": "0.28.1",
|
|
133
|
+
"@vitest/spy": "0.28.1",
|
|
134
|
+
"vite-node": "0.28.1",
|
|
135
|
+
"@vitest/utils": "0.28.1"
|
|
123
136
|
},
|
|
124
137
|
"devDependencies": {
|
|
125
138
|
"@antfu/install-pkg": "^0.1.1",
|
|
@@ -150,18 +163,13 @@
|
|
|
150
163
|
"mlly": "^1.1.0",
|
|
151
164
|
"natural-compare": "^1.4.0",
|
|
152
165
|
"p-limit": "^4.0.0",
|
|
153
|
-
"pathe": "^0.2.0",
|
|
154
166
|
"pkg-types": "^1.0.1",
|
|
155
167
|
"pretty-format": "^27.5.1",
|
|
156
168
|
"prompts": "^2.4.2",
|
|
157
169
|
"rollup": "^2.79.1",
|
|
158
170
|
"strip-ansi": "^7.0.1",
|
|
159
171
|
"typescript": "^4.9.4",
|
|
160
|
-
"ws": "^8.12.0"
|
|
161
|
-
"@vitest/expect": "0.27.3",
|
|
162
|
-
"@vitest/spy": "0.27.3",
|
|
163
|
-
"@vitest/ui": "0.27.3",
|
|
164
|
-
"@vitest/utils": "0.27.3"
|
|
172
|
+
"ws": "^8.12.0"
|
|
165
173
|
},
|
|
166
174
|
"scripts": {
|
|
167
175
|
"build": "rimraf dist && rollup -c",
|
package/runners.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/runners.js'
|
package/suite.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/suite.js'
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import { importModule } from 'local-pkg';
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
How it works:
|
|
5
|
-
`this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
class Node {
|
|
9
|
-
value;
|
|
10
|
-
next;
|
|
11
|
-
|
|
12
|
-
constructor(value) {
|
|
13
|
-
this.value = value;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class Queue {
|
|
18
|
-
#head;
|
|
19
|
-
#tail;
|
|
20
|
-
#size;
|
|
21
|
-
|
|
22
|
-
constructor() {
|
|
23
|
-
this.clear();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
enqueue(value) {
|
|
27
|
-
const node = new Node(value);
|
|
28
|
-
|
|
29
|
-
if (this.#head) {
|
|
30
|
-
this.#tail.next = node;
|
|
31
|
-
this.#tail = node;
|
|
32
|
-
} else {
|
|
33
|
-
this.#head = node;
|
|
34
|
-
this.#tail = node;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
this.#size++;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
dequeue() {
|
|
41
|
-
const current = this.#head;
|
|
42
|
-
if (!current) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this.#head = this.#head.next;
|
|
47
|
-
this.#size--;
|
|
48
|
-
return current.value;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
clear() {
|
|
52
|
-
this.#head = undefined;
|
|
53
|
-
this.#tail = undefined;
|
|
54
|
-
this.#size = 0;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
get size() {
|
|
58
|
-
return this.#size;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
* [Symbol.iterator]() {
|
|
62
|
-
let current = this.#head;
|
|
63
|
-
|
|
64
|
-
while (current) {
|
|
65
|
-
yield current.value;
|
|
66
|
-
current = current.next;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function pLimit(concurrency) {
|
|
72
|
-
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
|
|
73
|
-
throw new TypeError('Expected `concurrency` to be a number from 1 and up');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const queue = new Queue();
|
|
77
|
-
let activeCount = 0;
|
|
78
|
-
|
|
79
|
-
const next = () => {
|
|
80
|
-
activeCount--;
|
|
81
|
-
|
|
82
|
-
if (queue.size > 0) {
|
|
83
|
-
queue.dequeue()();
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const run = async (fn, resolve, args) => {
|
|
88
|
-
activeCount++;
|
|
89
|
-
|
|
90
|
-
const result = (async () => fn(...args))();
|
|
91
|
-
|
|
92
|
-
resolve(result);
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
await result;
|
|
96
|
-
} catch {}
|
|
97
|
-
|
|
98
|
-
next();
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const enqueue = (fn, resolve, args) => {
|
|
102
|
-
queue.enqueue(run.bind(undefined, fn, resolve, args));
|
|
103
|
-
|
|
104
|
-
(async () => {
|
|
105
|
-
// This function needs to wait until the next microtask before comparing
|
|
106
|
-
// `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
|
|
107
|
-
// when the run function is dequeued and called. The comparison in the if-statement
|
|
108
|
-
// needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
|
|
109
|
-
await Promise.resolve();
|
|
110
|
-
|
|
111
|
-
if (activeCount < concurrency && queue.size > 0) {
|
|
112
|
-
queue.dequeue()();
|
|
113
|
-
}
|
|
114
|
-
})();
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const generator = (fn, ...args) => new Promise(resolve => {
|
|
118
|
-
enqueue(fn, resolve, args);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
Object.defineProperties(generator, {
|
|
122
|
-
activeCount: {
|
|
123
|
-
get: () => activeCount,
|
|
124
|
-
},
|
|
125
|
-
pendingCount: {
|
|
126
|
-
get: () => queue.size,
|
|
127
|
-
},
|
|
128
|
-
clearQueue: {
|
|
129
|
-
value: () => {
|
|
130
|
-
queue.clear();
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
return generator;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const CoverageProviderMap = {
|
|
139
|
-
c8: "@vitest/coverage-c8",
|
|
140
|
-
istanbul: "@vitest/coverage-istanbul"
|
|
141
|
-
};
|
|
142
|
-
async function resolveCoverageProvider(provider) {
|
|
143
|
-
if (typeof provider === "string") {
|
|
144
|
-
const pkg = CoverageProviderMap[provider];
|
|
145
|
-
if (!pkg)
|
|
146
|
-
throw new Error(`Unknown coverage provider: ${provider}`);
|
|
147
|
-
return await importModule(pkg);
|
|
148
|
-
} else {
|
|
149
|
-
return provider;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
async function getCoverageProvider(options) {
|
|
153
|
-
if ((options == null ? void 0 : options.enabled) && (options == null ? void 0 : options.provider)) {
|
|
154
|
-
const { getProvider } = await resolveCoverageProvider(options.provider);
|
|
155
|
-
return await getProvider();
|
|
156
|
-
}
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
async function takeCoverageInsideWorker(options) {
|
|
160
|
-
if (options.enabled && options.provider) {
|
|
161
|
-
const { takeCoverage } = await resolveCoverageProvider(options.provider);
|
|
162
|
-
return await (takeCoverage == null ? void 0 : takeCoverage());
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function interpretTaskModes(suite, namePattern, onlyMode, parentIsOnly, allowOnly) {
|
|
167
|
-
const suiteIsOnly = parentIsOnly || suite.mode === "only";
|
|
168
|
-
suite.tasks.forEach((t) => {
|
|
169
|
-
const includeTask = suiteIsOnly || t.mode === "only";
|
|
170
|
-
if (onlyMode) {
|
|
171
|
-
if (t.type === "suite" && (includeTask || someTasksAreOnly(t))) {
|
|
172
|
-
if (t.mode === "only") {
|
|
173
|
-
checkAllowOnly(t, allowOnly);
|
|
174
|
-
t.mode = "run";
|
|
175
|
-
}
|
|
176
|
-
} else if (t.mode === "run" && !includeTask) {
|
|
177
|
-
t.mode = "skip";
|
|
178
|
-
} else if (t.mode === "only") {
|
|
179
|
-
checkAllowOnly(t, allowOnly);
|
|
180
|
-
t.mode = "run";
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
if (t.type === "test") {
|
|
184
|
-
if (namePattern && !getTaskFullName(t).match(namePattern))
|
|
185
|
-
t.mode = "skip";
|
|
186
|
-
} else if (t.type === "suite") {
|
|
187
|
-
if (t.mode === "skip")
|
|
188
|
-
skipAllTasks(t);
|
|
189
|
-
else
|
|
190
|
-
interpretTaskModes(t, namePattern, onlyMode, includeTask, allowOnly);
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
if (suite.mode === "run") {
|
|
194
|
-
if (suite.tasks.length && suite.tasks.every((i) => i.mode !== "run"))
|
|
195
|
-
suite.mode = "skip";
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
function getTaskFullName(task) {
|
|
199
|
-
return `${task.suite ? `${getTaskFullName(task.suite)} ` : ""}${task.name}`;
|
|
200
|
-
}
|
|
201
|
-
function someTasksAreOnly(suite) {
|
|
202
|
-
return suite.tasks.some((t) => t.mode === "only" || t.type === "suite" && someTasksAreOnly(t));
|
|
203
|
-
}
|
|
204
|
-
function skipAllTasks(suite) {
|
|
205
|
-
suite.tasks.forEach((t) => {
|
|
206
|
-
if (t.mode === "run") {
|
|
207
|
-
t.mode = "skip";
|
|
208
|
-
if (t.type === "suite")
|
|
209
|
-
skipAllTasks(t);
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
function checkAllowOnly(task, allowOnly) {
|
|
214
|
-
if (allowOnly)
|
|
215
|
-
return;
|
|
216
|
-
const error = new Error("[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error");
|
|
217
|
-
task.result = {
|
|
218
|
-
state: "fail",
|
|
219
|
-
error,
|
|
220
|
-
errors: [error]
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
function generateHash(str) {
|
|
224
|
-
let hash = 0;
|
|
225
|
-
if (str.length === 0)
|
|
226
|
-
return `${hash}`;
|
|
227
|
-
for (let i = 0; i < str.length; i++) {
|
|
228
|
-
const char = str.charCodeAt(i);
|
|
229
|
-
hash = (hash << 5) - hash + char;
|
|
230
|
-
hash = hash & hash;
|
|
231
|
-
}
|
|
232
|
-
return `${hash}`;
|
|
233
|
-
}
|
|
234
|
-
function calculateSuiteHash(parent) {
|
|
235
|
-
parent.tasks.forEach((t, idx) => {
|
|
236
|
-
t.id = `${parent.id}_${idx}`;
|
|
237
|
-
if (t.type === "suite")
|
|
238
|
-
calculateSuiteHash(t);
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export { CoverageProviderMap as C, getCoverageProvider as a, calculateSuiteHash as c, generateHash as g, interpretTaskModes as i, pLimit as p, someTasksAreOnly as s, takeCoverageInsideWorker as t };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { m as globalApis } from './chunk-utils-env.4ebb0106.js';
|
|
2
|
-
import { i as index } from './chunk-utils-import.eb63557e.js';
|
|
3
|
-
import 'node:url';
|
|
4
|
-
import 'path';
|
|
5
|
-
import 'std-env';
|
|
6
|
-
import './chunk-runtime-chain.07d16eac.js';
|
|
7
|
-
import 'util';
|
|
8
|
-
import 'chai';
|
|
9
|
-
import './chunk-mock-date.91595ccd.js';
|
|
10
|
-
import 'node:path';
|
|
11
|
-
import 'picocolors';
|
|
12
|
-
import 'local-pkg';
|
|
13
|
-
import './vendor-_commonjsHelpers.addc3445.js';
|
|
14
|
-
import './chunk-utils-timers.52534f96.js';
|
|
15
|
-
import './vendor-index.723a074f.js';
|
|
16
|
-
import 'tinyspy';
|
|
17
|
-
import './chunk-utils-source-map.832515f7.js';
|
|
18
|
-
import './chunk-runtime-rpc.e79efa9a.js';
|
|
19
|
-
import 'node:fs';
|
|
20
|
-
import 'fs';
|
|
21
|
-
|
|
22
|
-
function registerApiGlobally() {
|
|
23
|
-
globalApis.forEach((api) => {
|
|
24
|
-
globalThis[api] = index[api];
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { registerApiGlobally };
|