Skip to content

Commit 970aa60

Browse files
authored
ignore and warn on unknown manual coverage file paths (#473)
1 parent b4c638f commit 970aa60

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

src/files/filesloader.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {readFile} from "fs";
1+
import { existsSync, readFile } from "fs";
22
import glob from "glob";
3-
import {window, workspace, WorkspaceFolder} from "vscode";
4-
import {Config} from "../extension/config";
3+
import { window, workspace, WorkspaceFolder } from "vscode";
4+
import { Config } from "../extension/config";
55

66
export class FilesLoader {
77
private configStore: Config;
@@ -17,7 +17,14 @@ export class FilesLoader {
1717
public async findCoverageFiles(): Promise<Set<string>> {
1818
// Developers can manually define their absolute coverage paths
1919
if (this.configStore.manualCoverageFilePaths.length) {
20-
return new Set(this.configStore.manualCoverageFilePaths);
20+
const existingFiles = this.configStore.manualCoverageFilePaths.filter((file) => {
21+
if (!existsSync(file)) {
22+
window.showWarningMessage(`manualCoverageFilePaths contains "${file}" which does not exist!`);
23+
return false;
24+
}
25+
return true;
26+
});
27+
return new Set(existingFiles);
2128
} else {
2229
const fileNames = this.configStore.coverageFileNames;
2330
const files = await this.findCoverageInWorkspace(fileNames);

test/files/filesloader.test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import sinon from "sinon";
44
import * as vscode from "vscode";
55
import { Config } from "../../src/extension/config";
66

7+
import path from "path";
78
import { FilesLoader } from "../../src/files/filesloader";
89

910
const stubConfig = sinon.createStubInstance(Config) as Config;
@@ -40,10 +41,34 @@ suite("FilesLoader Tests", () => {
4041
});
4142

4243
test("findCoverageFiles returns manual coverage paths if set @unit", async () => {
43-
const coverageFiles = ["test.js", "test2.js"];
44+
const nodeTestFile = path.resolve(__dirname, "..", "..", "..", "example", "node", "lcov.info")
45+
const rubyTestFile = path.resolve(__dirname, "..", "..", "..", "example", "ruby", "lcov.info")
46+
const coverageFiles = [
47+
nodeTestFile,
48+
rubyTestFile,
49+
];
4450
stubConfig.manualCoverageFilePaths = coverageFiles;
4551
const filesLoader = new FilesLoader(stubConfig);
4652
const files = await filesLoader.findCoverageFiles();
4753
expect(new Set(coverageFiles)).to.deep.equal(files);
4854
});
55+
56+
test("findCoverageFiles returns only manual coverage paths that exist @unit", async () => {
57+
const nodeTestFile = path.resolve(__dirname, "..", "..", "..", "example", "node", "lcov.info")
58+
const unknownTestFile = path.resolve(__dirname, "..", "..", "..", "example", "unknown", "lcov.info")
59+
const rubyTestFile = path.resolve(__dirname, "..", "..", "..", "example", "ruby", "lcov.info")
60+
const coverageFiles = [
61+
nodeTestFile,
62+
unknownTestFile,
63+
rubyTestFile,
64+
];
65+
stubConfig.manualCoverageFilePaths = coverageFiles;
66+
const filesLoader = new FilesLoader(stubConfig);
67+
const files = await filesLoader.findCoverageFiles();
68+
expect(new Set([
69+
nodeTestFile,
70+
// unknownTestFile does not exist so it should not be included
71+
rubyTestFile,
72+
])).to.deep.equal(files);
73+
});
4974
});

0 commit comments

Comments
 (0)