Skip to content

Commit

Permalink
invert the logic
Browse files Browse the repository at this point in the history
  • Loading branch information
EnoahNetzach committed Aug 28, 2017
1 parent 10117e1 commit 99baa11
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion integration_tests/__tests__/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test('config as JSON', () => {
]);
const stdout = result.stdout.toString();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@
const path = require('path');
const runJest = require('../runJest');

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

describe('jest --failWithNoTests', () => {
test("doesn't fail the test suite if no files are found", () => {
describe('jest --passWithNoTests', () => {
test('fails the test suite if no files are found', () => {
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(0);
expect(status).toBe(1);
});

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

expect(stdout).toMatch('No tests found');
expect(status).toBe(1);
expect(status).toBe(0);
});
});
12 changes: 6 additions & 6 deletions packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,6 @@ const options = {
description: 'Use this flag to show full diffs instead of a patch.',
type: 'boolean',
},
failWithNoTests: {
default: false,
description:
'Will fail if no tests are found (for example while using `--testPathPattern`.)',
type: 'boolean',
},
findRelatedTests: {
default: undefined,
description:
Expand Down Expand Up @@ -346,6 +340,12 @@ const options = {
'also specified.',
type: 'string',
},
passWithNoTests: {
default: false,
description:
'Will not fail if no tests are found (for example while using `--testPathPattern`.)',
type: 'boolean',
},
preset: {
description: "A preset that is used as a base for Jest's configuration.",
type: 'string',
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-cli/src/run_jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ const runJest = async ({
globalConfig,
);

if (globalConfig.failWithNoTests) {
if (globalConfig.passWithNoTests) {
new Console(outputStream, outputStream).log(noTestsFoundMessage);
} else {
new Console(outputStream, outputStream).error(noTestsFoundMessage);

process.exit(1);
} else {
new Console(outputStream, outputStream).log(noTestsFoundMessage);
}
} else if (
allTests.length === 1 &&
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ const getConfigs = (
coverageReporters: options.coverageReporters,
coverageThreshold: options.coverageThreshold,
expand: options.expand,
failWithNoTests: options.failWithNoTests,
findRelatedTests: options.findRelatedTests,
forceExit: options.forceExit,
json: options.json,
Expand All @@ -98,6 +97,7 @@ const getConfigs = (
notify: options.notify,
onlyChanged: options.onlyChanged,
outputFile: options.outputFile,
passWithNoTests: options.passWithNoTests,
projects: options.projects,
replname: options.replname,
reporters: options.reporters,
Expand Down
2 changes: 1 addition & 1 deletion test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const DEFAULT_GLOBAL_CONFIG: GlobalConfig = {
coverageReporters: [],
coverageThreshold: {global: {}},
expand: false,
failWithNoTests: false,
findRelatedTests: false,
forceExit: false,
json: false,
Expand All @@ -37,6 +36,7 @@ const DEFAULT_GLOBAL_CONFIG: GlobalConfig = {
notify: false,
onlyChanged: false,
outputFile: null,
passWithNoTests: false,
projects: [],
replname: null,
reporters: [],
Expand Down
2 changes: 1 addition & 1 deletion types/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ export type GlobalConfig = {|
coverageReporters: Array<string>,
coverageThreshold: {global: {[key: string]: number}},
expand: boolean,
failWithNoTests: boolean,
findRelatedTests: boolean,
forceExit: boolean,
json: boolean,
Expand All @@ -165,6 +164,7 @@ export type GlobalConfig = {|
notify: boolean,
outputFile: ?Path,
onlyChanged: boolean,
passWithNoTests: boolean,
projects: Array<Glob>,
replname: ?string,
reporters: Array<ReporterConfig>,
Expand Down

0 comments on commit 99baa11

Please sign in to comment.