Skip to content

Commit

Permalink
Create and keep DependencyResolver in SearchSource for reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
chenesan committed Apr 26, 2020
1 parent 73271f0 commit 0d50802
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/jest-core/src/SearchSource.ts
Expand Up @@ -60,11 +60,13 @@ const hasSCM = (changedFilesInfo: ChangedFiles) => {

export default class SearchSource {
private _context: Context;
private _dependencyResolver: DependencyResolver | null;
private _testPathCases: TestPathCases = [];

constructor(context: Context) {
const {config} = context;
this._context = context;
this._dependencyResolver = null;

const rootPattern = new RegExp(
config.roots.map(dir => escapePathForRegex(dir + path.sep)).join('|'),
Expand Down Expand Up @@ -99,6 +101,17 @@ export default class SearchSource {
}
}

private _getOrBuildDependencyResolver(): DependencyResolver {
if (!this._dependencyResolver) {
this._dependencyResolver = new DependencyResolver(
this._context.resolver,
this._context.hasteFS,
buildSnapshotResolver(this._context.config),
);
}
return this._dependencyResolver;
}

private _filterTestPathsWithStats(
allPaths: Array<Test>,
testPathPattern?: string,
Expand Down Expand Up @@ -162,11 +175,7 @@ export default class SearchSource {
allPaths: Set<Config.Path>,
collectCoverage: boolean,
): SearchResult {
const dependencyResolver = new DependencyResolver(
this._context.resolver,
this._context.hasteFS,
buildSnapshotResolver(this._context.config),
);
const dependencyResolver = this._getOrBuildDependencyResolver();

if (!collectCoverage) {
return {
Expand Down Expand Up @@ -340,11 +349,7 @@ export default class SearchSource {
return [];
}
const {changedFiles} = changedFilesInfo;
const dependencyResolver = new DependencyResolver(
this._context.resolver,
this._context.hasteFS,
buildSnapshotResolver(this._context.config),
);
const dependencyResolver = this._getOrBuildDependencyResolver();
const relatedSourcesSet = new Set<string>();
changedFiles.forEach(filePath => {
const isTestFile = this.isTestFilePath(filePath);
Expand Down

0 comments on commit 0d50802

Please sign in to comment.