(
from: string,
moduleName: string,
moduleID: string,
mode: 'cjs' | 'esm',
)
| 154 | } |
| 155 | |
| 156 | private decideSync( |
| 157 | from: string, |
| 158 | moduleName: string, |
| 159 | moduleID: string, |
| 160 | mode: 'cjs' | 'esm', |
| 161 | ): boolean { |
| 162 | const explicitMap = |
| 163 | mode === 'cjs' ? this.explicitCjsMock : this.explicitEsmMock; |
| 164 | const explicit = explicitMap.get(moduleID); |
| 165 | if (explicit !== undefined) return explicit; |
| 166 | |
| 167 | const key = transitiveCacheKey(from, moduleID); |
| 168 | if ( |
| 169 | !this.shouldAutoMock || |
| 170 | this.resolution.isCoreModule(moduleName) || |
| 171 | this.shouldUnmockTransitiveDepsCache.get(key) |
| 172 | ) { |
| 173 | return false; |
| 174 | } |
| 175 | |
| 176 | const cached = this.shouldMockCache.get(moduleID); |
| 177 | if (cached !== undefined) return cached; |
| 178 | |
| 179 | let modulePath: string; |
| 180 | try { |
| 181 | modulePath = |
| 182 | mode === 'cjs' |
| 183 | ? this.resolution.resolveCjs(from, moduleName) |
| 184 | : this.resolution.resolveEsm(from, moduleName); |
| 185 | } catch (error) { |
| 186 | const manualMock = |
| 187 | mode === 'cjs' |
| 188 | ? this.resolution.getCjsMockModule(from, moduleName) |
| 189 | : this.resolution.getEsmMockModule(from, moduleName); |
| 190 | if (manualMock) { |
| 191 | this.shouldMockCache.set(moduleID, true); |
| 192 | return true; |
| 193 | } |
| 194 | throw error; |
| 195 | } |
| 196 | |
| 197 | if (this.unmockList?.test(modulePath)) { |
| 198 | this.shouldMockCache.set(moduleID, false); |
| 199 | return false; |
| 200 | } |
| 201 | |
| 202 | const currentModuleID = |
| 203 | mode === 'cjs' |
| 204 | ? this.resolution.getCjsModuleId(this.virtualCjsMocks, from) |
| 205 | : this.resolution.getEsmModuleId(this.virtualEsmMocks, from); |
| 206 | |
| 207 | return this.applyTransitive( |
| 208 | moduleID, |
| 209 | currentModuleID, |
| 210 | modulePath, |
| 211 | from, |
| 212 | key, |
| 213 | explicitMap, |
no test coverage detected