Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning message when there are no tests #8595

Merged
merged 4 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- `[jest-core]` Make watch plugin initialization errors look nice ([#8422](https://github.com/facebook/jest/pull/8422))
- `[jest-snapshot]` Prevent inline snapshots from drifting when inline snapshots are updated ([#8492](https://github.com/facebook/jest/pull/8492))
- `[jest-haste-map]` Don't throw on missing mapper in Node crawler ([#8558](https://github.com/facebook/jest/pull/8558))
- `[jest-core]` Fix incorrect `passWithNoTests` warning ([#8595](https://github.com/facebook/jest/pull/8595))

### Chore & Maintenance

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`getNoTestsFoundMessage returns correct message when monitoring only changed 1`] = `"<bold>No tests found related to files changed since last commit.</>"`;

exports[`getNoTestsFoundMessage returns correct message when monitoring only failures 1`] = `
"<bold>No failed test found.</>
<bold></><dim>Press \`f\` to quit \\"only failed tests\\" mode.</>"
`;

exports[`getNoTestsFoundMessage returns correct message with passWithNoTests 1`] = `"<bold>No tests found, exiting with code 0</>"`;

exports[`getNoTestsFoundMessage returns correct message with verbose option 1`] = `
"<bold>No tests found, exiting with code 1</>
Run with \`--passWithNoTests\` to exit with code 0

Pattern: <yellow>/path/pattern</> - 0 matches"
`;

exports[`getNoTestsFoundMessage returns correct message without options 1`] = `
"<bold>No tests found, exiting with code 1</>
Run with \`--passWithNoTests\` to exit with code 0
In <bold>/root/dir</>
0 files checked across 0 projects. Run with \`--verbose\` for more details.
Pattern: <yellow>/path/pattern</> - 0 matches"
`;
38 changes: 38 additions & 0 deletions packages/jest-core/src/__tests__/getNoTestsFoundMessage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

import getNoTestsFoundMessage from '../getNoTestsFoundMessage';

describe('getNoTestsFoundMessage', () => {
function createGlobalConfig(options) {
return {
rootDir: '/root/dir',
testPathPattern: '/path/pattern',
...options,
};
}

test('returns correct message when monitoring only failures', () => {
const config = createGlobalConfig({onlyFailures: true});
expect(getNoTestsFoundMessage([], config)).toMatchSnapshot();
});

test('returns correct message when monitoring only changed', () => {
const config = createGlobalConfig({onlyChanged: true});
expect(getNoTestsFoundMessage([], config)).toMatchSnapshot();
});

test('returns correct message with verbose option', () => {
const config = createGlobalConfig({verbose: true});
expect(getNoTestsFoundMessage([], config)).toMatchSnapshot();
});

test('returns correct message without options', () => {
const config = createGlobalConfig();
expect(getNoTestsFoundMessage([], config)).toMatchSnapshot();
});

test('returns correct message with passWithNoTests', () => {
const config = createGlobalConfig({passWithNoTests: true});
expect(getNoTestsFoundMessage([], config)).toMatchSnapshot();
});
});
7 changes: 7 additions & 0 deletions packages/jest-core/src/getNoTestFoundPassWithNoTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

import chalk from 'chalk';

export default function getNoTestFoundPassWithNoTests() {
return chalk.bold('No tests found, exiting with code 0');
}
4 changes: 4 additions & 0 deletions packages/jest-core/src/getNoTestsFoundMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import getNoTestFound from './getNoTestFound';
import getNoTestFoundRelatedToChangedFiles from './getNoTestFoundRelatedToChangedFiles';
import getNoTestFoundVerbose from './getNoTestFoundVerbose';
import getNoTestFoundFailed from './getNoTestFoundFailed';
import getNoTestFoundPassWithNoTests from './getNoTestFoundPassWithNoTests';

export default function getNoTestsFoundMessage(
testRunData: TestRunData,
Expand All @@ -22,6 +23,9 @@ export default function getNoTestsFoundMessage(
if (globalConfig.onlyChanged) {
return getNoTestFoundRelatedToChangedFiles(globalConfig);
}
if (globalConfig.passWithNoTests) {
return getNoTestFoundPassWithNoTests();
}
return testRunData.length === 1 || globalConfig.verbose
? getNoTestFoundVerbose(testRunData, globalConfig)
: getNoTestFound(testRunData, globalConfig);
Expand Down