-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unified 'no tests found' message for non-verbose MPR
- Loading branch information
Showing
7 changed files
with
135 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import chalk from 'chalk'; | ||
import pluralize from './pluralize'; | ||
|
||
const getNoTestFound = (testRunData, globalConfig): string => { | ||
const testFiles = testRunData.reduce( | ||
(current, testRun) => (current += testRun.matches.total), | ||
0, | ||
); | ||
return ( | ||
chalk.bold('No tests found') + | ||
'\n' + | ||
`In ${chalk.bold(process.cwd())}` + | ||
'\n' + | ||
` ${pluralize('file', testFiles, 's')} checked across ${pluralize( | ||
'project', | ||
testRunData.length, | ||
's', | ||
)}. for more details run with \`--verbose\`` + | ||
'\n' + | ||
`Pattern: ${chalk.yellow(globalConfig.testPathPattern)} - 0 matches` | ||
); | ||
}; | ||
|
||
module.exports = getNoTestFound; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import getNoTestFound from './get_no_test_found'; | ||
import getNoTestFoundRelatedToChangedFiles from './get_no_test_found_related_to_changed_files'; | ||
import getNoTestFoundVerbose from './get_no_test_found_verbose'; | ||
|
||
const getNoTestsFoundMessage = (testRunData, globalConfig): string => { | ||
if (globalConfig.onlyChanged) { | ||
return getNoTestFoundRelatedToChangedFiles(globalConfig); | ||
} | ||
return globalConfig.verbose | ||
? getNoTestFoundVerbose(testRunData, globalConfig) | ||
: getNoTestFound(testRunData, globalConfig); | ||
}; | ||
|
||
module.exports = getNoTestsFoundMessage; |
14 changes: 14 additions & 0 deletions
14
packages/jest-cli/src/get_no_test_found_related_to_changed_files.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import chalk from 'chalk'; | ||
|
||
const getNoTestFoundRelatedToChangedFiles = globalConfig => { | ||
return ( | ||
chalk.bold('No tests found related to files changed since last commit.\n') + | ||
chalk.dim( | ||
globalConfig.watch | ||
? 'Press `a` to run all tests, or run Jest with `--watchAll`.' | ||
: 'Run Jest without `-o` or with `--all` to run all tests.', | ||
) | ||
); | ||
}; | ||
|
||
module.exports = getNoTestFoundRelatedToChangedFiles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import chalk from 'chalk'; | ||
import pluralize from './pluralize'; | ||
|
||
const getNoTestFoundVerbose = (testRunData, globalConfig): string => { | ||
const individualResults = testRunData.map(testRun => { | ||
const stats = testRun.matches.stats || {}; | ||
const config = testRun.context.config; | ||
const statsMessage = Object.keys(stats) | ||
.map(key => { | ||
if (key === 'roots' && config.roots.length === 1) { | ||
return null; | ||
} | ||
const value = config[key]; | ||
if (value) { | ||
const matches = pluralize('match', stats[key], 'es'); | ||
return ` ${key}: ${chalk.yellow(value)} - ${matches}`; | ||
} | ||
return null; | ||
}) | ||
.filter(line => line) | ||
.join('\n'); | ||
|
||
return testRun.matches.total | ||
? `In ${chalk.bold(config.rootDir)}\n` + | ||
` ${pluralize('file', testRun.matches.total || 0, 's')} checked.\n` + | ||
statsMessage | ||
: `No files found in ${config.rootDir}.\n` + | ||
`Make sure Jest's configuration does not exclude this directory.` + | ||
`\nTo set up Jest, make sure a package.json file exists.\n` + | ||
`Jest Documentation: ` + | ||
`facebook.github.io/jest/docs/configuration.html`; | ||
}); | ||
return ( | ||
chalk.bold('No tests found') + | ||
'\n' + | ||
individualResults.join('\n') + | ||
'\n' + | ||
`Pattern: ${chalk.yellow(globalConfig.testPathPattern)} - 0 matches` | ||
); | ||
}; | ||
|
||
module.exports = getNoTestFoundVerbose; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const pluralize = (word: string, count: number, ending: string) => | ||
`${count} ${word}${count === 1 ? '' : ending}`; | ||
|
||
module.exports = pluralize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters