(
localModule: InitialModule,
options: TransformOptions | undefined,
moduleRegistry: ModuleRegistry,
from: string | null,
moduleName: string | undefined,
)
| 88 | } |
| 89 | |
| 90 | exec( |
| 91 | localModule: InitialModule, |
| 92 | options: TransformOptions | undefined, |
| 93 | moduleRegistry: ModuleRegistry, |
| 94 | from: string | null, |
| 95 | moduleName: string | undefined, |
| 96 | ): ExecResult { |
| 97 | if (!this.environment.global) { |
| 98 | return 'env-disposed'; |
| 99 | } |
| 100 | |
| 101 | const module = localModule as Module; |
| 102 | |
| 103 | const filename = module.filename; |
| 104 | const origCurrExecutingManualMock = this.currentlyExecutingManualMock; |
| 105 | this.currentlyExecutingManualMock = filename; |
| 106 | |
| 107 | try { |
| 108 | module.children = []; |
| 109 | |
| 110 | Object.defineProperty(module, 'parent', { |
| 111 | enumerable: true, |
| 112 | get() { |
| 113 | const key = from || ''; |
| 114 | return moduleRegistry.get(key) || null; |
| 115 | }, |
| 116 | }); |
| 117 | const modulePaths = this.resolution.getModulePaths(module.path); |
| 118 | const globalPaths = this.resolution.getGlobalPaths(moduleName); |
| 119 | module.paths = [...modulePaths, ...globalPaths]; |
| 120 | |
| 121 | Object.defineProperty(module, 'require', { |
| 122 | value: this.requireBuilder.for(localModule, options), |
| 123 | }); |
| 124 | |
| 125 | const transformedCode = this.transformCache.transform(filename, options); |
| 126 | |
| 127 | const compiledFunction = this.compile(transformedCode, filename); |
| 128 | if (compiledFunction === null) { |
| 129 | return 'env-disposed'; |
| 130 | } |
| 131 | |
| 132 | const jestObject = this.jestGlobals.jestObjectFor(filename); |
| 133 | |
| 134 | const lastArgs: [Jest | undefined, ...Array<Global.Global>] = [ |
| 135 | this.config.injectGlobals ? jestObject : undefined, |
| 136 | ...this.config.sandboxInjectedGlobals.map<Global.Global>( |
| 137 | globalVariable => { |
| 138 | if (this.environment.global[globalVariable]) { |
| 139 | return this.environment.global[globalVariable]; |
| 140 | } |
| 141 | |
| 142 | throw new Error( |
| 143 | `You have requested '${globalVariable}' as a global variable, but it was not present. Please check your config or your global environment.`, |
| 144 | ); |
| 145 | }, |
| 146 | ), |
| 147 | ]; |
no test coverage detected