(
from: string,
moduleName: string,
moduleID: string,
)
| 420 | } |
| 421 | |
| 422 | private _requireMockWithId<T>( |
| 423 | from: string, |
| 424 | moduleName: string, |
| 425 | moduleID: string, |
| 426 | ): T { |
| 427 | if (this.registries.hasMock(moduleID)) { |
| 428 | return this.registries.getMock(moduleID) as T; |
| 429 | } |
| 430 | |
| 431 | const mockRegistry = this.registries.getActiveMockRegistry(); |
| 432 | |
| 433 | const factory = this.mockState.getCjsFactory(moduleID); |
| 434 | if (factory) { |
| 435 | const module = factory(); |
| 436 | mockRegistry.set(moduleID, module); |
| 437 | return module as T; |
| 438 | } |
| 439 | |
| 440 | const manualMockPath = this._resolution.findManualMock(from, moduleName); |
| 441 | |
| 442 | if (manualMockPath) { |
| 443 | const localModule: InitialModule = { |
| 444 | children: [], |
| 445 | exports: {}, |
| 446 | filename: manualMockPath, |
| 447 | id: manualMockPath, |
| 448 | isPreloading: false, |
| 449 | loaded: false, |
| 450 | path: path.dirname(manualMockPath), |
| 451 | }; |
| 452 | |
| 453 | this.cjsLoader.loadModule( |
| 454 | localModule, |
| 455 | from, |
| 456 | moduleName, |
| 457 | manualMockPath, |
| 458 | undefined, |
| 459 | mockRegistry as ModuleRegistry, |
| 460 | ); |
| 461 | |
| 462 | mockRegistry.set(moduleID, localModule.exports); |
| 463 | } else { |
| 464 | // Look for a real module to generate an automock from |
| 465 | mockRegistry.set(moduleID, this._generateMock(from, moduleName)); |
| 466 | } |
| 467 | |
| 468 | return mockRegistry.get(moduleID) as T; |
| 469 | } |
| 470 | |
| 471 | private _getFullTransformationOptions( |
| 472 | options: TransformOptions = defaultTransformOptions, |
no test coverage detected