( argv: Config.Argv, projects: Array<string>, )
| 36 | type OnCompleteCallback = (results: AggregatedResult) => void | undefined; |
| 37 | |
| 38 | export async function runCLI( |
| 39 | argv: Config.Argv, |
| 40 | projects: Array<string>, |
| 41 | ): Promise<{ |
| 42 | results: AggregatedResult; |
| 43 | globalConfig: Config.GlobalConfig; |
| 44 | }> { |
| 45 | performance.mark('jest/runCLI:start'); |
| 46 | let results: AggregatedResult | undefined; |
| 47 | |
| 48 | // If we output a JSON object, we can't write anything to stdout, since |
| 49 | // it'll break the JSON structure and it won't be valid. |
| 50 | const outputStream = |
| 51 | argv.json || argv.useStderr ? process.stderr : process.stdout; |
| 52 | |
| 53 | const {globalConfig, configs, hasDeprecationWarnings} = await readConfigs( |
| 54 | argv, |
| 55 | projects, |
| 56 | ); |
| 57 | |
| 58 | if (argv.debug) { |
| 59 | logDebugMessages(globalConfig, configs, outputStream); |
| 60 | } |
| 61 | |
| 62 | if (argv.showConfig) { |
| 63 | logDebugMessages(globalConfig, configs, process.stdout); |
| 64 | exit(0); |
| 65 | } |
| 66 | |
| 67 | if (argv.clearCache) { |
| 68 | // stick in a Set to dedupe the deletions |
| 69 | const uniqueConfigDirectories = new Set( |
| 70 | configs.map(config => config.cacheDirectory), |
| 71 | ); |
| 72 | for (const cacheDirectory of uniqueConfigDirectories) { |
| 73 | fs.rmSync(cacheDirectory, {force: true, recursive: true}); |
| 74 | process.stdout.write(`Cleared ${cacheDirectory}\n`); |
| 75 | } |
| 76 | |
| 77 | exit(0); |
| 78 | } |
| 79 | |
| 80 | const configsOfProjectsToRun = getConfigsOfProjectsToRun(configs, { |
| 81 | ignoreProjects: argv.ignoreProjects, |
| 82 | selectProjects: argv.selectProjects, |
| 83 | }); |
| 84 | if (argv.selectProjects || argv.ignoreProjects) { |
| 85 | const namesMissingWarning = getProjectNamesMissingWarning(configs, { |
| 86 | ignoreProjects: argv.ignoreProjects, |
| 87 | selectProjects: argv.selectProjects, |
| 88 | }); |
| 89 | if (namesMissingWarning) { |
| 90 | outputStream.write(namesMissingWarning); |
| 91 | } |
| 92 | outputStream.write( |
| 93 | getSelectProjectsMessage(configsOfProjectsToRun, { |
| 94 | ignoreProjects: argv.ignoreProjects, |
| 95 | selectProjects: argv.selectProjects, |
no test coverage detected