Skip to content

Commit c87e010

Browse files
committed
invert the logic
1 parent 8fdfe5c commit c87e010

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

integration_tests/__tests__/config-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test('config as JSON', () => {
2121
]);
2222
const stdout = result.stdout.toString();
2323

24-
expect(result.status).toBe(0);
24+
expect(result.status).toBe(1);
2525
expect(stdout).toMatch('No tests found');
2626
});
2727

integration_tests/__tests__/failWithNoTests-test.js renamed to integration_tests/__tests__/passWithNoTests-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ const runJest = require('../runJest');
1313

1414
const DIR = path.resolve(__dirname, '../failWithNoTests');
1515

16-
describe('jest --failWithNoTests', () => {
17-
test("doesn't fail the test suite if no files are found", () => {
16+
describe('jest --passWithNoTests', () => {
17+
test('fails the test suite if no files are found', () => {
1818
const result = runJest(DIR, ['--testPathPattern', '/non/existing/path/']);
1919
const status = result.status;
2020
const stdout = result.stdout.toString();
2121

2222
expect(stdout).toMatch('No tests found');
23-
expect(status).toBe(0);
23+
expect(status).toBe(1);
2424
});
2525

26-
test('fails the test suite if no files are found', () => {
26+
test("doesn't fail the test suite if no files are found", () => {
2727
const result = runJest(DIR, [
2828
'--testPathPattern',
2929
'/non/existing/path/',
30-
'--failWithNoTests',
30+
'--passWithNoTests',
3131
]);
3232
const status = result.status;
3333
const stdout = result.stdout.toString();
3434

3535
expect(stdout).toMatch('No tests found');
36-
expect(status).toBe(1);
36+
expect(status).toBe(0);
3737
});
3838
});

packages/jest-cli/src/cli/args.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@ const options = {
169169
description: 'Use this flag to show full diffs instead of a patch.',
170170
type: 'boolean',
171171
},
172-
failWithNoTests: {
173-
default: false,
174-
description: 'Will fail if no tests are found (for example while using `--testPathPattern`.)',
175-
type: 'boolean',
176-
},
177172
findRelatedTests: {
178173
default: undefined,
179174
description: 'Find related tests for a list of source files that were ' +
@@ -290,6 +285,11 @@ const options = {
290285
'also specified.',
291286
type: 'string',
292287
},
288+
passWithNoTests: {
289+
default: false,
290+
description: 'Will not fail if no tests are found (for example while using `--testPathPattern`.)',
291+
type: 'boolean',
292+
},
293293
preset: {
294294
description: "A preset that is used as a base for Jest's configuration.",
295295
type: 'string',

packages/jest-cli/src/runJest.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ const runJest = async (
182182
if (!allTests.length) {
183183
const noTestsFoundMessage = getNoTestsFoundMessage(testRunData, pattern);
184184

185-
if (argv.failWithNoTests) {
185+
if (argv.passWithNoTests) {
186+
new Console(pipe, pipe).log(noTestsFoundMessage);
187+
} else {
186188
new Console(pipe, pipe).error(noTestsFoundMessage);
187189

188190
process.exit(1);
189-
} else {
190-
new Console(pipe, pipe).log(noTestsFoundMessage);
191191
}
192192
} else if (
193193
allTests.length === 1 &&

0 commit comments

Comments
 (0)