Skip to content

Commit

Permalink
fix: report coverage with negative columns (#557)
Browse files Browse the repository at this point in the history
Fixes #556
  • Loading branch information
sheremet-va authored Dec 16, 2024
1 parent 4f41223 commit b6c4bf7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,25 @@ export class TestRunner extends vscode.Disposable {
return

const coverage = readCoverageReport(reportsDirectory)
// TODO: quick patch, coverage shouldn't report negative columns
function ensureLoc(loc: any) {
if (!loc) {
return
}
if (loc.start?.column && loc.start.column < 0) {
loc.start.column = 0
}
if (loc.end?.column && loc.end.column < 0) {
loc.end.column = 0
}
}
for (const file in coverage) {
for (const key in coverage[file].branchMap) {
const branch = coverage[file].branchMap[key]
ensureLoc(branch.loc)
branch.locations?.forEach((loc: any) => ensureLoc(loc))
}
}
await coverageContext.applyJson(testRun, coverage)

rm(reportsDirectory, { recursive: true, force: true }).then(() => {
Expand Down
6 changes: 4 additions & 2 deletions src/testTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class TestTree extends vscode.Disposable {
// file test items have the project name in their id, so we need a separate map
// to store all of them
private testItemsByFile = new Map<string, vscode.TestItem[]>()
private testFiles = new Set<string>()

private watcher: ExtensionWatcher

Expand Down Expand Up @@ -134,7 +135,7 @@ export class TestTree extends vscode.Disposable {
if (cached)
return cached

const fileUri = vscode.Uri.file(file)
const fileUri = vscode.Uri.file(resolve(file))
const parentItem = this.getOrCreateFolderTestItem(api, dirname(file))
const label = `${basename(file)}${project ? ` [${project}]` : ''}`
const testFileItem = this.controller.createTestItem(
Expand All @@ -159,10 +160,11 @@ export class TestTree extends vscode.Disposable {
const cachedItems = this.testItemsByFile.get(normalizedFile) || []
cachedItems.push(testFileItem)
this.testItemsByFile.set(normalizedFile, cachedItems)
this.testFiles.add(fileUri.fsPath)
vscode.commands.executeCommand(
'setContext',
'vitest.testFiles',
Array.from(this.testItemsByFile.keys()),
Array.from(this.testFiles),
)

return testFileItem
Expand Down

0 comments on commit b6c4bf7

Please sign in to comment.