Skip to content

Commit e7f28f5

Browse files
authored
feat: log coverage when is a valid build (#189)
1 parent d967ca4 commit e7f28f5

File tree

4 files changed

+68
-18
lines changed

4 files changed

+68
-18
lines changed

dist/index.js

+16-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,26 @@ function run() {
4343
});
4444
const coverage = (totalHits / totalFinds) * 100;
4545
const isValidBuild = coverage >= minCoverage;
46+
const linesMissingCoverageByFile = Object.entries(linesMissingCoverage).map(
47+
([file, lines]) => {
48+
return `- ${file}: ${lines.join(', ')}`;
49+
}
50+
);
51+
let linesMissingCoverageMessage =
52+
`Lines not covered:\n` +
53+
linesMissingCoverageByFile.map((line) => ` ${line}`).join('\n');
4654
if (!isValidBuild) {
47-
const linesMissingCoverageByFile = Object.entries(
48-
linesMissingCoverage
49-
).map(([file, lines]) => {
50-
return `${file}: ${lines.join(', ')}`;
51-
});
52-
5355
core.setFailed(
5456
`${coverage} is less than min_coverage ${minCoverage}\n\n` +
55-
'Lines not covered:\n' +
56-
linesMissingCoverageByFile.map((line) => ` ${line}`).join('\n')
57+
linesMissingCoverageMessage
5758
);
59+
} else {
60+
var resultMessage = `Coverage: ${coverage}%.\n`;
61+
if (coverage < 100) {
62+
resultMessage += `${coverage} is greater than or equal to min_coverage ${minCoverage}.\n\n`;
63+
resultMessage += linesMissingCoverageMessage;
64+
}
65+
core.info(resultMessage);
5866
}
5967
});
6068
}

index.test.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ test('completes when the coverage is 100 and min_coverage is not provided', () =
4949
cp.execSync(`node ${ip}`, { env: process.env }).toString();
5050
});
5151

52+
test('logs message when the coverage is 100 and min_coverage is not provided', () => {
53+
const lcovPath = './fixtures/lcov.100.info';
54+
process.env['INPUT_PATH'] = lcovPath;
55+
const ip = path.join(__dirname, 'index.js');
56+
let result = cp.execSync(`node ${ip}`, { env: process.env }).toString();
57+
expect(result).toContain('Coverage: 100%.');
58+
});
59+
5260
test('completes when the coverage is higher than the threshold after excluding files', () => {
5361
const lcovPath = './fixtures/lcov.100.info';
5462
const exclude = '**/*_observer.dart';
@@ -84,13 +92,26 @@ test('fails when the coverage is below the min_coverage, even if we exclude file
8492
}
8593
});
8694

87-
test('completes when the coverage is above the given min_threshold', () => {
95+
test('show message when the coverage is above the given min_threshold', () => {
96+
const lcovPath = './fixtures/lcov.95.info';
97+
const minCoverage = 80;
98+
process.env['INPUT_PATH'] = lcovPath;
99+
process.env['INPUT_MIN_COVERAGE'] = minCoverage;
100+
const ip = path.join(__dirname, 'index.js');
101+
cp.execSync(`node ${ip}`, { env: process.env }).toString();
102+
});
103+
104+
test('show message when the coverage is above the given min_threshold', () => {
88105
const lcovPath = './fixtures/lcov.95.info';
89106
const minCoverage = 80;
90107
process.env['INPUT_PATH'] = lcovPath;
91108
process.env['INPUT_MIN_COVERAGE'] = minCoverage;
92109
const ip = path.join(__dirname, 'index.js');
93110
cp.execSync(`node ${ip}`, { env: process.env }).toString();
111+
let result = cp.execSync(`node ${ip}`, { env: process.env }).toString();
112+
expect(result).toContain(
113+
'Coverage: 95%.\n95 is greater than or equal to min_coverage 80.'
114+
);
94115
});
95116

96117
test('fails when the coverage is below the given min_threshold', () => {
@@ -124,3 +145,16 @@ test('shows lines that are missing coverage when failure occurs', () => {
124145
);
125146
}
126147
});
148+
149+
test('shows lines that are missing coverage when coverage is less than 100%', () => {
150+
const lcovPath = './fixtures/lcov.95.info';
151+
const minCoverage = 80;
152+
process.env['INPUT_PATH'] = lcovPath;
153+
process.env['INPUT_MIN_COVERAGE'] = minCoverage;
154+
const ip = path.join(__dirname, 'index.js');
155+
let result = cp.execSync(`node ${ip}`, { env: process.env }).toString();
156+
expect(result).toContain('Lines not covered');
157+
expect(result).toContain(
158+
'/Users/felix/Development/github.com/felangel/bloc/packages/bloc/lib/src/bloc_observer.dart: 20, 27, 36, 43, 51'
159+
);
160+
});

0 commit comments

Comments
 (0)