Skip to content

Commit

Permalink
fix(coverage): fix sourcemaps of uncovered lines (#2122)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Oct 8, 2022
1 parent 0bd3788 commit af3ad61
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/coverage-istanbul/src/provider.ts
Expand Up @@ -211,7 +211,7 @@ export class IstanbulCoverageProvider implements CoverageProvider {

const lastCoverage = this.instrumenter.lastFileCoverage()
if (lastCoverage)
coverageMap.data[lastCoverage.path] = lastCoverage
coverageMap.addFileCoverage(lastCoverage)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/coverage-test/coverage-test/coverage.istanbul.test.ts
Expand Up @@ -3,7 +3,7 @@ import { resolve } from 'pathe'
import { expect, test } from 'vitest'

test('istanbul html report', async () => {
const coveragePath = resolve('./coverage/coverage-test/src')
const coveragePath = resolve('./coverage')
const files = fs.readdirSync(coveragePath)

expect(files).toContain('index.html')
Expand All @@ -24,7 +24,7 @@ test('istanbul lcov report', async () => {
})

test('all includes untested files', () => {
const coveragePath = resolve('./coverage/coverage-test/src')
const coveragePath = resolve('./coverage')
const files = fs.readdirSync(coveragePath)

expect(files).toContain('untested-file.ts.html')
Expand Down
30 changes: 30 additions & 0 deletions test/coverage-test/src/untested-file.ts
@@ -1,3 +1,33 @@
/*
* Some top level comment which adds some padding. This helps us see
* if sourcemaps are off.
*/

export default function untestedFile() {
return 'This file should end up in report when {"all": true} is given'
}

function add(a: number, b: number) {
// This line should NOT be covered
return a + b
}

function multiply(a: number, b: number) {
// This line should NOT be covered
return a * b
}

export function math(a: number, b: number, operator: '*' | '+') {
if (operator === '*') {
// This line should NOT be covered
return multiply(a, b)
}

if (operator === '+') {
// This line should NOT be covered
return add(a, b)
}

// This line should NOT be covered
throw new Error('Unsupported operator')
}

0 comments on commit af3ad61

Please sign in to comment.