vitest 5.0.5 → 5.1.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 +1 -1
- package/dist/browser.d.ts +6 -5
- package/dist/browser.js +6 -6
- package/dist/chunks/{base.CzXt2BO_.js → base.Cof-UHJf.js} +17 -21
- package/dist/chunks/{browser.d.FGQ9_rK6.d.ts → browser.d.C7tWgUvw.d.ts} +4 -3
- package/dist/chunks/{cac.CLrZKo1g.js → cac.BYbt0aJp.js} +30 -16
- package/dist/chunks/{cli-api.De07GUeT.js → cli-api.COfZo8lK.js} +5226 -4385
- package/dist/chunks/{config.d.QBNYCgFU.d.ts → config.d.B3YV4t0O.d.ts} +169 -93
- package/dist/chunks/{console.DtI4yxfN.js → console.CQZ877Hi.js} +6 -3
- package/dist/chunks/{constants.-juJ8b_4.js → constants.DLYM6cZY.js} +1 -1
- package/dist/chunks/{coverage.-bm5IxnW.js → coverage.9iqXE2gN.js} +1 -1
- package/dist/chunks/{coverage.cTDc4uSS.js → coverage.jGCktcGP.js} +1 -1
- package/dist/chunks/{creator.C5g4egeG.js → creator.DHWmytIK.js} +11 -11
- package/dist/chunks/{doctor.BK86Cncq.js → doctor.B-oPbwps.js} +2 -2
- package/dist/chunks/{environment.d.BY56MoGs.d.ts → environment.d.BFQtFKdZ.d.ts} +1 -1
- package/dist/chunks/{globals.CXEE6_2C.js → globals.ZKtKSkEf.js} +7 -6
- package/dist/chunks/{index.CK-t0WMg.js → index.Bi0NXYPf.js} +165 -62
- package/dist/chunks/{index.aTZaPVhf.js → index.CZzC1gGg.js} +299 -440
- package/dist/chunks/{index.1TqnEahn.js → index.Di8au7q4.js} +104 -72
- package/dist/chunks/{index.CoUIxZd4.js → index.w_oBZ9N8.js} +5 -5
- package/dist/chunks/{init-forks.CRxIPOJR.js → init-forks.BaDXQSD8.js} +1 -1
- package/dist/chunks/{init-threads.Dv3kwST_.js → init-threads.ZX_Vov0z.js} +1 -1
- package/dist/chunks/{init.PvxYpuCm.js → init.CO4AB7HZ.js} +4 -4
- package/dist/chunks/{module-dependencies.CwNPkcV4.js → module-dependencies._2Eei3FO.js} +1 -1
- package/dist/chunks/{native.cdzHIdmv.js → native.upB-V0CK.js} +1 -1
- package/dist/chunks/{nativeModuleMocker.BxrHJNAF.js → nativeModuleMocker.Dh5azSB4.js} +4 -3
- package/dist/chunks/{nativeModuleRunner.xi64Afb2.js → nativeModuleRunner.9xPIMzi7.js} +1 -1
- package/dist/chunks/{node.uQulW0ei.js → node.B9mkVmLH.js} +1 -1
- package/dist/chunks/{pathe.M-eThtNZ.Ba-7h1rE.js → pathe.M-eThtNZ.zq3TM4NT.js} +1 -1
- package/dist/chunks/{plugin.d.C8mmycim.d.ts → plugin.d.LRFSN46m.d.ts} +191 -32
- package/dist/chunks/rawSnapshot.DqSiqIEx.js +356 -0
- package/dist/chunks/{resolver.CtCcxIy1.js → resolver.BzpmeQeT.js} +1 -1
- package/dist/chunks/{rpc.DpkUyY1N.js → rpc.Uhkwr2NM.js} +2 -2
- package/dist/chunks/{rpc.d.Cft1biqy.d.ts → rpc.d.3FOhdFx8.d.ts} +1 -1
- package/dist/chunks/{run.BPv-BBRv.js → run.CjdgFZiW.js} +28 -7
- package/dist/chunks/{setup-common.HGAqWOnX.js → setup-common.CqAQCXzx.js} +2 -2
- package/dist/chunks/{source-map.DdKI5IHB.js → source-map.DakdQc29.js} +43 -37
- package/dist/chunks/{source-map.d.kzFtk_dj.d.ts → source-map.d.BkG8YK_3.d.ts} +2 -1
- package/dist/chunks/{task-utils.d.PFh2BV6Q.d.ts → task-utils.d.D-gFPNFi.d.ts} +2 -1
- package/dist/chunks/{utils.DSfl_w8V.js → utils.BBk_icFG.js} +6 -3
- package/dist/chunks/{vm.FGl2rw_t.js → vm.b4MbCAJQ.js} +27 -14
- package/dist/chunks/{worker.d.BH-r1bPu.d.ts → worker.d.CyJRpyfZ.d.ts} +3 -3
- package/dist/cli.js +3 -3
- package/dist/config.cjs +1 -1
- package/dist/config.d.ts +11 -11
- package/dist/config.js +1 -1
- package/dist/index.d.ts +21 -15
- package/dist/index.js +6 -5
- package/dist/module-evaluator.d.ts +3 -2
- package/dist/node.d.ts +30 -12
- package/dist/node.js +16 -14
- package/dist/runtime.d.ts +4 -4
- package/dist/runtime.js +5 -4
- package/dist/task-utils.js +10 -4
- package/dist/worker.d.ts +4 -4
- package/dist/worker.js +14 -13
- package/dist/workers/forks.js +15 -14
- package/dist/workers/runVmTests.js +16 -12
- package/dist/workers/threads.js +15 -14
- package/dist/workers/vmForks.js +11 -10
- package/dist/workers/vmThreads.js +11 -10
- package/package.json +17 -17
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import fs__default from 'node:fs';
|
|
2
|
-
import { n as normalize,
|
|
2
|
+
import { n as normalize, m as splitFileAndPostfix$1, j as join, o as isBareImport } from './pathe.M-eThtNZ.zq3TM4NT.js';
|
|
3
3
|
import { i as isBuiltin, a as isBrowserExternal, t as toBuiltin } from './modules.BJuCwlRJ.js';
|
|
4
4
|
import { E as EnvironmentTeardownError, a as getSafeWorkerState } from './utils.DYj33du9.js';
|
|
5
5
|
import { pathToFileURL, URL as URL$1 } from 'node:url';
|
|
6
6
|
import { distDir } from '../path.js';
|
|
7
7
|
import { VitestModuleEvaluator, unwrapId } from '../module-evaluator.js';
|
|
8
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
8
9
|
import { isAbsolute, resolve } from 'node:path';
|
|
9
10
|
import vm from 'node:vm';
|
|
10
11
|
import { MockerRegistry, mockObject, RedirectedModule, AutomockedModule } from '@vitest/mocker';
|
|
@@ -104,10 +105,20 @@ class BareModuleMocker {
|
|
|
104
105
|
};
|
|
105
106
|
});
|
|
106
107
|
}
|
|
108
|
+
registeringMocks;
|
|
107
109
|
async resolveMocks() {
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
if (BareModuleMocker.pendingIds.length) {
|
|
111
|
+
const pendingIds = BareModuleMocker.pendingIds;
|
|
112
|
+
BareModuleMocker.pendingIds = [];
|
|
113
|
+
const registration = this.registerMocks(pendingIds, this.registeringMocks).finally(() => {
|
|
114
|
+
if (this.registeringMocks === registration) this.registeringMocks = void 0;
|
|
115
|
+
});
|
|
116
|
+
this.registeringMocks = registration;
|
|
117
|
+
}
|
|
118
|
+
await this.registeringMocks;
|
|
119
|
+
}
|
|
120
|
+
async registerMocks(pendingIds, previous) {
|
|
121
|
+
await previous?.catch(() => {});
|
|
111
122
|
const resolveMock = async (mock) => {
|
|
112
123
|
return {
|
|
113
124
|
mock,
|
|
@@ -142,8 +153,8 @@ class BareModuleMocker {
|
|
|
142
153
|
getDependencyMockByUrl(url) {
|
|
143
154
|
return this.getMockerRegistry().get(url);
|
|
144
155
|
}
|
|
145
|
-
findMockRedirect(mockPath, external) {
|
|
146
|
-
return findMockRedirect(this.root, mockPath, external);
|
|
156
|
+
findMockRedirect(mockPath, external, rawId) {
|
|
157
|
+
return findMockRedirect(this.root, mockPath, external, rawId);
|
|
147
158
|
}
|
|
148
159
|
mockObject(object, mockExportsOrModuleType, moduleType) {
|
|
149
160
|
let mockExports;
|
|
@@ -169,7 +180,7 @@ class BareModuleMocker {
|
|
|
169
180
|
if (mockType === "manual") registry.register("manual", originalId, id, url, factory);
|
|
170
181
|
else if (mockType === "autospy") registry.register("autospy", originalId, id, url);
|
|
171
182
|
else {
|
|
172
|
-
const redirect = this.findMockRedirect(id, external);
|
|
183
|
+
const redirect = this.findMockRedirect(id, external, originalId);
|
|
173
184
|
if (redirect) registry.register("redirect", originalId, id, url, redirect);
|
|
174
185
|
else registry.register("automock", originalId, id, url);
|
|
175
186
|
}
|
|
@@ -275,6 +286,10 @@ class VitestMocker extends BareModuleMocker {
|
|
|
275
286
|
moduleRunner;
|
|
276
287
|
options;
|
|
277
288
|
filterPublicKeys;
|
|
289
|
+
// factories that run in the current async context, the innermost is last
|
|
290
|
+
factoryContexts = new AsyncLocalStorage();
|
|
291
|
+
pendingFactories = /* @__PURE__ */ new Map();
|
|
292
|
+
waitListeners = /* @__PURE__ */ new Set();
|
|
278
293
|
constructor(moduleRunner, options) {
|
|
279
294
|
super(options);
|
|
280
295
|
this.moduleRunner = moduleRunner;
|
|
@@ -308,12 +323,69 @@ class VitestMocker extends BareModuleMocker {
|
|
|
308
323
|
}
|
|
309
324
|
invalidateModuleById(id) {
|
|
310
325
|
const mockId = this.getMockPath(id);
|
|
326
|
+
this.pendingFactories.delete(mockId);
|
|
311
327
|
const node = this.evaluatedModules.getModuleById(mockId);
|
|
312
328
|
if (node) {
|
|
313
329
|
this.evaluatedModules.invalidateModule(node);
|
|
314
330
|
node.mockedExports = void 0;
|
|
315
331
|
}
|
|
316
332
|
}
|
|
333
|
+
getMockContext() {
|
|
334
|
+
return { callstack: (this.factoryContexts.getStore()?.findLast((context) => this.pendingFactories.has(context.mockId)))?.callstack ?? null };
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Whether the factory of this mock runs in the current async context,
|
|
338
|
+
* or waits for a factory that runs in it. Such imports get the original module.
|
|
339
|
+
* The callstack cannot tell it: all imports from one module share the same array.
|
|
340
|
+
*/
|
|
341
|
+
isResolvingMock(mockId) {
|
|
342
|
+
if (!this.pendingFactories.has(mockId)) return false;
|
|
343
|
+
const factories = this.currentFactories();
|
|
344
|
+
return factories.includes(mockId) || this.waitsForFactories(mockId, factories);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Whether the module is still evaluating and waits for a factory
|
|
348
|
+
* that runs in the current async context.
|
|
349
|
+
*/
|
|
350
|
+
isWaitingForFactory(mod) {
|
|
351
|
+
return !!mod.promise && !mod.evaluated && this.waitsForFactories(mod.id);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Waits for the module evaluation. If the module starts to wait
|
|
355
|
+
* for a factory that waits for it, the factory gets the partial exports.
|
|
356
|
+
*/
|
|
357
|
+
awaitEvaluation(mod, request) {
|
|
358
|
+
if (!mod.promise || mod.evaluated) return request();
|
|
359
|
+
const factories = this.currentFactories();
|
|
360
|
+
if (!factories.length) return request();
|
|
361
|
+
let onWait;
|
|
362
|
+
const cycle = new Promise((resolve) => {
|
|
363
|
+
onWait = () => {
|
|
364
|
+
if (this.waitsForFactories(mod.id, factories)) resolve(mod.exports);
|
|
365
|
+
};
|
|
366
|
+
});
|
|
367
|
+
this.waitListeners.add(onWait);
|
|
368
|
+
return Promise.race([request(), cycle]).finally(() => this.waitListeners.delete(onWait));
|
|
369
|
+
}
|
|
370
|
+
currentFactories() {
|
|
371
|
+
return (this.factoryContexts.getStore() ?? []).map((context) => context.mockId);
|
|
372
|
+
}
|
|
373
|
+
waitsForFactories(id, factories = this.currentFactories()) {
|
|
374
|
+
const queue = [...factories];
|
|
375
|
+
const visited = new Set(factories);
|
|
376
|
+
// a factory that waits for the current one makes everything that waits for it wait too
|
|
377
|
+
while (queue.length) {
|
|
378
|
+
const waiting = this.pendingFactories.get(queue.pop())?.waiting;
|
|
379
|
+
if (waiting?.has(id)) return true;
|
|
380
|
+
waiting?.forEach((waiter) => {
|
|
381
|
+
if (this.pendingFactories.has(waiter) && !visited.has(waiter)) {
|
|
382
|
+
visited.add(waiter);
|
|
383
|
+
queue.push(waiter);
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
317
389
|
ensureModule(id, url) {
|
|
318
390
|
const node = this.evaluatedModules.ensureModule(id, url);
|
|
319
391
|
// TODO
|
|
@@ -326,9 +398,54 @@ class VitestMocker extends BareModuleMocker {
|
|
|
326
398
|
};
|
|
327
399
|
return node;
|
|
328
400
|
}
|
|
329
|
-
|
|
401
|
+
callFunctionMock(id, url, mock, callstack) {
|
|
330
402
|
const node = this.ensureModule(id, url);
|
|
331
|
-
if (node.exports) return node.exports;
|
|
403
|
+
if (node.exports) return Promise.resolve(node.exports);
|
|
404
|
+
return this.resolveMockOnce(id, callstack, () => this.resolveFunctionMock(node, mock));
|
|
405
|
+
}
|
|
406
|
+
resolveMockOnce(id, callstack, resolve) {
|
|
407
|
+
const contexts = this.factoryContexts.getStore() ?? [];
|
|
408
|
+
const waiting = [...callstack, ...contexts.map((context) => context.mockId)];
|
|
409
|
+
const pending = this.pendingFactories.get(id);
|
|
410
|
+
if (pending) {
|
|
411
|
+
waiting.forEach((waiter) => pending.waiting.add(waiter));
|
|
412
|
+
this.waitListeners.forEach((onWait) => onWait());
|
|
413
|
+
return pending.promise;
|
|
414
|
+
}
|
|
415
|
+
const factory = {
|
|
416
|
+
promise: this.factoryContexts.run([...contexts, {
|
|
417
|
+
mockId: id,
|
|
418
|
+
callstack
|
|
419
|
+
}], resolve).finally(() => {
|
|
420
|
+
if (this.pendingFactories.get(id) === factory) this.pendingFactories.delete(id);
|
|
421
|
+
if (!this.pendingFactories.size)
|
|
422
|
+
// an enabled storage slows down every promise on Node 22
|
|
423
|
+
this.factoryContexts.disable();
|
|
424
|
+
}),
|
|
425
|
+
waiting: new Set(waiting)
|
|
426
|
+
};
|
|
427
|
+
this.pendingFactories.set(id, factory);
|
|
428
|
+
return factory.promise;
|
|
429
|
+
}
|
|
430
|
+
async resolveAutomock(url, mockId, evaluatedNode, callstack, type) {
|
|
431
|
+
const Object = this.primitives.Object;
|
|
432
|
+
// we have to define a separate object that will copy all properties into itself
|
|
433
|
+
// and can't just use the same `exports` define automatically by Vite before the evaluator
|
|
434
|
+
const exports = Object.create(null);
|
|
435
|
+
Object.defineProperty(exports, Symbol.toStringTag, {
|
|
436
|
+
value: "Module",
|
|
437
|
+
configurable: true,
|
|
438
|
+
writable: true
|
|
439
|
+
});
|
|
440
|
+
const node = this.ensureModule(mockId, this.getMockPath(evaluatedNode.url));
|
|
441
|
+
node.meta = evaluatedNode.meta;
|
|
442
|
+
node.file = evaluatedNode.file;
|
|
443
|
+
node.mockedExports = exports;
|
|
444
|
+
const mod = await this.moduleRunner.cachedRequest(url, node, callstack, void 0, true);
|
|
445
|
+
this.mockObject(mod, exports, type);
|
|
446
|
+
return exports;
|
|
447
|
+
}
|
|
448
|
+
async resolveFunctionMock(node, mock) {
|
|
332
449
|
const exports = await mock.resolve();
|
|
333
450
|
const moduleExports = new Proxy(exports, { get: (target, prop) => {
|
|
334
451
|
const val = target[prop];
|
|
@@ -362,7 +479,7 @@ If you need to partially mock a module, you can use "importOriginal" helper insi
|
|
|
362
479
|
const { id, url, external } = await this.resolveId(rawId, importer);
|
|
363
480
|
let mock = this.getDependencyMock(id);
|
|
364
481
|
if (!mock) {
|
|
365
|
-
const redirect = this.findMockRedirect(id, external);
|
|
482
|
+
const redirect = this.findMockRedirect(id, external, rawId);
|
|
366
483
|
if (redirect) mock = new RedirectedModule(rawId, id, rawId, redirect);
|
|
367
484
|
else mock = new AutomockedModule(rawId, id, rawId);
|
|
368
485
|
}
|
|
@@ -372,7 +489,10 @@ If you need to partially mock a module, you can use "importOriginal" helper insi
|
|
|
372
489
|
const Object = this.primitives.Object;
|
|
373
490
|
return this.mockObject(mod, Object.create(Object.prototype), mock.type);
|
|
374
491
|
}
|
|
375
|
-
if (mock.type === "manual")
|
|
492
|
+
if (mock.type === "manual") {
|
|
493
|
+
const mockId = this.getMockPath(id);
|
|
494
|
+
return this.callFunctionMock(mockId, this.getMockPath(url), mock, [importer, mockId]);
|
|
495
|
+
}
|
|
376
496
|
const node = await this.moduleRunner.fetchModule(mock.redirect);
|
|
377
497
|
return this.moduleRunner.cachedRequest(mock.redirect, node, [importer], void 0, true);
|
|
378
498
|
}
|
|
@@ -388,36 +508,14 @@ If you need to partially mock a module, you can use "importOriginal" helper insi
|
|
|
388
508
|
});
|
|
389
509
|
if (mock.type === "automock" || mock.type === "autospy") {
|
|
390
510
|
const cache = this.evaluatedModules.getModuleById(mockId);
|
|
391
|
-
if (cache
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
value: "Module",
|
|
398
|
-
configurable: true,
|
|
399
|
-
writable: true
|
|
400
|
-
});
|
|
401
|
-
const node = this.ensureModule(mockId, this.getMockPath(evaluatedNode.url));
|
|
402
|
-
node.meta = evaluatedNode.meta;
|
|
403
|
-
node.file = evaluatedNode.file;
|
|
404
|
-
node.mockedExports = exports;
|
|
405
|
-
const mod = await this.moduleRunner.cachedRequest(url, node, callstack, void 0, true);
|
|
406
|
-
this.mockObject(mod, exports, mock.type);
|
|
407
|
-
return exports;
|
|
408
|
-
}
|
|
409
|
-
if (mock.type === "manual" && !callstack.includes(mockId) && !callstack.includes(url)) try {
|
|
410
|
-
callstack.push(mockId);
|
|
411
|
-
// this will not work if user does Promise.all(import(), import())
|
|
412
|
-
// we can also use AsyncLocalStorage to store callstack, but this won't work in the browser
|
|
413
|
-
// maybe we should improve mock API in the future?
|
|
414
|
-
this.mockContext.callstack = callstack;
|
|
415
|
-
return await this.callFunctionMock(mockId, this.getMockPath(url), mock);
|
|
416
|
-
} finally {
|
|
417
|
-
this.mockContext.callstack = null;
|
|
418
|
-
const indexMock = callstack.indexOf(mockId);
|
|
419
|
-
callstack.splice(indexMock, 1);
|
|
511
|
+
if (cache?.mockedExports) {
|
|
512
|
+
// while the original module evaluates, only its own imports get the partial object, like in a cycle
|
|
513
|
+
const isSelfImport = callstack.includes(evaluatedNode.id) || this.isResolvingMock(mockId);
|
|
514
|
+
if (!this.pendingFactories.has(mockId) || isSelfImport) return cache.mockedExports;
|
|
515
|
+
}
|
|
516
|
+
return this.resolveMockOnce(mockId, [...callstack, mockId], () => this.resolveAutomock(url, mockId, evaluatedNode, callstack, mock.type));
|
|
420
517
|
}
|
|
518
|
+
if (mock.type === "manual" && !callstack.includes(mockId) && !callstack.includes(url) && !this.isResolvingMock(mockId)) return this.callFunctionMock(mockId, this.getMockPath(url), mock, [...callstack, mockId]);
|
|
421
519
|
else if (mock.type === "redirect" && !callstack.includes(mock.redirect)) {
|
|
422
520
|
span.setAttribute("vitest.mock.redirect", mock.redirect);
|
|
423
521
|
return mock.redirect;
|
|
@@ -565,8 +663,7 @@ class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
|
|
|
565
663
|
}
|
|
566
664
|
_cachedRequest(url, module, callstack = [], metadata) {
|
|
567
665
|
this.vitestOptions.getWorkerState().dependencies?.add(module.id);
|
|
568
|
-
|
|
569
|
-
return super.cachedRequest(url, module, callstack, metadata);
|
|
666
|
+
return this.mocker.awaitEvaluation(module, () => super.cachedRequest(url, module, callstack, metadata));
|
|
570
667
|
}
|
|
571
668
|
/**
|
|
572
669
|
* @internal
|
|
@@ -574,6 +671,8 @@ class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
|
|
|
574
671
|
async cachedRequest(url, mod, callstack = [], metadata, ignoreMock = false) {
|
|
575
672
|
// Track for a better error message if dynamic import is not resolved properly
|
|
576
673
|
this._callstacks.set(mod, callstack);
|
|
674
|
+
// the factory imports a module that waits for this factory, treat it as a cycle
|
|
675
|
+
if (mod.exports && this.mocker.isWaitingForFactory(mod)) return mod.exports;
|
|
577
676
|
if (ignoreMock) return this._cachedRequest(url, mod, callstack, metadata);
|
|
578
677
|
let mocked;
|
|
579
678
|
if (mod.meta && "mockedModule" in mod.meta) {
|
|
@@ -585,7 +684,7 @@ class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
|
|
|
585
684
|
const node = await this.fetchModule(injectQuery(url, "_vitest_original"));
|
|
586
685
|
return this._cachedRequest(node.url, node, callstack, metadata);
|
|
587
686
|
}
|
|
588
|
-
if (callstack.includes(mockId) || callstack.includes(url) || "redirect" in currentMock && callstack.includes(currentMock.redirect)) {
|
|
687
|
+
if (callstack.includes(mockId) || this.mocker.isResolvingMock(mockId) || callstack.includes(url) || "redirect" in currentMock && callstack.includes(currentMock.redirect)) {
|
|
589
688
|
const node = await this.fetchModule(injectQuery(url, "_vitest_original"));
|
|
590
689
|
return this._cachedRequest(node.url, node, callstack, metadata);
|
|
591
690
|
}
|
|
@@ -697,24 +796,29 @@ function startVitestModuleRunner(options) {
|
|
|
697
796
|
context: options.context,
|
|
698
797
|
externalModulesExecutor: options.externalModulesExecutor
|
|
699
798
|
} : void 0;
|
|
700
|
-
// A fresh worker pays one
|
|
701
|
-
//
|
|
702
|
-
// them
|
|
703
|
-
// disk and
|
|
704
|
-
//
|
|
705
|
-
//
|
|
706
|
-
//
|
|
707
|
-
// scheduled rerun always sees the fresh transform.
|
|
799
|
+
// A fresh worker pays one sequential `fetch` round-trip per module in its
|
|
800
|
+
// test files' import graphs, even when the server has already processed
|
|
801
|
+
// them. So the module runner asks the server once for everything it has on
|
|
802
|
+
// disk for its first run request, and answers those fetches locally. Modules
|
|
803
|
+
// that only later files import are fetched one by one. Keeping the snapshot
|
|
804
|
+
// for the runner's lifetime is safe because a worker doesn't outlive a run,
|
|
805
|
+
// and the scheduled rerun picks up a file edited during a run.
|
|
708
806
|
let warmModules;
|
|
709
|
-
let warmModulesContext;
|
|
710
807
|
function fetchWarmModules() {
|
|
711
|
-
|
|
712
|
-
if (warmModulesContext !== workerState.ctx) {
|
|
713
|
-
warmModulesContext = workerState.ctx;
|
|
714
|
-
warmModules = rpc().fetchWarmModules(environment(), workerState.ctx.files.map((file) => file.filepath)).catch(() => null);
|
|
715
|
-
}
|
|
808
|
+
warmModules ??= rpc().fetchWarmModules(environment(), state().ctx.files.map((file) => file.filepath)).catch(() => null);
|
|
716
809
|
return warmModules;
|
|
717
810
|
}
|
|
811
|
+
// setup files are re-evaluated before every test file, so a reused worker
|
|
812
|
+
// resolves them and their `vi.mock` paths again each time
|
|
813
|
+
const resolvedIds = /* @__PURE__ */ new Map();
|
|
814
|
+
async function resolveId(id, importer) {
|
|
815
|
+
const key = `${environment()}\0${importer ?? ""}\0${id}`;
|
|
816
|
+
if (resolvedIds.has(key)) return resolvedIds.get(key);
|
|
817
|
+
const resolved = rpc().resolve(id, importer, environment());
|
|
818
|
+
resolvedIds.set(key, resolved);
|
|
819
|
+
resolved.then((value) => resolvedIds.set(key, value), () => resolvedIds.delete(key));
|
|
820
|
+
return resolved;
|
|
821
|
+
}
|
|
718
822
|
const evaluator = options.evaluator || new VitestModuleEvaluator(vm, {
|
|
719
823
|
traces,
|
|
720
824
|
metaEnv: state().metaEnv,
|
|
@@ -758,7 +862,7 @@ function startVitestModuleRunner(options) {
|
|
|
758
862
|
const rawId = unwrapId(id);
|
|
759
863
|
resolvingModules.add(rawId);
|
|
760
864
|
try {
|
|
761
|
-
if (VitestMocker.pendingIds.length) await moduleRunner.mocker.resolveMocks();
|
|
865
|
+
if (VitestMocker.pendingIds.length || moduleRunner.mocker.registeringMocks) await moduleRunner.mocker.resolveMocks();
|
|
762
866
|
if (!isImportActual) {
|
|
763
867
|
const resolvedMock = moduleRunner.mocker.getDependencyMockByUrl(id);
|
|
764
868
|
if (resolvedMock?.type === "manual" || resolvedMock?.type === "redirect") return {
|
|
@@ -820,9 +924,7 @@ function startVitestModuleRunner(options) {
|
|
|
820
924
|
resolvingModules.delete(rawId);
|
|
821
925
|
}
|
|
822
926
|
},
|
|
823
|
-
resolveId
|
|
824
|
-
return rpc().resolve(id, importer, environment());
|
|
825
|
-
}
|
|
927
|
+
resolveId
|
|
826
928
|
},
|
|
827
929
|
getWorkerState: state,
|
|
828
930
|
vm,
|
|
@@ -1543,7 +1645,8 @@ var node = {
|
|
|
1543
1645
|
configurable: true,
|
|
1544
1646
|
enumerable: descriptor.enumerable,
|
|
1545
1647
|
value: val,
|
|
1546
|
-
|
|
1648
|
+
// accessor globals like `performance` and `localStorage` (Node 25+) are assignable when they have a setter
|
|
1649
|
+
writable: descriptor.writable === true || typeof descriptor.set === "function"
|
|
1547
1650
|
});
|
|
1548
1651
|
return val;
|
|
1549
1652
|
},
|