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

fix: throw "lcov is empty" instead of "parsing error!" #104

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Empty file added fixtures/lcov.empty.info
Empty file.
16 changes: 15 additions & 1 deletion index.js
@@ -1,14 +1,19 @@
const core = require('@actions/core');
const minimatch = require('minimatch');
const parse = require('lcov-parse');
const fs = require('fs');

function run() {
const lcovPath = core.getInput('path');
const minCoverage = core.getInput('min_coverage');
const excluded = core.getInput('exclude');
const excludedFiles = excluded.split(' ');

parse(lcovPath, (_, data) => {
if (!canParse(lcovPath)) {
return;
}

parse(lcovPath, (err, data) => {
if (typeof data === 'undefined') {
core.setFailed('parsing error!');
return;
Expand Down Expand Up @@ -65,4 +70,13 @@ function shouldCalculateCoverageForFile(fileName, excludedFiles) {
return true;
}

function canParse(path) {
if (fs.existsSync(path) && fs.readFileSync(path).length === 0) {
core.setFailed('lcov is empty!');
return false;
}

return true;
}

run();
18 changes: 18 additions & 0 deletions index.test.js
Expand Up @@ -12,6 +12,21 @@ const getErrorOutput = (error) => {
return output;
};

test('empty LCOV throws an error', () => {
const lcovPath = './fixtures/lcov.empty.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();
expect(errorMessage).toContain('lcov is empty!');
}
});

test('invalid LCOV format throws an error', () => {
const lcovPath = './fixtures/lcov.error.info';
process.env['INPUT_PATH'] = lcovPath;
Expand All @@ -21,6 +36,9 @@ test('invalid LCOV format throws an error', () => {
fail('this code should fail');
} catch (err) {
expect(err).toBeDefined();

const errorMessage = err.stdout.toString();
expect(errorMessage).toContain('parsing error!');
}
});

Expand Down