diff --git a/Gruntfile.js b/Gruntfile.js index b9e7296..9cf19b1 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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', diff --git a/bin/cli.js b/bin/cli.js index 88b615a..0524668 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,5 +1,3 @@ -#!/usr/bin/env node - var debug = require('debug')('ylt:cli'); var YellowLabTools = require('../lib/yellowlabtools'); diff --git a/bin/server.js b/bin/server.js index f8b76aa..95bb8a5 100644 --- a/bin/server.js +++ b/bin/server.js @@ -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); }); diff --git a/server_config/settings.json b/server_config/settings.json index 2b05df1..5c69980 100644 --- a/server_config/settings.json +++ b/server_config/settings.json @@ -5,6 +5,6 @@ "authorizedKeys": { "1234567890": "contact@gaelmetais.com" }, - "maxAnonymousRunsPerDay": 24, + "maxAnonymousRunsPerDay": 50, "maxAnonymousCallsPerDay": 1000 } \ No newline at end of file diff --git a/test/api/apiTest.js b/test/api/apiTest.js index 3183bf2..e23f3d5 100644 --- a/test/api/apiTest.js +++ b/test/api/apiTest.js @@ -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) { diff --git a/test/fixtures/settings.json b/test/fixtures/settings.json new file mode 100644 index 0000000..619190f --- /dev/null +++ b/test/fixtures/settings.json @@ -0,0 +1,10 @@ +{ + "serverPort": "auto", + "googleAnalyticsId": "", + + "authorizedKeys": { + "1234567890": "contact@gaelmetais.com" + }, + "maxAnonymousRunsPerDay": 10, + "maxAnonymousCallsPerDay": 1000 +} \ No newline at end of file