Skip to content

Commit 49de719

Browse files
authored
fix: throw "lcov is empty" instead of "parsing error!" (#104)
1 parent ff39e7f commit 49de719

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

fixtures/lcov.empty.info

Whitespace-only changes.

index.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
const core = require('@actions/core');
22
const minimatch = require('minimatch');
33
const parse = require('lcov-parse');
4+
const fs = require('fs');
45

56
function run() {
67
const lcovPath = core.getInput('path');
78
const minCoverage = core.getInput('min_coverage');
89
const excluded = core.getInput('exclude');
910
const excludedFiles = excluded.split(' ');
1011

11-
parse(lcovPath, (_, data) => {
12+
if (!canParse(lcovPath)) {
13+
return;
14+
}
15+
16+
parse(lcovPath, (err, data) => {
1217
if (typeof data === 'undefined') {
1318
core.setFailed('parsing error!');
1419
return;
@@ -65,4 +70,13 @@ function shouldCalculateCoverageForFile(fileName, excludedFiles) {
6570
return true;
6671
}
6772

73+
function canParse(path) {
74+
if (fs.existsSync(path) && fs.readFileSync(path).length === 0) {
75+
core.setFailed('lcov is empty!');
76+
return false;
77+
}
78+
79+
return true;
80+
}
81+
6882
run();

index.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ const getErrorOutput = (error) => {
1212
return output;
1313
};
1414

15+
test('empty LCOV throws an error', () => {
16+
const lcovPath = './fixtures/lcov.empty.info';
17+
process.env['INPUT_PATH'] = lcovPath;
18+
const ip = path.join(__dirname, 'index.js');
19+
try {
20+
cp.execSync(`node ${ip}`, { env: process.env });
21+
fail('this code should fail');
22+
} catch (err) {
23+
expect(err).toBeDefined();
24+
25+
const errorMessage = err.stdout.toString();
26+
expect(errorMessage).toContain('lcov is empty!');
27+
}
28+
});
29+
1530
test('invalid LCOV format throws an error', () => {
1631
const lcovPath = './fixtures/lcov.error.info';
1732
process.env['INPUT_PATH'] = lcovPath;
@@ -21,6 +36,9 @@ test('invalid LCOV format throws an error', () => {
2136
fail('this code should fail');
2237
} catch (err) {
2338
expect(err).toBeDefined();
39+
40+
const errorMessage = err.stdout.toString();
41+
expect(errorMessage).toContain('parsing error!');
2442
}
2543
});
2644

0 commit comments

Comments
 (0)