vitest 0.31.0 → 0.31.2
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/dist/browser.d.ts +1 -2
- package/dist/browser.js +1 -1
- package/dist/child.js +2 -2
- package/dist/{chunk-api-setup.df3106cd.js → chunk-api-setup.3854747a.js} +1 -1
- package/dist/{chunk-install-pkg.e0e70dba.js → chunk-install-pkg.4207d842.js} +2 -2
- package/dist/{chunk-integrations-globals.88c8a0cf.js → chunk-integrations-globals.51b8ecab.js} +2 -2
- package/dist/cli.js +19 -3
- package/dist/config.cjs +1 -0
- package/dist/config.d.ts +10 -14
- package/dist/config.js +1 -0
- package/dist/coverage.d.ts +1 -2
- package/dist/entry.js +4 -3
- package/dist/environments.d.ts +1 -2
- package/dist/index.d.ts +5 -7
- package/dist/index.js +3 -3
- package/dist/node.d.ts +5 -3
- package/dist/node.js +3 -3
- package/dist/runners.d.ts +1 -2
- package/dist/runners.js +1 -1
- package/dist/{types-b7007192.d.ts → types-73d6349f.d.ts} +43 -21
- package/dist/{vendor-cli-api.de0530cb.js → vendor-cli-api.35332ab3.js} +193 -82
- package/dist/{vendor-execute.a08cff9c.js → vendor-execute.132a3e09.js} +15 -3
- package/dist/{vendor-index.7dcbfa46.js → vendor-index.5037f2c0.js} +35 -14
- package/dist/{vendor-index.b0b501c8.js → vendor-index.c8d81526.js} +1 -1
- package/dist/{vendor-setup.common.266b69fb.js → vendor-setup.common.3c71d21d.js} +1 -1
- package/dist/{vendor-vi.458e47b1.js → vendor-vi.c6384282.js} +11 -3
- package/dist/worker.js +2 -2
- package/package.json +17 -17
|
@@ -7,7 +7,7 @@ import { g as getWorkerState, a as getCurrentEnvironment } from './vendor-global
|
|
|
7
7
|
import { d as distDir } from './vendor-paths.84fc7a99.js';
|
|
8
8
|
import { existsSync, readdirSync } from 'node:fs';
|
|
9
9
|
import { getColors, getType } from '@vitest/utils';
|
|
10
|
-
import { e as getAllMockableProperties } from './vendor-index.
|
|
10
|
+
import { e as getAllMockableProperties } from './vendor-index.5037f2c0.js';
|
|
11
11
|
import { spyOn } from '@vitest/spy';
|
|
12
12
|
import { r as rpc } from './vendor-rpc.4d3d7a54.js';
|
|
13
13
|
|
|
@@ -47,11 +47,17 @@ const _VitestMocker = class {
|
|
|
47
47
|
get moduleCache() {
|
|
48
48
|
return this.executor.moduleCache;
|
|
49
49
|
}
|
|
50
|
+
get moduleDirectories() {
|
|
51
|
+
return this.executor.options.moduleDirectories || [];
|
|
52
|
+
}
|
|
50
53
|
deleteCachedItem(id) {
|
|
51
54
|
const mockId = this.getMockPath(id);
|
|
52
55
|
if (this.moduleCache.has(mockId))
|
|
53
56
|
this.moduleCache.delete(mockId);
|
|
54
57
|
}
|
|
58
|
+
isAModuleDirectory(path) {
|
|
59
|
+
return this.moduleDirectories.some((dir) => path.includes(dir));
|
|
60
|
+
}
|
|
55
61
|
getSuiteFilepath() {
|
|
56
62
|
return getWorkerState().filepath || "global";
|
|
57
63
|
}
|
|
@@ -66,7 +72,7 @@ const _VitestMocker = class {
|
|
|
66
72
|
}
|
|
67
73
|
async resolvePath(rawId, importer) {
|
|
68
74
|
const [id, fsPath] = await this.executor.resolveUrl(rawId, importer);
|
|
69
|
-
const external = !isAbsolute(fsPath) ||
|
|
75
|
+
const external = !isAbsolute(fsPath) || this.isAModuleDirectory(fsPath) ? rawId : null;
|
|
70
76
|
return {
|
|
71
77
|
id,
|
|
72
78
|
fsPath,
|
|
@@ -205,7 +211,12 @@ ${c.green(`vi.mock("${mockpath}", async () => {
|
|
|
205
211
|
if (!define(newContainer, property, isFunction ? value : {}))
|
|
206
212
|
continue;
|
|
207
213
|
if (isFunction) {
|
|
208
|
-
spyOn(newContainer, property).mockImplementation(() => void 0);
|
|
214
|
+
const mock = spyOn(newContainer, property).mockImplementation(() => void 0);
|
|
215
|
+
mock.mockRestore = () => {
|
|
216
|
+
mock.mockReset();
|
|
217
|
+
mock.mockImplementation(void 0);
|
|
218
|
+
return mock;
|
|
219
|
+
};
|
|
209
220
|
Object.defineProperty(newContainer[property], "length", { value: 0 });
|
|
210
221
|
}
|
|
211
222
|
refs.track(value, newContainer[property]);
|
|
@@ -334,6 +345,7 @@ async function startViteNode(ctx) {
|
|
|
334
345
|
moduleCache,
|
|
335
346
|
mockMap,
|
|
336
347
|
interopDefault: config.deps.interopDefault,
|
|
348
|
+
moduleDirectories: config.deps.moduleDirectories,
|
|
337
349
|
root: config.root,
|
|
338
350
|
base: config.base
|
|
339
351
|
});
|
|
@@ -95,18 +95,28 @@ class AggregateErrorPonyfill extends Error {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
const DEFAULT_TIMEOUT = 6e4;
|
|
98
|
+
function defaultSerialize(i) {
|
|
99
|
+
return i;
|
|
100
|
+
}
|
|
101
|
+
const defaultDeserialize = defaultSerialize;
|
|
102
|
+
const { setTimeout } = globalThis;
|
|
103
|
+
const random = Math.random.bind(Math);
|
|
98
104
|
function createBirpc(functions, options) {
|
|
99
105
|
const {
|
|
100
106
|
post,
|
|
101
107
|
on,
|
|
102
108
|
eventNames = [],
|
|
103
|
-
serialize =
|
|
104
|
-
deserialize =
|
|
109
|
+
serialize = defaultSerialize,
|
|
110
|
+
deserialize = defaultDeserialize,
|
|
111
|
+
resolver,
|
|
105
112
|
timeout = DEFAULT_TIMEOUT
|
|
106
113
|
} = options;
|
|
107
114
|
const rpcPromiseMap = /* @__PURE__ */ new Map();
|
|
115
|
+
let _promise;
|
|
108
116
|
const rpc = new Proxy({}, {
|
|
109
117
|
get(_, method) {
|
|
118
|
+
if (method === "$functions")
|
|
119
|
+
return functions;
|
|
110
120
|
const sendEvent = (...args) => {
|
|
111
121
|
post(serialize({ m: method, a: args, t: "q" }));
|
|
112
122
|
};
|
|
@@ -114,7 +124,8 @@ function createBirpc(functions, options) {
|
|
|
114
124
|
sendEvent.asEvent = sendEvent;
|
|
115
125
|
return sendEvent;
|
|
116
126
|
}
|
|
117
|
-
const sendCall = (...args) => {
|
|
127
|
+
const sendCall = async (...args) => {
|
|
128
|
+
await _promise;
|
|
118
129
|
return new Promise((resolve, reject) => {
|
|
119
130
|
const id = nanoid();
|
|
120
131
|
rpcPromiseMap.set(id, { resolve, reject });
|
|
@@ -131,25 +142,35 @@ function createBirpc(functions, options) {
|
|
|
131
142
|
return sendCall;
|
|
132
143
|
}
|
|
133
144
|
});
|
|
134
|
-
on(async (data, ...extra) => {
|
|
145
|
+
_promise = on(async (data, ...extra) => {
|
|
135
146
|
const msg = deserialize(data);
|
|
136
147
|
if (msg.t === "q") {
|
|
137
148
|
const { m: method, a: args } = msg;
|
|
138
149
|
let result, error;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
150
|
+
const fn = resolver ? resolver(method, functions[method]) : functions[method];
|
|
151
|
+
if (!fn) {
|
|
152
|
+
error = new Error(`[birpc] function "${method}" not found`);
|
|
153
|
+
} else {
|
|
154
|
+
try {
|
|
155
|
+
result = await fn.apply(rpc, args);
|
|
156
|
+
} catch (e) {
|
|
157
|
+
error = e;
|
|
158
|
+
}
|
|
143
159
|
}
|
|
144
|
-
if (msg.i)
|
|
160
|
+
if (msg.i) {
|
|
161
|
+
if (error && options.onError)
|
|
162
|
+
options.onError(error, method, args);
|
|
145
163
|
post(serialize({ t: "s", i: msg.i, r: result, e: error }), ...extra);
|
|
164
|
+
}
|
|
146
165
|
} else {
|
|
147
166
|
const { i: ack, r: result, e: error } = msg;
|
|
148
167
|
const promise = rpcPromiseMap.get(ack);
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
168
|
+
if (promise) {
|
|
169
|
+
if (error)
|
|
170
|
+
promise.reject(error);
|
|
171
|
+
else
|
|
172
|
+
promise.resolve(result);
|
|
173
|
+
}
|
|
153
174
|
rpcPromiseMap.delete(ack);
|
|
154
175
|
}
|
|
155
176
|
});
|
|
@@ -160,7 +181,7 @@ function nanoid(size = 21) {
|
|
|
160
181
|
let id = "";
|
|
161
182
|
let i = size;
|
|
162
183
|
while (i--)
|
|
163
|
-
id += urlAlphabet[
|
|
184
|
+
id += urlAlphabet[random() * 64 | 0];
|
|
164
185
|
return id;
|
|
165
186
|
}
|
|
166
187
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
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.
|
|
2
|
+
import { e as bench, c as createExpect, d as globalExpect, s as setupChaiConfig, v as vi, f as vitest } from './vendor-vi.c6384282.js';
|
|
3
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';
|
|
@@ -10,7 +10,7 @@ async function setupCommonEnv(config) {
|
|
|
10
10
|
globalSetup = true;
|
|
11
11
|
setSafeTimers();
|
|
12
12
|
if (config.globals)
|
|
13
|
-
(await import('./chunk-integrations-globals.
|
|
13
|
+
(await import('./chunk-integrations-globals.51b8ecab.js')).registerApiGlobally();
|
|
14
14
|
}
|
|
15
15
|
function setupDefines(defines) {
|
|
16
16
|
for (const key in defines)
|
|
@@ -152,7 +152,7 @@ var chaiSubset = {exports: {}};
|
|
|
152
152
|
var Subset = chaiSubset.exports;
|
|
153
153
|
|
|
154
154
|
function recordAsyncExpect(test, promise) {
|
|
155
|
-
if (test) {
|
|
155
|
+
if (test && promise instanceof Promise) {
|
|
156
156
|
promise = promise.finally(() => {
|
|
157
157
|
const index = test.promises.indexOf(promise);
|
|
158
158
|
if (index !== -1)
|
|
@@ -252,9 +252,13 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
252
252
|
chai.Assertion.prototype,
|
|
253
253
|
"toMatchInlineSnapshot",
|
|
254
254
|
function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
|
|
255
|
+
var _a;
|
|
256
|
+
const test = utils.flag(this, "vitest-test");
|
|
257
|
+
const isInsideEach = test && (test.each || ((_a = test.suite) == null ? void 0 : _a.each));
|
|
258
|
+
if (isInsideEach)
|
|
259
|
+
throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
|
|
255
260
|
const expected = utils.flag(this, "object");
|
|
256
261
|
const error = utils.flag(this, "error");
|
|
257
|
-
const test = utils.flag(this, "vitest-test");
|
|
258
262
|
if (typeof properties === "string") {
|
|
259
263
|
message = inlineSnapshot;
|
|
260
264
|
inlineSnapshot = properties;
|
|
@@ -295,9 +299,13 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
295
299
|
chai.Assertion.prototype,
|
|
296
300
|
"toThrowErrorMatchingInlineSnapshot",
|
|
297
301
|
function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
|
|
302
|
+
var _a;
|
|
303
|
+
const test = utils.flag(this, "vitest-test");
|
|
304
|
+
const isInsideEach = test && (test.each || ((_a = test.suite) == null ? void 0 : _a.each));
|
|
305
|
+
if (isInsideEach)
|
|
306
|
+
throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
|
|
298
307
|
const expected = utils.flag(this, "object");
|
|
299
308
|
const error = utils.flag(this, "error");
|
|
300
|
-
const test = utils.flag(this, "vitest-test");
|
|
301
309
|
const promise = utils.flag(this, "promise");
|
|
302
310
|
const errorMessage = utils.flag(this, "message");
|
|
303
311
|
getSnapshotClient().assert({
|
package/dist/worker.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { performance } from 'node:perf_hooks';
|
|
2
|
-
import { c as createBirpc } from './vendor-index.
|
|
2
|
+
import { c as createBirpc } from './vendor-index.5037f2c0.js';
|
|
3
3
|
import { workerId } from 'tinypool';
|
|
4
4
|
import { g as getWorkerState } from './vendor-global.6795f91f.js';
|
|
5
|
-
import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor-execute.
|
|
5
|
+
import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor-execute.132a3e09.js';
|
|
6
6
|
import { s as setupInspect } from './vendor-inspector.47fc8cbb.js';
|
|
7
7
|
import { a as rpcDone } from './vendor-rpc.4d3d7a54.js';
|
|
8
8
|
import '@vitest/utils';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.31.
|
|
4
|
+
"version": "0.31.2",
|
|
5
5
|
"description": "A blazing fast unit test framework powered by Vite",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
}
|
|
130
130
|
},
|
|
131
131
|
"dependencies": {
|
|
132
|
-
"@types/chai": "^4.3.
|
|
132
|
+
"@types/chai": "^4.3.5",
|
|
133
133
|
"@types/chai-subset": "^1.3.3",
|
|
134
134
|
"@types/node": "*",
|
|
135
135
|
"acorn": "^8.8.2",
|
|
@@ -144,22 +144,22 @@
|
|
|
144
144
|
"picocolors": "^1.0.0",
|
|
145
145
|
"std-env": "^3.3.2",
|
|
146
146
|
"strip-literal": "^1.0.1",
|
|
147
|
-
"tinybench": "^2.
|
|
147
|
+
"tinybench": "^2.5.0",
|
|
148
148
|
"tinypool": "^0.5.0",
|
|
149
149
|
"vite": "^3.0.0 || ^4.0.0",
|
|
150
150
|
"why-is-node-running": "^2.2.2",
|
|
151
|
-
"@vitest/
|
|
152
|
-
"
|
|
153
|
-
"
|
|
154
|
-
"@vitest/spy": "0.31.
|
|
155
|
-
"@vitest/utils": "0.31.
|
|
156
|
-
"@vitest/snapshot": "0.31.
|
|
151
|
+
"@vitest/runner": "0.31.2",
|
|
152
|
+
"vite-node": "0.31.2",
|
|
153
|
+
"@vitest/expect": "0.31.2",
|
|
154
|
+
"@vitest/spy": "0.31.2",
|
|
155
|
+
"@vitest/utils": "0.31.2",
|
|
156
|
+
"@vitest/snapshot": "0.31.2"
|
|
157
157
|
},
|
|
158
158
|
"devDependencies": {
|
|
159
|
-
"@ampproject/remapping": "^2.2.
|
|
159
|
+
"@ampproject/remapping": "^2.2.1",
|
|
160
160
|
"@antfu/install-pkg": "^0.1.1",
|
|
161
161
|
"@edge-runtime/vm": "2.1.2",
|
|
162
|
-
"@jridgewell/trace-mapping": "^0.3.
|
|
162
|
+
"@jridgewell/trace-mapping": "^0.3.18",
|
|
163
163
|
"@sinonjs/fake-timers": "^10.0.2",
|
|
164
164
|
"@types/diff": "^5.0.3",
|
|
165
165
|
"@types/estree": "^1.0.1",
|
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
"@types/micromatch": "^4.0.2",
|
|
170
170
|
"@types/prompts": "^2.4.4",
|
|
171
171
|
"@types/sinonjs__fake-timers": "^8.1.2",
|
|
172
|
-
"birpc": "0.2.
|
|
172
|
+
"birpc": "0.2.12",
|
|
173
173
|
"chai-subset": "^1.6.0",
|
|
174
174
|
"cli-truncate": "^3.1.0",
|
|
175
175
|
"event-target-polyfill": "^0.0.3",
|
|
@@ -179,19 +179,19 @@
|
|
|
179
179
|
"find-up": "^6.3.0",
|
|
180
180
|
"flatted": "^3.2.7",
|
|
181
181
|
"get-tsconfig": "^4.5.0",
|
|
182
|
-
"happy-dom": "^
|
|
183
|
-
"jsdom": "^21.1.
|
|
182
|
+
"happy-dom": "^9.10.7",
|
|
183
|
+
"jsdom": "^21.1.2",
|
|
184
184
|
"log-update": "^5.0.1",
|
|
185
185
|
"micromatch": "^4.0.5",
|
|
186
186
|
"mlly": "^1.2.0",
|
|
187
187
|
"p-limit": "^4.0.0",
|
|
188
|
-
"pkg-types": "^1.0.
|
|
189
|
-
"playwright": "^1.
|
|
188
|
+
"pkg-types": "^1.0.3",
|
|
189
|
+
"playwright": "^1.33.0",
|
|
190
190
|
"pretty-format": "^27.5.1",
|
|
191
191
|
"prompts": "^2.4.2",
|
|
192
192
|
"safaridriver": "^0.0.4",
|
|
193
193
|
"strip-ansi": "^7.0.1",
|
|
194
|
-
"webdriverio": "^8.
|
|
194
|
+
"webdriverio": "^8.9.0",
|
|
195
195
|
"ws": "^8.13.0"
|
|
196
196
|
},
|
|
197
197
|
"scripts": {
|