Skip to content

Commit

Permalink
Merge pull request #17219 from ckeditor/ck/17169
Browse files Browse the repository at this point in the history
Internal: Added the retrying test execution mechanism on CI. Closes #17169
  • Loading branch information
pomek authored Oct 4, 2024
2 parents 0802874 + f0907bb commit 683a4cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
34 changes: 26 additions & 8 deletions scripts/ci/check-unit-tests-for-package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ main()
} );

async function main() {
const { packageName, checkCoverage, allowNonFullCoverage, coverageFile } = getOptions( process.argv.slice( 2 ) );
const { packageName, checkCoverage, allowNonFullCoverage, coverageFile, attempts } = getOptions( process.argv.slice( 2 ) );

runTests( { packageName, checkCoverage } );
runTests( { packageName, checkCoverage, attempts } );

if ( checkCoverage && !allowNonFullCoverage ) {
const exitCode = checkCodeCoverage();
Expand All @@ -46,8 +46,9 @@ async function main() {
* @param {Object} options
* @param {String} options.packageName
* @param {Boolean} options.checkCoverage
* @param {Number} options.attempts
*/
function runTests( { packageName, checkCoverage } ) {
function runTests( { packageName, checkCoverage, attempts = 3 } ) {
const shortName = packageName.replace( /^ckeditor5?-/, '' );

const testCommand = [
Expand All @@ -59,10 +60,24 @@ function runTests( { packageName, checkCoverage } ) {
checkCoverage ? '--coverage' : null
].filter( Boolean );

execSync( testCommand.join( ' ' ), {
cwd: CKEDITOR5_ROOT_PATH,
stdio: 'inherit'
} );
try {
execSync( testCommand.join( ' ' ), {
cwd: CKEDITOR5_ROOT_PATH,
stdio: 'inherit'
} );
} catch ( err ) {
if ( !attempts ) {
throw err;
}

console.log( `\n⚠️ Retry the test execution. Remaining attempts: ${ attempts - 1 }.` );

return runTests( {
packageName,
checkCoverage,
attempts: attempts - 1
} );
}
}

function checkCodeCoverage() {
Expand Down Expand Up @@ -90,12 +105,14 @@ function checkCodeCoverage() {
* @returns {Boolean} options.checkCoverage
* @returns {Boolean} options.allowNonFullCoverage
* @returns {String|null} options.coverageFile
* @returns {Number} options.attempts
*/
function getOptions( argv ) {
const options = minimist( argv, {
string: [
'package-name',
'coverage-file'
'coverage-file',
'attempts'
],
boolean: [
'check-coverage',
Expand All @@ -107,6 +124,7 @@ function getOptions( argv ) {
}
} );

options.attempts = Number( options.attempts || 1 );
options.packageName = options[ 'package-name' ];
options.coverageFile = options[ 'coverage-file' ];
options.checkCoverage = options[ 'check-coverage' ];
Expand Down
1 change: 1 addition & 0 deletions scripts/ci/generate-circleci-configuration.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ function generateTestSteps( packages, { checkCoverage, coverageFile = null } ) {
const testCommand = [
'node',
'scripts/ci/check-unit-tests-for-package.mjs',
'--attempts 3',
'--package-name',
packageName,
checkCoverage ? '--check-coverage' : null,
Expand Down

0 comments on commit 683a4cf

Please sign in to comment.