Skip to content

Commit c799a02

Browse files
emilgoldsmithcpojer
authored andcommitted
Make [jest-cli] not error when no tests are found with --findRelatedTests, --lastCommit or --onlyChanged options (#5127)
1 parent 19376c1 commit c799a02

File tree

5 files changed

+82
-40
lines changed

5 files changed

+82
-40
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
## master
2+
3+
### Features
4+
5+
* `[jest-cli]` Make Jest exit without an error when no tests are found in
6+
the case of `--lastCommit`, `--findRelatedTests`, or `--onlyChanged` options
7+
having been passed to the CLI
8+
29
## jest 22.0.6
310

411
### Fixes
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
'use strict';
11+
12+
const path = require('path');
13+
const runJest = require('../runJest');
14+
15+
const DIR = path.resolve(__dirname, '../no_tests_found-test');
16+
17+
describe('No tests are found', () => {
18+
test('fails the test suite in standard situation', () => {
19+
const result = runJest(DIR, ['--testPathPattern', '/non/existing/path/']);
20+
const status = result.status;
21+
const stdout = result.stdout.toString();
22+
23+
expect(stdout).toMatch('No tests found');
24+
expect(status).toBe(1);
25+
});
26+
27+
test("doesn't fail the test suite if --passWithNoTests passed", () => {
28+
const result = runJest(DIR, [
29+
'--testPathPattern',
30+
'/non/existing/path/',
31+
'--passWithNoTests',
32+
]);
33+
const status = result.status;
34+
const stdout = result.stdout.toString();
35+
36+
expect(stdout).toMatch('No tests found');
37+
expect(status).toBe(0);
38+
});
39+
40+
test("doesn't fail the test suite if using --lastCommit", () => {
41+
// Since there are no files in DIR no tests will be found
42+
const result = runJest(DIR, ['--lastCommit']);
43+
const status = result.status;
44+
const stdout = result.stdout.toString();
45+
46+
expect(stdout).toMatch('No tests found');
47+
expect(status).toBe(0);
48+
});
49+
50+
test("doesn't fail the test suite if using --onlyChanged", () => {
51+
// Since there are no files in DIR no tests will be found
52+
const result = runJest(DIR, ['--onlyChanged']);
53+
const status = result.status;
54+
const stdout = result.stdout.toString();
55+
56+
expect(stdout).toMatch('No tests found');
57+
expect(status).toBe(0);
58+
});
59+
60+
test("doesn't fail the test suite if using --findRelatedTests", () => {
61+
// Since there are no files in DIR no tests will be found
62+
const result = runJest(DIR, ['--findRelatedTests', '/non/existing/path']);
63+
const status = result.status;
64+
const stdout = result.stdout.toString();
65+
66+
expect(stdout).toMatch('No tests found');
67+
expect(status).toBe(0);
68+
});
69+
});

integration_tests/__tests__/pass_with_no_tests.test.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

packages/jest-cli/src/run_jest.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ export default (async function runJest({
153153
globalConfig,
154154
);
155155

156-
if (globalConfig.passWithNoTests) {
156+
if (
157+
globalConfig.passWithNoTests ||
158+
globalConfig.findRelatedTests ||
159+
globalConfig.lastCommit ||
160+
globalConfig.onlyChanged
161+
) {
157162
new Console(outputStream, outputStream).log(noTestsFoundMessage);
158163
} else {
159164
new Console(outputStream, outputStream).error(noTestsFoundMessage);

0 commit comments

Comments
 (0)