|
1 | 1 | import { existsSync, readdirSync } from 'node:fs'
|
2 | 2 | import vm from 'node:vm'
|
3 |
| -import { basename, dirname, extname, isAbsolute, join, relative, resolve } from 'pathe' |
| 3 | +import { basename, dirname, extname, isAbsolute, join, resolve } from 'pathe' |
4 | 4 | import { getType, highlight } from '@vitest/utils'
|
5 | 5 | import { isNodeBuiltin } from 'vite-node/utils'
|
6 | 6 | import { distDir } from '../paths'
|
@@ -168,7 +168,7 @@ export class VitestMocker {
|
168 | 168 | if (mock.type === 'unmock')
|
169 | 169 | this.unmockPath(fsPath)
|
170 | 170 | if (mock.type === 'mock')
|
171 |
| - this.mockPath(mock.id, fsPath, external, mock.factory, mock.throwIfCached) |
| 171 | + this.mockPath(mock.id, fsPath, external, mock.factory) |
172 | 172 | }))
|
173 | 173 |
|
174 | 174 | VitestMocker.pendingIds = []
|
@@ -408,19 +408,19 @@ export class VitestMocker {
|
408 | 408 | this.deleteCachedItem(id)
|
409 | 409 | }
|
410 | 410 |
|
411 |
| - public mockPath(originalId: string, path: string, external: string | null, factory: MockFactory | undefined, throwIfExists: boolean) { |
| 411 | + public mockPath(originalId: string, path: string, external: string | null, factory: MockFactory | undefined) { |
412 | 412 | const id = this.normalizePath(path)
|
413 | 413 |
|
414 |
| - const { config } = this.executor.state |
415 |
| - const isIsolatedThreads = config.pool === 'threads' && (config.poolOptions?.threads?.isolate ?? true) |
416 |
| - const isIsolatedForks = config.pool === 'forks' && (config.poolOptions?.forks?.isolate ?? true) |
| 414 | + // const { config } = this.executor.state |
| 415 | + // const isIsolatedThreads = config.pool === 'threads' && (config.poolOptions?.threads?.isolate ?? true) |
| 416 | + // const isIsolatedForks = config.pool === 'forks' && (config.poolOptions?.forks?.isolate ?? true) |
417 | 417 |
|
418 | 418 | // TODO: find a good way to throw this error even in non-isolated mode
|
419 |
| - if (throwIfExists && (isIsolatedThreads || isIsolatedForks || config.pool === 'vmThreads')) { |
420 |
| - const cached = this.moduleCache.has(id) && this.moduleCache.getByModuleId(id) |
421 |
| - if (cached && cached.importers.size) |
422 |
| - 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`) |
423 |
| - } |
| 419 | + // if (throwIfExists && (isIsolatedThreads || isIsolatedForks || config.pool === 'vmThreads')) { |
| 420 | + // const cached = this.moduleCache.has(id) && this.moduleCache.getByModuleId(id) |
| 421 | + // if (cached && cached.importers.size) |
| 422 | + // 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`) |
| 423 | + // } |
424 | 424 |
|
425 | 425 | const suitefile = this.getSuiteFilepath()
|
426 | 426 | const mocks = this.mockMap.get(suitefile) || {}
|
|
0 commit comments