Skip to content

Commit

Permalink
Create searchSources at first for reuse in runJest
Browse files Browse the repository at this point in the history
  • Loading branch information
chenesan committed Apr 26, 2020
1 parent e724874 commit 73271f0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/jest-core/src/runJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ import type {Filter, TestRunData} from './types';

const getTestPaths = async (
globalConfig: Config.GlobalConfig,
context: Context,
source: SearchSource,
outputStream: NodeJS.WriteStream,
changedFiles: ChangedFiles | undefined,
jestHooks: JestHookEmitter,
filter?: Filter,
) => {
const source = new SearchSource(context);
const data = await source.getTestPaths(globalConfig, changedFiles, filter);

if (!data.tests.length && globalConfig.onlyChanged && data.noSCM) {
Expand Down Expand Up @@ -167,11 +166,14 @@ export default async function runJest({
}
}

const searchSources = contexts.map(context => new SearchSource(context));

const testRunData: TestRunData = await Promise.all(
contexts.map(async context => {
contexts.map(async (context, index) => {
const searchSource = searchSources[index];
const matches = await getTestPaths(
globalConfig,
context,
searchSource,
outputStream,
changedFilesPromise && (await changedFilesPromise),
jestHooks,
Expand Down Expand Up @@ -246,8 +248,8 @@ export default async function runJest({
if (changedFilesInfo.changedFiles) {
testSchedulerContext.changedFiles = changedFilesInfo.changedFiles;
const sourcesRelatedToTestsInChangedFilesArray = contexts
.map(context => {
const searchSource = new SearchSource(context);
.map((_, index) => {
const searchSource = searchSources[index];
const relatedSourceFromTestsInChangedFiles = searchSource.findRelatedSourcesFromTestsInChangedFiles(
changedFilesInfo,
);
Expand Down

0 comments on commit 73271f0

Please sign in to comment.