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: log coverage when is a valid build #189

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 12 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

24 changes: 16 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,26 @@ function run() {
});
const coverage = (totalHits / totalFinds) * 100;
const isValidBuild = coverage >= minCoverage;
const linesMissingCoverageByFile = Object.entries(linesMissingCoverage).map(
([file, lines]) => {
return `- ${file}: ${lines.join(', ')}`;
}
);
let linesMissingCoverageMessage = `Lines not covered:\n` +
linesMissingCoverageByFile.map((line) => ` ${line}`).join('\n');
if (!isValidBuild) {
const linesMissingCoverageByFile = Object.entries(
linesMissingCoverage
).map(([file, lines]) => {
return `${file}: ${lines.join(', ')}`;
});

core.setFailed(
`${coverage} is less than min_coverage ${minCoverage}\n\n` +
'Lines not covered:\n' +
linesMissingCoverageByFile.map((line) => ` ${line}`).join('\n')
linesMissingCoverageMessage
);
} else {
var resultMessage = `Coverage: ${coverage}%.\n`;
if (coverage < 100) {
resultMessage += `Coverage is more than min_coverage ${minCoverage}.\n\n`
felangel marked this conversation as resolved.
Show resolved Hide resolved
resultMessage += linesMissingCoverageMessage;

}
core.info(resultMessage);
}
});
}
Expand Down
34 changes: 33 additions & 1 deletion index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ test('completes when the coverage is 100 and min_coverage is not provided', () =
cp.execSync(`node ${ip}`, { env: process.env }).toString();
});

test('logs message when the coverage is 100 and min_coverage is not provided', () => {
const lcovPath = './fixtures/lcov.100.info';
process.env['INPUT_PATH'] = lcovPath;
const ip = path.join(__dirname, 'index.js');
let result = cp.execSync(`node ${ip}`, { env: process.env }).toString();
expect(result).toContain('Coverage: 100%.')
});

test('completes when the coverage is higher than the threshold after excluding files', () => {
const lcovPath = './fixtures/lcov.100.info';
const exclude = '**/*_observer.dart';
Expand Down Expand Up @@ -84,13 +92,24 @@ test('fails when the coverage is below the min_coverage, even if we exclude file
}
});

test('completes when the coverage is above the given min_threshold', () => {
test('show message when the coverage is above the given min_threshold', () => {
const lcovPath = './fixtures/lcov.95.info';
const minCoverage = 80;
process.env['INPUT_PATH'] = lcovPath;
process.env['INPUT_MIN_COVERAGE'] = minCoverage;
const ip = path.join(__dirname, 'index.js');
cp.execSync(`node ${ip}`, { env: process.env }).toString();
});

test('show message when the coverage is above the given min_threshold', () => {
const lcovPath = './fixtures/lcov.95.info';
const minCoverage = 80;
process.env['INPUT_PATH'] = lcovPath;
process.env['INPUT_MIN_COVERAGE'] = minCoverage;
const ip = path.join(__dirname, 'index.js');
cp.execSync(`node ${ip}`, { env: process.env }).toString();
let result = cp.execSync(`node ${ip}`, { env: process.env }).toString();
expect(result).toContain('Coverage: 95%.\nCoverage is more than min_coverage 80.')
felangel marked this conversation as resolved.
Show resolved Hide resolved
});

test('fails when the coverage is below the given min_threshold', () => {
Expand Down Expand Up @@ -124,3 +143,16 @@ test('shows lines that are missing coverage when failure occurs', () => {
);
}
});

test('shows lines that are missing coverage when coverage is less than 100%', () => {
const lcovPath = './fixtures/lcov.95.info';
const minCoverage = 80;
process.env['INPUT_PATH'] = lcovPath;
process.env['INPUT_MIN_COVERAGE'] = minCoverage;
const ip = path.join(__dirname, 'index.js');
let result = cp.execSync(`node ${ip}`, { env: process.env }).toString();
expect(result).toContain('Lines not covered');
expect(result).toContain(
'/Users/felix/Development/github.com/felangel/bloc/packages/bloc/lib/src/bloc_observer.dart: 20, 27, 36, 43, 51'
);
});