Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(coverage): fix sourcemaps of uncovered lines #2122

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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')
}