Skip to content

Commit c09fc48

Browse files
authored
feat: include better error logging (#235)
* feat: include better error logging * chore: removed redundant test
1 parent 318adf4 commit c09fc48

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

index.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,28 @@ function shouldCalculateCoverageForFile(fileName, excludedFiles) {
7979
}
8080

8181
function canParse(path) {
82-
if (fs.existsSync(path) && fs.readFileSync(path).length === 0) {
83-
core.setFailed('lcov is empty!');
82+
if (!fs.existsSync(path)) {
83+
core.setFailed(
84+
`❌ Failed to find an lcov file at ${path}.
85+
Make sure to generate an lcov file before running VeryGoodCoverage and set the \
86+
path input to the correct location.
87+
88+
For example:
89+
uses: VeryGoodOpenSource/very_good_coverage@v2
90+
with:
91+
path: 'my_project/coverage/lcov.info'
92+
`
93+
);
94+
return false;
95+
}
96+
97+
if (fs.readFileSync(path).length === 0) {
98+
core.setFailed(
99+
`❌ Found an empty lcov file at "${path}".
100+
An empty lcov file was found but with no coverage data. This might be because \
101+
you have no test files or your tests are not generating any coverage data.
102+
`
103+
);
84104
return false;
85105
}
86106

index.test.js

+32-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,38 @@ test('empty LCOV throws an error', () => {
2222
} catch (err) {
2323
expect(err).toBeDefined();
2424

25-
const errorMessage = err.stdout.toString();
26-
expect(errorMessage).toContain('lcov is empty!');
25+
const errorMessage = err.stdout.toString().replace(/%0A/g, '\n');
26+
expect(errorMessage).toContain(
27+
`❌ Found an empty lcov file at "${lcovPath}".
28+
An empty lcov file was found but with no coverage data. This might be because \
29+
you have no test files or your tests are not generating any coverage data.
30+
`
31+
);
32+
}
33+
});
34+
35+
test('non-existent LCOV throws an error', () => {
36+
const lcovPath = './fixtures/not-found.info';
37+
process.env['INPUT_PATH'] = lcovPath;
38+
const ip = path.join(__dirname, 'index.js');
39+
try {
40+
cp.execSync(`node ${ip}`, { env: process.env });
41+
fail('this code should fail');
42+
} catch (err) {
43+
expect(err).toBeDefined();
44+
45+
const errorMessage = err.stdout.toString().replace(/%0A/g, '\n');
46+
expect(errorMessage).toContain(
47+
`❌ Failed to find an lcov file at ${lcovPath}.
48+
Make sure to generate an lcov file before running VeryGoodCoverage and set the \
49+
path input to the correct location.
50+
51+
For example:
52+
uses: VeryGoodOpenSource/very_good_coverage@v2
53+
with:
54+
path: 'my_project/coverage/lcov.info'
55+
`
56+
);
2757
}
2858
});
2959

0 commit comments

Comments
 (0)