({
contexts,
globalConfig,
outputStream,
testWatcher,
jestHooks = new JestHook().getEmitter(),
startRun,
changedFilesPromise,
onComplete,
failedTestsCache,
filter,
}: {
globalConfig: Config.GlobalConfig;
contexts: Array<TestContext>;
outputStream: WriteStream;
testWatcher: TestWatcher;
jestHooks?: JestHookEmitter;
startRun: (globalConfig: Config.GlobalConfig) => void;
changedFilesPromise?: ChangedFilesPromise;
onComplete: (testResults: AggregatedResult) => void;
failedTestsCache?: FailedTestsCache;
filter?: Filter;
})
| 157 | }; |
| 158 | |
| 159 | export default async function runJest({ |
| 160 | contexts, |
| 161 | globalConfig, |
| 162 | outputStream, |
| 163 | testWatcher, |
| 164 | jestHooks = new JestHook().getEmitter(), |
| 165 | startRun, |
| 166 | changedFilesPromise, |
| 167 | onComplete, |
| 168 | failedTestsCache, |
| 169 | filter, |
| 170 | }: { |
| 171 | globalConfig: Config.GlobalConfig; |
| 172 | contexts: Array<TestContext>; |
| 173 | outputStream: WriteStream; |
| 174 | testWatcher: TestWatcher; |
| 175 | jestHooks?: JestHookEmitter; |
| 176 | startRun: (globalConfig: Config.GlobalConfig) => void; |
| 177 | changedFilesPromise?: ChangedFilesPromise; |
| 178 | onComplete: (testResults: AggregatedResult) => void; |
| 179 | failedTestsCache?: FailedTestsCache; |
| 180 | filter?: Filter; |
| 181 | }): Promise<void> { |
| 182 | // Clear cache for required modules - there might be different resolutions |
| 183 | // from Jest's config loading to running the tests |
| 184 | Resolver.clearDefaultResolverCache(); |
| 185 | |
| 186 | const Sequencer: typeof TestSequencer = await requireOrImportModule( |
| 187 | globalConfig.testSequencer, |
| 188 | ); |
| 189 | const sequencer = new Sequencer({contexts, globalConfig}); |
| 190 | let allTests: Array<Test> = []; |
| 191 | |
| 192 | if (changedFilesPromise && globalConfig.watch) { |
| 193 | const {repos} = await changedFilesPromise; |
| 194 | |
| 195 | const noSCM = ( |
| 196 | Object.keys(repos) as Array<keyof ChangedFiles['repos']> |
| 197 | ).every(scm => repos[scm].size === 0); |
| 198 | if (noSCM) { |
| 199 | process.stderr.write( |
| 200 | `\n${chalk.bold( |
| 201 | '--watch', |
| 202 | )} is not supported without git/hg, please use --watchAll\n`, |
| 203 | ); |
| 204 | exit(1); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | const searchSources = contexts.map(context => new SearchSource(context)); |
| 209 | |
| 210 | performance.mark('jest/getTestPaths:start'); |
| 211 | const testRunData: TestRunData = await Promise.all( |
| 212 | contexts.map(async (context, index) => { |
| 213 | const searchSource = searchSources[index]; |
| 214 | const matches = await getTestPaths( |
| 215 | globalConfig, |
| 216 | context.config, |
no test coverage detected