Skip to content

Commit

Permalink
fix(leak-detector): wait more ticks for GC to run (#10366)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Aug 5, 2020
1 parent 9625826 commit f077751
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Fixes

- `[jest-leak-detector]` Wait properly for GC runs due to changes in Node 14.7 ([#10366](https://github.com/facebook/jest/pull/10366))
- `[jest-worker]` Downgrade minimum node version to 10.13 ([#10352](https://github.com/facebook/jest/pull/10352))

### Chore & Maintenance
Expand Down
14 changes: 10 additions & 4 deletions packages/jest-leak-detector/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

import {setFlagsFromString} from 'v8';
import {runInNewContext} from 'vm';
import {promisify} from 'util';
import prettyFormat = require('pretty-format');
import {isPrimitive} from 'jest-get-type';

const tick = promisify(setImmediate);

export default class {
private _isReferenceBeingHeld: boolean;

Expand Down Expand Up @@ -46,12 +49,15 @@ export default class {
value = null;
}

isLeaking(): Promise<boolean> {
async isLeaking(): Promise<boolean> {
this._runGarbageCollector();

return new Promise(resolve =>
setImmediate(() => resolve(this._isReferenceBeingHeld)),
);
// wait some ticks to allow GC to run properly, see https://github.com/nodejs/node/issues/34636#issuecomment-669366235
for (let i = 0; i < 10; i++) {
await tick();
}

return this._isReferenceBeingHeld;
}

private _runGarbageCollector() {
Expand Down

0 comments on commit f077751

Please sign in to comment.