Launch the test server with coverage

This commit is contained in:
Gaël Métais
2014-12-13 12:11:33 +01:00
parent 0da2ad0c10
commit 3ad6cdef51
6 changed files with 53 additions and 25 deletions
+40 -2
View File
@@ -58,7 +58,8 @@ module.exports = function(grunt) {
coverage: {
files: [
{src: ['test/**'], dest: 'coverage/'},
{src: ['lib/metadata/**'], dest: 'coverage/'}
{src: ['lib/metadata/**'], dest: 'coverage/'},
{src: ['bin/**'], dest: 'coverage/'}
]
}
},
@@ -70,6 +71,10 @@ module.exports = function(grunt) {
coverageLib: {
src: ['lib/'],
dest: 'coverage/lib/'
},
coverageBin: {
src: ['bin/'],
dest: 'coverage/bin/'
}
},
mochaTest: {
@@ -106,7 +111,7 @@ module.exports = function(grunt) {
testServer: {
options: {
port: 8387,
server: './bin/server.js'
server: './coverage/bin/server.js'
}
},
testSuite: {
@@ -118,6 +123,37 @@ module.exports = function(grunt) {
}
});
// Custom task: copies the test settings.json file to the coverage folder, and checks if there's no missing fields
grunt.registerTask('copy-test-server-settings', function() {
var mainSettingsFile = './server_config/settings.json';
var testSettingsFile = './test/fixtures/settings.json';
var mainSettings = grunt.file.readJSON(mainSettingsFile);
var testSettings = grunt.file.readJSON(testSettingsFile);
// Recursively compare keys of two objects (not the values)
function compareKeys(original, copy, context) {
for (var key in original) {
if (!copy[key] && copy[key] !== '' && copy[key] !== 0) {
grunt.fail.warn('Settings file ' + testSettingsFile + ' doesn\'t contain key ' + context + '.' + key);
}
if (original[key] !== null && typeof original[key] === 'object') {
compareKeys(original[key], copy[key], context + '.' + key);
}
}
}
compareKeys(mainSettings, testSettings, 'settings');
var outputFile = './coverage/server_config/settings.json';
grunt.file.write(outputFile, JSON.stringify(testSettings, null, 4));
grunt.verbose.ok('File ' + outputFile + ' created');
});
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.registerTask('icons', [
@@ -141,6 +177,7 @@ module.exports = function(grunt) {
grunt.registerTask('test', [
'build',
'jshint',
'copy-test-server-settings',
'express:testServer',
'express:testSuite',
'clean:coverage',
@@ -153,6 +190,7 @@ module.exports = function(grunt) {
grunt.registerTask('test-current-work', [
'build',
'jshint',
'copy-test-server-settings',
'express:testServer',
'express:testSuite',
'clean:coverage',
-2
View File
@@ -1,5 +1,3 @@
#!/usr/bin/env node
var debug = require('debug')('ylt:cli');
var YellowLabTools = require('../lib/yellowlabtools');
+1 -3
View File
@@ -1,6 +1,3 @@
// Config file
var settings = require('../server_config/settings.json');
var express = require('express');
var app = express();
var server = require('http').createServer(app);
@@ -25,6 +22,7 @@ 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);
});
+1 -1
View File
@@ -5,6 +5,6 @@
"authorizedKeys": {
"1234567890": "contact@gaelmetais.com"
},
"maxAnonymousRunsPerDay": 24,
"maxAnonymousRunsPerDay": 50,
"maxAnonymousCallsPerDay": 1000
}
+1 -17
View File
@@ -66,7 +66,7 @@ describe('api', function() {
});
});
it('should accept up to 24 anonymous runs to the API', function(done) {
it('should accept up to 10 anonymous runs to the API', function(done) {
this.timeout(15000);
function launchRun() {
@@ -96,13 +96,6 @@ describe('api', function() {
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(function(response, body) {
@@ -115,15 +108,6 @@ describe('api', function() {
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(launchRun)
.then(function(response, body) {
+10
View File
@@ -0,0 +1,10 @@
{
"serverPort": "auto",
"googleAnalyticsId": "",
"authorizedKeys": {
"1234567890": "contact@gaelmetais.com"
},
"maxAnonymousRunsPerDay": 10,
"maxAnonymousCallsPerDay": 1000
}