Skip to content

Commit 99baa11

Browse files
committed
invert the logic
1 parent 10117e1 commit 99baa11

File tree

8 files changed

+20
-20
lines changed

8 files changed

+20
-20
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__/fail_with_no_tests-test.js renamed to integration_tests/__tests__/pass_with_no_tests-test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@
1313
const path = require('path');
1414
const runJest = require('../runJest');
1515

16-
const DIR = path.resolve(__dirname, '../fail_with_no_tests');
16+
const DIR = path.resolve(__dirname, '../pass_with_no_tests-test');
1717

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

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

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

3737
expect(stdout).toMatch('No tests found');
38-
expect(status).toBe(1);
38+
expect(status).toBe(0);
3939
});
4040
});

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,6 @@ const options = {
208208
description: 'Use this flag to show full diffs instead of a patch.',
209209
type: 'boolean',
210210
},
211-
failWithNoTests: {
212-
default: false,
213-
description:
214-
'Will fail if no tests are found (for example while using `--testPathPattern`.)',
215-
type: 'boolean',
216-
},
217211
findRelatedTests: {
218212
default: undefined,
219213
description:
@@ -346,6 +340,12 @@ const options = {
346340
'also specified.',
347341
type: 'string',
348342
},
343+
passWithNoTests: {
344+
default: false,
345+
description:
346+
'Will not fail if no tests are found (for example while using `--testPathPattern`.)',
347+
type: 'boolean',
348+
},
349349
preset: {
350350
description: "A preset that is used as a base for Jest's configuration.",
351351
type: 'string',

packages/jest-cli/src/run_jest.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ const runJest = async ({
131131
globalConfig,
132132
);
133133

134-
if (globalConfig.failWithNoTests) {
134+
if (globalConfig.passWithNoTests) {
135+
new Console(outputStream, outputStream).log(noTestsFoundMessage);
136+
} else {
135137
new Console(outputStream, outputStream).error(noTestsFoundMessage);
136138

137139
process.exit(1);
138-
} else {
139-
new Console(outputStream, outputStream).log(noTestsFoundMessage);
140140
}
141141
} else if (
142142
allTests.length === 1 &&

packages/jest-config/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ const getConfigs = (
8383
coverageReporters: options.coverageReporters,
8484
coverageThreshold: options.coverageThreshold,
8585
expand: options.expand,
86-
failWithNoTests: options.failWithNoTests,
8786
findRelatedTests: options.findRelatedTests,
8887
forceExit: options.forceExit,
8988
json: options.json,
@@ -98,6 +97,7 @@ const getConfigs = (
9897
notify: options.notify,
9998
onlyChanged: options.onlyChanged,
10099
outputFile: options.outputFile,
100+
passWithNoTests: options.passWithNoTests,
101101
projects: options.projects,
102102
replname: options.replname,
103103
reporters: options.reporters,

test_utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const DEFAULT_GLOBAL_CONFIG: GlobalConfig = {
2222
coverageReporters: [],
2323
coverageThreshold: {global: {}},
2424
expand: false,
25-
failWithNoTests: false,
2625
findRelatedTests: false,
2726
forceExit: false,
2827
json: false,
@@ -37,6 +36,7 @@ const DEFAULT_GLOBAL_CONFIG: GlobalConfig = {
3736
notify: false,
3837
onlyChanged: false,
3938
outputFile: null,
39+
passWithNoTests: false,
4040
projects: [],
4141
replname: null,
4242
reporters: [],

types/Config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ export type GlobalConfig = {|
150150
coverageReporters: Array<string>,
151151
coverageThreshold: {global: {[key: string]: number}},
152152
expand: boolean,
153-
failWithNoTests: boolean,
154153
findRelatedTests: boolean,
155154
forceExit: boolean,
156155
json: boolean,
@@ -165,6 +164,7 @@ export type GlobalConfig = {|
165164
notify: boolean,
166165
outputFile: ?Path,
167166
onlyChanged: boolean,
167+
passWithNoTests: boolean,
168168
projects: Array<Glob>,
169169
replname: ?string,
170170
reporters: Array<ReporterConfig>,

0 commit comments

Comments
 (0)