Skip to content

Commit

Permalink
do not collect RANDOMBYTESREQUEST
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Apr 8, 2021
1 parent 594e863 commit 0aed689
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 32 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -48,7 +48,7 @@
- `[jest-config]` [**BREAKING**] Change default file extension order by moving json behind ts and tsx ([10572](https://github.com/facebook/jest/pull/10572))
- `[jest-console]` `console.dir` now respects the second argument correctly ([#10638](https://github.com/facebook/jest/pull/10638))
- `[jest-core]` Don't report PerformanceObserver as open handle ([#11123](https://github.com/facebook/jest/pull/11123))
- `[jest-core]` Run GC detecting open handles ([#11278](https://github.com/facebook/jest/pull/11278))
- `[jest-core]` Do not collect `RANDOMBYTESREQUEST` as open handles ([#11278](https://github.com/facebook/jest/pull/11278))
- `[jest-each]` [**BREAKING**] Ignore excess words in headings ([#8766](https://github.com/facebook/jest/pull/8766))
- `[jest-environment]` [**BREAKING**] Drop support for `runScript` for test environments ([#11155](https://github.com/facebook/jest/pull/11155))
- `[jest-environment-jsdom]` Use inner realm’s `ArrayBuffer` constructor ([#10885](https://github.com/facebook/jest/pull/10885))
Expand Down
32 changes: 4 additions & 28 deletions packages/jest-core/src/collectHandles.ts
Expand Up @@ -8,15 +8,12 @@
/* eslint-disable local/ban-types-eventually */

import * as asyncHooks from 'async_hooks';
import {promisify} from 'util';
import {setFlagsFromString} from 'v8';
import {runInNewContext} from 'vm';
import stripAnsi = require('strip-ansi');
import type {Config} from '@jest/types';
import {formatExecError} from 'jest-message-util';
import {ErrorWithStack} from 'jest-util';

export type HandleCollectionResult = () => Promise<Array<Error>>;
export type HandleCollectionResult = () => Array<Error>;

function stackIsFromUser(stack: string) {
// Either the test file, or something required by it
Expand All @@ -42,21 +39,6 @@ function stackIsFromUser(stack: string) {

const alwaysActive = () => true;

const tick = promisify(setImmediate);

function runGarbageCollector() {
const isGarbageCollectorHidden = !global.gc;

// GC is usually hidden, so we have to expose it before running.
setFlagsFromString('--expose-gc');
runInNewContext('gc')();

// The GC was not initially exposed, so let's hide it again.
if (isGarbageCollectorHidden) {
setFlagsFromString('--no-expose-gc');
}
}

// Inspired by https://github.com/mafintosh/why-is-node-running/blob/master/index.js
// Extracted as we want to format the result ourselves
export default function collectHandles(): HandleCollectionResult {
Expand All @@ -78,7 +60,8 @@ export default function collectHandles(): HandleCollectionResult {
type === 'PROMISE' ||
type === 'TIMERWRAP' ||
type === 'ELDHISTOGRAM' ||
type === 'PerformanceObserver'
type === 'PerformanceObserver' ||
type === 'RANDOMBYTESREQUEST'
) {
return;
}
Expand Down Expand Up @@ -108,14 +91,7 @@ export default function collectHandles(): HandleCollectionResult {

hook.enable();

return async () => {
runGarbageCollector();

// 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 () => {
hook.disable();

// Get errors for every async resource still referenced at this moment
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-core/src/runJest.ts
Expand Up @@ -75,7 +75,7 @@ type ProcessResultOptions = Pick<
outputStream: NodeJS.WriteStream;
};

const processResults = async (
const processResults = (
runResults: AggregatedResult,
options: ProcessResultOptions,
) => {
Expand All @@ -89,7 +89,7 @@ const processResults = async (
} = options;

if (collectHandles) {
runResults.openHandles = await collectHandles();
runResults.openHandles = collectHandles();
} else {
runResults.openHandles = [];
}
Expand Down Expand Up @@ -278,7 +278,7 @@ export default async function runJest({
await runGlobalHook({allTests, globalConfig, moduleName: 'globalTeardown'});
}

await processResults(results, {
processResults(results, {
collectHandles,
json: globalConfig.json,
onComplete,
Expand Down

0 comments on commit 0aed689

Please sign in to comment.