Skip to content

Commit

Permalink
Make listTests always print to console.log (#4391)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jseminck authored and cpojer committed Sep 1, 2017
1 parent de74b38 commit a344d49
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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"
`;

Expand Down
9 changes: 4 additions & 5 deletions integration_tests/__tests__/list_tests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

const runJest = require('../runJest');
const path = require('path');
const {EOL} = require('os');

const testRootDir = path.resolve(__dirname, '..', '..');

Expand All @@ -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();
});
});
4 changes: 2 additions & 2 deletions packages/jest-cli/src/run_jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit a344d49

Please sign in to comment.