Skip to content

Commit

Permalink
Add --listTests flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Karol Kuczmarski authored and cpojer committed May 3, 2017
1 parent 7b6597f commit 7755849
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/en/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ Write test results to a file when the `--json` option is also specified.

Will run all tests affected by file changes in the last commit made.

### `--listTests`

Lists all tests Jest will run given the other arguments, and exits.

### `--logHeapUsage`

Logs the heap usage after every test. Useful to debug memory leaks. Use together with `--runInBand` and `--expose-gc` in node.
Expand Down
21 changes: 21 additions & 0 deletions integration_tests/__tests__/list_tests-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+jsinfra
*/
'use strict';

const runJest = require('../runJest');

describe('--listTests flag', () => {
it('causes tests to be printed out as JSON', () => {
const {status, stdout} = runJest('list_tests', ['--listTests']);

expect(status).toBe(0);
expect(() => JSON.parse(stdout)).not.toThrow();
});
});
14 changes: 14 additions & 0 deletions integration_tests/list_tests/__tests__/dummy-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

it("isn't actually run", () => {
// (because it is only used for --listTests)
expect(true).toBe(false);
});
5 changes: 5 additions & 0 deletions integration_tests/list_tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"jest": {
"testEnvironment": "node"
}
}
5 changes: 5 additions & 0 deletions packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ const options = {
'commit made.',
type: 'boolean',
},
listTests: {
default: false,
description: 'Lists all tests Jest will run given the arguments and exits.',
type: 'boolean',
},
logHeapUsage: {
default: undefined,
description: 'Logs the heap usage after every test. Useful to debug ' +
Expand Down
8 changes: 8 additions & 0 deletions packages/jest-cli/src/runJest.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ const runJest = async (
);

allTests = sequencer.sort(allTests);

// With --listTests, simply print the test info as JSON and exit.
if (globalConfig.listTests) {
const testsJson = JSON.stringify(allTests, null, ' ');
new Console(pipe, pipe).log(testsJson);
process.exit(0);
}

if (!allTests.length) {
new Console(pipe, pipe).log(getNoTestsFoundMessage(testRunData, pattern));
} else if (
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const getConfigs = (
coverageThreshold: options.coverageThreshold,
expand: options.expand,
forceExit: options.forceExit,
listTests: options.listTests,
logHeapUsage: options.logHeapUsage,
mapCoverage: options.mapCoverage,
noStackTrace: options.noStackTrace,
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ function normalize(options: InitialOptions, argv: Object = {}) {
case 'coverageThreshold':
case 'expand':
case 'globals':
case 'listTests':
case 'logHeapUsage':
case 'mapCoverage':
case 'moduleDirectories':
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/validConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = ({
haste: {
providesModuleNodeModules: ['react', 'react-native'],
},
listTests: false,
logHeapUsage: true,
mapCoverage: false,
moduleDirectories: ['node_modules'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const validConfig = {
haste: {
providesModuleNodeModules: ['react', 'react-native'],
},
listTests: true,
logHeapUsage: true,
moduleDirectories: ['node_modules'],
moduleFileExtensions: ['js', 'json', 'jsx', 'node'],
Expand Down
1 change: 1 addition & 0 deletions types/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export type GlobalConfig = {|
coverageThreshold: {global: {[key: string]: number}},
expand: boolean,
forceExit: boolean,
listTests: boolean,
logHeapUsage: boolean,
mapCoverage: boolean,
noStackTrace: boolean,
Expand Down

0 comments on commit 7755849

Please sign in to comment.