diff --git a/Gruntfile.js b/Gruntfile.js index 9cf19b1..ac5dc6a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -108,12 +108,6 @@ module.exports = function(grunt) { showStack: true } }, - testServer: { - options: { - port: 8387, - server: './coverage/bin/server.js' - } - }, testSuite: { options: { port: 8388, @@ -148,7 +142,7 @@ module.exports = function(grunt) { var outputFile = './coverage/server_config/settings.json'; grunt.file.write(outputFile, JSON.stringify(testSettings, null, 4)); - grunt.verbose.ok('File ' + outputFile + ' created'); + grunt.log.ok('File ' + outputFile + ' created'); }); @@ -177,10 +171,9 @@ module.exports = function(grunt) { grunt.registerTask('test', [ 'build', 'jshint', - 'copy-test-server-settings', - 'express:testServer', 'express:testSuite', 'clean:coverage', + 'copy-test-server-settings', 'blanket', 'copy:coverage', 'mochaTest:test', @@ -190,10 +183,9 @@ module.exports = function(grunt) { grunt.registerTask('test-current-work', [ 'build', 'jshint', - 'copy-test-server-settings', - 'express:testServer', 'express:testSuite', 'clean:coverage', + 'copy-test-server-settings', 'blanket', 'copy:coverage', 'mochaTest:test-current-work' diff --git a/bin/server.js b/bin/server.js index 95bb8a5..cc7199c 100644 --- a/bin/server.js +++ b/bin/server.js @@ -20,13 +20,14 @@ var uiController = require('../lib/server/controllers/uiController')( // Let's start the server! -if (!process.env.GRUNTED) { - // The server is not launched by Grunt - var settings = require('../server_config/settings.json'); - server.listen(settings.serverPort, function() { - console.log('Listening on port %d', server.address().port); - }); -} +var settings = require('../server_config/settings.json'); +server.listen(settings.serverPort, function() { + console.log('Listening on port %d', server.address().port); -// For Grunt -module.exports = app; \ No newline at end of file + // For the tests + if (server.startTests) { + server.startTests(); + } +}); + +module.exports = server; \ No newline at end of file diff --git a/test/api/apiTest.js b/test/api/apiTest.js index e23f3d5..da46653 100644 --- a/test/api/apiTest.js +++ b/test/api/apiTest.js @@ -14,7 +14,12 @@ var wwwUrl = 'http://localhost:8388'; describe('api', function() { var runId; + var apiServer; + before(function(done) { + apiServer = require('../../bin/server.js'); + apiServer.startTests = done; + }); it('should refuse a query with an invalid key', function(done) { this.timeout(5000); @@ -67,7 +72,7 @@ describe('api', function() { }); it('should accept up to 10 anonymous runs to the API', function(done) { - this.timeout(15000); + this.timeout(5000); function launchRun() { var deferred = Q.defer(); @@ -126,5 +131,8 @@ describe('api', function() { }); - + after(function() { + console.log('Closing the server'); + apiServer.close(); + }); }); diff --git a/test/fixtures/settings.json b/test/fixtures/settings.json index 619190f..75b2365 100644 --- a/test/fixtures/settings.json +++ b/test/fixtures/settings.json @@ -1,5 +1,5 @@ { - "serverPort": "auto", + "serverPort": "8387", "googleAnalyticsId": "", "authorizedKeys": {