MCPcopy
hub / github.com/jestjs/jest / runCLI

Function runCLI

packages/jest-core/src/cli/index.ts:38–141  ·  view source on GitHub ↗
(
  argv: Config.Argv,
  projects: Array<string>,
)

Source from the content-addressed store, hash-verified

36type OnCompleteCallback = (results: AggregatedResult) => void | undefined;
37
38export 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,

Callers 2

runFunction · 0.90
run-jest.jsFile · 0.50

Calls 11

readConfigsFunction · 0.90
formatHandleErrorsFunction · 0.90
pluralizeFunction · 0.90
logDebugMessagesFunction · 0.85
exitFunction · 0.85
getSelectProjectsMessageFunction · 0.85
_run10000Function · 0.85
writeMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected