calculate percentage for lcov file
This commit is contained in:
parent
80ba4ab18c
commit
22c7408fb4
@ -30,12 +30,12 @@ class CoverageReport
|
|||||||
def lcov_covered_percent(lcov_result)
|
def lcov_covered_percent(lcov_result)
|
||||||
lines = lcov_result.map { |r| r['lines']['details'] }.flatten
|
lines = lcov_result.map { |r| r['lines']['details'] }.flatten
|
||||||
total_lines = lines.count&.to_f
|
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
|
(covered_lines / total_lines) * 100
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute_lcov_parse(report_path)
|
def execute_lcov_parse(report_path)
|
||||||
`node bin/lcov-parse.js #{report_path}`
|
JSON.parse(`node bin/lcov-parse.js #{report_path}`)
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_json(path)
|
def read_json(path)
|
||||||
|
|||||||
@ -9,7 +9,7 @@ describe CoverageReport do
|
|||||||
# end
|
# end
|
||||||
|
|
||||||
it '.lcov' do
|
it '.lcov' do
|
||||||
result = CoverageReport.lcov('./spec/fixtures/example.lcov', { min: 80 })
|
result = CoverageReport.lcov('./spec/fixtures/example.lcov', min: 80)
|
||||||
expect(result['lines']['covered_percent']).to eq('sas')
|
expect(result['lines']['covered_percent']).to eq(85.60606060606061)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user