From 725203200786f018680691ad1f9cd37fec0cb367 Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Sun, 16 Aug 2015 00:19:52 +0300 Subject: [PATCH 1/2] Adding coverage report for server-side tests using istanbul --- gruntfile.js | 18 ++++++++++++++++++ .../tests/server/article.server.model.tests.js | 1 + package.json | 1 + test.js | 13 +++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 test.js diff --git a/gruntfile.js b/gruntfile.js index 112bb3d118..d8d2ce1ba0 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -176,6 +176,21 @@ module.exports = function (grunt) { reporter: 'spec' } }, + mocha_istanbul: { + coverage: { + src: testAssets.tests.server, + options: { + print: 'detail', + coverage: true, + require: 'test.js', + coverageFolder: 'coverage', + check: { + lines: 40, + statements: 40 + } + } + } + }, karma: { unit: { configFile: 'karma.conf.js' @@ -252,6 +267,9 @@ module.exports = function (grunt) { grunt.registerTask('test', ['env:test', 'lint', 'mkdir:upload', 'copy:localConfig', 'server', 'mochaTest', 'karma:unit']); grunt.registerTask('test:server', ['env:test', 'lint', 'server', 'mochaTest']); grunt.registerTask('test:client', ['env:test', 'lint', 'server', 'karma:unit']); + // Run project coverage + grunt.registerTask('coverage', ['env:test', 'lint', 'mocha_istanbul:coverage']); + // Run the project in development mode grunt.registerTask('default', ['env:dev', 'lint', 'mkdir:upload', 'copy:localConfig', 'concurrent:default']); diff --git a/modules/articles/tests/server/article.server.model.tests.js b/modules/articles/tests/server/article.server.model.tests.js index 0031f1191d..f45d154c79 100644 --- a/modules/articles/tests/server/article.server.model.tests.js +++ b/modules/articles/tests/server/article.server.model.tests.js @@ -40,6 +40,7 @@ describe('Article Model Unit Tests:', function () { describe('Method Save', function () { it('should be able to save without problems', function (done) { + this.timeout(10000); return article.save(function (err) { should.not.exist(err); done(); diff --git a/package.json b/package.json index c9a92c38ca..36e4da7f5c 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "grunt-env": "~0.4.4", "grunt-karma": "~0.11.2", "grunt-mocha-test": "~0.12.7", + "grunt-mocha-istanbul": "^2.4.0", "grunt-ng-annotate": "^1.0.1", "grunt-node-inspector": "~0.2.0", "grunt-nodemon": "~0.4.0", diff --git a/test.js b/test.js new file mode 100644 index 0000000000..b0ee644cd7 --- /dev/null +++ b/test.js @@ -0,0 +1,13 @@ +'use strict'; + +/** + * Module dependencies. + */ +var app, db, config; + +var path = require('path'); +var app = require(path.resolve('./config/lib/app')); + +app.init(function (app, db, config) { + console.log('Initialized test automation'); +}); From 7c286b00bbdbf4a3048c3e90adfb4d4f65dd3a44 Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Wed, 19 Aug 2015 21:49:30 +0300 Subject: [PATCH 2/2] adding support for coveralls integration for mean.js to report live project code coverage information --- README.md | 1 + gruntfile.js | 12 +++++++++++- package.json | 3 ++- test.js | 6 +++--- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5236b582e1..4e5ecf764d 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/meanjs/mean?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/meanjs/mean.svg?branch=master)](https://travis-ci.org/meanjs/mean) [![Dependencies Status](https://david-dm.org/meanjs/mean.svg)](https://david-dm.org/meanjs/mean) +[![Coverage Status](https://coveralls.io/repos/meanjs/mean/badge.svg?branch=master&service=github)](https://coveralls.io/github/meanjs/mean?branch=master) MEAN.JS is a full-stack JavaScript open-source solution, which provides a solid starting point for [MongoDB](http://www.mongodb.org/), [Node.js](http://www.nodejs.org/), [Express](http://expressjs.com/), and [AngularJS](http://angularjs.org/) based applications. The idea is to solve the common issues with connecting those frameworks, build a robust framework to support daily development needs, and help developers use better practices while working with popular JavaScript components. diff --git a/gruntfile.js b/gruntfile.js index d8d2ce1ba0..5f7c0e9bcf 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -184,10 +184,11 @@ module.exports = function (grunt) { coverage: true, require: 'test.js', coverageFolder: 'coverage', + reportFormats: ['cobertura','lcovonly'], check: { lines: 40, statements: 40 - } + } } } }, @@ -219,6 +220,15 @@ module.exports = function (grunt) { } }); + grunt.event.on('coverage', function(lcovFileContents, done) { + require('coveralls').handleInput(lcovFileContents, function(err) { + if (err) { + return done(err); + } + done(); + }); + }); + // Load NPM tasks require('load-grunt-tasks')(grunt); diff --git a/package.json b/package.json index 36e4da7f5c..e148738c64 100644 --- a/package.json +++ b/package.json @@ -105,6 +105,7 @@ "load-grunt-tasks": "^3.2.0", "run-sequence": "^1.1.1", "should": "^7.0.1", - "supertest": "^1.0.1" + "supertest": "^1.0.1", + "coveralls": "^2.11.4" } } diff --git a/test.js b/test.js index b0ee644cd7..daf3386e1f 100644 --- a/test.js +++ b/test.js @@ -3,11 +3,11 @@ /** * Module dependencies. */ -var app, db, config; +var app; var path = require('path'); var app = require(path.resolve('./config/lib/app')); -app.init(function (app, db, config) { - console.log('Initialized test automation'); +app.init(function () { + console.log('Initialized test automation'); });