File tree 1 file changed +17
-1
lines changed
packages/jest-environment-node/src 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -214,7 +214,23 @@ export default class NodeEnvironment implements JestEnvironment<Timer> {
214
214
if ( this . fakeTimersModern ) {
215
215
this . fakeTimersModern . dispose ( ) ;
216
216
}
217
- this . context = null ;
217
+
218
+ if ( this . context ) {
219
+ // remove any leftover listeners that may hold references to sizable memory
220
+ this . context . process . removeAllListeners ( ) ;
221
+ const cluster = runInContext (
222
+ "require('node:cluster')" ,
223
+ Object . assign ( this . context , {
224
+ require :
225
+ // get native require instead of webpack's
226
+ // @ts -expect-error https://webpack.js.org/api/module-variables/#__non_webpack_require__-webpack-specific
227
+ __non_webpack_require__ ,
228
+ } ) ,
229
+ ) ;
230
+ cluster . removeAllListeners ( ) ;
231
+
232
+ this . context = null ;
233
+ }
218
234
this . fakeTimers = null ;
219
235
this . fakeTimersModern = null ;
220
236
this . _globalProxy . clear ( ) ;
You can’t perform that action at this time.
0 commit comments