Skip to content

Commit cb6ae16

Browse files
committed
do not collect RANDOMBYTESREQUEST
1 parent 74ed376 commit cb6ae16

File tree

3 files changed

+8
-32
lines changed

3 files changed

+8
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
- `[jest-console]` `console.dir` now respects the second argument correctly ([#10638](https://github.com/facebook/jest/pull/10638))
5151
- `[jest-core]` Don't report PerformanceObserver as open handle ([#11123](https://github.com/facebook/jest/pull/11123))
5252
- `[jest-core]` Use `WeakRef` to hold timers when detecting open handles ([#11277](https://github.com/facebook/jest/pull/11277))
53-
- `[jest-core]` Run GC detecting open handles ([#11278](https://github.com/facebook/jest/pull/11278))
53+
- `[jest-core]` Do not collect `RANDOMBYTESREQUEST` as open handles ([#11278](https://github.com/facebook/jest/pull/11278))
5454
- `[jest-each]` [**BREAKING**] Ignore excess words in headings ([#8766](https://github.com/facebook/jest/pull/8766))
5555
- `[jest-environment]` [**BREAKING**] Drop support for `runScript` for test environments ([#11155](https://github.com/facebook/jest/pull/11155))
5656
- `[jest-environment-jsdom]` Use inner realm’s `ArrayBuffer` constructor ([#10885](https://github.com/facebook/jest/pull/10885))

packages/jest-core/src/collectHandles.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@
88
/* eslint-disable local/ban-types-eventually */
99

1010
import * as asyncHooks from 'async_hooks';
11-
import {promisify} from 'util';
12-
import {setFlagsFromString} from 'v8';
13-
import {runInNewContext} from 'vm';
1411
import stripAnsi = require('strip-ansi');
1512
import type {Config} from '@jest/types';
1613
import {formatExecError} from 'jest-message-util';
1714
import {ErrorWithStack} from 'jest-util';
1815

19-
export type HandleCollectionResult = () => Promise<Array<Error>>;
16+
export type HandleCollectionResult = () => Array<Error>;
2017

2118
function stackIsFromUser(stack: string) {
2219
// Either the test file, or something required by it
@@ -44,21 +41,6 @@ const alwaysActive = () => true;
4441

4542
const hasWeakRef = typeof WeakRef === 'function';
4643

47-
const tick = promisify(setImmediate);
48-
49-
function runGarbageCollector() {
50-
const isGarbageCollectorHidden = !global.gc;
51-
52-
// GC is usually hidden, so we have to expose it before running.
53-
setFlagsFromString('--expose-gc');
54-
runInNewContext('gc')();
55-
56-
// The GC was not initially exposed, so let's hide it again.
57-
if (isGarbageCollectorHidden) {
58-
setFlagsFromString('--no-expose-gc');
59-
}
60-
}
61-
6244
// Inspired by https://github.com/mafintosh/why-is-node-running/blob/master/index.js
6345
// Extracted as we want to format the result ourselves
6446
export default function collectHandles(): HandleCollectionResult {
@@ -80,7 +62,8 @@ export default function collectHandles(): HandleCollectionResult {
8062
type === 'PROMISE' ||
8163
type === 'TIMERWRAP' ||
8264
type === 'ELDHISTOGRAM' ||
83-
type === 'PerformanceObserver'
65+
type === 'PerformanceObserver' ||
66+
type === 'RANDOMBYTESREQUEST'
8467
) {
8568
return;
8669
}
@@ -118,14 +101,7 @@ export default function collectHandles(): HandleCollectionResult {
118101

119102
hook.enable();
120103

121-
return async () => {
122-
runGarbageCollector();
123-
124-
// wait some ticks to allow GC to run properly, see https://github.com/nodejs/node/issues/34636#issuecomment-669366235
125-
for (let i = 0; i < 10; i++) {
126-
await tick();
127-
}
128-
104+
return () => {
129105
hook.disable();
130106

131107
// Get errors for every async resource still referenced at this moment

packages/jest-core/src/runJest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ type ProcessResultOptions = Pick<
7575
outputStream: NodeJS.WriteStream;
7676
};
7777

78-
const processResults = async (
78+
const processResults = (
7979
runResults: AggregatedResult,
8080
options: ProcessResultOptions,
8181
) => {
@@ -89,7 +89,7 @@ const processResults = async (
8989
} = options;
9090

9191
if (collectHandles) {
92-
runResults.openHandles = await collectHandles();
92+
runResults.openHandles = collectHandles();
9393
} else {
9494
runResults.openHandles = [];
9595
}
@@ -278,7 +278,7 @@ export default async function runJest({
278278
await runGlobalHook({allTests, globalConfig, moduleName: 'globalTeardown'});
279279
}
280280

281-
await processResults(results, {
281+
processResults(results, {
282282
collectHandles,
283283
json: globalConfig.json,
284284
onComplete,

0 commit comments

Comments
 (0)