vitest 0.8.3 → 0.9.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/dist/{chunk-api-setup.175eacf7.js → chunk-api-setup.e8071f5b.js} +4 -4
- package/dist/{chunk-constants.6062c404.js → chunk-constants.596ee4d5.js} +1 -1
- package/dist/{chunk-defaults.e5535971.js → chunk-defaults.731639a8.js} +4 -3
- package/dist/chunk-integrations-globals.d1145578.js +23 -0
- package/dist/{chunk-runtime-chain.766f27fd.js → chunk-runtime-chain.a5280da7.js} +232 -171
- package/dist/{chunk-runtime-mocker.def94aba.js → chunk-runtime-mocker.ff55be7d.js} +32 -35
- package/dist/chunk-runtime-rpc.3f693817.js +7 -0
- package/dist/{chunk-utils-base.8408f73a.js → chunk-utils-global.35d3b35d.js} +18 -1
- package/dist/{chunk-utils-timers.7bdeea22.js → chunk-utils-timers.73950dcb.js} +13 -10
- package/dist/{chunk-vite-node-externalize.ecc58a1f.js → chunk-vite-node-externalize.2004587d.js} +233 -76
- package/dist/{chunk-vite-node-utils.3c7ce184.js → chunk-vite-node-utils.5fa30ee7.js} +1 -1
- package/dist/cli.js +7 -7
- package/dist/config.cjs +3 -2
- package/dist/config.d.ts +26 -2
- package/dist/config.js +3 -2
- package/dist/entry.js +85 -53
- package/dist/index.d.ts +29 -10
- package/dist/index.js +5 -6
- package/dist/node.d.ts +21 -4
- package/dist/node.js +7 -8
- package/dist/{jest-mock.js → spy.js} +3 -0
- package/dist/worker.js +5 -6
- package/package.json +16 -16
- package/dist/chunk-integrations-globals.ade0c248.js +0 -24
- package/dist/chunk-runtime-rpc.e8aa1ebe.js +0 -8
- package/dist/chunk-utils-global.7bcfa03c.js +0 -5
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { n as normalizeRequestId, i as isNodeBuiltin, t as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.
|
|
1
|
+
import { n as normalizeRequestId, i as isNodeBuiltin, t as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.5fa30ee7.js';
|
|
2
2
|
import { normalizePath } from 'vite';
|
|
3
|
-
import {
|
|
3
|
+
import { g as getWorkerState, B as isWindows, C as mergeSlashes, k as dirname, h as basename, w as resolve } from './chunk-utils-global.35d3b35d.js';
|
|
4
4
|
import { existsSync, readdirSync } from 'fs';
|
|
5
|
-
import { d as distDir } from './chunk-constants.
|
|
6
|
-
import { g as getWorkerState } from './chunk-utils-global.7bcfa03c.js';
|
|
5
|
+
import { d as distDir } from './chunk-constants.596ee4d5.js';
|
|
7
6
|
|
|
8
7
|
var __defProp = Object.defineProperty;
|
|
9
8
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
@@ -21,21 +20,19 @@ var __spreadValues = (a, b) => {
|
|
|
21
20
|
}
|
|
22
21
|
return a;
|
|
23
22
|
};
|
|
24
|
-
function
|
|
23
|
+
function getType(value) {
|
|
25
24
|
return Object.prototype.toString.apply(value).slice(8, -1);
|
|
26
25
|
}
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Object.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
return newProto;
|
|
26
|
+
function getAllProperties(obj) {
|
|
27
|
+
const allProps = /* @__PURE__ */ new Set();
|
|
28
|
+
let curr = obj;
|
|
29
|
+
do {
|
|
30
|
+
if (curr === Object.prototype || curr === Function.prototype || curr === RegExp.prototype)
|
|
31
|
+
break;
|
|
32
|
+
const props = Object.getOwnPropertyNames(curr);
|
|
33
|
+
props.forEach((prop) => allProps.add(prop));
|
|
34
|
+
} while (curr = Object.getPrototypeOf(curr));
|
|
35
|
+
return Array.from(allProps);
|
|
39
36
|
}
|
|
40
37
|
const _VitestMocker = class {
|
|
41
38
|
constructor(options, moduleCache, request) {
|
|
@@ -127,26 +124,26 @@ const _VitestMocker = class {
|
|
|
127
124
|
const fullPath = resolve(dir, "__mocks__", baseId);
|
|
128
125
|
return existsSync(fullPath) ? fullPath.replace(this.root, "") : null;
|
|
129
126
|
}
|
|
130
|
-
|
|
131
|
-
if (!_VitestMocker.spyModule)
|
|
132
|
-
throw new Error("
|
|
133
|
-
|
|
134
|
-
|
|
127
|
+
mockValue(value) {
|
|
128
|
+
if (!_VitestMocker.spyModule) {
|
|
129
|
+
throw new Error("Error: Spy module is not defined. This is likely an internal bug in Vitest. Please report it to https://github.com/vitest-dev/vitest/issues");
|
|
130
|
+
}
|
|
131
|
+
const type = getType(value);
|
|
132
|
+
if (Array.isArray(value))
|
|
135
133
|
return [];
|
|
136
134
|
else if (type !== "Object" && type !== "Module")
|
|
137
|
-
return
|
|
138
|
-
const newObj =
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
_VitestMocker.spyModule.spyOn(newObj, k).mockImplementation(() => {
|
|
146
|
-
});
|
|
135
|
+
return value;
|
|
136
|
+
const newObj = {};
|
|
137
|
+
const proproperties = getAllProperties(value);
|
|
138
|
+
for (const k of proproperties) {
|
|
139
|
+
newObj[k] = this.mockValue(value[k]);
|
|
140
|
+
const type2 = getType(value[k]);
|
|
141
|
+
if (type2.includes("Function") && !value[k]._isMockFunction) {
|
|
142
|
+
_VitestMocker.spyModule.spyOn(newObj, k).mockImplementation(() => void 0);
|
|
147
143
|
Object.defineProperty(newObj[k], "length", { value: 0 });
|
|
148
144
|
}
|
|
149
145
|
}
|
|
146
|
+
Object.setPrototypeOf(newObj, Object.getPrototypeOf(value));
|
|
150
147
|
return newObj;
|
|
151
148
|
}
|
|
152
149
|
unmockPath(path) {
|
|
@@ -178,7 +175,7 @@ const _VitestMocker = class {
|
|
|
178
175
|
await this.ensureSpy();
|
|
179
176
|
const fsPath = this.getFsPath(path, external);
|
|
180
177
|
const mod = await this.request(fsPath);
|
|
181
|
-
return this.
|
|
178
|
+
return this.mockValue(mod);
|
|
182
179
|
}
|
|
183
180
|
if (typeof mock === "function")
|
|
184
181
|
return this.callFunctionMock(path, mock);
|
|
@@ -187,7 +184,7 @@ const _VitestMocker = class {
|
|
|
187
184
|
async ensureSpy() {
|
|
188
185
|
if (_VitestMocker.spyModule)
|
|
189
186
|
return;
|
|
190
|
-
_VitestMocker.spyModule = await this.request(resolve(distDir, "
|
|
187
|
+
_VitestMocker.spyModule = await this.request(resolve(distDir, "spy.js"));
|
|
191
188
|
}
|
|
192
189
|
async requestWithMock(dep) {
|
|
193
190
|
var _a;
|
|
@@ -201,7 +198,7 @@ const _VitestMocker = class {
|
|
|
201
198
|
return cache.exports;
|
|
202
199
|
const cacheKey = toFilePath(dep, this.root);
|
|
203
200
|
const mod = ((_a = this.moduleCache.get(cacheKey)) == null ? void 0 : _a.exports) || await this.request(dep);
|
|
204
|
-
const exports = this.
|
|
201
|
+
const exports = this.mockValue(mod);
|
|
205
202
|
this.emit("mocked", cacheName, { exports });
|
|
206
203
|
return exports;
|
|
207
204
|
}
|
|
@@ -248,6 +248,10 @@ const index = {
|
|
|
248
248
|
..._path
|
|
249
249
|
};
|
|
250
250
|
|
|
251
|
+
function getWorkerState() {
|
|
252
|
+
return globalThis.__vitest_worker__;
|
|
253
|
+
}
|
|
254
|
+
|
|
251
255
|
function notNullish(v) {
|
|
252
256
|
return v != null;
|
|
253
257
|
}
|
|
@@ -349,6 +353,19 @@ function partitionSuiteChildren(suite) {
|
|
|
349
353
|
tasksGroups.push(tasksGroup);
|
|
350
354
|
return tasksGroups;
|
|
351
355
|
}
|
|
356
|
+
function resetModules() {
|
|
357
|
+
const modules = getWorkerState().moduleCache;
|
|
358
|
+
const vitestPaths = [
|
|
359
|
+
/\/vitest\/dist\//,
|
|
360
|
+
/vitest-virtual-\w+\/dist/,
|
|
361
|
+
/@vitest\/dist/
|
|
362
|
+
];
|
|
363
|
+
modules.forEach((_, path) => {
|
|
364
|
+
if (vitestPaths.some((re) => re.test(path)))
|
|
365
|
+
return;
|
|
366
|
+
modules.delete(path);
|
|
367
|
+
});
|
|
368
|
+
}
|
|
352
369
|
function getFullName(task) {
|
|
353
370
|
return getNames(task).join(c.dim(" > "));
|
|
354
371
|
}
|
|
@@ -405,4 +422,4 @@ function getCallLastIndex(code) {
|
|
|
405
422
|
return null;
|
|
406
423
|
}
|
|
407
424
|
|
|
408
|
-
export {
|
|
425
|
+
export { extname as A, isWindows as B, mergeSlashes as C, partitionSuiteChildren as D, hasTests as E, index as a, getCallLastIndex as b, getNames as c, c as d, assertTypes as e, notNullish as f, getWorkerState as g, basename as h, isObject as i, join as j, dirname as k, isAbsolute as l, relative as m, noop as n, getTests as o, getFullName as p, hasFailed as q, resetModules as r, slash as s, toArray as t, hasFailedSnapshot as u, getSuites as v, resolve as w, deepMerge as x, toNamespacedPath as y, ensurePackageInstalled as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { s as slash, f as notNullish, d as c } from './chunk-utils-global.35d3b35d.js';
|
|
2
2
|
|
|
3
3
|
const setTimeout$1 = globalThis.setTimeout;
|
|
4
4
|
const setInterval = globalThis.setInterval;
|
|
@@ -3360,7 +3360,7 @@ function parseStacktrace(e, full = false) {
|
|
|
3360
3360
|
const match = line.match(stackFnCallRE) || line.match(stackBarePathRE);
|
|
3361
3361
|
if (!match)
|
|
3362
3362
|
return null;
|
|
3363
|
-
let file = match[2];
|
|
3363
|
+
let file = slash(match[2]);
|
|
3364
3364
|
if (file.startsWith("file://"))
|
|
3365
3365
|
file = file.slice(7);
|
|
3366
3366
|
if (!full && stackIgnorePatterns.some((p) => file.includes(p)))
|
|
@@ -4589,9 +4589,10 @@ function cliTruncate(text, columns, options) {
|
|
|
4589
4589
|
function formatLine(line, outputTruncateLength) {
|
|
4590
4590
|
return cliTruncate(line, (outputTruncateLength ?? (process.stdout.columns || 80)) - 4);
|
|
4591
4591
|
}
|
|
4592
|
-
function unifiedDiff(actual, expected,
|
|
4592
|
+
function unifiedDiff(actual, expected, options = {}) {
|
|
4593
4593
|
if (actual === expected)
|
|
4594
4594
|
return "";
|
|
4595
|
+
const { outputTruncateLength, showLegend = true } = options;
|
|
4595
4596
|
const indent = " ";
|
|
4596
4597
|
const diffLimit = 15;
|
|
4597
4598
|
const counts = {
|
|
@@ -4638,13 +4639,15 @@ function unifiedDiff(actual, expected, outputTruncateLength) {
|
|
|
4638
4639
|
return "--";
|
|
4639
4640
|
return ` ${line}`;
|
|
4640
4641
|
});
|
|
4641
|
-
if (
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4642
|
+
if (showLegend) {
|
|
4643
|
+
if (isCompact) {
|
|
4644
|
+
formatted = [
|
|
4645
|
+
`${c.green("- Expected")} ${formatted[0]}`,
|
|
4646
|
+
`${c.red("+ Received")} ${formatted[1]}`
|
|
4647
|
+
];
|
|
4648
|
+
} else {
|
|
4649
|
+
formatted.unshift(c.green(`- Expected - ${counts["-"]}`), c.red(`+ Received + ${counts["+"]}`), "");
|
|
4650
|
+
}
|
|
4648
4651
|
}
|
|
4649
4652
|
return formatted.map((i) => indent + i).join("\n");
|
|
4650
4653
|
}
|