calculate percentage for lcov file

This commit is contained in:
Miguel Savignano 2019-11-03 01:20:47 +01:00
parent 80ba4ab18c
commit 22c7408fb4
2 changed files with 4 additions and 4 deletions

View File

@ -30,12 +30,12 @@ class CoverageReport
def lcov_covered_percent(lcov_result)
lines = lcov_result.map { |r| r['lines']['details'] }.flatten
total_lines = lines.count&.to_f
covered_lines = lines.select { |r| r['hit'] == 1 }.count&.to_f
covered_lines = lines.select { |r| r['hit'] >= 1 }.count&.to_f
(covered_lines / total_lines) * 100
end
def execute_lcov_parse(report_path)
`node bin/lcov-parse.js #{report_path}`
JSON.parse(`node bin/lcov-parse.js #{report_path}`)
end
def read_json(path)

View File

@ -9,7 +9,7 @@ describe CoverageReport do
# end
it '.lcov' do
result = CoverageReport.lcov('./spec/fixtures/example.lcov', { min: 80 })
expect(result['lines']['covered_percent']).to eq('sas')
result = CoverageReport.lcov('./spec/fixtures/example.lcov', min: 80)
expect(result['lines']['covered_percent']).to eq(85.60606060606061)
end
end