vitest 0.21.0 → 0.22.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 +61 -4
- package/dist/browser.d.ts +4 -5
- package/dist/browser.mjs +9 -9
- package/dist/{chunk-api-setup.89eb0e7a.mjs → chunk-api-setup.377c28aa.mjs} +9 -9
- package/dist/chunk-constants.71e8a211.mjs +284 -0
- package/dist/{chunk-install-pkg.6c6dc0c2.mjs → chunk-install-pkg.3aa3eae6.mjs} +3 -2
- package/dist/{chunk-defaults.8390340d.mjs → chunk-integrations-coverage.d205bd87.mjs} +23 -152
- package/dist/{chunk-integrations-globals.a798d352.mjs → chunk-integrations-globals.60af7da3.mjs} +8 -8
- package/dist/{chunk-mock-date.ea3b3121.mjs → chunk-mock-date.304e29b1.mjs} +11 -255
- package/dist/chunk-node-git.9a7e3153.mjs +78 -0
- package/dist/{chunk-runtime-chain.44b4224d.mjs → chunk-runtime-chain.be610650.mjs} +4 -3
- package/dist/{chunk-runtime-error.95e53764.mjs → chunk-runtime-error.1104e45a.mjs} +13 -12
- package/dist/{chunk-runtime-hooks.291644ec.mjs → chunk-runtime-hooks.5d7073db.mjs} +3 -3
- package/dist/{chunk-runtime-mocker.6190d6a3.mjs → chunk-runtime-mocker.49d21aa6.mjs} +19 -5
- package/dist/{chunk-runtime-rpc.fc50dcc0.mjs → chunk-runtime-rpc.57586b73.mjs} +1 -1
- package/dist/{chunk-utils-source-map.d307e4ea.mjs → chunk-utils-source-map.bbf3ad19.mjs} +2 -1
- package/dist/{chunk-vite-node-client.b59ba135.mjs → chunk-vite-node-client.cddda63d.mjs} +49 -21
- package/dist/{chunk-vite-node-debug.dbce2e1f.mjs → chunk-vite-node-debug.536c4c5b.mjs} +3 -3
- package/dist/{chunk-vite-node-externalize.80bed9b3.mjs → chunk-vite-node-externalize.c843f497.mjs} +186 -50
- package/dist/chunk-vite-node-utils.b432150c.mjs +6921 -0
- package/dist/cli-wrapper.mjs +124 -0
- package/dist/cli.mjs +16 -15
- package/dist/config.cjs +3 -0
- package/dist/config.d.ts +6 -3
- package/dist/config.mjs +2 -1
- package/dist/entry.mjs +9 -9
- package/dist/{global-644546f7.d.ts → global-fe52f84b.d.ts} +512 -177
- package/dist/{index-3f764034.d.ts → index-ea17aa0c.d.ts} +4 -52
- package/dist/index.d.ts +5 -6
- package/dist/index.mjs +7 -5
- package/dist/loader.mjs +4 -3
- package/dist/node.d.ts +3 -3
- package/dist/node.mjs +16 -15
- package/dist/suite.mjs +6 -4
- package/dist/{vendor-index.61438b77.mjs → vendor-index.29636037.mjs} +1 -61
- package/dist/{vendor-index.62ce5c33.mjs → vendor-index.2ae8040a.mjs} +0 -0
- package/dist/vendor-index.9d9196cc.mjs +61 -0
- package/dist/{vendor-index.de788b6a.mjs → vendor-index.ae96af6e.mjs} +14 -14
- package/dist/{chunk-node-git.e0dc0a7e.mjs → vendor-index.fbec8a81.mjs} +5 -73
- package/dist/worker.mjs +9 -9
- package/package.json +9 -13
- package/vitest.mjs +1 -1
- package/dist/chunk-constants.9da1ef26.mjs +0 -38
- package/dist/chunk-vite-node-utils.96438e82.mjs +0 -1114
- package/dist/mocker-5e2a8e41.d.ts +0 -3
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { e as environments, t as
|
|
2
|
-
import { r as resetRunOnceCounter, i as index, v as vi } from './chunk-runtime-hooks.
|
|
3
|
-
import {
|
|
4
|
-
import { e as clearCollectorContext, f as defaultSuite, h as setHooks, j as getHooks, k as collectorContext, l as setState, G as GLOBAL_EXPECT, m as getFn, n as getState } from './chunk-runtime-chain.
|
|
5
|
-
import { r as rpc } from './chunk-runtime-rpc.
|
|
1
|
+
import { e as environments, t as takeCoverageInsideWorker, p as pLimit } from './chunk-integrations-coverage.d205bd87.mjs';
|
|
2
|
+
import { r as resetRunOnceCounter, i as index, v as vi } from './chunk-runtime-hooks.5d7073db.mjs';
|
|
3
|
+
import { f as deepClone, h as getType, j as isNode, R as RealDate, t as toArray, k as relativePath, l as isBrowser, p as partitionSuiteChildren, o as shuffle, q as hasTests, u as hasFailed, d as getFullName } from './chunk-mock-date.304e29b1.mjs';
|
|
4
|
+
import { e as clearCollectorContext, f as defaultSuite, h as setHooks, j as getHooks, k as collectorContext, l as setState, G as GLOBAL_EXPECT, m as getFn, n as getState } from './chunk-runtime-chain.be610650.mjs';
|
|
5
|
+
import { r as rpc } from './chunk-runtime-rpc.57586b73.mjs';
|
|
6
6
|
import util$1 from 'util';
|
|
7
7
|
import { util } from 'chai';
|
|
8
|
-
import { s as stringify } from './chunk-utils-source-map.
|
|
8
|
+
import { s as stringify } from './chunk-utils-source-map.bbf3ad19.mjs';
|
|
9
9
|
import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
|
|
10
10
|
import { a as safeClearTimeout, s as safeSetTimeout } from './chunk-utils-timers.b48455ed.mjs';
|
|
11
11
|
|
|
@@ -131,7 +131,7 @@ async function setupGlobalEnv(config) {
|
|
|
131
131
|
if (isNode)
|
|
132
132
|
await setupConsoleLogSpy();
|
|
133
133
|
if (config.globals)
|
|
134
|
-
(await import('./chunk-integrations-globals.
|
|
134
|
+
(await import('./chunk-integrations-globals.60af7da3.mjs')).registerApiGlobally();
|
|
135
135
|
}
|
|
136
136
|
function setupDefines(defines) {
|
|
137
137
|
for (const key in defines)
|
|
@@ -442,7 +442,7 @@ async function sendTasksUpdate() {
|
|
|
442
442
|
async function runTest(test) {
|
|
443
443
|
var _a, _b;
|
|
444
444
|
if (test.mode !== "run") {
|
|
445
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
445
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.be610650.mjs').then(function (n) { return n.p; });
|
|
446
446
|
getSnapshotClient().skipTestSnapshots(test);
|
|
447
447
|
return;
|
|
448
448
|
}
|
|
@@ -458,7 +458,7 @@ async function runTest(test) {
|
|
|
458
458
|
updateTask(test);
|
|
459
459
|
clearModuleMocks();
|
|
460
460
|
if (isNode) {
|
|
461
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
461
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.be610650.mjs').then(function (n) { return n.p; });
|
|
462
462
|
await getSnapshotClient().setTest(test);
|
|
463
463
|
}
|
|
464
464
|
const workerState = getWorkerState();
|
|
@@ -511,7 +511,7 @@ async function runTest(test) {
|
|
|
511
511
|
if (isBrowser && test.result.error)
|
|
512
512
|
console.error(test.result.error.message, test.result.error.stackStr);
|
|
513
513
|
if (isNode) {
|
|
514
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
514
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.be610650.mjs').then(function (n) { return n.p; });
|
|
515
515
|
getSnapshotClient().clearTest();
|
|
516
516
|
}
|
|
517
517
|
test.result.duration = now() - start;
|
|
@@ -623,10 +623,11 @@ async function startTestsBrowser(paths, config) {
|
|
|
623
623
|
async function startTestsNode(paths, config) {
|
|
624
624
|
const files = await collectTests(paths, config);
|
|
625
625
|
rpc().onCollected(files);
|
|
626
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
626
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.be610650.mjs').then(function (n) { return n.p; });
|
|
627
627
|
getSnapshotClient().clear();
|
|
628
628
|
await runFiles(files, config);
|
|
629
|
-
|
|
629
|
+
const coverage = await takeCoverageInsideWorker(config.coverage);
|
|
630
|
+
rpc().onAfterSuiteRun({ coverage });
|
|
630
631
|
await getSnapshotClient().saveCurrent();
|
|
631
632
|
await sendTasksUpdate();
|
|
632
633
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, c as createExpect, b as globalExpect } from './chunk-runtime-chain.
|
|
2
|
-
import { R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-mock-date.
|
|
1
|
+
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, c as createExpect, b as globalExpect } from './chunk-runtime-chain.be610650.mjs';
|
|
2
|
+
import { R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-mock-date.304e29b1.mjs';
|
|
3
3
|
import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
|
|
4
|
-
import { p as parseStacktrace } from './chunk-utils-source-map.
|
|
4
|
+
import { p as parseStacktrace } from './chunk-utils-source-map.bbf3ad19.mjs';
|
|
5
5
|
import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
|
|
6
6
|
import util from 'util';
|
|
7
7
|
import { spyOn, fn, isMockFunction, spies } from './spy.mjs';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { V as ViteNodeRunner } from './chunk-vite-node-client.
|
|
1
|
+
import { V as ViteNodeRunner } from './chunk-vite-node-client.cddda63d.mjs';
|
|
2
2
|
import { normalizePath } from 'vite';
|
|
3
|
-
import {
|
|
3
|
+
import { C as isWindows, D as mergeSlashes, s as slash, h as getType, E as getAllMockableProperties } from './chunk-mock-date.304e29b1.mjs';
|
|
4
4
|
import { existsSync, readdirSync } from 'fs';
|
|
5
|
-
import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.
|
|
6
|
-
import { d as distDir } from './chunk-constants.
|
|
5
|
+
import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.b432150c.mjs';
|
|
6
|
+
import { d as dirname, j as join, b as basename, a as resolve, c as distDir } from './chunk-constants.71e8a211.mjs';
|
|
7
7
|
import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
|
|
8
8
|
|
|
9
9
|
class RefTracker {
|
|
@@ -78,8 +78,22 @@ const _VitestMocker = class {
|
|
|
78
78
|
if (cached)
|
|
79
79
|
return cached;
|
|
80
80
|
const exports = await mock();
|
|
81
|
+
if (exports === null || typeof exports !== "object")
|
|
82
|
+
throw new Error('[vitest] vi.mock(path: string, factory?: () => unknown) is not returning an object. Did you mean to return an object with a "default" key?');
|
|
81
83
|
this.moduleCache.set(dep, { exports });
|
|
82
|
-
|
|
84
|
+
const exportHandler = {
|
|
85
|
+
get(target, prop) {
|
|
86
|
+
const val = target[prop];
|
|
87
|
+
if (prop === "then") {
|
|
88
|
+
if (target instanceof Promise)
|
|
89
|
+
return target.then.bind(target);
|
|
90
|
+
} else if (!(prop in target)) {
|
|
91
|
+
throw new Error(`[vitest] No "${prop}" export is defined on the "${dep}"`);
|
|
92
|
+
}
|
|
93
|
+
return val;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return new Proxy(exports, exportHandler);
|
|
83
97
|
}
|
|
84
98
|
getMockPath(dep) {
|
|
85
99
|
return `mock:${dep}`;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
2
|
import { pathToFileURL, fileURLToPath } from 'url';
|
|
3
3
|
import vm from 'vm';
|
|
4
|
-
import {
|
|
5
|
-
import { s as slash, n as normalizeRequestId, b as toFilePath, i as isNodeBuiltin, c as isPrimitive, d as normalizeModuleId, m as mergeSlashes } from './chunk-vite-node-utils.
|
|
4
|
+
import { a as resolve, d as dirname, i as isAbsolute, h as extname } from './chunk-constants.71e8a211.mjs';
|
|
5
|
+
import { s as slash, n as normalizeRequestId, b as toFilePath, i as isNodeBuiltin, c as isPrimitive, d as normalizeModuleId, m as mergeSlashes } from './chunk-vite-node-utils.b432150c.mjs';
|
|
6
6
|
import createDebug from 'debug';
|
|
7
7
|
|
|
8
8
|
const debugExecute = createDebug("vite-node:client:execute");
|
|
@@ -45,7 +45,7 @@ class ModuleCacheMap extends Map {
|
|
|
45
45
|
normalizePath(fsPath) {
|
|
46
46
|
return normalizeModuleId(fsPath);
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
update(fsPath, mod) {
|
|
49
49
|
fsPath = this.normalizePath(fsPath);
|
|
50
50
|
if (!super.has(fsPath))
|
|
51
51
|
super.set(fsPath, mod);
|
|
@@ -53,14 +53,33 @@ class ModuleCacheMap extends Map {
|
|
|
53
53
|
Object.assign(super.get(fsPath), mod);
|
|
54
54
|
return this;
|
|
55
55
|
}
|
|
56
|
+
set(fsPath, mod) {
|
|
57
|
+
fsPath = this.normalizePath(fsPath);
|
|
58
|
+
return super.set(fsPath, mod);
|
|
59
|
+
}
|
|
56
60
|
get(fsPath) {
|
|
57
61
|
fsPath = this.normalizePath(fsPath);
|
|
62
|
+
if (!super.has(fsPath))
|
|
63
|
+
super.set(fsPath, {});
|
|
58
64
|
return super.get(fsPath);
|
|
59
65
|
}
|
|
60
66
|
delete(fsPath) {
|
|
61
67
|
fsPath = this.normalizePath(fsPath);
|
|
62
68
|
return super.delete(fsPath);
|
|
63
69
|
}
|
|
70
|
+
invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
|
|
71
|
+
for (const _id of ids) {
|
|
72
|
+
const id = this.normalizePath(_id);
|
|
73
|
+
if (invalidated.has(id))
|
|
74
|
+
continue;
|
|
75
|
+
invalidated.add(id);
|
|
76
|
+
const mod = super.get(id);
|
|
77
|
+
if (mod == null ? void 0 : mod.importers)
|
|
78
|
+
this.invalidateDepTree(mod.importers, invalidated);
|
|
79
|
+
super.delete(id);
|
|
80
|
+
}
|
|
81
|
+
return invalidated;
|
|
82
|
+
}
|
|
64
83
|
}
|
|
65
84
|
class ViteNodeRunner {
|
|
66
85
|
constructor(options) {
|
|
@@ -76,39 +95,44 @@ class ViteNodeRunner {
|
|
|
76
95
|
return await this.cachedRequest(id, []);
|
|
77
96
|
}
|
|
78
97
|
async cachedRequest(rawId, callstack) {
|
|
79
|
-
var _a, _b, _c, _d;
|
|
80
98
|
const id = normalizeRequestId(rawId, this.options.base);
|
|
81
99
|
const fsPath = toFilePath(id, this.root);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
100
|
+
const mod = this.moduleCache.get(fsPath);
|
|
101
|
+
const importee = callstack[callstack.length - 1];
|
|
102
|
+
if (!mod.importers)
|
|
103
|
+
mod.importers = /* @__PURE__ */ new Set();
|
|
104
|
+
if (importee)
|
|
105
|
+
mod.importers.add(importee);
|
|
106
|
+
if (callstack.includes(fsPath) && mod.exports)
|
|
107
|
+
return mod.exports;
|
|
108
|
+
if (mod.promise)
|
|
109
|
+
return mod.promise;
|
|
86
110
|
const promise = this.directRequest(id, fsPath, callstack);
|
|
87
|
-
|
|
111
|
+
Object.assign(mod, { promise });
|
|
88
112
|
return await promise;
|
|
89
113
|
}
|
|
90
114
|
async directRequest(id, fsPath, _callstack) {
|
|
91
115
|
const callstack = [..._callstack, fsPath];
|
|
116
|
+
const mod = this.moduleCache.get(fsPath);
|
|
92
117
|
const request = async (dep) => {
|
|
93
118
|
var _a;
|
|
94
|
-
const
|
|
119
|
+
const depFsPath = toFilePath(normalizeRequestId(dep, this.options.base), this.root);
|
|
95
120
|
const getStack = () => {
|
|
96
121
|
return `stack:
|
|
97
|
-
${[...callstack,
|
|
122
|
+
${[...callstack, depFsPath].reverse().map((p) => `- ${p}`).join("\n")}`;
|
|
98
123
|
};
|
|
99
124
|
let debugTimer;
|
|
100
125
|
if (this.debug)
|
|
101
|
-
debugTimer = setTimeout(() => console.warn(() => `module ${
|
|
126
|
+
debugTimer = setTimeout(() => console.warn(() => `module ${depFsPath} takes over 2s to load.
|
|
102
127
|
${getStack()}`), 2e3);
|
|
103
128
|
try {
|
|
104
|
-
if (callstack.includes(
|
|
105
|
-
const depExports = (_a = this.moduleCache.get(
|
|
129
|
+
if (callstack.includes(depFsPath)) {
|
|
130
|
+
const depExports = (_a = this.moduleCache.get(depFsPath)) == null ? void 0 : _a.exports;
|
|
106
131
|
if (depExports)
|
|
107
132
|
return depExports;
|
|
108
133
|
throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
|
|
109
134
|
}
|
|
110
|
-
|
|
111
|
-
return mod;
|
|
135
|
+
return await this.cachedRequest(dep, callstack);
|
|
112
136
|
} finally {
|
|
113
137
|
if (debugTimer)
|
|
114
138
|
clearTimeout(debugTimer);
|
|
@@ -132,17 +156,21 @@ ${getStack()}`), 2e3);
|
|
|
132
156
|
let { code: transformed, externalize } = await this.options.fetchModule(id);
|
|
133
157
|
if (externalize) {
|
|
134
158
|
debugNative(externalize);
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
return
|
|
159
|
+
const exports2 = await this.interopedImport(externalize);
|
|
160
|
+
mod.exports = exports2;
|
|
161
|
+
return exports2;
|
|
138
162
|
}
|
|
139
163
|
if (transformed == null)
|
|
140
164
|
throw new Error(`[vite-node] Failed to load ${id}`);
|
|
141
165
|
const url = pathToFileURL(fsPath).href;
|
|
142
166
|
const meta = { url };
|
|
143
167
|
const exports = /* @__PURE__ */ Object.create(null);
|
|
144
|
-
exports
|
|
145
|
-
|
|
168
|
+
Object.defineProperty(exports, Symbol.toStringTag, {
|
|
169
|
+
value: "Module",
|
|
170
|
+
enumerable: false,
|
|
171
|
+
configurable: false
|
|
172
|
+
});
|
|
173
|
+
Object.assign(mod, { code: transformed, exports });
|
|
146
174
|
const __filename = fileURLToPath(url);
|
|
147
175
|
const moduleProxy = {
|
|
148
176
|
set exports(value) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { existsSync, promises } from 'fs';
|
|
2
|
-
import {
|
|
3
|
-
import 'path';
|
|
2
|
+
import { a as resolve, p as picocolors, j as join } from './chunk-constants.71e8a211.mjs';
|
|
4
3
|
import 'tty';
|
|
5
|
-
import '
|
|
4
|
+
import 'url';
|
|
5
|
+
import 'path';
|
|
6
6
|
|
|
7
7
|
function hashCode(s) {
|
|
8
8
|
return s.split("").reduce((a, b) => {
|