diff --git a/packages/jest-core/src/getNoTestFound.ts b/packages/jest-core/src/getNoTestFound.ts index d1fa85d3ec8e..b609b8752e79 100644 --- a/packages/jest-core/src/getNoTestFound.ts +++ b/packages/jest-core/src/getNoTestFound.ts @@ -30,11 +30,7 @@ export default function getNoTestFound( )} - 0 matches`; } - return ( - chalk.bold('No tests found, exiting with code 1') + - '\n' + - 'Run with `--passWithNoTests` to exit with code 0' + - '\n' + + const fixedMessage = `In ${chalk.bold(globalConfig.rootDir)}` + '\n' + ` ${pluralize('file', testFiles, 's')} checked across ${pluralize( @@ -43,6 +39,19 @@ export default function getNoTestFound( 's', )}. Run with \`--verbose\` for more details.` + '\n' + - dataMessage + dataMessage; + + if (globalConfig.passWithNoTests) { + return ( + chalk.bold('No tests found, exiting with code 0') + '\n' + fixedMessage + ); + } + + return ( + chalk.bold('No tests found, exiting with code 1') + + '\n' + + 'Run with `--passWithNoTests` to exit with code 0' + + '\n' + + fixedMessage ); } diff --git a/packages/jest-core/src/getNoTestFoundVerbose.ts b/packages/jest-core/src/getNoTestFoundVerbose.ts index 5e0177a9c3d1..aabe958786c8 100644 --- a/packages/jest-core/src/getNoTestFoundVerbose.ts +++ b/packages/jest-core/src/getNoTestFoundVerbose.ts @@ -52,6 +52,16 @@ export default function getNoTestFoundVerbose( )} - 0 matches`; } + if (globalConfig.passWithNoTests) { + return ( + chalk.bold('No tests found, exiting with code 0') + + '\n' + + individualResults.join('\n') + + '\n' + + dataMessage + ); + } + return ( chalk.bold('No tests found, exiting with code 1') + '\n' +