File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
packages/jest-environment-node/src Expand file tree Collapse file tree 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> {
214214 if ( this . fakeTimersModern ) {
215215 this . fakeTimersModern . dispose ( ) ;
216216 }
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+ }
218234 this . fakeTimers = null ;
219235 this . fakeTimersModern = null ;
220236 this . _globalProxy . clear ( ) ;
You can’t perform that action at this time.
0 commit comments