Browse Source

Launch the test server with coverage

Gaël Métais 10 năm trước cách đây
mục cha
commit
3ad6cdef51
6 tập tin đã thay đổi với 53 bổ sung25 xóa
  1. 40 2
      Gruntfile.js
  2. 0 2
      bin/cli.js
  3. 1 3
      bin/server.js
  4. 1 1
      server_config/settings.json
  5. 1 17
      test/api/apiTest.js
  6. 10 0
      test/fixtures/settings.json

+ 40 - 2
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',

+ 0 - 2
bin/cli.js

@@ -1,5 +1,3 @@
-#!/usr/bin/env node
-
 var debug = require('debug')('ylt:cli');
 
 var YellowLabTools = require('../lib/yellowlabtools');

+ 1 - 3
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);
     });

+ 1 - 1
server_config/settings.json

@@ -5,6 +5,6 @@
     "authorizedKeys": {
         "1234567890": "contact@gaelmetais.com"
     },
-    "maxAnonymousRunsPerDay": 24,
+    "maxAnonymousRunsPerDay": 50,
     "maxAnonymousCallsPerDay": 1000
 }

+ 1 - 17
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) {
 

+ 10 - 0
test/fixtures/settings.json

@@ -0,0 +1,10 @@
+{
+    "serverPort": "auto",
+    "googleAnalyticsId": "",
+    
+    "authorizedKeys": {
+        "1234567890": "contact@gaelmetais.com"
+    },
+    "maxAnonymousRunsPerDay": 10,
+    "maxAnonymousCallsPerDay": 1000
+}