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
63 changes: 62 additions & 1 deletion __tests__/utils/general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {parseLCov} from '../../src/utils/lcov'
import {
filterCoverageByFile,
coalesceLineNumbers,
intersectLineRanges
intersectLineRanges,
correctLineTotals
} from '../../src/utils/general'

test('filterCoverageByFile', async function () {
Expand Down Expand Up @@ -48,3 +49,63 @@ test('range intersections', function () {

expect(intersectLineRanges(a, b)).toEqual(expected)
})

test('correctLineTotals', function () {
const mockCoverage = [
{
file: 'test.ts',
title: 'Test File',
lines: {
found: 0, // Incorrect initial value
hit: 0, // Incorrect initial value
details: [
{line: 1, hit: 1, name: 'line1'},
{line: 2, hit: 0, name: 'line2'},
{line: 3, hit: 2, name: 'line3'},
{line: 4, hit: 0, name: 'line4'}
]
}
}
]

const result = correctLineTotals(mockCoverage)
expect(result[0].lines.found).toBe(4)
expect(result[0].lines.hit).toBe(2)
expect(result[0].file).toBe('test.ts')
expect(result[0].title).toBe('Test File')

// Test with multiple files
const multiFileMock = [
{
file: 'file1.ts',
title: 'File 1',
lines: {
found: 0,
hit: 0,
details: [
{line: 1, hit: 1, name: 'line1'},
{line: 2, hit: 1, name: 'line2'}
]
}
},
{
file: 'file2.ts',
title: 'File 2',
lines: {
found: 0,
hit: 0,
details: [
{line: 1, hit: 0, name: 'line1'},
{line: 2, hit: 0, name: 'line2'},
{line: 3, hit: 1, name: 'line3'}
]
}
}
]

const multiResult = correctLineTotals(multiFileMock)
expect(multiResult[0].lines.found).toBe(2)
expect(multiResult[0].lines.hit).toBe(2)
expect(multiResult[1].lines.found).toBe(3)
expect(multiResult[1].lines.hit).toBe(1)
})
8 changes: 7 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {env} from 'node:process'
import * as core from '@actions/core'
import * as github from '@actions/github'
import {filterCoverageByFile} from './utils/general'
import {correctLineTotals, filterCoverageByFile} from './utils/general'
import {parseLCov} from './utils/lcov'
import {parseClover} from './utils/clover'
import {parseGoCoverage} from './utils/gocoverage'
Expand Down Expand Up @@ -56,6 +56,9 @@ export async function play(): Promise<void> {
// lcov default
var parsedCov = await parseLCov(COVERAGE_FILE_PATH, workspacePath)
}
// Correct line totals
parsedCov = correctLineTotals(parsedCov)

// Sum up lines.found for each entry in parsedCov
const totalLines = parsedCov.reduce(
(acc, entry) => acc + entry.lines.found,
Expand Down
11 changes: 11 additions & 0 deletions src/utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ export function intersectLineRanges(
return result
}

export function correctLineTotals(coverage: CoverageParsed): CoverageParsed {
return coverage.map(item => ({
...item,
lines: {
...item.lines,
found: item.lines.details.length,
hit: item.lines.details.filter(line => line.hit > 0).length
}
}))
}

export type CoverageParsed = {
file: string
title: string
Expand Down