From 881146500c18c2a18582af586e130ceffd66f41c Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Tue, 31 Mar 2020 14:06:38 +0200 Subject: [PATCH] qunit task rejects on failure --- gulpfile.js | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index ea3f1336..ac1429dd 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -65,7 +65,10 @@ gulp.task('test-qunit', function() { let testFiles = glob.sync('test/*.html' ) - return Promise.all( testFiles.map( filename => { + let totalTests = 0; + let failingTests = 0; + + let tests = Promise.all( testFiles.map( filename => { return new Promise( ( resolve, reject ) => { runQunitPuppeteer({ targetUrl: `file://${path.join(__dirname, filename)}`, @@ -74,20 +77,43 @@ gulp.task('test-qunit', function() { puppeteerArgs: ['--allow-file-access-from-files'] }) .then(result => { - console.log(`\n\n${('Testing '+filename+'...').bold.blue}`); - printResultSummary(result, console); if( result.stats.failed > 0 ) { + console.log(`${'!'} ${filename} [${result.stats.passed}/${result.stats.total}] in ${result.stats.runtime}ms`.red); + // printResultSummary(result, console); printFailedTests(result, console); } + else { + console.log(`${'✔'} ${filename} [${result.stats.passed}/${result.stats.total}] in ${result.stats.runtime}ms`.green); + } + + totalTests += result.stats.total; + failingTests += result.stats.failed; resolve(); }) - .catch(ex => { - console.error(ex); + .catch(error => { + console.error(error); reject(); }); } ) - } ) ) + } ) ); + + return new Promise( ( resolve, reject ) => { + + tests.then( () => { + if( failingTests > 0 ) { + reject( new Error(`${failingTests}/${totalTests} tests failed`.red) ); + } + else { + console.log(`${'✔'} Passed ${totalTests} tests`.green.bold); + resolve(); + } + } ) + .catch( () => { + reject(); + } ); + + } ); } ) gulp.task('test', gulp.series(