Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include better error logging #235

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,28 @@ function shouldCalculateCoverageForFile(fileName, excludedFiles) {
}

function canParse(path) {
if (fs.existsSync(path) && fs.readFileSync(path).length === 0) {
core.setFailed('lcov is empty!');
if (!fs.existsSync(path)) {
core.setFailed(
`❌ Failed to find an lcov file at ${path}.
Make sure to generate an lcov file before running VeryGoodCoverage and set the \
path input to the correct location.

For example:
uses: VeryGoodOpenSource/very_good_coverage@v2
with:
path: 'my_project/coverage/lcov.info'
`
);
return false;
}

if (fs.readFileSync(path).length === 0) {
core.setFailed(
`❌ Found an empty lcov file at "${path}".
An empty lcov file was found but with no coverage data. This might be because \
you have no test files or your tests are not generating any coverage data.
`
);
return false;
}

Expand Down
34 changes: 32 additions & 2 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,38 @@ test('empty LCOV throws an error', () => {
} catch (err) {
expect(err).toBeDefined();

const errorMessage = err.stdout.toString();
expect(errorMessage).toContain('lcov is empty!');
const errorMessage = err.stdout.toString().replace(/%0A/g, '\n');
expect(errorMessage).toContain(
`❌ Found an empty lcov file at "${lcovPath}".
An empty lcov file was found but with no coverage data. This might be because \
you have no test files or your tests are not generating any coverage data.
`
);
}
});

test('non-existent LCOV throws an error', () => {
const lcovPath = './fixtures/not-found.info';
process.env['INPUT_PATH'] = lcovPath;
const ip = path.join(__dirname, 'index.js');
try {
cp.execSync(`node ${ip}`, { env: process.env });
fail('this code should fail');
} catch (err) {
expect(err).toBeDefined();

const errorMessage = err.stdout.toString().replace(/%0A/g, '\n');
expect(errorMessage).toContain(
`❌ Failed to find an lcov file at ${lcovPath}.
Make sure to generate an lcov file before running VeryGoodCoverage and set the \
path input to the correct location.

For example:
uses: VeryGoodOpenSource/very_good_coverage@v2
with:
path: 'my_project/coverage/lcov.info'
`
);
}
});

Expand Down