-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
getNoTestFoundVerbose.ts
74 lines (68 loc) · 2.24 KB
/
getNoTestFoundVerbose.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import chalk from 'chalk';
import {Config} from '@jest/types';
import pluralize from './pluralize';
import {Stats, TestRunData} from './types';
export default function getNoTestFoundVerbose(
testRunData: TestRunData,
globalConfig: Config.GlobalConfig,
): string {
const individualResults = testRunData.map(testRun => {
const stats = testRun.matches.stats || ({} as Stats);
const config = testRun.context.config;
const statsMessage = (Object.keys(stats) as Array<keyof Stats>)
.map(key => {
if (key === 'roots' && config.roots.length === 1) {
return null;
}
const value = (config as {[key: string]: unknown})[key];
if (value) {
const valueAsString = Array.isArray(value)
? value.join(', ')
: String(value);
const matches = pluralize('match', stats[key] || 0, 'es');
return ` ${key}: ${chalk.yellow(valueAsString)} - ${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`;
});
let dataMessage;
if (globalConfig.runTestsByPath) {
dataMessage = `Files: ${globalConfig.nonFlagArgs
.map(p => `"${p}"`)
.join(', ')}`;
} else {
dataMessage = `Pattern: ${chalk.yellow(
globalConfig.testPathPattern,
)} - 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' +
'Run with `--passWithNoTests` to exit with code 0' +
'\n' +
individualResults.join('\n') +
'\n' +
dataMessage
);
}