| 45 | |
| 46 | let gcFunc: (() => void) | undefined = (globalThis as any).gc; |
| 47 | function runGC() { |
| 48 | if (!gcFunc) { |
| 49 | v8.setFlagsFromString('--expose-gc'); |
| 50 | gcFunc = vm.runInNewContext('gc'); |
| 51 | v8.setFlagsFromString('--no-expose-gc'); |
| 52 | if (!gcFunc) { |
| 53 | throw new Error( |
| 54 | 'Cannot find `global.gc` function. Please run node with `--expose-gc` and report this issue in jest repo.', |
| 55 | ); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | gcFunc(); |
| 60 | } |
| 61 | |
| 62 | // Inspired by https://github.com/mafintosh/why-is-node-running/blob/master/index.js |
| 63 | // Extracted as we want to format the result ourselves |