Skip to content

Add setting to exclude files/directories from code coverage reports #965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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