Refactored Gulp tasks to exist within a tasks folder

This commit is contained in:
Kevin Gisi
2015-06-06 10:16:26 -04:00
parent 6a397a8be5
commit f613a5e5a7
4 changed files with 150 additions and 125 deletions

79
tasks/gulp-tests.js Normal file
View File

@@ -0,0 +1,79 @@
import { pipe, awaitPort, kill } from './taskHelper';
import { exec } from 'child_process';
import gulp from 'gulp';
import Q from 'q';
const TEST_SERVER_PORT = 3001
const TEST_DB = 'habitrpg_test'
const TEST_DB_URI = `mongodb://localhost/${TEST_DB}`
let testBin = (string) => {
return `NODE_ENV=testing ./node_modules/.bin/${string}`;
};
gulp.task('test:prepare:mongo', (cb) => {
exec(`mongo "${TEST_DB}" --eval "db.dropDatabase()"`, cb);
});
gulp.task('test:prepare:build', (cb) => {
exec(testBin('grunt build:test'), cb);
});
gulp.task('test:prepare:webdriver', (cb) => {
exec('./node_modules/protractor/bin/webdriver-manager update', cb);
});
gulp.task('test:prepare', [
'test:prepare:build',
'test:prepare:mongo',
'test:prepare:webdriver'
]);
gulp.task('test:common', ['test:prepare'], (cb) => {
let runner = exec(
testBin('mocha test/common'), cb
);
pipe(runner);
});
gulp.task('test:api', ['test:prepare'], (cb) => {
let runner = exec(
testBin('mocha test/api'), cb
);
pipe(runner);
});
gulp.task('test:karma', ['test:prepare'], (cb) => {
let runner = exec(
testBin('grunt karma:continuous'), cb
);
pipe(runner);
});
gulp.task('test:e2e', ['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)
]).then(() => {
exec('DISPLAY=:99 NODE_ENV=testing ./node_modules/protractor/bin/protractor protractor.conf.js', () => {
support.forEach(kill);
cb();
})
});
});
gulp.task('test', [
'test:prepare',
'test:common',
'test:karma',
'test:api',
'test:e2e'
]);