Skip to content

Commit

Permalink
Make [jest-cli] not error when no tests are found with --findRelatedT…
Browse files Browse the repository at this point in the history
…ests, --lastCommit or --onlyChanged options (#5127)
  • Loading branch information
emilgoldsmith authored and cpojer committed Jan 12, 2018
1 parent 19376c1 commit c799a02
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 40 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## master

### Features

* `[jest-cli]` Make Jest exit without an error when no tests are found in
the case of `--lastCommit`, `--findRelatedTests`, or `--onlyChanged` options
having been passed to the CLI

## jest 22.0.6

### Fixes
Expand Down
69 changes: 69 additions & 0 deletions integration_tests/__tests__/no_tests_found.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

'use strict';

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

const DIR = path.resolve(__dirname, '../no_tests_found-test');

describe('No tests are found', () => {
test('fails the test suite in standard situation', () => {
const result = runJest(DIR, ['--testPathPattern', '/non/existing/path/']);
const status = result.status;
const stdout = result.stdout.toString();

expect(stdout).toMatch('No tests found');
expect(status).toBe(1);
});

test("doesn't fail the test suite if --passWithNoTests passed", () => {
const result = runJest(DIR, [
'--testPathPattern',
'/non/existing/path/',
'--passWithNoTests',
]);
const status = result.status;
const stdout = result.stdout.toString();

expect(stdout).toMatch('No tests found');
expect(status).toBe(0);
});

test("doesn't fail the test suite if using --lastCommit", () => {
// Since there are no files in DIR no tests will be found
const result = runJest(DIR, ['--lastCommit']);
const status = result.status;
const stdout = result.stdout.toString();

expect(stdout).toMatch('No tests found');
expect(status).toBe(0);
});

test("doesn't fail the test suite if using --onlyChanged", () => {
// Since there are no files in DIR no tests will be found
const result = runJest(DIR, ['--onlyChanged']);
const status = result.status;
const stdout = result.stdout.toString();

expect(stdout).toMatch('No tests found');
expect(status).toBe(0);
});

test("doesn't fail the test suite if using --findRelatedTests", () => {
// Since there are no files in DIR no tests will be found
const result = runJest(DIR, ['--findRelatedTests', '/non/existing/path']);
const status = result.status;
const stdout = result.stdout.toString();

expect(stdout).toMatch('No tests found');
expect(status).toBe(0);
});
});
39 changes: 0 additions & 39 deletions integration_tests/__tests__/pass_with_no_tests.test.js

This file was deleted.

7 changes: 6 additions & 1 deletion packages/jest-cli/src/run_jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ export default (async function runJest({
globalConfig,
);

if (globalConfig.passWithNoTests) {
if (
globalConfig.passWithNoTests ||
globalConfig.findRelatedTests ||
globalConfig.lastCommit ||
globalConfig.onlyChanged
) {
new Console(outputStream, outputStream).log(noTestsFoundMessage);
} else {
new Console(outputStream, outputStream).error(noTestsFoundMessage);
Expand Down

0 comments on commit c799a02

Please sign in to comment.