Skip to content

Commit

Permalink
Merge pull request #181 from ryanluker/175-coverage-file-names
Browse files Browse the repository at this point in the history
Add coverage file names config and cleanup historical method
  • Loading branch information
ryanluker authored Oct 28, 2018
2 parents 4292eb1 + 1f206dd commit 07d71bc
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 38 deletions.
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@
],
"description": "paths that will be ignored by the extension"
},
"coverage-gutters.coverageFileNames": {
"type": "Array<string>",
"default": [
"lcov.info",
"cov.xml",
"jacoco.xml"
],
"description": "Coverage file names for the extension to automatically look for"
},
"coverage-gutters.customizable.status-bar-toggler-watchCoverageAndVisibleEditors-enabled": {
"type": "boolean",
"default": true,
Expand Down
27 changes: 10 additions & 17 deletions src/coverage-system/coverageservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ export class CoverageService {
private filesLoader: FilesLoader;
private renderer: Renderer;
private coverageParser: CoverageParser;
private lcovWatcher: FileSystemWatcher;
private xmlWatcher: FileSystemWatcher;
private coverageWatcher: FileSystemWatcher;
private editorWatcher: Disposable;
private sectionFinder: SectionFinder;

private cache: Map<string, Section>;
private status: Status;

constructor(
configStore: IConfigStore,
Expand Down Expand Up @@ -65,7 +63,7 @@ export class CoverageService {
}

public dispose() {
this.xmlWatcher.dispose();
this.coverageWatcher.dispose();
this.editorWatcher.dispose();
this.cache = new Map(); // reset cache to empty
const visibleEditors = window.visibleTextEditors;
Expand Down Expand Up @@ -105,7 +103,6 @@ export class CoverageService {
}

private updateServiceState(state: Status) {
this.status = state;
this.outputChannel.appendLine(
`[${Date.now()}][coverageservice]: ${state}`);
}
Expand All @@ -119,19 +116,15 @@ export class CoverageService {
}

private listenToFileSystem() {
this.lcovWatcher = workspace.createFileSystemWatcher(
`**/${this.configStore.lcovFileName}`,
const fileNames = this.configStore.coverageFileNames.toString();
// Creates a BlobPattern for all coverage files.
// EX: `**/{cov.xml, lcov.info}`
this.coverageWatcher = workspace.createFileSystemWatcher(
`**/{${fileNames}}`,
);
this.lcovWatcher.onDidChange(this.loadCacheAndRender.bind(this));
this.lcovWatcher.onDidCreate(this.loadCacheAndRender.bind(this));
this.lcovWatcher.onDidDelete(this.loadCacheAndRender.bind(this));

this.xmlWatcher = workspace.createFileSystemWatcher(
`**/${this.configStore.xmlFileName}`,
);
this.xmlWatcher.onDidChange(this.loadCacheAndRender.bind(this));
this.xmlWatcher.onDidCreate(this.loadCacheAndRender.bind(this));
this.xmlWatcher.onDidDelete(this.loadCacheAndRender.bind(this));
this.coverageWatcher.onDidChange(this.loadCacheAndRender.bind(this));
this.coverageWatcher.onDidCreate(this.loadCacheAndRender.bind(this));
this.coverageWatcher.onDidDelete(this.loadCacheAndRender.bind(this));
}

private async handleEditorEvents(textEditors: TextEditor[]) {
Expand Down
20 changes: 12 additions & 8 deletions src/extension/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {InterfaceVscode} from "../wrappers/vscode";
import {Reporter} from "./reporter";

export interface IConfigStore {
lcovFileName: string;
xmlFileName: string;
coverageFileNames: string[];
fullCoverageDecorationType: TextEditorDecorationType;
partialCoverageDecorationType: TextEditorDecorationType;
noCoverageDecorationType: TextEditorDecorationType;
Expand All @@ -22,8 +21,7 @@ export class Config {
private context: ExtensionContext;
private reporter: Reporter;

private lcovFileName: string;
private xmlFileName: string;
private coverageFileNames: string[];
private fullCoverageDecorationType: TextEditorDecorationType;
private partialCoverageDecorationType: TextEditorDecorationType;
private noCoverageDecorationType: TextEditorDecorationType;
Expand All @@ -39,13 +37,12 @@ export class Config {

public get(): IConfigStore {
return {
coverageFileNames: this.coverageFileNames,
fullCoverageDecorationType: this.fullCoverageDecorationType,
ignoredPathGlobs: this.ignoredPaths,
lcovFileName: this.lcovFileName,
noCoverageDecorationType: this.noCoverageDecorationType,
partialCoverageDecorationType: this.partialCoverageDecorationType,
showStatusBarToggler: this.showStatusBarToggler,
xmlFileName: this.xmlFileName,
};
}

Expand All @@ -64,8 +61,15 @@ export class Config {
const rootConfig = this.vscode.getConfiguration("coverage-gutters");

// Basic configurations
this.lcovFileName = rootConfig.get("lcovname") as string;
this.xmlFileName = rootConfig.get("xmlname") as string;
// TODO: remove lcovname and xmlname in 3.0.0 release
const lcovName = rootConfig.get("lcovname") as string;
const xmlName = rootConfig.get("xmlname") as string;
this.coverageFileNames = rootConfig.get("coverageFileNames") as string[];
this.coverageFileNames.push(lcovName, xmlName);

// Make fileNames unique
this.coverageFileNames = [...new Set(this.coverageFileNames)];

const STATUS_BAR_TOGGLER = "status-bar-toggler-watchCoverageAndVisibleEditors-enabled";
this.showStatusBarToggler = rootCustomConfig.get(STATUS_BAR_TOGGLER) as boolean;

Expand Down
5 changes: 1 addition & 4 deletions src/files/filesloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ export class FilesLoader {
* Finds all coverages files by xml and lcov and returns them
*/
public async findCoverageFiles(): Promise<Set<string>> {
const fileNames = [
this.configStore.lcovFileName,
this.configStore.xmlFileName,
];
const fileNames = this.configStore.coverageFileNames;
const files = await this.findCoverageInWorkspace(fileNames);
if (!files.size) { throw new Error("Could not find a Coverage file!"); }
return files;
Expand Down
25 changes: 20 additions & 5 deletions test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ suite("Extension Tests", function() {
this.timeout(25000);

test("Run display coverage on node test file @integration", async () => {
// Wait for extension to load
await sleep(2000);

const extension = await vscode.extensions.getExtension("ryanluker.vscode-coverage-gutters");
if (!extension) {
throw new Error("Could not load extension");
Expand All @@ -14,7 +17,7 @@ suite("Extension Tests", function() {
const emptyLines = extension.exports.emptyLastCoverage;
const testCoverage = await vscode.workspace.findFiles("**/test-coverage.js", "**/node_modules/**");
const testDocument = await vscode.workspace.openTextDocument(testCoverage[0]);
const testEditor = await vscode.window.showTextDocument(testDocument);
await vscode.window.showTextDocument(testDocument);
await vscode.commands.executeCommand("extension.displayCoverage");

// Wait for decorations to load
Expand All @@ -29,6 +32,9 @@ suite("Extension Tests", function() {
});

test("Run display coverage on python test file @integration", async () => {
// Wait for extension to load
await sleep(2000);

const extension = await vscode.extensions.getExtension("ryanluker.vscode-coverage-gutters");
if (!extension) {
throw new Error("Could not load extension");
Expand All @@ -37,7 +43,7 @@ suite("Extension Tests", function() {
const emptyLines = extension.exports.emptyLastCoverage;
const testCoverage = await vscode.workspace.findFiles("**/bar/a.py", "**/node_modules/**");
const testDocument = await vscode.workspace.openTextDocument(testCoverage[0]);
const testEditor = await vscode.window.showTextDocument(testDocument);
await vscode.window.showTextDocument(testDocument);
await vscode.commands.executeCommand("extension.displayCoverage");

// Wait for decorations to load
Expand All @@ -51,6 +57,9 @@ suite("Extension Tests", function() {
});

test("Run display coverage on php test file number 1 @integration", async () => {
// Wait for extension to load
await sleep(2000);

const extension = await vscode.extensions.getExtension("ryanluker.vscode-coverage-gutters");
if (!extension) {
throw new Error("Could not load extension");
Expand All @@ -59,7 +68,7 @@ suite("Extension Tests", function() {
const emptyLines = extension.exports.emptyLastCoverage;
const testCoverage = await vscode.workspace.findFiles("**/main.php", "**/node_modules/**");
const testDocument = await vscode.workspace.openTextDocument(testCoverage[0]);
const testEditor = await vscode.window.showTextDocument(testDocument);
await vscode.window.showTextDocument(testDocument);
await vscode.commands.executeCommand("extension.displayCoverage");

// Wait for decorations to load
Expand All @@ -73,6 +82,9 @@ suite("Extension Tests", function() {
});

test("Run display coverage on php test file number 2 @integration", async () => {
// Wait for extension to load
await sleep(2000);

const extension = await vscode.extensions.getExtension("ryanluker.vscode-coverage-gutters");
if (!extension) {
throw new Error("Could not load extension");
Expand All @@ -81,7 +93,7 @@ suite("Extension Tests", function() {
const emptyLines = extension.exports.emptyLastCoverage;
const testCoverage = await vscode.workspace.findFiles("**/main2.php", "**/node_modules/**");
const testDocument = await vscode.workspace.openTextDocument(testCoverage[0]);
const testEditor = await vscode.window.showTextDocument(testDocument);
await vscode.window.showTextDocument(testDocument);
await vscode.commands.executeCommand("extension.displayCoverage");

// Wait for decorations to load
Expand All @@ -95,6 +107,9 @@ suite("Extension Tests", function() {
});

test("Run display coverage on java test file @integration", async () => {
// Wait for extension to load
await sleep(2000);

const extension = await vscode.extensions.getExtension("ryanluker.vscode-coverage-gutters");
if (!extension) {
throw new Error("Could not load extension");
Expand All @@ -103,7 +118,7 @@ suite("Extension Tests", function() {
const emptyLines = extension.exports.emptyLastCoverage;
const testCoverage = await vscode.workspace.findFiles("**/mycompany/app/App.java", "**/node_modules/**");
const testDocument = await vscode.workspace.openTextDocument(testCoverage[0]);
const testEditor = await vscode.window.showTextDocument(testDocument);
await vscode.window.showTextDocument(testDocument);
await vscode.commands.executeCommand("extension.displayCoverage");

// Wait for decorations to load
Expand Down
21 changes: 19 additions & 2 deletions test/extension/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ suite("Config Tests", function() {

getConfiguration: () => {
return {
get: () => "123",
coverageFileNames: ["test.xml", "lcov.info"],
get: (key) => {
if (key === "coverageFileNames") {
return ["test.xml", "lcov.info"];
} else if (key === "lcovname") {
return "lcov.info";
}
return "123";
},
lcovname: "lcov.info",
test1: "test1",
test2: "test2",
test3: "test3",
xmlname: "name.xml",
};
},
};
Expand All @@ -43,7 +53,14 @@ suite("Config Tests", function() {
test("Can get configStore after initialization @unit", function() {
const config = new Config(fakeVscode, fakeContext, fakeReport);
const store = config.get();
assert.notEqual(store.lcovFileName, null);
assert.notEqual(store.coverageFileNames, null);
});

test("Can get coverage file names @unit", function() {
const config = new Config(fakeVscode, fakeContext, fakeReport);
const store = config.get();
// Check that unique file names is being applied
assert.equal(store.coverageFileNames.length, 3);
});

test("Should remove gutter icons if path is blank, allows breakpoint usage @unit", function() {
Expand Down
3 changes: 1 addition & 2 deletions test/fakeConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { IConfigStore } from "../src/extension/config";

export const fakeConfig: IConfigStore = {
coverageFileNames: ["test.ts", "test.xml"],
fullCoverageDecorationType: {
key: "testKey",
dispose() { },
},
ignoredPathGlobs: ["test/*"],
lcovFileName: "test.ts",
noCoverageDecorationType: {
key: "testKey4",
dispose() { },
Expand All @@ -16,5 +16,4 @@ export const fakeConfig: IConfigStore = {
dispose() { },
},
showStatusBarToggler: true,
xmlFileName: "test.xml",
};

0 comments on commit 07d71bc

Please sign in to comment.