Skip to content

Commit

Permalink
chore: throw mocker error if pool is vmThreads
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jan 9, 2024
1 parent ca62f37 commit 743795e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vitest/src/runtime/mocker.ts
Expand Up @@ -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`)
Expand Down

0 comments on commit 743795e

Please sign in to comment.