From a344d497160e4ab8f8e8a1d122395a4a52a3ce61 Mon Sep 17 00:00:00 2001 From: Joachim Seminck Date: Fri, 1 Sep 2017 11:51:33 +0300 Subject: [PATCH] Make listTests always print to console.log (#4391) * Make listTests always print to console.log * Update snapshot * Update snapshot a second time * Try to remove EOL splitting * Re-add normalize paths * Also update snapshot * Split by \n instead of EOL --- .../__tests__/__snapshots__/list_tests.test.js.snap | 3 ++- integration_tests/__tests__/list_tests.test.js | 9 ++++----- packages/jest-cli/src/run_jest.js | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/integration_tests/__tests__/__snapshots__/list_tests.test.js.snap b/integration_tests/__tests__/__snapshots__/list_tests.test.js.snap index 2aaa350699d3..5b62c5592066 100644 --- a/integration_tests/__tests__/__snapshots__/list_tests.test.js.snap +++ b/integration_tests/__tests__/__snapshots__/list_tests.test.js.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`--listTests flag causes tests to be printed in different lines 1`] = ` -"/MOCK_ABOLUTE_PATH/integration_tests/list_tests/__tests__/dummy.test.js +" +/MOCK_ABOLUTE_PATH/integration_tests/list_tests/__tests__/dummy.test.js /MOCK_ABOLUTE_PATH/integration_tests/list_tests/__tests__/other.test.js" `; diff --git a/integration_tests/__tests__/list_tests.test.js b/integration_tests/__tests__/list_tests.test.js index 855784ab79ca..1c174ff4e4a3 100644 --- a/integration_tests/__tests__/list_tests.test.js +++ b/integration_tests/__tests__/list_tests.test.js @@ -11,7 +11,6 @@ const runJest = require('../runJest'); const path = require('path'); -const {EOL} = require('os'); const testRootDir = path.resolve(__dirname, '..', '..'); @@ -28,17 +27,17 @@ describe('--listTests flag', () => { expect(status).toBe(0); expect( - normalizePaths(stdout).split(EOL).sort().join(EOL), + normalizePaths(stdout).split('\n').sort().join('\n'), ).toMatchSnapshot(); }); it('causes tests to be printed out as JSON when using the --json flag', () => { - const {status, stderr} = runJest('list_tests', ['--listTests', '--json']); + const {status, stdout} = runJest('list_tests', ['--listTests', '--json']); expect(status).toBe(0); - expect(() => JSON.parse(stderr)).not.toThrow(); + expect(() => JSON.parse(stdout)).not.toThrow(); expect( - JSON.stringify(JSON.parse(stderr).map(normalizePaths).sort()), + JSON.stringify(JSON.parse(stdout).map(normalizePaths).sort()), ).toMatchSnapshot(); }); }); diff --git a/packages/jest-cli/src/run_jest.js b/packages/jest-cli/src/run_jest.js index f0c7573c1f9c..f3160a6ca6df 100644 --- a/packages/jest-cli/src/run_jest.js +++ b/packages/jest-cli/src/run_jest.js @@ -116,9 +116,9 @@ const runJest = async ({ if (globalConfig.listTests) { const testsPaths = allTests.map(test => test.path); if (globalConfig.json) { - outputStream.write(JSON.stringify(testsPaths)); + console.log(JSON.stringify(testsPaths)); } else { - outputStream.write(testsPaths.join('\n')); + console.log(testsPaths.join('\n')); } onComplete && onComplete(makeEmptyAggregatedTestResult());