Inspired by @Telokis comment in jest/issues/6399.
Fixes leaks in:
- graceful-fs
- agent-base (puppeteer dep)
PRs are welcome.
yarn add --dev jest-leak-fixer
package.json
{
...
"scripts": {
...
"test": "jest-fixer-apply && yarn test:detect-leaks; test_exit_code=$? && jest-fixer-restore; exit $test_exit_code",
"test:detect-leaks": "jest --detectLeaks",
}
}
globalSetup.js
'use strict'
const jestLeakFixer = require('jest-leak-fixer')
...
module.exports = () => {
jestLeakFixer.apply()
...
}
globalTeardown.js
'use strict'
const jestLeakFixer = require('jest-leak-fixer')
...
module.exports = () => {
...
jestLeakFixer.restore()
}