Skip to content
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
26 changes: 18 additions & 8 deletions src/coverage-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,24 @@ export class CoverageParser {

private recomputeStats(data: any[] ) {
data.forEach((section) => {
if(!section.hit || !section.found){
if(!section.lines.hit || !section.lines.found){
section.lines.hit = section.lines.details.reduce((a, b) => a + (b.hit > 0 ? 1 : 0), 0);
section.lines.found = section.lines.details.length;
}
});
}

private async convertSectionsToMap(workspaceFolder: vscode.WorkspaceFolder, data: Section[]): Promise<Map<string, Section>> {
private async convertSectionsToMap(workspaceFolder: vscode.WorkspaceFolder, filename: string, data: Section[]): Promise<Map<string, Section>> {
this.recomputeStats(data);

const sections = new Map<string, Section>();
const addToSectionsMap = async (section: { title: string; file: string; }) => {
this.recomputeStats(data);
const intermediatePath = this.stripPath(filename);
let filePath = section.file;
if(iopath.isAbsolute(section.file)){
if (!!intermediatePath) {
filePath = iopath.join(intermediatePath, filePath);
}
if(iopath.isAbsolute(section.file) || filePath.includes(workspaceFolder.uri.fsPath)){
//Convert to a path relative to the workspace root
filePath = filePath.replace(workspaceFolder.uri.fsPath, "");
}
Expand Down Expand Up @@ -100,7 +105,7 @@ export class CoverageParser {
try {
parseContentCobertura(xmlFile, async (err: any, data: any[]) => {
checkError(err);
const sections = await this.convertSectionsToMap(workspaceFolder, data);
const sections = await this.convertSectionsToMap(workspaceFolder, filename, data);
return resolve(sections);
}, true);
} catch (error) {
Expand All @@ -122,7 +127,7 @@ export class CoverageParser {
try {
parseContentJacoco(xmlFile, async (err: any, data: any[]) => {
checkError(err);
const sections = await this.convertSectionsToMap(workspaceFolder, data);
const sections = await this.convertSectionsToMap(workspaceFolder, filename, data);
return resolve(sections);
});
} catch (error) {
Expand All @@ -134,7 +139,7 @@ export class CoverageParser {
private async xmlExtractClover(workspaceFolder: vscode.WorkspaceFolder, filename: string, xmlFile: string) {
try {
const data = await parseContentClover(xmlFile);
const sections = await this.convertSectionsToMap(workspaceFolder, data);
const sections = await this.convertSectionsToMap(workspaceFolder, filename, data);
return sections;
} catch (error) {
error.message = `filename: ${filename} ${error.message}`;
Expand All @@ -156,7 +161,7 @@ export class CoverageParser {
try {
source(lcovFile, async (err: Error, data: any[]) => {
checkError(err);
const sections = await this.convertSectionsToMap(workspaceFolder, data);
const sections = await this.convertSectionsToMap(workspaceFolder, filename, data);
return resolve(sections);
});
} catch (error) {
Expand All @@ -172,4 +177,9 @@ export class CoverageParser {
`[${Date.now()}][coverageparser][${system}]: Error: ${message}\n${stackTrace}`,
);
}

// Removes the coverage dir and file from coverage path
private stripPath(filename: String) {
return (filename || '').split('/').slice(0, -2).join('/');
}
}
2 changes: 1 addition & 1 deletion src/data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class FileCoverageDataProvider implements vscode.TreeDataProvider<Coverag
let rootProjectPath = vscode.workspace.workspaceFolders[0].uri.fsPath;
let coveragePath = iopath.join(rootProjectPath, `${this.configStore.current.coverageFilePaths}`);
vscode.workspace.fs.delete(vscode.Uri.parse(coveragePath), { recursive: true });
this.logger.info('Cleaning coverage workspace with success')
this.logger.info('Cleaning coverage workspace with success');
}
}
}
Expand Down
19 changes: 10 additions & 9 deletions src/files-loader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscodeLogging from '@vscode-logging/logger';
import * as fs from 'fs';
import * as glob from 'glob';
import { readFile } from "fs";
import * as iopath from "path";
import * as vscode from 'vscode';
Expand Down Expand Up @@ -30,15 +30,16 @@ export class FilesLoader {
for (const workspaceFolder of vscode.workspace.workspaceFolders) {
for (const filePath of filesPaths) {
for (const fileName of fileNames) {
const testPath = iopath.join(filePath, fileName);
const coveragePaths: string[] = glob.sync(testPath, { cwd: workspaceFolder.uri.fsPath }) || [];
this.logger.debug(`total files found: ${coveragePaths.length}`);

const coverageFileFullPath = iopath.join(workspaceFolder.uri.fsPath, filePath, fileName);

if (fs.existsSync(coverageFileFullPath) && fs.lstatSync(coverageFileFullPath).isFile()) {

if (!coverageFiles.has(workspaceFolder.uri.fsPath)){
coverageFiles.set(workspaceFolder.uri.fsPath, new WorkspaceFolderCoverageFiles(workspaceFolder));
}
coverageFiles.get(workspaceFolder.uri.fsPath)?.coverageFiles.add(new WorkspaceFolderCoverageFile(coverageFileFullPath, await this.load(coverageFileFullPath)));
if (!!coveragePaths.length && !coverageFiles.has(workspaceFolder.uri.fsPath)){
coverageFiles.set(workspaceFolder.uri.fsPath, new WorkspaceFolderCoverageFiles(workspaceFolder));
}
for (const coveragePath of coveragePaths) {
const filePath = iopath.join(workspaceFolder.uri.fsPath, coveragePath);
coverageFiles.get(workspaceFolder.uri.fsPath)?.coverageFiles.add(new WorkspaceFolderCoverageFile(filePath, await this.load(filePath)));
}
}
}
Expand Down