diff --git a/packages/jest-circus/src/index.js b/packages/jest-circus/src/index.js index 790987a43349..606d24c31a1b 100644 --- a/packages/jest-circus/src/index.js +++ b/packages/jest-circus/src/index.js @@ -29,8 +29,16 @@ describe.skip = (blockName: BlockName, blockFn: BlockFn) => _dispatchDescribe(blockFn, blockName, 'skip'); const _dispatchDescribe = (blockFn, blockName, mode?: BlockMode) => { + const asyncError = new Error(); + + // Without this line v8 stores references to all closures + // in the stack in the Error object. This line stringifies the stack + // property to allow garbage-collecting objects on the stack + // https://crbug.com/v8/7142 + asyncError.stack = asyncError.stack; + dispatch({ - asyncError: new Error(), + asyncError, blockName, mode, name: 'start_describe_definition', @@ -48,6 +56,13 @@ const _addHook = (fn: HookFn, hookType: HookType, hookFn, timeout: ?number) => { if (Error.captureStackTrace) { Error.captureStackTrace(asyncError, hookFn); } + + // Without this line v8 stores references to all closures + // in the stack in the Error object. This line stringifies the stack + // property to allow garbage-collecting objects on the stack + // https://crbug.com/v8/7142 + asyncError.stack = asyncError.stack; + dispatch({asyncError, fn, hookType, name: 'add_hook', timeout}); }; @@ -81,6 +96,12 @@ const test = (testName: TestName, fn: TestFn, timeout?: number) => { Error.captureStackTrace(asyncError, test); } + // Without this line v8 stores references to all closures + // in the stack in the Error object. This line stringifies the stack + // property to allow garbage-collecting objects on the stack + // https://crbug.com/v8/7142 + asyncError.stack = asyncError.stack; + return dispatch({ asyncError, fn, @@ -96,6 +117,12 @@ test.skip = (testName: TestName, fn?: TestFn, timeout?: number) => { Error.captureStackTrace(asyncError, test); } + // Without this line v8 stores references to all closures + // in the stack in the Error object. This line stringifies the stack + // property to allow garbage-collecting objects on the stack + // https://crbug.com/v8/7142 + asyncError.stack = asyncError.stack; + return dispatch({ asyncError, fn, @@ -111,6 +138,12 @@ test.only = (testName: TestName, fn: TestFn, timeout?: number) => { Error.captureStackTrace(asyncError, test); } + // Without this line v8 stores references to all closures + // in the stack in the Error object. This line stringifies the stack + // property to allow garbage-collecting objects on the stack + // https://crbug.com/v8/7142 + asyncError.stack = asyncError.stack; + return dispatch({ asyncError, fn,