()
| 50 | let MAX = 20; |
| 51 | |
| 52 | export function initDevModeChecks() { |
| 53 | misbehavingPromises = new Set<Promise<any>>(); |
| 54 | |
| 55 | try { |
| 56 | // eslint-disable-next-line @typescript-eslint/no-var-requires |
| 57 | require('mocha').afterAll?.(() => { |
| 58 | collectGarbage(); |
| 59 | console.log("showing!"); |
| 60 | showActiveHandles(); |
| 61 | }); |
| 62 | } catch { |
| 63 | // ignore |
| 64 | console.log('oops'); |
| 65 | } |
| 66 | |
| 67 | process.on('unhandledRejection', (reason: any, p) => { |
| 68 | |
| 69 | console.log(`Unhandled Rejection at: Promise ${p} - reason:, ${(reason as any)?.stack ?? reason}`); |
| 70 | }); |
| 71 | |
| 72 | process.on('multipleResolves', (type, promise, reason) => { |
| 73 | if (misbehavingPromises.has(promise)) { |
| 74 | return; |
| 75 | } |
| 76 | if (reason && (reason as any).stack) { |
| 77 | console.error((reason as any).stack); |
| 78 | return; |
| 79 | } |
| 80 | if (!MAX--) { |
| 81 | throw new Error('MAX MULTIPLE RESOLVED REACHED'); |
| 82 | } |
| 83 | console.error({text: 'Multiple Resolves', type, promise, reason}); |
| 84 | }); |
| 85 | |
| 86 | process.on('exit', showActiveHandles); |
| 87 | } |
| 88 | |
| 89 | initDevModeChecks(); |
no test coverage detected