8
8
/* eslint-disable local/ban-types-eventually */
9
9
10
10
import * as asyncHooks from 'async_hooks' ;
11
- import { promisify } from 'util' ;
12
- import { setFlagsFromString } from 'v8' ;
13
- import { runInNewContext } from 'vm' ;
14
11
import stripAnsi = require( 'strip-ansi' ) ;
15
12
import type { Config } from '@jest/types' ;
16
13
import { formatExecError } from 'jest-message-util' ;
17
14
import { ErrorWithStack } from 'jest-util' ;
18
15
19
- export type HandleCollectionResult = ( ) => Promise < Array < Error > > ;
16
+ export type HandleCollectionResult = ( ) => Array < Error > ;
20
17
21
18
function stackIsFromUser ( stack : string ) {
22
19
// Either the test file, or something required by it
@@ -44,21 +41,6 @@ const alwaysActive = () => true;
44
41
45
42
const hasWeakRef = typeof WeakRef === 'function' ;
46
43
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
-
62
44
// Inspired by https://github.com/mafintosh/why-is-node-running/blob/master/index.js
63
45
// Extracted as we want to format the result ourselves
64
46
export default function collectHandles ( ) : HandleCollectionResult {
@@ -80,7 +62,8 @@ export default function collectHandles(): HandleCollectionResult {
80
62
type === 'PROMISE' ||
81
63
type === 'TIMERWRAP' ||
82
64
type === 'ELDHISTOGRAM' ||
83
- type === 'PerformanceObserver'
65
+ type === 'PerformanceObserver' ||
66
+ type === 'RANDOMBYTESREQUEST'
84
67
) {
85
68
return ;
86
69
}
@@ -118,14 +101,7 @@ export default function collectHandles(): HandleCollectionResult {
118
101
119
102
hook . enable ( ) ;
120
103
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 ( ) => {
129
105
hook . disable ( ) ;
130
106
131
107
// Get errors for every async resource still referenced at this moment
0 commit comments