Skip to content

Commit

Permalink
Add Ruby support (#21)
Browse files Browse the repository at this point in the history
* Add Ruby instructions

* Handle relative paths in lcov files

* Remove deprecated upload artifact action (not needed)
  • Loading branch information
ggilder authored Dec 16, 2024
1 parent 0c1b2a3 commit 7f086b8
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 20 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,3 @@ jobs:
exit 1
fi
id: diff

# If index.js was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@v2
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: dist
path: dist/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Set up `npm run test:cov` in your `package.json` scripts to run `jest --coverage
* Java/Groovy can use Clover format
* PHPUnit will output Clover with the [`--coverage-clover` flag](https://docs.phpunit.de/en/10.2/textui.html#code-coverage)
* C++: GCC Gcov can output Lcov format; [this blog post](https://shenxianpeng.github.io/2021/07/gcov-example/) may help you get started.
* Ruby: Simplecov can output Lcov format when you add the [`simplecov-lcov`](https://github.com/fortissimo1997/simplecov-lcov) gem to your Gemfile. Make sure to set `SimpleCov::Formatter::LcovFormatter.config.report_with_single_file` to `true` and provide the path to the output file using `COVERAGE_FILE_PATH` as described above.

## Contributing

Expand Down
6 changes: 3 additions & 3 deletions __tests__/fixtures/lcov.info
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TN:
SF:src/utils/general.ts
SF:./src/utils/general.ts
FN:2,getFileNameFirstItemFromPath
FNF:1
FNH:0
Expand Down Expand Up @@ -29,7 +29,7 @@ BRF:16
BRH:0
end_of_record
TN:
SF:src/utils/github.ts
SF:./src/utils/github.ts
FN:10,(anonymous_13)
FN:17,(anonymous_14)
FN:27,(anonymous_15)
Expand Down Expand Up @@ -95,7 +95,7 @@ BRF:15
BRH:0
end_of_record
TN:
SF:src/utils/lcov.ts
SF:./src/utils/lcov.ts
FN:5,parseLCov
FN:14,filterCoverageByFile
FN:15,(anonymous_17)
Expand Down
2 changes: 1 addition & 1 deletion __tests__/utils/general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

test('filterCoverageByFile', async function () {
const path = getFixturePath('lcov.info')
const parsedLcov = await parseLCov(path)
const parsedLcov = await parseLCov(path, '')
const output = filterCoverageByFile(parsedLcov)
expect(output).toMatchSnapshot()
})
Expand Down
4 changes: 2 additions & 2 deletions __tests__/utils/lcov.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {getFixturePath} from '../fixtures/util'

test('should parse lCov file', async function () {
const path = getFixturePath('lcov.info')
const output = await parseLCov(path)
const output = await parseLCov(path, process.cwd())
expect(output).toMatchSnapshot()
})

test('should throw err if lCov file path is not given', async function () {
await expect(parseLCov('')).rejects.toThrow('No LCov path provided')
await expect(parseLCov('', '')).rejects.toThrow('No LCov path provided')
})
11 changes: 8 additions & 3 deletions 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.

2 changes: 1 addition & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function play(): Promise<void> {
var parsedCov = await parseGoCoverage(COVERAGE_FILE_PATH, 'go.mod')
} else {
// lcov default
var parsedCov = await parseLCov(COVERAGE_FILE_PATH)
var parsedCov = await parseLCov(COVERAGE_FILE_PATH, workspacePath)
}
// Sum up lines.found for each entry in parsedCov
const totalLines = parsedCov.reduce(
Expand Down
15 changes: 13 additions & 2 deletions src/utils/lcov.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import * as NodeUtil from 'util'
import * as fs from 'fs'
import * as path from 'path'
import {CoverageParsed} from './general'
import parser from 'lcov-parse'

export async function parseLCov(lcovPath: string): Promise<CoverageParsed> {
export async function parseLCov(
lcovPath: string,
workspacePath: string
): Promise<CoverageParsed> {
if (!lcovPath) {
throw Error('No LCov path provided')
}

const parserPromise = NodeUtil.promisify(parser)
const fileRaw = fs.readFileSync(lcovPath, 'utf8')
return parserPromise(fileRaw) as CoverageParsed
const parsed = (await parserPromise(fileRaw)) as CoverageParsed

for (const entry of parsed) {
entry.file = path.relative(workspacePath, entry.file)
}

return parsed
}

0 comments on commit 7f086b8

Please sign in to comment.