From 76a5f2c2e53811f7932d79e1cfe499060752a430 Mon Sep 17 00:00:00 2001 From: Brian Pilati Date: Tue, 12 Aug 2025 13:52:31 -0500 Subject: [PATCH] feat(warns): Updated the pipeline locally to be a warn --- .github/scripts/check-coverage-thresholds.js | 39 ++++++++++++++++++-- .husky/pre-push | 16 ++++++-- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/.github/scripts/check-coverage-thresholds.js b/.github/scripts/check-coverage-thresholds.js index 1ac87bac9..3847bafd5 100644 --- a/.github/scripts/check-coverage-thresholds.js +++ b/.github/scripts/check-coverage-thresholds.js @@ -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); } diff --git a/.husky/pre-push b/.husky/pre-push index 2921f385c..85c4fcf43 100644 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -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 } \ No newline at end of file