| 270 | ) {} |
| 271 | |
| 272 | resolve(): T { |
| 273 | if (this.cache) { |
| 274 | return this.cache |
| 275 | } |
| 276 | let exports: any |
| 277 | try { |
| 278 | exports = this.factory() |
| 279 | } |
| 280 | catch (err: any) { |
| 281 | throw createHelpfulError(err) |
| 282 | } |
| 283 | |
| 284 | if (typeof exports === 'object' && typeof exports?.then === 'function') { |
| 285 | return exports.then( |
| 286 | (result: T) => { |
| 287 | assertValidExports(this.raw, result) |
| 288 | return (this.cache = result) |
| 289 | }, |
| 290 | (error: any) => { |
| 291 | throw createHelpfulError(error) |
| 292 | }, |
| 293 | ) |
| 294 | } |
| 295 | |
| 296 | assertValidExports(this.raw, exports) |
| 297 | |
| 298 | return (this.cache = exports) |
| 299 | } |
| 300 | |
| 301 | static fromJSON(data: ManualMockedModuleSerialized, factory: () => any): ManualMockedModule { |
| 302 | return new ManualMockedModule(data.raw, data.id, data.url, factory) |