Skip to content

Commit b3880d6

Browse files
authored
Add setting to exclude files/directories from code coverage reports (#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
1 parent c002d57 commit b3880d6

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,19 @@
346346
}
347347
}
348348
},
349+
{
350+
"title": "Code Coverage",
351+
"properties": {
352+
"swift.excludeFromCodeCoverage": {
353+
"description": "A list of paths to exclude from code coverage reports. Paths can be absolute or relative to the workspace root.",
354+
"type": "array",
355+
"items": {
356+
"type": "string"
357+
},
358+
"default": []
359+
}
360+
}
361+
},
349362
{
350363
"title": "User Interface",
351364
"properties": {

src/configuration.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,12 @@ const configuration = {
154154
},
155155
};
156156
},
157-
157+
/** Files and directories to exclude from the code coverage. */
158+
get excludeFromCodeCoverage(): string[] {
159+
return vscode.workspace
160+
.getConfiguration("swift")
161+
.get<string[]>("excludeFromCodeCoverage", []);
162+
},
158163
/** Files and directories to exclude from the Package Dependencies view. */
159164
get excludePathsFromPackageDependencies(): string[] {
160165
return vscode.workspace

src/coverage/LcovResults.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,17 @@ export class TestCoverage {
198198
private ignoredFilenamesRegex(): string {
199199
const basePath = this.folderContext.folder.path;
200200
const buildFolder = path.join(basePath, ".build");
201+
const snippetsFolder = path.join(basePath, "Snippets");
202+
const pluginsFolder = path.join(basePath, "Plugins");
201203
const testTargets = this.folderContext.swiftPackage
202204
.getTargets(TargetType.test)
203205
.map(target => path.join(basePath, target.path));
204206

205-
return [buildFolder, ...testTargets].join("|");
207+
const excluded = configuration.excludeFromCodeCoverage.map(target =>
208+
path.isAbsolute(target) ? target : path.join(basePath, target)
209+
);
210+
211+
return [buildFolder, snippetsFolder, pluginsFolder, ...testTargets, ...excluded].join("|");
206212
}
207213

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

0 commit comments

Comments
 (0)