From b4cf4247c0e41fc9dd2faa700ff59455c4809528 Mon Sep 17 00:00:00 2001 From: germanrcuriel Date: Sun, 3 Nov 2013 00:40:43 +0100 Subject: [PATCH] Add Coverage report for Unit tests issue #361 - Added shell:jscoverage task to convert library folder to generate coverage report with mocha - Added shell:mocha_unit_coverage task to generate unit test coverage report - Added shell:mocha_integration_coverage task to generate integration test coverage report - Added clean:jscoverage task to remove converted folder when finished - Registered test-coverage Grunt task to include all the above - Added coverage files to .gitignore --- .gitignore | 6 +++++- Gruntfile.js | 17 +++++++++++++++++ index.js | 9 ++++++--- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index e30b35fa06c..269e131f4ff 100644 --- a/.gitignore +++ b/.gitignore @@ -57,4 +57,8 @@ CHANGELOG.md config.js # Built asset files -/core/built \ No newline at end of file +/core/built + +# Coverage reports +coverage_integration.html +coverage_unit.html \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index c038578bded..5db172cc3a1 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -251,6 +251,15 @@ var path = require('path'), shell: { bourbon: { command: 'bourbon install --path <%= paths.adminAssets %>/sass/modules/' + }, + jscoverage: { + command: 'jscoverage core core-cov' + }, + mocha_unit_coverage: { + command: 'NODE_ENV=testing APP_COVERAGE=1 ./node_modules/.bin/mocha --timeout 15000 --reporter html-cov > coverage_unit.html ./core-cov/test/unit' + }, + mocha_integration_coverage: { + command: 'NODE_ENV=testing APP_COVERAGE=1 ./node_modules/.bin/mocha --timeout 15000 --reporter html-cov > coverage_integration.html ./core-cov/test/integration' } }, @@ -296,6 +305,9 @@ var path = require('path'), }, test: { src: ['content/data/ghost-test.db'] + }, + jscoverage: { + src: ['core-cov'] } }, @@ -865,6 +877,11 @@ var path = require('path'), grunt.registerTask('validate', 'Run tests and lint code', ['jslint', 'test-unit', 'test-integration', 'test-functional']); + // ## Coverage report for Unit and Integration Tests + + grunt.registerTask('test-coverage', 'Generate unit and integration tests coverage report', ['clean:test', 'setTestEnv', 'loadConfig', 'express:test', 'shell:jscoverage', 'shell:mocha_unit_coverage', 'shell:mocha_integration_coverage', 'clean:jscoverage']); + + // ## Documentation grunt.registerTask('docs', 'Generate Docs', ['groc']); diff --git a/index.js b/index.js index fef21300a40..23ca0045086 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,16 @@ // # Ghost bootloader // Orchestrates the loading of Ghost -var configLoader = require('./core/config-loader.js'), - error = require('./core/server/errorHandling'); +var core_path = process.env.APP_COVERAGE + ? './core-cov' + : './core', + configLoader = require(core_path + '/config-loader.js'), + error = require(core_path + '/server/errorHandling'); // If no env is set, default to development process.env.NODE_ENV = process.env.NODE_ENV || 'development'; configLoader.loadConfig().then(function () { // The server and its dependencies require a populated config - require('./core/server'); + require(core_path + '/server'); }).otherwise(error.logAndThrowError);