File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed
jest-environment-node/src Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -216,6 +216,9 @@ export default class NodeEnvironment implements JestEnvironment<Timer> {
216216 }
217217
218218 if ( this . context ) {
219+ // source-map-support keeps memory leftovers in `Error.prepareStackTrace`
220+ runInContext ( "Error.prepareStackTrace = () => '';" , this . context ) ;
221+
219222 // remove any leftover listeners that may hold references to sizable memory
220223 this . context . process . removeAllListeners ( ) ;
221224 const cluster = runInContext (
Original file line number Diff line number Diff line change @@ -312,8 +312,12 @@ async function runTestInternal(
312312 sendMessageToJest ,
313313 ) ;
314314 } catch ( error : any ) {
315- // Access stack before uninstalling sourcemaps
316- error . stack ;
315+ // Access all stacks before uninstalling sourcemaps
316+ let e = error ;
317+ while ( typeof e === 'object' && 'stack' in e ) {
318+ e . stack ;
319+ e = e ?. cause ?? { } ;
320+ }
317321
318322 throw error ;
319323 } finally {
You can’t perform that action at this time.
0 commit comments