From a66a571a6a126cd33cfc357fa172f29b6afd517c Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Sat, 15 Sep 2018 22:04:07 +0200 Subject: [PATCH 1/4] Fix a memory leak in Error objects (#6965) --- CHANGELOG.md | 1 + packages/jest-jasmine2/src/jasmine/Spec.js | 6 ++++++ packages/jest-jasmine2/src/jasmine_async.js | 12 ++++++++++++ packages/jest-jasmine2/src/queue_runner.js | 1 + 4 files changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37191ffdcc36..0cc18fc14391 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/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); }, ); From 68eb9a232dcbd4ecf85bb1f0bdad5cb850dff81a Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Sun, 16 Sep 2018 00:54:40 -0700 Subject: [PATCH 2/4] chore: add runtimeArgs in VSCode launch.json (#6985) --- .vscode/launch.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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"] } ] } From 7308bbc6cc880a2f21c1ab214c0b179a4b89abdb Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 16 Sep 2018 21:52:15 +0200 Subject: [PATCH 3/4] chore: use useDots option in silent reporter (#6984) --- jest.config.ci.js | 5 +---- package.json | 2 +- yarn.lock | 6 +++--- 3 files changed, 5 insertions(+), 8 deletions(-) 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 ba3f2d4695e6..8fa17629c427 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": "^2.0.0", "karma-browserify": "^5.1.1", diff --git a/yarn.lock b/yarn.lock index ba482d20889e..74b19f946ec9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5986,9 +5986,9 @@ jest-resolve@^22.4.2: browser-resolve "^1.11.2" chalk "^2.0.1" -jest-silent-reporter@^0.1.0: - version "0.1.0" - resolved "https://registry.yarnpkg.com/jest-silent-reporter/-/jest-silent-reporter-0.1.0.tgz#9628c58c7f018b26c902836de278f40a4b072570" +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: chalk "^2.3.1" jest-util "^23.0.0" From 5c8ec2f31e0c4e083c4a9d42ea6955aa51bf7e9b Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Sun, 16 Sep 2018 13:19:07 -0700 Subject: [PATCH 4/4] Add badge of vulnerabilities from snyk.io (#6986) --- README.md | 1 + 1 file changed, 1 insertion(+) 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.