Skip to content

Commit

Permalink
Only start up server in tests if it is not already running.
Browse files Browse the repository at this point in the history
  • Loading branch information
crookedneighbor committed Oct 25, 2015
1 parent 96c77da commit 45afc9f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion protractor.conf.js
Expand Up @@ -14,7 +14,7 @@ exports.config = {

// A base URL for your application under test. Calls to protractor.get()
// with relative paths will be prepended with this.
baseUrl: 'http://localhost:3001',
baseUrl: 'http://localhost:3003',

// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
Expand Down
35 changes: 18 additions & 17 deletions tasks/gulp-tests.js
Expand Up @@ -9,9 +9,9 @@ import Q from 'q';
import Mocha from 'mocha';
import { resolve } from 'path';

const E2E_TEST_SERVER_PORT = 3001
const API_TEST_SERVER_PORT = 3003
const TEST_SERVER_PORT = 3003
const TEST_DB = 'habitrpg_test'
let server;

const TEST_DB_URI = `mongodb://localhost/${TEST_DB}`

Expand Down Expand Up @@ -45,6 +45,12 @@ gulp.task('test:prepare:mongo', (cb) => {
});
});

gulp.task('test:prepare:server', ['test:prepare:mongo'], () => {
if (!server) {
server = exec(`NODE_DB_URI="${TEST_DB_URI}" PORT="${TEST_SERVER_PORT}" node ./website/src/server.js`);
}
});

gulp.task('test:prepare:build', (cb) => {
exec(testBin('grunt build:test'), cb);
});
Expand Down Expand Up @@ -228,15 +234,15 @@ gulp.task('test:karma:safe', ['test:prepare:build'], (cb) => {
pipe(runner);
});

gulp.task('test:e2e', ['test:prepare'], (cb) => {
gulp.task('test:e2e', ['test:prepare', 'test:prepare:server'], (cb) => {
let support = [
'Xvfb :99 -screen 0 1024x768x24 -extension RANDR',
`NODE_DB_URI="${TEST_DB_URI}" PORT="${E2E_TEST_SERVER_PORT}" node ./website/src/server.js`,
'./node_modules/protractor/bin/webdriver-manager start',
].map(exec);
support.push(server);

Q.all([
awaitPort(3001),
awaitPort(TEST_SERVER_PORT),
awaitPort(4444)
]).then(() => {
let runner = exec(
Expand All @@ -253,15 +259,14 @@ gulp.task('test:e2e', ['test:prepare'], (cb) => {
});
});

gulp.task('test:e2e:safe', ['test:prepare'], (cb) => {
gulp.task('test:e2e:safe', ['test:prepare', 'test:prepare:server'], (cb) => {
let support = [
'Xvfb :99 -screen 0 1024x768x24 -extension RANDR',
`NODE_DB_URI="${TEST_DB_URI}" PORT="${E2E_TEST_SERVER_PORT}" node ./website/src/server.js`,
'./node_modules/protractor/bin/webdriver-manager start',
].map(exec);

Q.all([
awaitPort(3001),
awaitPort(TEST_SERVER_PORT),
awaitPort(4444)
]).then(() => {
let runner = exec(
Expand All @@ -285,12 +290,10 @@ gulp.task('test:e2e:safe', ['test:prepare'], (cb) => {
});
});

gulp.task('test:api', ['test:prepare:mongo'], (done) => {
gulp.task('test:api', ['test:prepare:server'], (done) => {
require('../test/helpers/globals.helper');

let server = exec(`NODE_DB_URI="${TEST_DB_URI}" PORT="${API_TEST_SERVER_PORT}" node ./website/src/server.js`);

awaitPort(API_TEST_SERVER_PORT).then(() => {
awaitPort(TEST_SERVER_PORT).then(() => {
let mocha = new Mocha({reporter: 'spec'});
let tests = glob('./test/api/**/*.js');

Expand All @@ -314,10 +317,8 @@ gulp.task('test:api:watch', () => {
gulp.watch(['website/src/**', 'test/api/**'], ['test:api']);
});

gulp.task('test:api:safe', ['test:prepare:mongo'], (done) => {
let server = exec(`NODE_DB_URI="${TEST_DB_URI}" PORT="${API_TEST_SERVER_PORT}" node ./website/src/server.js`);

awaitPort(API_TEST_SERVER_PORT).then(() => {
gulp.task('test:api:safe', ['test:prepare:server'], (done) => {
awaitPort(TEST_SERVER_PORT).then(() => {
let runner = exec(
testBin(API_TEST_COMMAND),
(err, stdout, stderr) => {
Expand All @@ -327,7 +328,6 @@ gulp.task('test:api:safe', ['test:prepare:mongo'], (done) => {
fail: testCount(stderr, /(\d+) failing/),
pend: testCount(stdout, /(\d+) pending/)
});
kill(server);
done();
}
);
Expand Down Expand Up @@ -368,6 +368,7 @@ gulp.task('test', [

if (totals[1] > 0) throw "ERROR: There are failing tests!"
else {
kill(server);
console.log('\n\x1b[36mThanks for helping keep Habitica clean!\x1b[0m');
process.exit();
}
Expand Down

0 comments on commit 45afc9f

Please sign in to comment.