vitest 0.17.1 → 0.19.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 +6 -6
- package/dist/browser.d.ts +1850 -0
- package/dist/browser.mjs +20 -0
- package/dist/{chunk-api-setup.c728e251.mjs → chunk-api-setup.0cf2c96a.mjs} +37 -11
- package/dist/{chunk-constants.27550afb.mjs → chunk-constants.38b43a44.mjs} +3 -3
- package/dist/{chunk-env-node.aa51c4cc.mjs → chunk-defaults.408a0cfe.mjs} +457 -455
- package/dist/{chunk-install-pkg.6f5930c3.mjs → chunk-install-pkg.6c6dc0c2.mjs} +11 -10
- package/dist/chunk-integrations-globals.803277be.mjs +24 -0
- package/dist/chunk-node-git.9058b82a.mjs +1139 -0
- package/dist/chunk-runtime-chain.1e1aabb3.mjs +2025 -0
- package/dist/{vendor-entry.1ad8a08d.mjs → chunk-runtime-error.d82dd2cf.mjs} +167 -183
- package/dist/{chunk-runtime-chain.6d23d202.mjs → chunk-runtime-hooks.db398170.mjs} +33 -2012
- package/dist/{chunk-runtime-mocker.34b9d585.mjs → chunk-runtime-mocker.dfdfd57b.mjs} +70 -22
- package/dist/{chunk-runtime-rpc.d986adb9.mjs → chunk-runtime-rpc.45d8ee19.mjs} +1 -1
- package/dist/{chunk-utils-global.4828c2e2.mjs → chunk-utils-global.2aa95025.mjs} +14 -9
- package/dist/{chunk-utils-source-map.a9047343.mjs → chunk-utils-source-map.8b066ce2.mjs} +2 -2
- package/dist/{chunk-vite-node-externalize.0fc8ed68.mjs → chunk-vite-node-externalize.a2813ad7.mjs} +1202 -2178
- package/dist/chunk-vite-node-utils.ad73f2ab.mjs +1433 -0
- package/dist/cli.mjs +11 -13
- package/dist/config.cjs +4 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.mjs +4 -1
- package/dist/entry.mjs +54 -10
- package/dist/index.d.ts +126 -58
- package/dist/index.mjs +12 -9
- package/dist/node.d.ts +109 -58
- package/dist/node.mjs +12 -14
- package/dist/spy.mjs +102 -2
- package/dist/suite.mjs +13 -0
- package/dist/vendor-index.61438b77.mjs +335 -0
- package/dist/{vendor-index.a2a385d8.mjs → vendor-index.62ce5c33.mjs} +6 -338
- package/dist/{vendor-index.98e769c1.mjs → vendor-index.de788b6a.mjs} +7 -7
- package/dist/worker.mjs +6 -6
- package/package.json +20 -12
- package/dist/chunk-integrations-globals.3df36e26.mjs +0 -26
- package/dist/chunk-integrations-spy.674b628e.mjs +0 -102
- package/dist/chunk-vite-node-utils.0f776286.mjs +0 -9195
|
@@ -1,9 +1,30 @@
|
|
|
1
|
-
import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.
|
|
1
|
+
import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.ad73f2ab.mjs';
|
|
2
2
|
import { normalizePath } from 'vite';
|
|
3
|
-
import {
|
|
3
|
+
import { g as getWorkerState, T as isWindows, U as mergeSlashes, d as dirname, j as join, D as basename, C as resolve, c as slash, q as getType, V as getAllProperties } from './chunk-utils-global.2aa95025.mjs';
|
|
4
4
|
import { existsSync, readdirSync } from 'fs';
|
|
5
|
-
import { d as distDir } from './chunk-constants.
|
|
5
|
+
import { d as distDir } from './chunk-constants.38b43a44.mjs';
|
|
6
6
|
|
|
7
|
+
class RefTracker {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.idMap = /* @__PURE__ */ new Map();
|
|
10
|
+
this.mockedValueMap = /* @__PURE__ */ new Map();
|
|
11
|
+
}
|
|
12
|
+
getId(value) {
|
|
13
|
+
return this.idMap.get(value);
|
|
14
|
+
}
|
|
15
|
+
getMockedValue(id) {
|
|
16
|
+
return this.mockedValueMap.get(id);
|
|
17
|
+
}
|
|
18
|
+
track(originalValue, mockedValue) {
|
|
19
|
+
const newId = this.idMap.size;
|
|
20
|
+
this.idMap.set(originalValue, newId);
|
|
21
|
+
this.mockedValueMap.set(newId, mockedValue);
|
|
22
|
+
return newId;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function isSpecialProp(prop, parentType) {
|
|
26
|
+
return parentType.includes("Function") && typeof prop === "string" && ["arguments", "callee", "caller", "length", "name"].includes(prop);
|
|
27
|
+
}
|
|
7
28
|
const _VitestMocker = class {
|
|
8
29
|
constructor(options, moduleCache, request) {
|
|
9
30
|
this.options = options;
|
|
@@ -91,27 +112,54 @@ const _VitestMocker = class {
|
|
|
91
112
|
const fullPath = resolve(dir, "__mocks__", baseId);
|
|
92
113
|
return existsSync(fullPath) ? fullPath : null;
|
|
93
114
|
}
|
|
94
|
-
|
|
115
|
+
mockObject(object) {
|
|
95
116
|
if (!_VitestMocker.spyModule) {
|
|
96
117
|
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");
|
|
97
118
|
}
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
119
|
+
const spyModule = _VitestMocker.spyModule;
|
|
120
|
+
const finalizers = new Array();
|
|
121
|
+
const refs = new RefTracker();
|
|
122
|
+
const mockPropertiesOf = (container, newContainer) => {
|
|
123
|
+
const containerType = getType(container);
|
|
124
|
+
const isModule = containerType === "Module" || !!container.__esModule;
|
|
125
|
+
for (const property of getAllProperties(container)) {
|
|
126
|
+
if (!isModule) {
|
|
127
|
+
const descriptor = Object.getOwnPropertyDescriptor(container, property);
|
|
128
|
+
if ((descriptor == null ? void 0 : descriptor.get) || (descriptor == null ? void 0 : descriptor.set))
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (isSpecialProp(property, containerType))
|
|
132
|
+
continue;
|
|
133
|
+
const value = container[property];
|
|
134
|
+
const refId = refs.getId(value);
|
|
135
|
+
if (refId) {
|
|
136
|
+
finalizers.push(() => newContainer[property] = refs.getMockedValue(refId));
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const type = getType(value);
|
|
140
|
+
if (Array.isArray(value)) {
|
|
141
|
+
newContainer[property] = [];
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const isFunction = type.includes("Function") && typeof value === "function";
|
|
145
|
+
if ((!isFunction || value.__isMockFunction) && type !== "Object" && type !== "Module") {
|
|
146
|
+
newContainer[property] = value;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
newContainer[property] = isFunction ? value : {};
|
|
150
|
+
if (isFunction) {
|
|
151
|
+
spyModule.spyOn(newContainer, property).mockImplementation(() => void 0);
|
|
152
|
+
Object.defineProperty(newContainer[property], "length", { value: 0 });
|
|
153
|
+
}
|
|
154
|
+
refs.track(value, newContainer[property]);
|
|
155
|
+
mockPropertiesOf(value, newContainer[property]);
|
|
111
156
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
157
|
+
};
|
|
158
|
+
const mockedObject = {};
|
|
159
|
+
mockPropertiesOf(object, mockedObject);
|
|
160
|
+
for (const finalizer of finalizers)
|
|
161
|
+
finalizer();
|
|
162
|
+
return mockedObject;
|
|
115
163
|
}
|
|
116
164
|
unmockPath(path) {
|
|
117
165
|
const suitefile = this.getSuiteFilepath();
|
|
@@ -142,7 +190,7 @@ const _VitestMocker = class {
|
|
|
142
190
|
if (mock === null) {
|
|
143
191
|
await this.ensureSpy();
|
|
144
192
|
const mod = await this.request(fsPath);
|
|
145
|
-
return this.
|
|
193
|
+
return this.mockObject(mod);
|
|
146
194
|
}
|
|
147
195
|
if (typeof mock === "function")
|
|
148
196
|
return this.callFunctionMock(fsPath, mock);
|
|
@@ -168,7 +216,7 @@ const _VitestMocker = class {
|
|
|
168
216
|
return cache.exports;
|
|
169
217
|
const cacheKey = toFilePath(dep, this.root);
|
|
170
218
|
const mod = ((_a = this.moduleCache.get(cacheKey)) == null ? void 0 : _a.exports) || await this.request(dep);
|
|
171
|
-
const exports = this.
|
|
219
|
+
const exports = this.mockObject(mod);
|
|
172
220
|
this.moduleCache.set(cacheName, { exports });
|
|
173
221
|
return exports;
|
|
174
222
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import path, { relative as relative$1 } from 'path';
|
|
1
2
|
import require$$0 from 'tty';
|
|
2
3
|
import { isPackageExists } from 'local-pkg';
|
|
3
|
-
import path from 'path';
|
|
4
4
|
|
|
5
5
|
var picocolors = {exports: {}};
|
|
6
6
|
|
|
@@ -304,9 +304,9 @@ function isFinalObj(obj) {
|
|
|
304
304
|
}
|
|
305
305
|
function collectOwnProperties(obj, collector) {
|
|
306
306
|
const props = Object.getOwnPropertyNames(obj);
|
|
307
|
-
const
|
|
307
|
+
const symbols = Object.getOwnPropertySymbols(obj);
|
|
308
308
|
props.forEach((prop) => collector.add(prop));
|
|
309
|
-
|
|
309
|
+
symbols.forEach((symbol) => collector.add(symbol));
|
|
310
310
|
}
|
|
311
311
|
function getAllProperties(obj) {
|
|
312
312
|
const allProps = /* @__PURE__ */ new Set();
|
|
@@ -482,8 +482,11 @@ function withSafeTimers(fn) {
|
|
|
482
482
|
}
|
|
483
483
|
}
|
|
484
484
|
|
|
485
|
-
|
|
485
|
+
var _a;
|
|
486
|
+
const isNode = typeof process < "u" && typeof process.stdout < "u" && !((_a = process.versions) == null ? void 0 : _a.deno) && !globalThis.window;
|
|
487
|
+
const isBrowser = typeof window !== "undefined";
|
|
486
488
|
const isWindows = isNode && process.platform === "win32";
|
|
489
|
+
const relativePath = isBrowser ? relative$1 : relative;
|
|
487
490
|
function partitionSuiteChildren(suite) {
|
|
488
491
|
let tasksGroup = [];
|
|
489
492
|
const tasksGroups = [];
|
|
@@ -515,22 +518,23 @@ function resetModules() {
|
|
|
515
518
|
function getFullName(task) {
|
|
516
519
|
return getNames(task).join(picocolors.exports.dim(" > "));
|
|
517
520
|
}
|
|
518
|
-
async function ensurePackageInstalled(dependency,
|
|
519
|
-
if (isPackageExists(dependency))
|
|
521
|
+
async function ensurePackageInstalled(dependency, root) {
|
|
522
|
+
if (isPackageExists(dependency, { paths: [root] }))
|
|
520
523
|
return true;
|
|
524
|
+
const promptInstall = !process.env.CI && process.stdout.isTTY;
|
|
521
525
|
process.stderr.write(picocolors.exports.red(`${picocolors.exports.inverse(picocolors.exports.red(" MISSING DEP "))} Can not find dependency '${dependency}'
|
|
522
526
|
|
|
523
527
|
`));
|
|
524
528
|
if (!promptInstall)
|
|
525
529
|
return false;
|
|
526
|
-
const prompts = await import('./vendor-index.
|
|
530
|
+
const prompts = await import('./vendor-index.de788b6a.mjs').then(function (n) { return n.i; });
|
|
527
531
|
const { install } = await prompts.prompt({
|
|
528
532
|
type: "confirm",
|
|
529
533
|
name: "install",
|
|
530
534
|
message: picocolors.exports.reset(`Do you want to install ${picocolors.exports.green(dependency)}?`)
|
|
531
535
|
});
|
|
532
536
|
if (install) {
|
|
533
|
-
await (await import('./chunk-install-pkg.
|
|
537
|
+
await (await import('./chunk-install-pkg.6c6dc0c2.mjs')).installPackage(dependency, { dev: true });
|
|
534
538
|
process.stderr.write(picocolors.exports.yellow(`
|
|
535
539
|
Package ${dependency} installed, re-run the command to start.
|
|
536
540
|
`));
|
|
@@ -567,6 +571,7 @@ function getCallLastIndex(code) {
|
|
|
567
571
|
}
|
|
568
572
|
return null;
|
|
569
573
|
}
|
|
574
|
+
isNode ? relative : relative$1;
|
|
570
575
|
class AggregateErrorPonyfill extends Error {
|
|
571
576
|
constructor(errors, message = "") {
|
|
572
577
|
super(message);
|
|
@@ -574,4 +579,4 @@ class AggregateErrorPonyfill extends Error {
|
|
|
574
579
|
}
|
|
575
580
|
}
|
|
576
581
|
|
|
577
|
-
export {
|
|
582
|
+
export { hasTests as A, hasFailed as B, resolve as C, basename as D, AggregateErrorPonyfill as E, isAbsolute as F, relative as G, getTests as H, hasFailedSnapshot as I, safeSetInterval as J, safeClearInterval as K, getSuites as L, normalize as M, deepMerge as N, toNamespacedPath as O, ensurePackageInstalled as P, stdout as Q, RealDate as R, extname as S, isWindows as T, mergeSlashes as U, getAllProperties as V, resetModules as a, getCallLastIndex as b, slash as c, dirname as d, getNames as e, assertTypes as f, getWorkerState as g, getFullName as h, isObject as i, join as j, safeClearTimeout as k, notNullish as l, mockDate as m, noop as n, deepClone as o, picocolors as p, getType as q, resetDate as r, safeSetTimeout as s, isNode as t, toArray as u, relativePath as v, withSafeTimers as w, isBrowser as x, partitionSuiteChildren as y, shuffle as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as slash, l as notNullish, p as picocolors } from './chunk-utils-global.2aa95025.mjs';
|
|
2
2
|
|
|
3
3
|
var build = {};
|
|
4
4
|
|
|
@@ -7435,4 +7435,4 @@ var matcherUtils = /*#__PURE__*/Object.freeze({
|
|
|
7435
7435
|
diff: diff
|
|
7436
7436
|
});
|
|
7437
7437
|
|
|
7438
|
-
export {
|
|
7438
|
+
export { plugins_1 as a, posToNumber as b, stripAnsi as c, cliTruncate as d, stringWidth as e, format_1 as f, getOriginalPos as g, ansiStyles as h, sliceAnsi as i, interpretSourcePos as j, lineSplitRE as l, matcherUtils as m, numberToPos as n, parseStacktrace as p, stringify as s, unifiedDiff as u };
|