(
specifier: string,
referencingIdentifier: string,
context: VMContext,
)
| 1084 | } |
| 1085 | |
| 1086 | private async resolveModule<T = unknown>( |
| 1087 | specifier: string, |
| 1088 | referencingIdentifier: string, |
| 1089 | context: VMContext, |
| 1090 | ): Promise<T> { |
| 1091 | if ( |
| 1092 | this.testState.bailIfTornDown( |
| 1093 | 'You are trying to `import` a file after the Jest environment has been torn down.', |
| 1094 | ) |
| 1095 | ) { |
| 1096 | // @ts-expect-error -- exiting |
| 1097 | return; |
| 1098 | } |
| 1099 | |
| 1100 | const registry = this.registries.getActiveEsmRegistry(); |
| 1101 | |
| 1102 | if (specifier === '@jest/globals') { |
| 1103 | const globalsIdentifier = `@jest/globals/${referencingIdentifier}`; |
| 1104 | const fromCache = registry.get(globalsIdentifier); |
| 1105 | if (fromCache) { |
| 1106 | return fromCache as T; |
| 1107 | } |
| 1108 | const globals = evaluateSyntheticModule( |
| 1109 | this.jestGlobals.esmGlobalsModule(referencingIdentifier, context), |
| 1110 | ); |
| 1111 | registry.set(globalsIdentifier, globals); |
| 1112 | return globals as T; |
| 1113 | } |
| 1114 | |
| 1115 | if (specifier.startsWith('data:')) { |
| 1116 | const dataDecision = await this.mockState.shouldMockEsmAsync( |
| 1117 | referencingIdentifier, |
| 1118 | specifier, |
| 1119 | ); |
| 1120 | if (dataDecision.shouldMock) { |
| 1121 | return this.importMock(specifier, dataDecision.moduleID, context); |
| 1122 | } |
| 1123 | const fromCache = registry.get(specifier); |
| 1124 | if (fromCache) { |
| 1125 | return fromCache as T; |
| 1126 | } |
| 1127 | const {mime, code} = parseDataUri(specifier); |
| 1128 | let module: VMModule; |
| 1129 | if (mime === 'application/wasm') { |
| 1130 | module = await this.importWasmModule( |
| 1131 | new Uint8Array(code as Buffer), |
| 1132 | specifier, |
| 1133 | context, |
| 1134 | ); |
| 1135 | } else if (mime === 'application/json') { |
| 1136 | module = buildJsonSyntheticModule(code as string, specifier, context); |
| 1137 | } else { |
| 1138 | module = new SourceTextModule(code as string, { |
| 1139 | context, |
| 1140 | identifier: specifier, |
| 1141 | importModuleDynamically: this.dynamicImport, |
| 1142 | initializeImportMeta(meta) { |
| 1143 | meta.url = specifier; |
no test coverage detected