Skip to content

Commit

Permalink
Unified 'no tests found' message for non-verbose MPR (#4354)
Browse files Browse the repository at this point in the history
  • Loading branch information
chitchu authored and cpojer committed Aug 25, 2017
1 parent f509856 commit 44b1c6d
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 54 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
24 changes: 24 additions & 0 deletions packages/jest-cli/src/get_no_test_found.js
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;
14 changes: 14 additions & 0 deletions packages/jest-cli/src/get_no_test_found_message.js
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;
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;
42 changes: 42 additions & 0 deletions packages/jest-cli/src/get_no_test_found_verbose.js
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;
4 changes: 4 additions & 0 deletions packages/jest-cli/src/pluralize.js
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;
55 changes: 1 addition & 54 deletions packages/jest-cli/src/run_jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import type TestWatcher from './test_watcher';

import path from 'path';
import {Console, formatTestResults} from 'jest-util';
import chalk from 'chalk';
import fs from 'graceful-fs';
import getNoTestsFoundMessage from './get_no_test_found_message';
import SearchSource from './search_source';
import TestScheduler from './test_scheduler';
import TestSequencer from './test_sequencer';
Expand All @@ -31,59 +31,6 @@ const setConfig = (contexts, newConfig) =>
)),
);

const getNoTestsFoundMessage = (testRunData, globalConfig) => {
if (globalConfig.onlyChanged) {
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.',
)
);
}

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) {
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`
);
};

const getTestPaths = async (
globalConfig,
context,
Expand Down

0 comments on commit 44b1c6d

Please sign in to comment.