Skip to content

Commit

Permalink
Add setting to exclude files/directories from code coverage reports (#…
Browse files Browse the repository at this point in the history
…965)

* Add setting to exclude files/directories from code coverage reports

Adds `swift.excludeFromCodeCoverage` which provides a list of absolute
or relative paths to exclude from the code coverage reports. Relative
paths are specified from the workspace root.

Issue: #963

* Remove Snippets/Plugins folders from coverage reports
  • Loading branch information
plemarquand authored Jul 11, 2024
1 parent c002d57 commit b3880d6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,19 @@
}
}
},
{
"title": "Code Coverage",
"properties": {
"swift.excludeFromCodeCoverage": {
"description": "A list of paths to exclude from code coverage reports. Paths can be absolute or relative to the workspace root.",
"type": "array",
"items": {
"type": "string"
},
"default": []
}
}
},
{
"title": "User Interface",
"properties": {
Expand Down
7 changes: 6 additions & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ const configuration = {
},
};
},

/** Files and directories to exclude from the code coverage. */
get excludeFromCodeCoverage(): string[] {
return vscode.workspace
.getConfiguration("swift")
.get<string[]>("excludeFromCodeCoverage", []);
},
/** Files and directories to exclude from the Package Dependencies view. */
get excludePathsFromPackageDependencies(): string[] {
return vscode.workspace
Expand Down
8 changes: 7 additions & 1 deletion src/coverage/LcovResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,17 @@ export class TestCoverage {
private ignoredFilenamesRegex(): string {
const basePath = this.folderContext.folder.path;
const buildFolder = path.join(basePath, ".build");
const snippetsFolder = path.join(basePath, "Snippets");
const pluginsFolder = path.join(basePath, "Plugins");
const testTargets = this.folderContext.swiftPackage
.getTargets(TargetType.test)
.map(target => path.join(basePath, target.path));

return [buildFolder, ...testTargets].join("|");
const excluded = configuration.excludeFromCodeCoverage.map(target =>
path.isAbsolute(target) ? target : path.join(basePath, target)
);

return [buildFolder, snippetsFolder, pluginsFolder, ...testTargets, ...excluded].join("|");
}

private async loadLcov(lcovContents: string): Promise<lcov.LcovFile[]> {
Expand Down

0 comments on commit b3880d6

Please sign in to comment.