From bb0c74f6689703728f2935fdb0524b8588376ef6 Mon Sep 17 00:00:00 2001 From: Neil Kistner Date: Sun, 26 Feb 2017 20:19:17 -0600 Subject: [PATCH] Fix behavior of `--silent` flag (#3003) --- .../__snapshots__/console-test.js.snap | 17 +++++++++++++++++ integration_tests/__tests__/console-test.js | 18 ++++++++++++++++++ packages/jest-cli/src/runJest.js | 8 +++++--- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/integration_tests/__tests__/__snapshots__/console-test.js.snap b/integration_tests/__tests__/__snapshots__/console-test.js.snap index c6617ce1678f..a327e3efea5b 100644 --- a/integration_tests/__tests__/__snapshots__/console-test.js.snap +++ b/integration_tests/__tests__/__snapshots__/console-test.js.snap @@ -57,3 +57,20 @@ Time: <> Ran all test suites. " `; + +exports[`does not print to console with --silent 1`] = `""`; + +exports[`does not print to console with --silent 2`] = ` +" PASS __tests__/console-test.js + +" +`; + +exports[`does not print to console with --silent 3`] = ` +"Test Suites: 1 passed, 1 total +Tests: 1 passed, 1 total +Snapshots: 0 total +Time: <> +Ran all test suites. +" +`; diff --git a/integration_tests/__tests__/console-test.js b/integration_tests/__tests__/console-test.js index ecbf53cdbd54..9e1aa0d03350 100644 --- a/integration_tests/__tests__/console-test.js +++ b/integration_tests/__tests__/console-test.js @@ -34,3 +34,21 @@ test('console printing with --verbose', () => { expect(rest).toMatchSnapshot(); expect(summary).toMatchSnapshot(); }); + +test('does not print to console with --silent', () => { + const {stderr, stdout, status} = + runJest('console', [ + // Need to pass --config because console test specifies `verbose: false` + '--config=' + JSON.stringify({ + testEnvironment: 'node', + }), + '--silent', + '--no-cache', + ]); + const {summary, rest} = extractSummary(stderr); + + expect(status).toBe(0); + expect(stdout).toMatchSnapshot(); + expect(rest).toMatchSnapshot(); + expect(summary).toMatchSnapshot(); +}); diff --git a/packages/jest-cli/src/runJest.js b/packages/jest-cli/src/runJest.js index e3e11923bcae..b50e24e04225 100644 --- a/packages/jest-cli/src/runJest.js +++ b/packages/jest-cli/src/runJest.js @@ -86,9 +86,11 @@ const runJest = ( } return data; }).then(data => { - if (data.paths.length === 1 && config.verbose !== false) { - // $FlowFixMe - config = Object.assign({}, config, {verbose: true}); + if (data.paths.length === 1) { + if (config.silent !== true && config.verbose !== false) { + // $FlowFixMe + config = Object.assign({}, config, {verbose: true}); + } } return new TestRunner(