diff --git a/.vscode/launch.json b/.vscode/launch.json index 28e6fa352059..f4106b4f6605 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,8 @@ "request": "launch", "name": "Debug Jest with current test file", "program": "${workspaceFolder}/packages/jest-cli/bin/jest.js", - "args": ["--runInBand", "${file}"] + "args": ["--runInBand", "${file}"], + "runtimeArgs": ["-r", "flow-remove-types/register"] } ] } diff --git a/CHANGELOG.md b/CHANGELOG.md index 7de83039f155..edb71fe78bfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Fixes - `[jest-haste-map]` [**BREAKING**] Replaced internal data structures to improve performance ([#6960](https://github.com/facebook/jest/pull/6960)) +- `[jest-jasmine2]` Fix memory leak in Error objects hold by the framework ([#6965](https://github.com/facebook/jest/pull/6965)) ### Chore & Maintenance diff --git a/README.md b/README.md index 2c5d74597e93..0c3a1199fee3 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Backers on Open Collective Sponsors on Open Collective License: MIT + Known Vulnerabilities

**👩🏻‍💻 Developer Ready**: Complete and ready to set-up JavaScript testing solution. Works out of the box for any React project. diff --git a/jest.config.ci.js b/jest.config.ci.js index 3245d107fa7e..a5ca92a7711d 100644 --- a/jest.config.ci.js +++ b/jest.config.ci.js @@ -1,12 +1,9 @@ 'use strict'; -// TODO: Configure the reporter directly: https://github.com/rickhanlonii/jest-silent-reporter/commit/e9a306210f89fa22705823f4c920ed4eecdfb83d#r30109923 -process.env.JEST_SILENT_REPORTER_DOTS = true; - // Object spread is just node 8 module.exports = Object.assign({}, require('./jest.config'), { reporters: [ ['jest-junit', {output: 'reports/junit/js-test-results.xml'}], - 'jest-silent-reporter', + ['jest-silent-reporter', {useDots: true}], ], }); diff --git a/package.json b/package.json index 71ced53772b8..7e4e4af764ae 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "istanbul-lib-coverage": "^1.0.0", "jasmine-reporters": "^2.2.0", "jest-junit": "^5.1.0", - "jest-silent-reporter": "^0.1.0", + "jest-silent-reporter": "^0.1.1", "jquery": "^3.2.1", "karma": "^3.0.0", "karma-browserify": "^5.1.1", diff --git a/packages/jest-jasmine2/src/jasmine/Spec.js b/packages/jest-jasmine2/src/jasmine/Spec.js index e9016b7e9fb0..807c3c168f75 100644 --- a/packages/jest-jasmine2/src/jasmine/Spec.js +++ b/packages/jest-jasmine2/src/jasmine/Spec.js @@ -66,6 +66,12 @@ export default function Spec(attrs: Object) { this.initError = new Error(); this.initError.name = ''; + // 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 + this.initError.stack = this.initError.stack; + this.queueableFn.initError = this.initError; this.result = { diff --git a/packages/jest-jasmine2/src/jasmine_async.js b/packages/jest-jasmine2/src/jasmine_async.js index d7bb10c481b0..1eaf0a8f2a4f 100644 --- a/packages/jest-jasmine2/src/jasmine_async.js +++ b/packages/jest-jasmine2/src/jasmine_async.js @@ -37,6 +37,12 @@ function promisifyLifeCycleFunction(originalFn, env) { const extraError = 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 + extraError.stack = extraError.stack; + // We make *all* functions async and run `done` right away if they // didn't return a promise. const asyncJestLifecycle = function(done) { @@ -79,6 +85,12 @@ function promisifyIt(originalFn, env) { const extraError = 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 + extraError.stack = extraError.stack; + const asyncJestTest = function(done) { const wrappedFn = isGeneratorFn(fn) ? co.wrap(fn) : fn; const returnValue = wrappedFn.call({}); diff --git a/packages/jest-jasmine2/src/queue_runner.js b/packages/jest-jasmine2/src/queue_runner.js index 5155a43374ef..d72ec1bfabbd 100644 --- a/packages/jest-jasmine2/src/queue_runner.js +++ b/packages/jest-jasmine2/src/queue_runner.js @@ -73,6 +73,7 @@ export default function queueRunner(options: Options) { 'Timeout - Async callback was not invoked within the ' + timeoutMs + 'ms timeout specified by jest.setTimeout.'; + initError.stack = initError.message + initError.stack; options.onException(initError); }, ); diff --git a/yarn.lock b/yarn.lock index eab0b7f40346..a4bd01ae5f55 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6451,7 +6451,7 @@ jest-junit@^5.1.0: strip-ansi "^4.0.0" xml "^1.0.1" -jest-silent-reporter@^0.1.0: +jest-silent-reporter@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/jest-silent-reporter/-/jest-silent-reporter-0.1.1.tgz#2580704abf6245009f486fbea68f697dd7db2f48" dependencies: