Skip to content

Commit

Permalink
Unified 'no tests found' message for non-verbose MPR
Browse files Browse the repository at this point in the history
  • Loading branch information
chitchu committed Aug 25, 2017
1 parent f509856 commit af3dbff
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 34 deletions.
36 changes: 36 additions & 0 deletions integration_tests/__tests__/multi_project_runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,42 @@ test('can pass projects or global config', () => {
expect(sortLines(result1.rest)).toBe(sortLines(result2.rest));
});

test('"No tests found" message for projects', () => {
writeFiles(DIR, {
'.watchmanconfig': '',
'package.json': '{}',
'project1/__tests__/file1.test.js': `
const file1 = require('file1');
test('file1', () => {});
`,
'project1/file1.js': fileContentWithProvidesModule('file1'),
'project1/jest.config.js': `module.exports = {rootDir: './'}`,
'project2/__tests__/file1.test.js': `
const file1 = require('file1');
test('file1', () => {});
`,
'project2/file1.js': fileContentWithProvidesModule('file1'),
'project2/jest.config.js': `module.exports = {rootDir: './'}`,
});
const {stdout: verboseOutput} = runJest(DIR, [
'xyz321',
'--verbose',
'--projects',
'project1',
'project2',
]);
expect(verboseOutput).toContain('Pattern: xyz321 - 0 matches');
const {stdout} = runJest(DIR, [
'xyz321',
'--projects',
'project1',
'project2',
]);
expect(stdout).toContain(
' 6 files checked across 2 projects. for more details run with `--verbose`',
);
});

test('resolves projects and their <rootDir> properly', () => {
writeFiles(DIR, {
'.watchmanconfig': '',
Expand Down
88 changes: 54 additions & 34 deletions packages/jest-cli/src/run_jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,41 +47,61 @@ const getNoTestsFoundMessage = (testRunData, globalConfig) => {

const pluralize = (word: string, count: number, ending: string) =>
`${count} ${word}${count === 1 ? '' : ending}`;
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) {
if (globalConfig.verbose) {
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;
}
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`
);
})
.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`
);
} else {
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`
);
}
};

const getTestPaths = async (
Expand Down

0 comments on commit af3dbff

Please sign in to comment.