From 743795eb40f5645e8c5135e0a1e82debc82eb6ed Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Tue, 9 Jan 2024 16:41:25 +0100 Subject: [PATCH] chore: throw mocker error if pool is vmThreads --- packages/vitest/src/runtime/mocker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vitest/src/runtime/mocker.ts b/packages/vitest/src/runtime/mocker.ts index f1c912736fa7..7608b76e9806 100644 --- a/packages/vitest/src/runtime/mocker.ts +++ b/packages/vitest/src/runtime/mocker.ts @@ -415,7 +415,7 @@ export class VitestMocker { const isIsolatedForks = config.pool === 'forks' && (config.poolOptions?.forks?.isolate ?? true) // TODO: find a good way to throw this error even in non-isolated mode - if (throwIfExists && (isIsolatedThreads || isIsolatedForks)) { + if (throwIfExists && (isIsolatedThreads || isIsolatedForks || config.pool === 'vmThreads')) { const cached = this.moduleCache.has(id) && this.moduleCache.getByModuleId(id) if (cached && cached.importers.size) throw new Error(`[vitest] Cannot mock "${originalId}" because it is already loaded by "${[...cached.importers.values()].map(i => relative(this.root, i)).join('", "')}".\n\nPlease, remove the import if you want static imports to be mocked, or clear module cache by calling "vi.resetModules()" before mocking if you are going to import the file again. See: https://vitest.dev/guide/common-errors.html#cannot-mock-mocked-file-js-because-it-is-already-loaded`)