Skip to content

Commit

Permalink
Fix warning message when there are no tests (#8595)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaykayehnn authored and SimenB committed Jun 24, 2019
1 parent 3f5a0e8 commit 5d42d0a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
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';