|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | // Licensed under the MIT license. |
3 | 3 |
|
4 | | -import { BranchCoverage, DeclarationCoverage, FileCoverage, FileCoverageDetail, Position, StatementCoverage, TestRun, Uri } from 'vscode'; |
| 4 | +import * as minimatch from 'minimatch'; |
| 5 | +import { BranchCoverage, DeclarationCoverage, FileCoverage, FileCoverageDetail, Position, StatementCoverage, Uri } from 'vscode'; |
5 | 6 | import { getJacocoReportBasePath } from '../utils/coverageUtils'; |
6 | 7 | import { executeJavaLanguageServerCommand } from '../utils/commandUtils'; |
7 | 8 | import { JavaTestRunnerDelegateCommands } from '../constants'; |
| 9 | +import { IRunTestContext } from '../java-test-runner.api'; |
8 | 10 |
|
9 | 11 | export class JavaTestCoverageProvider { |
10 | 12 |
|
11 | 13 | private coverageDetails: Map<Uri, FileCoverageDetail[]> = new Map<Uri, FileCoverageDetail[]>(); |
12 | 14 |
|
13 | | - public async provideFileCoverage(run: TestRun, projectName: string): Promise<void> { |
| 15 | + public async provideFileCoverage({testRun: run, projectName, testConfig}: IRunTestContext): Promise<void> { |
14 | 16 | const sourceFileCoverages: ISourceFileCoverage[] = await executeJavaLanguageServerCommand<void>(JavaTestRunnerDelegateCommands.GET_COVERAGE_DETAIL, |
15 | 17 | projectName, getJacocoReportBasePath(projectName)) || []; |
16 | | - for (const sourceFileCoverage of sourceFileCoverages) { |
| 18 | + const excludePatterns: minimatch.Minimatch[] = (testConfig?.coverage?.excludes ?? []).map((pattern: string) => |
| 19 | + new minimatch.Minimatch(pattern, {flipNegate: true, nonegate: true})); |
| 20 | + const filteredCoverages: ISourceFileCoverage[] = excludePatterns.length > 0 |
| 21 | + ? sourceFileCoverages.filter((sourceFileCoverage: ISourceFileCoverage) => { |
| 22 | + const uri: Uri = Uri.parse(sourceFileCoverage.uriString); |
| 23 | + return !excludePatterns.some((exclusion: minimatch.Minimatch) => exclusion.match(uri.fsPath)); |
| 24 | + }) |
| 25 | + : sourceFileCoverages; |
| 26 | + for (const sourceFileCoverage of filteredCoverages) { |
17 | 27 | const uri: Uri = Uri.parse(sourceFileCoverage.uriString); |
18 | 28 | const detailedCoverage: FileCoverageDetail[] = []; |
19 | 29 | for (const lineCoverage of sourceFileCoverage.lineCoverages) { |
|
0 commit comments