vitest 0.29.8 → 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.
- package/LICENSE.md +2 -81
- package/dist/browser.d.ts +5 -3
- package/dist/browser.js +5 -6
- package/dist/child.js +12 -16
- package/dist/{chunk-api-setup.3aabe9ac.js → chunk-api-setup.6662587e.js} +53 -48
- package/dist/{chunk-install-pkg.6aa7cf6d.js → chunk-install-pkg.6450b372.js} +32 -32
- package/dist/chunk-integrations-globals.d419838f.js +26 -0
- package/dist/{chunk-node-git.ed5bded8.js → chunk-node-git.4c43bd73.js} +4 -2
- package/dist/cli-wrapper.js +6 -5
- package/dist/cli.js +26 -26
- package/dist/config.cjs +15 -2
- package/dist/config.d.ts +15 -4
- package/dist/config.js +10 -1
- package/dist/coverage.d.ts +5 -2
- package/dist/coverage.js +6 -0
- package/dist/entry.js +34 -34
- package/dist/environments.d.ts +5 -2
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +11 -10
- package/dist/index.js +9 -11
- package/dist/loader.js +396 -13
- package/dist/node.d.ts +9 -7
- package/dist/node.js +27 -30
- package/dist/runners.d.ts +5 -2
- package/dist/runners.js +34 -31
- package/dist/{types-94cfe4b4.d.ts → types-f03c83c4.d.ts} +225 -306
- package/dist/{chunk-node-pkg.30d8b37e.js → vendor-cli-api.c04eaa34.js} +3845 -3326
- package/dist/vendor-constants.538d9b49.js +54 -0
- package/dist/{chunk-runtime-mocker.3283818a.js → vendor-execute.8eaab47b.js} +9 -12
- package/dist/{chunk-utils-base.b5ddfcc9.js → vendor-index.4f82d248.js} +80 -10
- package/dist/{chunk-env-node.affdd278.js → vendor-index.75f2b63d.js} +9 -2
- package/dist/{chunk-integrations-utils.23c19408.js → vendor-index.81b9e499.js} +22 -21
- package/dist/{vendor-index.2cbcdd1e.js → vendor-index.c1e09929.js} +458 -373
- package/dist/vendor-index.fad2598b.js +44 -0
- package/dist/{vendor-index.534e612c.js → vendor-index.fc98d30f.js} +2 -2
- package/dist/{chunk-runtime-inspector.b1427a10.js → vendor-inspector.47fc8cbb.js} +5 -2
- package/dist/{chunk-runtime-rpc.d6aa57f8.js → vendor-rpc.4d3d7a54.js} +5 -5
- package/dist/{chunk-integrations-run-once.ea614f17.js → vendor-run-once.69ce7172.js} +3 -3
- package/dist/{chunk-runtime-setup.5d504677.js → vendor-setup.common.cef38f4e.js} +2 -2
- package/dist/vendor-tasks.042d6084.js +14 -0
- package/dist/{chunk-utils-import.e488ace3.js → vendor-vi.a3ff54b1.js} +73 -2957
- package/dist/worker.js +13 -18
- package/package.json +29 -34
- package/dist/chunk-constants.bc18a549.js +0 -36
- package/dist/chunk-integrations-globals.49802775.js +0 -28
- package/dist/chunk-snapshot-env.a347d647.js +0 -11
- package/dist/chunk-utils-env.6b856dbf.js +0 -64
- package/dist/chunk-utils-tasks.8781fd71.js +0 -107
- package/dist/env-afee91f0.d.ts +0 -10
- package/dist/vendor-index.783e7f3e.js +0 -71
- package/dist/vendor-index.bdee400f.js +0 -396
- package/dist/vendor-magic-string.es.b3bc5745.js +0 -1591
- /package/dist/{vendor-_commonjsHelpers.addc3445.js → vendor-_commonjsHelpers.76cdd49e.js} +0 -0
- /package/dist/{chunk-integrations-coverage.d93ee824.js → vendor-coverage.a585b712.js} +0 -0
- /package/dist/{chunk-utils-global.fd174983.js → vendor-global.6795f91f.js} +0 -0
- /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,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, a as getCurrentEnvironment } from './
|
|
8
|
-
import { d as distDir } from './
|
|
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 {
|
|
10
|
+
import { e as getAllMockableProperties } from './vendor-index.4f82d248.js';
|
|
12
11
|
import { spyOn } from '@vitest/spy';
|
|
13
|
-
import { r as rpc } from './
|
|
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 (
|
|
317
|
+
if (!isPrimitive(error)) {
|
|
322
318
|
error.VITEST_TEST_NAME = (_a = worker.current) == null ? void 0 : _a.name;
|
|
323
|
-
|
|
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"));
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import '@vitest/utils';
|
|
2
|
+
|
|
1
3
|
function isFinalObj(obj) {
|
|
2
4
|
return obj === Object.prototype || obj === Function.prototype || obj === RegExp.prototype;
|
|
3
5
|
}
|
|
@@ -36,14 +38,11 @@ function getAllMockableProperties(obj, isModule) {
|
|
|
36
38
|
}
|
|
37
39
|
return Array.from(allProps.values());
|
|
38
40
|
}
|
|
39
|
-
function notNullish(v) {
|
|
40
|
-
return v != null;
|
|
41
|
-
}
|
|
42
41
|
function slash(str) {
|
|
43
42
|
return str.replace(/\\/g, "/");
|
|
44
43
|
}
|
|
45
|
-
|
|
46
|
-
}
|
|
44
|
+
function noop() {
|
|
45
|
+
}
|
|
47
46
|
function toArray(array) {
|
|
48
47
|
if (array === null || array === void 0)
|
|
49
48
|
array = [];
|
|
@@ -51,10 +50,11 @@ function toArray(array) {
|
|
|
51
50
|
return array;
|
|
52
51
|
return [array];
|
|
53
52
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
58
|
}
|
|
59
59
|
function deepMerge(target, ...sources) {
|
|
60
60
|
if (!sources.length)
|
|
@@ -88,4 +88,74 @@ function getEnvironmentTransformMode(config, environment) {
|
|
|
88
88
|
return environment === "happy-dom" || environment === "jsdom" ? "web" : "ssr";
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
|
|
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
|
-
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
107
|
-
|
|
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
|
-
|
|
111
|
-
vi: vi,
|
|
104
|
+
expectTypeOf: dist.expectTypeOf,
|
|
112
105
|
getRunningMode: getRunningMode,
|
|
106
|
+
isFirstRun: isFirstRun,
|
|
113
107
|
isWatchMode: isWatchMode,
|
|
114
|
-
|
|
115
|
-
|
|
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 };
|