vitest 0.32.4 → 0.34.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 +0 -83
- package/dist/browser.d.ts +3 -2
- package/dist/browser.js +4 -8
- package/dist/child.js +43 -29
- package/dist/{chunk-api-setup.8f785c4a.js → chunk-api-setup.644415c3.js} +13 -7
- package/dist/{chunk-install-pkg.3fc886f2.js → chunk-install-pkg.dd70081b.js} +14 -13
- package/dist/{chunk-integrations-globals.0093e2ed.js → chunk-integrations-globals.877c84db.js} +7 -6
- package/dist/chunk-runtime-console.ea222ffb.js +108 -0
- package/dist/cli.js +15 -16
- package/dist/config.cjs +6 -5
- package/dist/config.d.ts +15 -19
- package/dist/config.js +6 -5
- package/dist/coverage.d.ts +3 -2
- package/dist/entry-vm.js +60 -0
- package/dist/entry.js +34 -213
- package/dist/environments.d.ts +3 -2
- package/dist/environments.js +4 -2
- package/dist/execute.js +15 -0
- package/dist/index.d.ts +12 -7
- package/dist/index.js +8 -7
- package/dist/loader.js +6 -4
- package/dist/node.d.ts +6 -53
- package/dist/node.js +17 -20
- package/dist/runners.d.ts +3 -2
- package/dist/runners.js +6 -5
- package/dist/{types-198fd1d9.d.ts → types-3c7dbfa5.d.ts} +139 -121
- package/dist/vendor-base.9c08bbd0.js +96 -0
- package/dist/{vendor-coverage.2e41927a.js → vendor-coverage.78040316.js} +1 -2
- package/dist/vendor-date.6e993429.js +50 -0
- package/dist/{vendor-environments.75f2b63d.js → vendor-environments.443ecd82.js} +202 -3
- package/dist/vendor-execute.9ab1c1a7.js +978 -0
- package/dist/{vendor-global.6795f91f.js → vendor-global.97e4527c.js} +2 -1
- package/dist/{vendor-index.23ac4e13.js → vendor-index.087d1af7.js} +2 -20
- package/dist/vendor-index.9378c9a4.js +89 -0
- package/dist/vendor-index.b271ebe4.js +92 -0
- package/dist/{vendor-index.2af39fbb.js → vendor-index.eff408fd.js} +2 -3
- package/dist/{vendor-cli-api.cb31e1db.js → vendor-node.00226ab1.js} +1671 -1882
- package/dist/{vendor-rpc.ad5b08c7.js → vendor-rpc.cbd8e972.js} +7 -4
- package/dist/{vendor-run-once.1fa85ba7.js → vendor-run-once.3e5ef7d7.js} +1 -2
- package/dist/vendor-source-map.e6c1997b.js +747 -0
- package/dist/{vendor-vi.dd6706cb.js → vendor-vi.271667ef.js} +26 -59
- package/dist/vm.js +114 -0
- package/dist/worker.js +39 -27
- package/execute.d.ts +1 -0
- package/package.json +14 -11
- package/suppress-warnings.cjs +2 -0
- package/dist/vendor-execute.3576af13.js +0 -421
- package/dist/vendor-index.cc463d9e.js +0 -189
- package/dist/vendor-tasks.f9d75aed.js +0 -14
|
@@ -1,421 +0,0 @@
|
|
|
1
|
-
import { pathToFileURL } from 'node:url';
|
|
2
|
-
import { ModuleCacheMap, ViteNodeRunner } from 'vite-node/client';
|
|
3
|
-
import { isNodeBuiltin, isInternalRequest, isPrimitive } from 'vite-node/utils';
|
|
4
|
-
import { isAbsolute, dirname, join, basename, extname, resolve, normalize, relative } from 'pathe';
|
|
5
|
-
import { processError } from '@vitest/utils/error';
|
|
6
|
-
import { g as getWorkerState, a as getCurrentEnvironment } from './vendor-global.6795f91f.js';
|
|
7
|
-
import { d as distDir } from './vendor-paths.84fc7a99.js';
|
|
8
|
-
import { existsSync, readdirSync } from 'node:fs';
|
|
9
|
-
import { getColors, getType } from '@vitest/utils';
|
|
10
|
-
import { g as getAllMockableProperties } from './vendor-index.cc463d9e.js';
|
|
11
|
-
import { spyOn } from '@vitest/spy';
|
|
12
|
-
import { a as rpc } from './vendor-rpc.ad5b08c7.js';
|
|
13
|
-
|
|
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];
|
|
15
|
-
class RefTracker {
|
|
16
|
-
idMap = /* @__PURE__ */ new Map();
|
|
17
|
-
mockedValueMap = /* @__PURE__ */ new Map();
|
|
18
|
-
getId(value) {
|
|
19
|
-
return this.idMap.get(value);
|
|
20
|
-
}
|
|
21
|
-
getMockedValue(id) {
|
|
22
|
-
return this.mockedValueMap.get(id);
|
|
23
|
-
}
|
|
24
|
-
track(originalValue, mockedValue) {
|
|
25
|
-
const newId = this.idMap.size;
|
|
26
|
-
this.idMap.set(originalValue, newId);
|
|
27
|
-
this.mockedValueMap.set(newId, mockedValue);
|
|
28
|
-
return newId;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function isSpecialProp(prop, parentType) {
|
|
32
|
-
return parentType.includes("Function") && typeof prop === "string" && ["arguments", "callee", "caller", "length", "name"].includes(prop);
|
|
33
|
-
}
|
|
34
|
-
class VitestMocker {
|
|
35
|
-
constructor(executor) {
|
|
36
|
-
this.executor = executor;
|
|
37
|
-
}
|
|
38
|
-
static pendingIds = [];
|
|
39
|
-
resolveCache = /* @__PURE__ */ new Map();
|
|
40
|
-
get root() {
|
|
41
|
-
return this.executor.options.root;
|
|
42
|
-
}
|
|
43
|
-
get mockMap() {
|
|
44
|
-
return this.executor.options.mockMap;
|
|
45
|
-
}
|
|
46
|
-
get moduleCache() {
|
|
47
|
-
return this.executor.moduleCache;
|
|
48
|
-
}
|
|
49
|
-
get moduleDirectories() {
|
|
50
|
-
return this.executor.options.moduleDirectories || [];
|
|
51
|
-
}
|
|
52
|
-
deleteCachedItem(id) {
|
|
53
|
-
const mockId = this.getMockPath(id);
|
|
54
|
-
if (this.moduleCache.has(mockId))
|
|
55
|
-
this.moduleCache.delete(mockId);
|
|
56
|
-
}
|
|
57
|
-
isAModuleDirectory(path) {
|
|
58
|
-
return this.moduleDirectories.some((dir) => path.includes(dir));
|
|
59
|
-
}
|
|
60
|
-
getSuiteFilepath() {
|
|
61
|
-
return getWorkerState().filepath || "global";
|
|
62
|
-
}
|
|
63
|
-
getMocks() {
|
|
64
|
-
const suite = this.getSuiteFilepath();
|
|
65
|
-
const suiteMocks = this.mockMap.get(suite);
|
|
66
|
-
const globalMocks = this.mockMap.get("global");
|
|
67
|
-
return {
|
|
68
|
-
...globalMocks,
|
|
69
|
-
...suiteMocks
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
async resolvePath(rawId, importer) {
|
|
73
|
-
let id;
|
|
74
|
-
let fsPath;
|
|
75
|
-
try {
|
|
76
|
-
[id, fsPath] = await this.executor.originalResolveUrl(rawId, importer);
|
|
77
|
-
} catch (error) {
|
|
78
|
-
if (error.code === "ERR_MODULE_NOT_FOUND") {
|
|
79
|
-
const { id: unresolvedId } = error[Symbol.for("vitest.error.not_found.data")];
|
|
80
|
-
id = unresolvedId;
|
|
81
|
-
fsPath = unresolvedId;
|
|
82
|
-
} else {
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
const external = !isAbsolute(fsPath) || this.isAModuleDirectory(fsPath) ? rawId : null;
|
|
87
|
-
return {
|
|
88
|
-
id,
|
|
89
|
-
fsPath,
|
|
90
|
-
external
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
async resolveMocks() {
|
|
94
|
-
if (!VitestMocker.pendingIds.length)
|
|
95
|
-
return;
|
|
96
|
-
await Promise.all(VitestMocker.pendingIds.map(async (mock) => {
|
|
97
|
-
const { fsPath, external } = await this.resolvePath(mock.id, mock.importer);
|
|
98
|
-
if (mock.type === "unmock")
|
|
99
|
-
this.unmockPath(fsPath);
|
|
100
|
-
if (mock.type === "mock")
|
|
101
|
-
this.mockPath(mock.id, fsPath, external, mock.factory);
|
|
102
|
-
}));
|
|
103
|
-
VitestMocker.pendingIds = [];
|
|
104
|
-
}
|
|
105
|
-
async callFunctionMock(dep, mock) {
|
|
106
|
-
var _a, _b;
|
|
107
|
-
const cached = (_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports;
|
|
108
|
-
if (cached)
|
|
109
|
-
return cached;
|
|
110
|
-
let exports;
|
|
111
|
-
try {
|
|
112
|
-
exports = await mock();
|
|
113
|
-
} catch (err) {
|
|
114
|
-
const vitestError = new Error(
|
|
115
|
-
'[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'
|
|
116
|
-
);
|
|
117
|
-
vitestError.cause = err;
|
|
118
|
-
throw vitestError;
|
|
119
|
-
}
|
|
120
|
-
const filepath = dep.slice(5);
|
|
121
|
-
const mockpath = ((_b = this.resolveCache.get(this.getSuiteFilepath())) == null ? void 0 : _b[filepath]) || filepath;
|
|
122
|
-
if (exports === null || typeof exports !== "object")
|
|
123
|
-
throw new Error(`[vitest] vi.mock("${mockpath}", factory?: () => unknown) is not returning an object. Did you mean to return an object with a "default" key?`);
|
|
124
|
-
const moduleExports = new Proxy(exports, {
|
|
125
|
-
get(target, prop) {
|
|
126
|
-
const val = target[prop];
|
|
127
|
-
if (prop === "then") {
|
|
128
|
-
if (target instanceof Promise)
|
|
129
|
-
return target.then.bind(target);
|
|
130
|
-
} else if (!(prop in target)) {
|
|
131
|
-
if (filterPublicKeys.includes(prop))
|
|
132
|
-
return void 0;
|
|
133
|
-
const c = getColors();
|
|
134
|
-
throw new Error(
|
|
135
|
-
`[vitest] No "${String(prop)}" export is defined on the "${mockpath}" mock. Did you forget to return it from "vi.mock"?
|
|
136
|
-
If you need to partially mock a module, you can use "vi.importActual" inside:
|
|
137
|
-
|
|
138
|
-
${c.green(`vi.mock("${mockpath}", async () => {
|
|
139
|
-
const actual = await vi.importActual("${mockpath}")
|
|
140
|
-
return {
|
|
141
|
-
...actual,
|
|
142
|
-
// your mocked methods
|
|
143
|
-
},
|
|
144
|
-
})`)}
|
|
145
|
-
`
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
return val;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
this.moduleCache.set(dep, { exports: moduleExports });
|
|
152
|
-
return moduleExports;
|
|
153
|
-
}
|
|
154
|
-
getMockPath(dep) {
|
|
155
|
-
return `mock:${dep}`;
|
|
156
|
-
}
|
|
157
|
-
getDependencyMock(id) {
|
|
158
|
-
return this.getMocks()[id];
|
|
159
|
-
}
|
|
160
|
-
normalizePath(path) {
|
|
161
|
-
return this.moduleCache.normalizePath(path);
|
|
162
|
-
}
|
|
163
|
-
resolveMockPath(mockPath, external) {
|
|
164
|
-
const path = external || mockPath;
|
|
165
|
-
if (external || isNodeBuiltin(mockPath) || !existsSync(mockPath)) {
|
|
166
|
-
const mockDirname = dirname(path);
|
|
167
|
-
const mockFolder = join(this.root, "__mocks__", mockDirname);
|
|
168
|
-
if (!existsSync(mockFolder))
|
|
169
|
-
return null;
|
|
170
|
-
const files = readdirSync(mockFolder);
|
|
171
|
-
const baseOriginal = basename(path);
|
|
172
|
-
for (const file of files) {
|
|
173
|
-
const baseFile = basename(file, extname(file));
|
|
174
|
-
if (baseFile === baseOriginal)
|
|
175
|
-
return resolve(mockFolder, file);
|
|
176
|
-
}
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
const dir = dirname(path);
|
|
180
|
-
const baseId = basename(path);
|
|
181
|
-
const fullPath = resolve(dir, "__mocks__", baseId);
|
|
182
|
-
return existsSync(fullPath) ? fullPath : null;
|
|
183
|
-
}
|
|
184
|
-
mockObject(object, mockExports = {}) {
|
|
185
|
-
const finalizers = new Array();
|
|
186
|
-
const refs = new RefTracker();
|
|
187
|
-
const define = (container, key, value) => {
|
|
188
|
-
try {
|
|
189
|
-
container[key] = value;
|
|
190
|
-
return true;
|
|
191
|
-
} catch {
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
const mockPropertiesOf = (container, newContainer) => {
|
|
196
|
-
const containerType = getType(container);
|
|
197
|
-
const isModule = containerType === "Module" || !!container.__esModule;
|
|
198
|
-
for (const { key: property, descriptor } of getAllMockableProperties(container, isModule)) {
|
|
199
|
-
if (!isModule && descriptor.get) {
|
|
200
|
-
try {
|
|
201
|
-
Object.defineProperty(newContainer, property, descriptor);
|
|
202
|
-
} catch (error) {
|
|
203
|
-
}
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
if (isSpecialProp(property, containerType))
|
|
207
|
-
continue;
|
|
208
|
-
const value = container[property];
|
|
209
|
-
const refId = refs.getId(value);
|
|
210
|
-
if (refId !== void 0) {
|
|
211
|
-
finalizers.push(() => define(newContainer, property, refs.getMockedValue(refId)));
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
const type = getType(value);
|
|
215
|
-
if (Array.isArray(value)) {
|
|
216
|
-
define(newContainer, property, []);
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
const isFunction = type.includes("Function") && typeof value === "function";
|
|
220
|
-
if ((!isFunction || value.__isMockFunction) && type !== "Object" && type !== "Module") {
|
|
221
|
-
define(newContainer, property, value);
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
if (!define(newContainer, property, isFunction ? value : {}))
|
|
225
|
-
continue;
|
|
226
|
-
if (isFunction) {
|
|
227
|
-
const mock = spyOn(newContainer, property).mockImplementation(() => void 0);
|
|
228
|
-
mock.mockRestore = () => {
|
|
229
|
-
mock.mockReset();
|
|
230
|
-
mock.mockImplementation(() => void 0);
|
|
231
|
-
return mock;
|
|
232
|
-
};
|
|
233
|
-
Object.defineProperty(newContainer[property], "length", { value: 0 });
|
|
234
|
-
}
|
|
235
|
-
refs.track(value, newContainer[property]);
|
|
236
|
-
mockPropertiesOf(value, newContainer[property]);
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
const mockedObject = mockExports;
|
|
240
|
-
mockPropertiesOf(object, mockedObject);
|
|
241
|
-
for (const finalizer of finalizers)
|
|
242
|
-
finalizer();
|
|
243
|
-
return mockedObject;
|
|
244
|
-
}
|
|
245
|
-
unmockPath(path) {
|
|
246
|
-
const suitefile = this.getSuiteFilepath();
|
|
247
|
-
const id = this.normalizePath(path);
|
|
248
|
-
const mock = this.mockMap.get(suitefile);
|
|
249
|
-
if (mock && id in mock)
|
|
250
|
-
delete mock[id];
|
|
251
|
-
this.deleteCachedItem(id);
|
|
252
|
-
}
|
|
253
|
-
mockPath(originalId, path, external, factory) {
|
|
254
|
-
const suitefile = this.getSuiteFilepath();
|
|
255
|
-
const id = this.normalizePath(path);
|
|
256
|
-
const mocks = this.mockMap.get(suitefile) || {};
|
|
257
|
-
const resolves = this.resolveCache.get(suitefile) || {};
|
|
258
|
-
mocks[id] = factory || this.resolveMockPath(path, external);
|
|
259
|
-
resolves[id] = originalId;
|
|
260
|
-
this.mockMap.set(suitefile, mocks);
|
|
261
|
-
this.resolveCache.set(suitefile, resolves);
|
|
262
|
-
this.deleteCachedItem(id);
|
|
263
|
-
}
|
|
264
|
-
async importActual(rawId, importee) {
|
|
265
|
-
const { id, fsPath } = await this.resolvePath(rawId, importee);
|
|
266
|
-
const result = await this.executor.cachedRequest(id, fsPath, [importee]);
|
|
267
|
-
return result;
|
|
268
|
-
}
|
|
269
|
-
async importMock(rawId, importee) {
|
|
270
|
-
const { id, fsPath, external } = await this.resolvePath(rawId, importee);
|
|
271
|
-
const normalizedId = this.normalizePath(fsPath);
|
|
272
|
-
let mock = this.getDependencyMock(normalizedId);
|
|
273
|
-
if (mock === void 0)
|
|
274
|
-
mock = this.resolveMockPath(fsPath, external);
|
|
275
|
-
if (mock === null) {
|
|
276
|
-
const mod = await this.executor.cachedRequest(id, fsPath, [importee]);
|
|
277
|
-
return this.mockObject(mod);
|
|
278
|
-
}
|
|
279
|
-
if (typeof mock === "function")
|
|
280
|
-
return this.callFunctionMock(fsPath, mock);
|
|
281
|
-
return this.executor.dependencyRequest(mock, mock, [importee]);
|
|
282
|
-
}
|
|
283
|
-
async requestWithMock(url, callstack) {
|
|
284
|
-
const id = this.normalizePath(url);
|
|
285
|
-
const mock = this.getDependencyMock(id);
|
|
286
|
-
const mockPath = this.getMockPath(id);
|
|
287
|
-
if (mock === null) {
|
|
288
|
-
const cache = this.moduleCache.get(mockPath);
|
|
289
|
-
if (cache.exports)
|
|
290
|
-
return cache.exports;
|
|
291
|
-
const exports = {};
|
|
292
|
-
this.moduleCache.set(mockPath, { exports });
|
|
293
|
-
const mod = await this.executor.directRequest(url, url, callstack);
|
|
294
|
-
this.mockObject(mod, exports);
|
|
295
|
-
return exports;
|
|
296
|
-
}
|
|
297
|
-
if (typeof mock === "function" && !callstack.includes(mockPath) && !callstack.includes(url)) {
|
|
298
|
-
callstack.push(mockPath);
|
|
299
|
-
const result = await this.callFunctionMock(mockPath, mock);
|
|
300
|
-
const indexMock = callstack.indexOf(mockPath);
|
|
301
|
-
callstack.splice(indexMock, 1);
|
|
302
|
-
return result;
|
|
303
|
-
}
|
|
304
|
-
if (typeof mock === "string" && !callstack.includes(mock))
|
|
305
|
-
return mock;
|
|
306
|
-
}
|
|
307
|
-
queueMock(id, importer, factory) {
|
|
308
|
-
VitestMocker.pendingIds.push({ type: "mock", id, importer, factory });
|
|
309
|
-
}
|
|
310
|
-
queueUnmock(id, importer) {
|
|
311
|
-
VitestMocker.pendingIds.push({ type: "unmock", id, importer });
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
async function createVitestExecutor(options) {
|
|
316
|
-
const runner = new VitestExecutor(options);
|
|
317
|
-
await runner.executeId("/@vite/env");
|
|
318
|
-
return runner;
|
|
319
|
-
}
|
|
320
|
-
let _viteNode;
|
|
321
|
-
const moduleCache = new ModuleCacheMap();
|
|
322
|
-
const mockMap = /* @__PURE__ */ new Map();
|
|
323
|
-
async function startViteNode(ctx) {
|
|
324
|
-
if (_viteNode)
|
|
325
|
-
return _viteNode;
|
|
326
|
-
const { config } = ctx;
|
|
327
|
-
const processExit = process.exit;
|
|
328
|
-
process.exit = (code = process.exitCode || 0) => {
|
|
329
|
-
const error = new Error(`process.exit called with "${code}"`);
|
|
330
|
-
rpc().onWorkerExit(error, code);
|
|
331
|
-
return processExit(code);
|
|
332
|
-
};
|
|
333
|
-
function catchError(err, type) {
|
|
334
|
-
var _a;
|
|
335
|
-
const worker = getWorkerState();
|
|
336
|
-
const error = processError(err);
|
|
337
|
-
if (!isPrimitive(error)) {
|
|
338
|
-
error.VITEST_TEST_NAME = (_a = worker.current) == null ? void 0 : _a.name;
|
|
339
|
-
if (worker.filepath)
|
|
340
|
-
error.VITEST_TEST_PATH = relative(config.root, worker.filepath);
|
|
341
|
-
error.VITEST_AFTER_ENV_TEARDOWN = worker.environmentTeardownRun;
|
|
342
|
-
}
|
|
343
|
-
rpc().onUnhandledError(error, type);
|
|
344
|
-
}
|
|
345
|
-
process.on("uncaughtException", (e) => catchError(e, "Uncaught Exception"));
|
|
346
|
-
process.on("unhandledRejection", (e) => catchError(e, "Unhandled Rejection"));
|
|
347
|
-
const executor = await createVitestExecutor({
|
|
348
|
-
fetchModule(id) {
|
|
349
|
-
return rpc().fetch(id, ctx.environment.name);
|
|
350
|
-
},
|
|
351
|
-
resolveId(id, importer) {
|
|
352
|
-
return rpc().resolveId(id, importer, ctx.environment.name);
|
|
353
|
-
},
|
|
354
|
-
moduleCache,
|
|
355
|
-
mockMap,
|
|
356
|
-
interopDefault: config.deps.interopDefault,
|
|
357
|
-
moduleDirectories: config.deps.moduleDirectories,
|
|
358
|
-
root: config.root,
|
|
359
|
-
base: config.base
|
|
360
|
-
});
|
|
361
|
-
const { run } = await import(pathToFileURL(resolve(distDir, "entry.js")).href);
|
|
362
|
-
_viteNode = { run, executor };
|
|
363
|
-
return _viteNode;
|
|
364
|
-
}
|
|
365
|
-
class VitestExecutor extends ViteNodeRunner {
|
|
366
|
-
constructor(options) {
|
|
367
|
-
super(options);
|
|
368
|
-
this.options = options;
|
|
369
|
-
this.mocker = new VitestMocker(this);
|
|
370
|
-
Object.defineProperty(globalThis, "__vitest_mocker__", {
|
|
371
|
-
value: this.mocker,
|
|
372
|
-
writable: true,
|
|
373
|
-
configurable: true
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
mocker;
|
|
377
|
-
shouldResolveId(id, _importee) {
|
|
378
|
-
if (isInternalRequest(id) || id.startsWith("data:"))
|
|
379
|
-
return false;
|
|
380
|
-
const environment = getCurrentEnvironment();
|
|
381
|
-
return environment === "node" ? !isNodeBuiltin(id) : !id.startsWith("node:");
|
|
382
|
-
}
|
|
383
|
-
async originalResolveUrl(id, importer) {
|
|
384
|
-
return super.resolveUrl(id, importer);
|
|
385
|
-
}
|
|
386
|
-
async resolveUrl(id, importer) {
|
|
387
|
-
if (VitestMocker.pendingIds.length)
|
|
388
|
-
await this.mocker.resolveMocks();
|
|
389
|
-
if (importer && importer.startsWith("mock:"))
|
|
390
|
-
importer = importer.slice(5);
|
|
391
|
-
try {
|
|
392
|
-
return await super.resolveUrl(id, importer);
|
|
393
|
-
} catch (error) {
|
|
394
|
-
if (error.code === "ERR_MODULE_NOT_FOUND") {
|
|
395
|
-
const { id: id2 } = error[Symbol.for("vitest.error.not_found.data")];
|
|
396
|
-
const path = this.mocker.normalizePath(id2);
|
|
397
|
-
const mock = this.mocker.getDependencyMock(path);
|
|
398
|
-
if (mock !== void 0)
|
|
399
|
-
return [id2, id2];
|
|
400
|
-
}
|
|
401
|
-
throw error;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
async dependencyRequest(id, fsPath, callstack) {
|
|
405
|
-
const mocked = await this.mocker.requestWithMock(fsPath, callstack);
|
|
406
|
-
if (typeof mocked === "string")
|
|
407
|
-
return super.dependencyRequest(mocked, mocked, callstack);
|
|
408
|
-
if (mocked && typeof mocked === "object")
|
|
409
|
-
return mocked;
|
|
410
|
-
return super.dependencyRequest(id, fsPath, callstack);
|
|
411
|
-
}
|
|
412
|
-
prepareContext(context) {
|
|
413
|
-
const workerState = getWorkerState();
|
|
414
|
-
if (workerState.filepath && normalize(workerState.filepath) === normalize(context.__filename)) {
|
|
415
|
-
Object.defineProperty(context.__vite_ssr_import_meta__, "vitest", { get: () => globalThis.__vitest_index__ });
|
|
416
|
-
}
|
|
417
|
-
return context;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
export { VitestExecutor as V, mockMap as a, moduleCache as m, startViteNode as s };
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import '@vitest/utils';
|
|
2
|
-
|
|
3
|
-
function isFinalObj(obj) {
|
|
4
|
-
return obj === Object.prototype || obj === Function.prototype || obj === RegExp.prototype;
|
|
5
|
-
}
|
|
6
|
-
function collectOwnProperties(obj, collector) {
|
|
7
|
-
const collect = typeof collector === "function" ? collector : (key) => collector.add(key);
|
|
8
|
-
Object.getOwnPropertyNames(obj).forEach(collect);
|
|
9
|
-
Object.getOwnPropertySymbols(obj).forEach(collect);
|
|
10
|
-
}
|
|
11
|
-
function groupBy(collection, iteratee) {
|
|
12
|
-
return collection.reduce((acc, item) => {
|
|
13
|
-
const key = iteratee(item);
|
|
14
|
-
acc[key] || (acc[key] = []);
|
|
15
|
-
acc[key].push(item);
|
|
16
|
-
return acc;
|
|
17
|
-
}, {});
|
|
18
|
-
}
|
|
19
|
-
function isPrimitive(value) {
|
|
20
|
-
return value === null || typeof value !== "function" && typeof value !== "object";
|
|
21
|
-
}
|
|
22
|
-
function getAllMockableProperties(obj, isModule) {
|
|
23
|
-
const allProps = /* @__PURE__ */ new Map();
|
|
24
|
-
let curr = obj;
|
|
25
|
-
do {
|
|
26
|
-
if (isFinalObj(curr))
|
|
27
|
-
break;
|
|
28
|
-
collectOwnProperties(curr, (key) => {
|
|
29
|
-
const descriptor = Object.getOwnPropertyDescriptor(curr, key);
|
|
30
|
-
if (descriptor)
|
|
31
|
-
allProps.set(key, { key, descriptor });
|
|
32
|
-
});
|
|
33
|
-
} while (curr = Object.getPrototypeOf(curr));
|
|
34
|
-
if (isModule && !allProps.has("default") && "default" in obj) {
|
|
35
|
-
const descriptor = Object.getOwnPropertyDescriptor(obj, "default");
|
|
36
|
-
if (descriptor)
|
|
37
|
-
allProps.set("default", { key: "default", descriptor });
|
|
38
|
-
}
|
|
39
|
-
return Array.from(allProps.values());
|
|
40
|
-
}
|
|
41
|
-
function slash(str) {
|
|
42
|
-
return str.replace(/\\/g, "/");
|
|
43
|
-
}
|
|
44
|
-
function noop() {
|
|
45
|
-
}
|
|
46
|
-
function toArray(array) {
|
|
47
|
-
if (array === null || array === void 0)
|
|
48
|
-
array = [];
|
|
49
|
-
if (Array.isArray(array))
|
|
50
|
-
return array;
|
|
51
|
-
return [array];
|
|
52
|
-
}
|
|
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
|
-
}
|
|
59
|
-
function deepMerge(target, ...sources) {
|
|
60
|
-
if (!sources.length)
|
|
61
|
-
return target;
|
|
62
|
-
const source = sources.shift();
|
|
63
|
-
if (source === void 0)
|
|
64
|
-
return target;
|
|
65
|
-
if (isMergeableObject(target) && isMergeableObject(source)) {
|
|
66
|
-
Object.keys(source).forEach((key) => {
|
|
67
|
-
if (isMergeableObject(source[key])) {
|
|
68
|
-
if (!target[key])
|
|
69
|
-
target[key] = {};
|
|
70
|
-
deepMerge(target[key], source[key]);
|
|
71
|
-
} else {
|
|
72
|
-
target[key] = source[key];
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
return deepMerge(target, ...sources);
|
|
77
|
-
}
|
|
78
|
-
function isMergeableObject(item) {
|
|
79
|
-
return isPlainObject(item) && !Array.isArray(item);
|
|
80
|
-
}
|
|
81
|
-
function stdout() {
|
|
82
|
-
return console._stdout || process.stdout;
|
|
83
|
-
}
|
|
84
|
-
function getEnvironmentTransformMode(config, environment) {
|
|
85
|
-
var _a, _b, _c, _d, _e, _f;
|
|
86
|
-
if (!((_c = (_b = (_a = config.deps) == null ? void 0 : _a.experimentalOptimizer) == null ? void 0 : _b.ssr) == null ? void 0 : _c.enabled) && !((_f = (_e = (_d = config.deps) == null ? void 0 : _d.experimentalOptimizer) == null ? void 0 : _e.web) == null ? void 0 : _f.enabled))
|
|
87
|
-
return void 0;
|
|
88
|
-
return environment === "happy-dom" || environment === "jsdom" ? "web" : "ssr";
|
|
89
|
-
}
|
|
90
|
-
class AggregateErrorPonyfill extends Error {
|
|
91
|
-
errors;
|
|
92
|
-
constructor(errors, message = "") {
|
|
93
|
-
super(message);
|
|
94
|
-
this.errors = [...errors];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const DEFAULT_TIMEOUT = 6e4;
|
|
99
|
-
function defaultSerialize(i) {
|
|
100
|
-
return i;
|
|
101
|
-
}
|
|
102
|
-
const defaultDeserialize = defaultSerialize;
|
|
103
|
-
const { setTimeout } = globalThis;
|
|
104
|
-
const random = Math.random.bind(Math);
|
|
105
|
-
function createBirpc(functions, options) {
|
|
106
|
-
const {
|
|
107
|
-
post,
|
|
108
|
-
on,
|
|
109
|
-
eventNames = [],
|
|
110
|
-
serialize = defaultSerialize,
|
|
111
|
-
deserialize = defaultDeserialize,
|
|
112
|
-
resolver,
|
|
113
|
-
timeout = DEFAULT_TIMEOUT
|
|
114
|
-
} = options;
|
|
115
|
-
const rpcPromiseMap = /* @__PURE__ */ new Map();
|
|
116
|
-
let _promise;
|
|
117
|
-
const rpc = new Proxy({}, {
|
|
118
|
-
get(_, method) {
|
|
119
|
-
if (method === "$functions")
|
|
120
|
-
return functions;
|
|
121
|
-
const sendEvent = (...args) => {
|
|
122
|
-
post(serialize({ m: method, a: args, t: "q" }));
|
|
123
|
-
};
|
|
124
|
-
if (eventNames.includes(method)) {
|
|
125
|
-
sendEvent.asEvent = sendEvent;
|
|
126
|
-
return sendEvent;
|
|
127
|
-
}
|
|
128
|
-
const sendCall = async (...args) => {
|
|
129
|
-
await _promise;
|
|
130
|
-
return new Promise((resolve, reject) => {
|
|
131
|
-
const id = nanoid();
|
|
132
|
-
rpcPromiseMap.set(id, { resolve, reject });
|
|
133
|
-
post(serialize({ m: method, a: args, i: id, t: "q" }));
|
|
134
|
-
if (timeout >= 0) {
|
|
135
|
-
setTimeout(() => {
|
|
136
|
-
reject(new Error(`[birpc] timeout on calling "${method}"`));
|
|
137
|
-
rpcPromiseMap.delete(id);
|
|
138
|
-
}, timeout);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
};
|
|
142
|
-
sendCall.asEvent = sendEvent;
|
|
143
|
-
return sendCall;
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
_promise = on(async (data, ...extra) => {
|
|
147
|
-
const msg = deserialize(data);
|
|
148
|
-
if (msg.t === "q") {
|
|
149
|
-
const { m: method, a: args } = msg;
|
|
150
|
-
let result, error;
|
|
151
|
-
const fn = resolver ? resolver(method, functions[method]) : functions[method];
|
|
152
|
-
if (!fn) {
|
|
153
|
-
error = new Error(`[birpc] function "${method}" not found`);
|
|
154
|
-
} else {
|
|
155
|
-
try {
|
|
156
|
-
result = await fn.apply(rpc, args);
|
|
157
|
-
} catch (e) {
|
|
158
|
-
error = e;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (msg.i) {
|
|
162
|
-
if (error && options.onError)
|
|
163
|
-
options.onError(error, method, args);
|
|
164
|
-
post(serialize({ t: "s", i: msg.i, r: result, e: error }), ...extra);
|
|
165
|
-
}
|
|
166
|
-
} else {
|
|
167
|
-
const { i: ack, r: result, e: error } = msg;
|
|
168
|
-
const promise = rpcPromiseMap.get(ack);
|
|
169
|
-
if (promise) {
|
|
170
|
-
if (error)
|
|
171
|
-
promise.reject(error);
|
|
172
|
-
else
|
|
173
|
-
promise.resolve(result);
|
|
174
|
-
}
|
|
175
|
-
rpcPromiseMap.delete(ack);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
return rpc;
|
|
179
|
-
}
|
|
180
|
-
const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
181
|
-
function nanoid(size = 21) {
|
|
182
|
-
let id = "";
|
|
183
|
-
let i = size;
|
|
184
|
-
while (i--)
|
|
185
|
-
id += urlAlphabet[random() * 64 | 0];
|
|
186
|
-
return id;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export { AggregateErrorPonyfill as A, groupBy as a, getEnvironmentTransformMode as b, createBirpc as c, deepMerge as d, stdout as e, getAllMockableProperties as g, isPrimitive as i, noop as n, slash as s, toArray as t };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { getNames, getTests } from '@vitest/runner/utils';
|
|
2
|
-
import '@vitest/utils';
|
|
3
|
-
|
|
4
|
-
function hasFailedSnapshot(suite) {
|
|
5
|
-
return getTests(suite).some((s) => {
|
|
6
|
-
var _a, _b;
|
|
7
|
-
return (_b = (_a = s.result) == null ? void 0 : _a.errors) == null ? void 0 : _b.some((e) => typeof (e == null ? void 0 : e.message) === "string" && e.message.match(/Snapshot .* mismatched/));
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
function getFullName(task, separator = " > ") {
|
|
11
|
-
return getNames(task).join(separator);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { getFullName as g, hasFailedSnapshot as h };
|