qunit task rejects on failure

This commit is contained in:
Hakim El Hattab 2020-03-31 14:06:38 +02:00
parent ca29e3dd29
commit 881146500c

View File

@ -65,7 +65,10 @@ gulp.task('test-qunit', function() {
let testFiles = glob.sync('test/*.html' ) 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 ) => { return new Promise( ( resolve, reject ) => {
runQunitPuppeteer({ runQunitPuppeteer({
targetUrl: `file://${path.join(__dirname, filename)}`, targetUrl: `file://${path.join(__dirname, filename)}`,
@ -74,20 +77,43 @@ gulp.task('test-qunit', function() {
puppeteerArgs: ['--allow-file-access-from-files'] puppeteerArgs: ['--allow-file-access-from-files']
}) })
.then(result => { .then(result => {
console.log(`\n\n${('Testing '+filename+'...').bold.blue}`);
printResultSummary(result, console);
if( result.stats.failed > 0 ) { 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); 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(); resolve();
}) })
.catch(ex => { .catch(error => {
console.error(ex); console.error(error);
reject(); 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( gulp.task('test', gulp.series(