Skip to content

Commit eedea3b

Browse files
authored
Merge pull request #245 from bp-cos/feature/local-pipeline-warn
feat(warns): Updated the pipeline locally to be a warn
2 parents 8b9c92d + 76a5f2c commit eedea3b

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

.github/scripts/check-coverage-thresholds.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,55 @@ const thresholds = jestConfig.coverageThreshold.global;
88

99
let failed = false;
1010
const errors = [];
11+
const leftBracket = `*${' '.repeat(3)}`;
12+
const rightBracket = `${' '.repeat(3)}*`;
13+
const warnMessage =
14+
'This is only a warn. In the future, you will not be able to push to github until the thresholds are updated.';
15+
16+
function formatErrorsWithAlignedStars(error, isSecondline = false) {
17+
const totalWidth = warnMessage.length;
18+
const spaces = totalWidth - error.length - (isSecondline ? 4 : 0);
19+
return `${leftBracket}${isSecondline ? '\t' : ''}${error}${' '.repeat(spaces)}${rightBracket}`;
20+
}
21+
22+
// Example usage:
23+
1124
for (const key of ['branches', 'functions', 'lines', 'statements']) {
1225
const current = summary[key].pct;
1326
const threshold = thresholds[key];
1427
if (current > threshold) {
1528
errors.push(
16-
`Coverage for ${key} (${current}%) is above the threshold (${threshold}%).\n\tPlease update the coverageThreshold.global.${key} in the jest.config.js to ${current}!`
29+
formatErrorsWithAlignedStars(`Coverage for ${key} (${current}%) is above the threshold (${threshold}%).`)
30+
);
31+
errors.push(
32+
formatErrorsWithAlignedStars(
33+
`Please update the coverageThreshold.global.${key} in the jest.config.js to ---> ${current} <---`,
34+
true
35+
)
1736
);
37+
errors.push(`${leftBracket}${' '.repeat(warnMessage.length)}${rightBracket}`);
1838
failed = true;
1939
}
2040
}
2141

2242
if (failed) {
43+
const stars = '*'.repeat(warnMessage.length + 8);
2344
execSync('clear', { stdio: 'inherit' });
45+
console.log(warnMessage.length);
2446
console.log('\n\nCongratulations! You have successfully run the coverage check and added tests.');
2547
console.log('\n\nThe jest.config.js file is not insync with your new test additions.');
2648
console.log('Please update the coverage thresholds in jest.config.js.');
2749
console.log('You will need to commit again once you have updated the jst.config.js file.');
28-
console.log('This is only necessary until we hit 100% coverage.\n\n');
29-
errors.forEach((err) => console.error(`${err}\n`));
30-
process.exit(1);
50+
console.log('This is only necessary until we hit 100% coverage.');
51+
console.log(`\n\n${stars}`);
52+
errors.forEach((err) => {
53+
console.error(err);
54+
});
55+
console.log(`${stars}`);
56+
console.log(`\n\n${stars}`);
57+
console.log(`${leftBracket}${' '.repeat(warnMessage.length)}${rightBracket}`);
58+
console.log(`${leftBracket}${warnMessage}${rightBracket}`);
59+
console.log(`${leftBracket}${' '.repeat(warnMessage.length)}${rightBracket}`);
60+
console.log(`${stars}\n\n`);
61+
// process.exit(1);
3162
}

.husky/pre-push

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
# npm run build
22

33
npm run test:coverage || {
4-
printf "\n\nERROR: Testing errors or coverage issues were found. Please address them before proceeding.\n\n\n\n"
5-
exit 1
4+
printf "\n\nERROR: Testing errors or coverage issues were found."
5+
printf "\n\nIn the future this will block your ability to push to github until it is resolved."
6+
printf "\n\nThe same pipeline runs on github."
7+
printf "\n\nYou are seeing this error because code was added without test coverage."
8+
# printf "\n\n Please address them before proceeding.\n\n\n\n"
9+
# exit 1
610
}
711

812
npm run test:check-coverage-thresholds || {
9-
printf "\n\nERROR: Coverage thresholds were not met. Please address them before proceeding.\n\n\n\n"
10-
exit 1
13+
printf "\n\nERROR: Coverage thresholds were not met."
14+
printf "\n\nIn the future this will block your ability to push to github until it is resolved."
15+
printf "\n\nThe same pipeline runs on github."
16+
printf "\n\nYou are seeing this error because test coverage increased without updating the jest.config.js thresholds."
17+
#printf "\n\nPlease address them before proceeding.\n\n\n\n"
18+
# exit 1
1119
}

0 commit comments

Comments
 (0)