Skip to content

Commit 5d42d0a

Browse files
kaykayehnnSimenB
authored andcommitted
Fix warning message when there are no tests (#8595)
1 parent 3f5a0e8 commit 5d42d0a

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- `[jest-core]` Make watch plugin initialization errors look nice ([#8422](https://github.com/facebook/jest/pull/8422))
1616
- `[jest-snapshot]` Prevent inline snapshots from drifting when inline snapshots are updated ([#8492](https://github.com/facebook/jest/pull/8492))
1717
- `[jest-haste-map]` Don't throw on missing mapper in Node crawler ([#8558](https://github.com/facebook/jest/pull/8558))
18+
- `[jest-core]` Fix incorrect `passWithNoTests` warning ([#8595](https://github.com/facebook/jest/pull/8595))
1819

1920
### Chore & Maintenance
2021

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`getNoTestsFoundMessage returns correct message when monitoring only changed 1`] = `"<bold>No tests found related to files changed since last commit.</>"`;
4+
5+
exports[`getNoTestsFoundMessage returns correct message when monitoring only failures 1`] = `
6+
"<bold>No failed test found.</>
7+
<bold></><dim>Press \`f\` to quit \\"only failed tests\\" mode.</>"
8+
`;
9+
10+
exports[`getNoTestsFoundMessage returns correct message with passWithNoTests 1`] = `"<bold>No tests found, exiting with code 0</>"`;
11+
12+
exports[`getNoTestsFoundMessage returns correct message with verbose option 1`] = `
13+
"<bold>No tests found, exiting with code 1</>
14+
Run with \`--passWithNoTests\` to exit with code 0
15+
16+
Pattern: <yellow>/path/pattern</> - 0 matches"
17+
`;
18+
19+
exports[`getNoTestsFoundMessage returns correct message without options 1`] = `
20+
"<bold>No tests found, exiting with code 1</>
21+
Run with \`--passWithNoTests\` to exit with code 0
22+
In <bold>/root/dir</>
23+
0 files checked across 0 projects. Run with \`--verbose\` for more details.
24+
Pattern: <yellow>/path/pattern</> - 0 matches"
25+
`;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2+
3+
import getNoTestsFoundMessage from '../getNoTestsFoundMessage';
4+
5+
describe('getNoTestsFoundMessage', () => {
6+
function createGlobalConfig(options) {
7+
return {
8+
rootDir: '/root/dir',
9+
testPathPattern: '/path/pattern',
10+
...options,
11+
};
12+
}
13+
14+
test('returns correct message when monitoring only failures', () => {
15+
const config = createGlobalConfig({onlyFailures: true});
16+
expect(getNoTestsFoundMessage([], config)).toMatchSnapshot();
17+
});
18+
19+
test('returns correct message when monitoring only changed', () => {
20+
const config = createGlobalConfig({onlyChanged: true});
21+
expect(getNoTestsFoundMessage([], config)).toMatchSnapshot();
22+
});
23+
24+
test('returns correct message with verbose option', () => {
25+
const config = createGlobalConfig({verbose: true});
26+
expect(getNoTestsFoundMessage([], config)).toMatchSnapshot();
27+
});
28+
29+
test('returns correct message without options', () => {
30+
const config = createGlobalConfig();
31+
expect(getNoTestsFoundMessage([], config)).toMatchSnapshot();
32+
});
33+
34+
test('returns correct message with passWithNoTests', () => {
35+
const config = createGlobalConfig({passWithNoTests: true});
36+
expect(getNoTestsFoundMessage([], config)).toMatchSnapshot();
37+
});
38+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2+
3+
import chalk from 'chalk';
4+
5+
export default function getNoTestFoundPassWithNoTests() {
6+
return chalk.bold('No tests found, exiting with code 0');
7+
}

packages/jest-core/src/getNoTestsFoundMessage.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import getNoTestFound from './getNoTestFound';
1111
import getNoTestFoundRelatedToChangedFiles from './getNoTestFoundRelatedToChangedFiles';
1212
import getNoTestFoundVerbose from './getNoTestFoundVerbose';
1313
import getNoTestFoundFailed from './getNoTestFoundFailed';
14+
import getNoTestFoundPassWithNoTests from './getNoTestFoundPassWithNoTests';
1415

1516
export default function getNoTestsFoundMessage(
1617
testRunData: TestRunData,
@@ -22,6 +23,9 @@ export default function getNoTestsFoundMessage(
2223
if (globalConfig.onlyChanged) {
2324
return getNoTestFoundRelatedToChangedFiles(globalConfig);
2425
}
26+
if (globalConfig.passWithNoTests) {
27+
return getNoTestFoundPassWithNoTests();
28+
}
2529
return testRunData.length === 1 || globalConfig.verbose
2630
? getNoTestFoundVerbose(testRunData, globalConfig)
2731
: getNoTestFound(testRunData, globalConfig);

0 commit comments

Comments
 (0)