vitest 0.30.1 → 0.31.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 +1 -264
- package/dist/browser.d.ts +3 -4
- package/dist/browser.js +2 -2
- package/dist/child.js +12 -4
- package/dist/{chunk-api-setup.c93e5069.js → chunk-api-setup.86042fed.js} +9 -2
- package/dist/{chunk-install-pkg.ee5cc9a8.js → chunk-install-pkg.d1609923.js} +4 -5
- package/dist/{chunk-integrations-globals.d419838f.js → chunk-integrations-globals.88c8a0cf.js} +2 -2
- package/dist/cli.js +23 -8
- package/dist/config.cjs +1 -0
- package/dist/config.d.ts +11 -14
- package/dist/config.js +1 -0
- package/dist/coverage.d.ts +5 -5
- package/dist/coverage.js +6 -6
- package/dist/entry.js +21 -5
- package/dist/environments.d.ts +3 -4
- package/dist/index.d.ts +13 -5
- package/dist/index.js +3 -3
- package/dist/loader.js +1 -0
- package/dist/node.d.ts +4 -5
- package/dist/node.js +6 -7
- package/dist/runners.d.ts +7 -5
- package/dist/runners.js +11 -1
- package/dist/{types-e3c9754d.d.ts → types-ad1c3f45.d.ts} +94 -334
- package/dist/{vendor-cli-api.70680cd5.js → vendor-cli-api.d608f86b.js} +2092 -2340
- package/dist/{vendor-coverage.a585b712.js → vendor-coverage.c8fd34c3.js} +2 -0
- package/dist/{vendor-execute.70609f6f.js → vendor-execute.3e144152.js} +2 -2
- package/dist/{vendor-index.7dcbfa46.js → vendor-index.3982ff76.js} +33 -13
- package/dist/{vendor-index.81b9e499.js → vendor-index.b0b501c8.js} +1 -1
- package/dist/{vendor-setup.common.cef38f4e.js → vendor-setup.common.266b69fb.js} +1 -1
- package/dist/{vendor-vi.a3ff54b1.js → vendor-vi.458e47b1.js} +9 -1
- package/dist/worker.js +12 -4
- package/package.json +20 -19
- package/suppress-warnings.cjs +1 -0
|
@@ -8,6 +8,8 @@ async function resolveCoverageProviderModule(options, loader) {
|
|
|
8
8
|
const provider = options.provider;
|
|
9
9
|
if (provider === "c8" || provider === "istanbul") {
|
|
10
10
|
const { default: coverageModule } = await loader.executeId(CoverageProviderMap[provider]);
|
|
11
|
+
if (!coverageModule)
|
|
12
|
+
throw new Error(`Failed to load ${CoverageProviderMap[provider]}. Default export is missing.`);
|
|
11
13
|
return coverageModule;
|
|
12
14
|
}
|
|
13
15
|
let customProviderModule;
|
|
@@ -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.3982ff76.js';
|
|
11
11
|
import { spyOn } from '@vitest/spy';
|
|
12
12
|
import { r as rpc } from './vendor-rpc.4d3d7a54.js';
|
|
13
13
|
|
|
@@ -93,7 +93,7 @@ const _VitestMocker = class {
|
|
|
93
93
|
exports = await mock();
|
|
94
94
|
} catch (err) {
|
|
95
95
|
const vitestError = new Error(
|
|
96
|
-
'[vitest] There was an error when mocking a module. If you are using "vi.mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api
|
|
96
|
+
'[vitest] There was an error when mocking a module. If you are using "vi.mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api/vi.html#vi-mock'
|
|
97
97
|
);
|
|
98
98
|
vitestError.cause = err;
|
|
99
99
|
throw vitestError;
|
|
@@ -95,18 +95,27 @@ 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;
|
|
98
103
|
function createBirpc(functions, options) {
|
|
99
104
|
const {
|
|
100
105
|
post,
|
|
101
106
|
on,
|
|
102
107
|
eventNames = [],
|
|
103
|
-
serialize =
|
|
104
|
-
deserialize =
|
|
108
|
+
serialize = defaultSerialize,
|
|
109
|
+
deserialize = defaultDeserialize,
|
|
110
|
+
resolver,
|
|
105
111
|
timeout = DEFAULT_TIMEOUT
|
|
106
112
|
} = options;
|
|
107
113
|
const rpcPromiseMap = /* @__PURE__ */ new Map();
|
|
114
|
+
let _promise;
|
|
108
115
|
const rpc = new Proxy({}, {
|
|
109
116
|
get(_, method) {
|
|
117
|
+
if (method === "$functions")
|
|
118
|
+
return functions;
|
|
110
119
|
const sendEvent = (...args) => {
|
|
111
120
|
post(serialize({ m: method, a: args, t: "q" }));
|
|
112
121
|
};
|
|
@@ -114,7 +123,8 @@ function createBirpc(functions, options) {
|
|
|
114
123
|
sendEvent.asEvent = sendEvent;
|
|
115
124
|
return sendEvent;
|
|
116
125
|
}
|
|
117
|
-
const sendCall = (...args) => {
|
|
126
|
+
const sendCall = async (...args) => {
|
|
127
|
+
await _promise;
|
|
118
128
|
return new Promise((resolve, reject) => {
|
|
119
129
|
const id = nanoid();
|
|
120
130
|
rpcPromiseMap.set(id, { resolve, reject });
|
|
@@ -131,25 +141,35 @@ function createBirpc(functions, options) {
|
|
|
131
141
|
return sendCall;
|
|
132
142
|
}
|
|
133
143
|
});
|
|
134
|
-
on(async (data, ...extra) => {
|
|
144
|
+
_promise = on(async (data, ...extra) => {
|
|
135
145
|
const msg = deserialize(data);
|
|
136
146
|
if (msg.t === "q") {
|
|
137
147
|
const { m: method, a: args } = msg;
|
|
138
148
|
let result, error;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
149
|
+
const fn = resolver ? resolver(method, functions[method]) : functions[method];
|
|
150
|
+
if (!fn) {
|
|
151
|
+
error = new Error(`[birpc] function "${method}" not found`);
|
|
152
|
+
} else {
|
|
153
|
+
try {
|
|
154
|
+
result = await fn.apply(rpc, args);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
error = e;
|
|
157
|
+
}
|
|
143
158
|
}
|
|
144
|
-
if (msg.i)
|
|
159
|
+
if (msg.i) {
|
|
160
|
+
if (error && options.onError)
|
|
161
|
+
options.onError(error, method, args);
|
|
145
162
|
post(serialize({ t: "s", i: msg.i, r: result, e: error }), ...extra);
|
|
163
|
+
}
|
|
146
164
|
} else {
|
|
147
165
|
const { i: ack, r: result, e: error } = msg;
|
|
148
166
|
const promise = rpcPromiseMap.get(ack);
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
167
|
+
if (promise) {
|
|
168
|
+
if (error)
|
|
169
|
+
promise.reject(error);
|
|
170
|
+
else
|
|
171
|
+
promise.resolve(result);
|
|
172
|
+
}
|
|
153
173
|
rpcPromiseMap.delete(ack);
|
|
154
174
|
}
|
|
155
175
|
});
|
|
@@ -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.458e47b1.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.88c8a0cf.js')).registerApiGlobally();
|
|
14
14
|
}
|
|
15
15
|
function setupDefines(defines) {
|
|
16
16
|
for (const key in defines)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getCurrentSuite, getCurrentTest } from '@vitest/runner';
|
|
2
2
|
import { createChainable, getNames } from '@vitest/runner/utils';
|
|
3
|
-
import { getSafeTimers, noop, createSimpleStackTrace, parseSingleStack } from '@vitest/utils';
|
|
3
|
+
import { getSafeTimers, noop, assertTypes, createSimpleStackTrace, parseSingleStack } from '@vitest/utils';
|
|
4
4
|
import { d as isRunningInBenchmark, c as resetModules } from './vendor-index.fad2598b.js';
|
|
5
5
|
import * as chai$1 from 'chai';
|
|
6
6
|
import { c as commonjsGlobal } from './vendor-_commonjsHelpers.76cdd49e.js';
|
|
@@ -3116,6 +3116,10 @@ function createVitest() {
|
|
|
3116
3116
|
let _mockedDate = null;
|
|
3117
3117
|
let _config = null;
|
|
3118
3118
|
const workerState = getWorkerState();
|
|
3119
|
+
if (!workerState) {
|
|
3120
|
+
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';
|
|
3121
|
+
throw new Error(errorMsg);
|
|
3122
|
+
}
|
|
3119
3123
|
const _timers = new FakeTimers({
|
|
3120
3124
|
global: globalThis,
|
|
3121
3125
|
config: workerState.config.fakeTimers
|
|
@@ -3202,6 +3206,10 @@ function createVitest() {
|
|
|
3202
3206
|
// mocks
|
|
3203
3207
|
spyOn,
|
|
3204
3208
|
fn,
|
|
3209
|
+
hoisted(factory) {
|
|
3210
|
+
assertTypes(factory, '"vi.hoisted" factory', ["function"]);
|
|
3211
|
+
return factory();
|
|
3212
|
+
},
|
|
3205
3213
|
mock(path, factory) {
|
|
3206
3214
|
const importer = getImporter();
|
|
3207
3215
|
_mocker.queueMock(
|
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.3982ff76.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.3e144152.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';
|
|
@@ -22,20 +22,28 @@ function init(ctx) {
|
|
|
22
22
|
const { config, port, workerId: workerId$1 } = ctx;
|
|
23
23
|
process.env.VITEST_WORKER_ID = String(workerId$1);
|
|
24
24
|
process.env.VITEST_POOL_ID = String(workerId);
|
|
25
|
+
let setCancel = (_reason) => {
|
|
26
|
+
};
|
|
27
|
+
const onCancel = new Promise((resolve) => {
|
|
28
|
+
setCancel = resolve;
|
|
29
|
+
});
|
|
25
30
|
globalThis.__vitest_environment__ = config.environment;
|
|
26
31
|
globalThis.__vitest_worker__ = {
|
|
27
32
|
ctx,
|
|
28
33
|
moduleCache,
|
|
29
34
|
config,
|
|
30
35
|
mockMap,
|
|
36
|
+
onCancel,
|
|
31
37
|
durations: {
|
|
32
38
|
environment: 0,
|
|
33
39
|
prepare: performance.now()
|
|
34
40
|
},
|
|
35
41
|
rpc: createBirpc(
|
|
36
|
-
{},
|
|
37
42
|
{
|
|
38
|
-
|
|
43
|
+
onCancel: setCancel
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
eventNames: ["onUserConsoleLog", "onFinished", "onCollected", "onWorkerExit", "onCancel"],
|
|
39
47
|
post(v) {
|
|
40
48
|
port.postMessage(v);
|
|
41
49
|
},
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.31.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",
|
|
8
|
-
"funding": "https://
|
|
8
|
+
"funding": "https://opencollective.com/vitest",
|
|
9
9
|
"homepage": "https://github.com/vitest-dev/vitest#readme",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -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",
|
|
@@ -142,33 +142,34 @@
|
|
|
142
142
|
"magic-string": "^0.30.0",
|
|
143
143
|
"pathe": "^1.1.0",
|
|
144
144
|
"picocolors": "^1.0.0",
|
|
145
|
-
"source-map": "^0.6.1",
|
|
146
145
|
"std-env": "^3.3.2",
|
|
147
146
|
"strip-literal": "^1.0.1",
|
|
148
|
-
"tinybench": "^2.
|
|
149
|
-
"tinypool": "^0.
|
|
147
|
+
"tinybench": "^2.5.0",
|
|
148
|
+
"tinypool": "^0.5.0",
|
|
150
149
|
"vite": "^3.0.0 || ^4.0.0",
|
|
151
150
|
"why-is-node-running": "^2.2.2",
|
|
152
|
-
"@vitest/
|
|
153
|
-
"
|
|
154
|
-
"@vitest/
|
|
155
|
-
"@vitest/spy": "0.
|
|
156
|
-
"@vitest/utils": "0.
|
|
157
|
-
"
|
|
151
|
+
"@vitest/runner": "0.31.1",
|
|
152
|
+
"vite-node": "0.31.1",
|
|
153
|
+
"@vitest/expect": "0.31.1",
|
|
154
|
+
"@vitest/spy": "0.31.1",
|
|
155
|
+
"@vitest/utils": "0.31.1",
|
|
156
|
+
"@vitest/snapshot": "0.31.1"
|
|
158
157
|
},
|
|
159
158
|
"devDependencies": {
|
|
160
|
-
"@ampproject/remapping": "^2.2.
|
|
159
|
+
"@ampproject/remapping": "^2.2.1",
|
|
161
160
|
"@antfu/install-pkg": "^0.1.1",
|
|
162
161
|
"@edge-runtime/vm": "2.1.2",
|
|
162
|
+
"@jridgewell/trace-mapping": "^0.3.18",
|
|
163
163
|
"@sinonjs/fake-timers": "^10.0.2",
|
|
164
164
|
"@types/diff": "^5.0.3",
|
|
165
|
+
"@types/estree": "^1.0.1",
|
|
165
166
|
"@types/istanbul-lib-coverage": "^2.0.4",
|
|
166
167
|
"@types/istanbul-reports": "^3.0.1",
|
|
167
168
|
"@types/jsdom": "^21.1.1",
|
|
168
169
|
"@types/micromatch": "^4.0.2",
|
|
169
170
|
"@types/prompts": "^2.4.4",
|
|
170
171
|
"@types/sinonjs__fake-timers": "^8.1.2",
|
|
171
|
-
"birpc": "0.2.
|
|
172
|
+
"birpc": "0.2.11",
|
|
172
173
|
"chai-subset": "^1.6.0",
|
|
173
174
|
"cli-truncate": "^3.1.0",
|
|
174
175
|
"event-target-polyfill": "^0.0.3",
|
|
@@ -178,19 +179,19 @@
|
|
|
178
179
|
"find-up": "^6.3.0",
|
|
179
180
|
"flatted": "^3.2.7",
|
|
180
181
|
"get-tsconfig": "^4.5.0",
|
|
181
|
-
"happy-dom": "^
|
|
182
|
-
"jsdom": "^21.1.
|
|
182
|
+
"happy-dom": "^9.10.7",
|
|
183
|
+
"jsdom": "^21.1.2",
|
|
183
184
|
"log-update": "^5.0.1",
|
|
184
185
|
"micromatch": "^4.0.5",
|
|
185
186
|
"mlly": "^1.2.0",
|
|
186
187
|
"p-limit": "^4.0.0",
|
|
187
|
-
"pkg-types": "^1.0.
|
|
188
|
-
"playwright": "^1.
|
|
188
|
+
"pkg-types": "^1.0.3",
|
|
189
|
+
"playwright": "^1.33.0",
|
|
189
190
|
"pretty-format": "^27.5.1",
|
|
190
191
|
"prompts": "^2.4.2",
|
|
191
192
|
"safaridriver": "^0.0.4",
|
|
192
193
|
"strip-ansi": "^7.0.1",
|
|
193
|
-
"webdriverio": "^8.
|
|
194
|
+
"webdriverio": "^8.9.0",
|
|
194
195
|
"ws": "^8.13.0"
|
|
195
196
|
},
|
|
196
197
|
"scripts": {
|
package/suppress-warnings.cjs
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
const ignoreWarnings = new Set([
|
|
5
5
|
'--experimental-loader is an experimental feature. This feature could change at any time',
|
|
6
6
|
'Custom ESM Loaders is an experimental feature. This feature could change at any time',
|
|
7
|
+
'Custom ESM Loaders is an experimental feature and might change at any time',
|
|
7
8
|
])
|
|
8
9
|
|
|
9
10
|
const { emit } = process
|