Skip to content
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
39 changes: 35 additions & 4 deletions .github/scripts/check-coverage-thresholds.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,55 @@ const thresholds = jestConfig.coverageThreshold.global;

let failed = false;
const errors = [];
const leftBracket = `*${' '.repeat(3)}`;
const rightBracket = `${' '.repeat(3)}*`;
const warnMessage =
'This is only a warn. In the future, you will not be able to push to github until the thresholds are updated.';

function formatErrorsWithAlignedStars(error, isSecondline = false) {
const totalWidth = warnMessage.length;
const spaces = totalWidth - error.length - (isSecondline ? 4 : 0);
return `${leftBracket}${isSecondline ? '\t' : ''}${error}${' '.repeat(spaces)}${rightBracket}`;
}

// Example usage:

for (const key of ['branches', 'functions', 'lines', 'statements']) {
const current = summary[key].pct;
const threshold = thresholds[key];
if (current > threshold) {
errors.push(
`Coverage for ${key} (${current}%) is above the threshold (${threshold}%).\n\tPlease update the coverageThreshold.global.${key} in the jest.config.js to ${current}!`
formatErrorsWithAlignedStars(`Coverage for ${key} (${current}%) is above the threshold (${threshold}%).`)
);
errors.push(
formatErrorsWithAlignedStars(
`Please update the coverageThreshold.global.${key} in the jest.config.js to ---> ${current} <---`,
true
)
);
errors.push(`${leftBracket}${' '.repeat(warnMessage.length)}${rightBracket}`);
failed = true;
}
}

if (failed) {
const stars = '*'.repeat(warnMessage.length + 8);
execSync('clear', { stdio: 'inherit' });
console.log(warnMessage.length);
console.log('\n\nCongratulations! You have successfully run the coverage check and added tests.');
console.log('\n\nThe jest.config.js file is not insync with your new test additions.');
console.log('Please update the coverage thresholds in jest.config.js.');
console.log('You will need to commit again once you have updated the jst.config.js file.');
console.log('This is only necessary until we hit 100% coverage.\n\n');
errors.forEach((err) => console.error(`${err}\n`));
process.exit(1);
console.log('This is only necessary until we hit 100% coverage.');
console.log(`\n\n${stars}`);
errors.forEach((err) => {
console.error(err);
});
console.log(`${stars}`);
console.log(`\n\n${stars}`);
console.log(`${leftBracket}${' '.repeat(warnMessage.length)}${rightBracket}`);
console.log(`${leftBracket}${warnMessage}${rightBracket}`);
console.log(`${leftBracket}${' '.repeat(warnMessage.length)}${rightBracket}`);
console.log(`${stars}\n\n`);
// process.exit(1);
}
16 changes: 12 additions & 4 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# npm run build

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

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