(
allPaths: Set<string>,
collectCoverage: boolean,
)
| 175 | } |
| 176 | |
| 177 | async findRelatedTests( |
| 178 | allPaths: Set<string>, |
| 179 | collectCoverage: boolean, |
| 180 | ): Promise<SearchResult> { |
| 181 | const dependencyResolver = await this._getOrBuildDependencyResolver(); |
| 182 | |
| 183 | if (!collectCoverage) { |
| 184 | return { |
| 185 | tests: toTests( |
| 186 | this._context, |
| 187 | dependencyResolver.resolveInverse( |
| 188 | allPaths, |
| 189 | this.isTestFilePath.bind(this), |
| 190 | {skipNodeResolution: this._context.config.skipNodeResolution}, |
| 191 | ), |
| 192 | ), |
| 193 | }; |
| 194 | } |
| 195 | |
| 196 | const testModulesMap = dependencyResolver.resolveInverseModuleMap( |
| 197 | allPaths, |
| 198 | this.isTestFilePath.bind(this), |
| 199 | {skipNodeResolution: this._context.config.skipNodeResolution}, |
| 200 | ); |
| 201 | |
| 202 | const allPathsAbsolute = new Set([...allPaths].map(p => path.resolve(p))); |
| 203 | |
| 204 | const collectCoverageFrom = new Set<string>(); |
| 205 | |
| 206 | for (const testModule of testModulesMap) { |
| 207 | if (!testModule.dependencies) { |
| 208 | continue; |
| 209 | } |
| 210 | |
| 211 | for (const p of testModule.dependencies) { |
| 212 | if (!allPathsAbsolute.has(p)) { |
| 213 | continue; |
| 214 | } |
| 215 | |
| 216 | const filename = replaceRootDirInPath(this._context.config.rootDir, p); |
| 217 | collectCoverageFrom.add( |
| 218 | path.isAbsolute(filename) |
| 219 | ? path.relative(this._context.config.rootDir, filename) |
| 220 | : filename, |
| 221 | ); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | return { |
| 226 | collectCoverageFrom, |
| 227 | tests: toTests( |
| 228 | this._context, |
| 229 | testModulesMap.map(testModule => testModule.file), |
| 230 | ), |
| 231 | }; |
| 232 | } |
| 233 | |
| 234 | findTestsByPaths(paths: Array<string>): SearchResult { |
no test coverage detected