From 9b31cf462a986fd9bb8f93c2f6f874c989ef9c2d Mon Sep 17 00:00:00 2001 From: Alexander Bragdon Date: Wed, 1 Jul 2015 14:42:43 -0400 Subject: [PATCH] Creates safe versions of tests for Common, API, Karma, and E2E that don't pass errors via callback. The summary information will check if any tests failed and throw an error after all tests have been run. --- tasks/gulp-tests.js | 78 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 10 deletions(-) diff --git a/tasks/gulp-tests.js b/tasks/gulp-tests.js index 3445a7d48f..c5b85f2d27 100644 --- a/tasks/gulp-tests.js +++ b/tasks/gulp-tests.js @@ -45,6 +45,16 @@ gulp.task('test:prepare', [ ]); gulp.task('test:common', ['test:prepare:build'], (cb) => { + let runner = exec( + testBin('mocha test/common'), + (err, stdout, stderr) => { + cb(err); + } + ); + pipe(runner); +}); + +gulp.task('test:common:safe', ['test:prepare:build'], (cb) => { let runner = exec( testBin('mocha test/common'), (err, stdout, stderr) => { @@ -54,7 +64,7 @@ gulp.task('test:common', ['test:prepare:build'], (cb) => { fail: testCount(stderr, /(\d+) failing/), pend: testCount(stdout, /(\d+) pending/) }); - cb(err); + cb(); } ); pipe(runner); @@ -62,6 +72,16 @@ gulp.task('test:common', ['test:prepare:build'], (cb) => { gulp.task('test:api', ['test:prepare:mongo'], (cb) => { + let runner = exec( + testBin("istanbul cover -i 'website/src/**' --dir coverage/api ./node_modules/.bin/_mocha -- test/api"), + (err, stdout, stderr) => { + cb(err); + } + ); + pipe(runner); +}); + +gulp.task('test:api:safe', ['test:prepare:mongo'], (cb) => { let runner = exec( testBin("istanbul cover -i 'website/src/**' --dir coverage/api ./node_modules/.bin/_mocha -- test/api"), (err, stdout, stderr) => { @@ -71,10 +91,10 @@ gulp.task('test:api', ['test:prepare:mongo'], (cb) => { fail: testCount(stderr, /(\d+) failing/), pend: testCount(stdout, /(\d+) pending/) }); - cb(err); + cb(); } ); - pipe(runner); + pipe(runner) }); gulp.task('test:api:clean', (cb) => { @@ -89,6 +109,16 @@ gulp.task('test:api:watch', [ }); gulp.task('test:karma', ['test:prepare:build'], (cb) => { + let runner = exec( + testBin('karma start --single-run'), + (err, stdout) => { + cb(err); + } + ); + pipe(runner); +}); + +gulp.task('test:karma:safe', ['test:prepare:build'], (cb) => { let runner = exec( testBin('karma start --single-run'), (err, stdout) => { @@ -98,7 +128,7 @@ gulp.task('test:karma', ['test:prepare:build'], (cb) => { fail: testCount(stdout, /(\d+) tests failed/), pend: testCount(stdout, /(\d+) tests skipped/) }); - cb(err); + cb(); } ); pipe(runner); @@ -111,6 +141,31 @@ gulp.task('test:e2e', ['test:prepare'], (cb) => { './node_modules/protractor/bin/webdriver-manager start', ].map(exec); + Q.all([ + awaitPort(3001), + awaitPort(4444) + ]).then(() => { + let runner = exec( + 'DISPLAY=:99 NODE_ENV=testing ./node_modules/protractor/bin/protractor protractor.conf.js', + (err, stdout, stderr) => { + /* + * Note: As it stands, protractor wont report pending specs + */ + support.forEach(kill); + cb(err); + } + ); + pipe(runner); + }); +}); + +gulp.task('test:e2e:safe', ['test:prepare'], (cb) => { + let support = [ + 'Xvfb :99 -screen 0 1024x768x24 -extension RANDR', + `NODE_DB_URI="${TEST_DB_URI}" PORT="${TEST_SERVER_PORT}" node ./website/src/server.js`, + './node_modules/protractor/bin/webdriver-manager start', + ].map(exec); + Q.all([ awaitPort(3001), awaitPort(4444) @@ -129,7 +184,7 @@ gulp.task('test:e2e', ['test:prepare'], (cb) => { pend: 0 }); support.forEach(kill); - cb(err); + cb(); } ); pipe(runner); @@ -137,10 +192,10 @@ gulp.task('test:e2e', ['test:prepare'], (cb) => { }); gulp.task('test', [ - 'test:common', - 'test:karma', - 'test:api', - 'test:e2e' + 'test:common:safe', + 'test:karma:safe', + 'test:api:safe', + 'test:e2e:safe' ], () => { let totals = [0,0,0]; @@ -164,5 +219,8 @@ gulp.task('test', [ `\x1b[36mPending: ${totals[2]}\t` ); - console.log('\n\x1b[36mThanks for helping keep Habitica clean!\x1b[0m'); + if (totals[1] > 0) throw "ERROR: There are failing tests!" + else { + console.log('\n\x1b[36mThanks for helping keep Habitica clean!\x1b[0m'); + } });