Skip to content

Commit 7a99308

Browse files
committed
Adding nyc code coverage functionality
1 parent 922af4e commit 7a99308

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

Gruntfile.js

+34-1
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,41 @@ module.exports = function(grunt) {
161161
},
162162
src: ['test/*/*.js']
163163
}
164-
}
164+
},
165+
mocha_nyc: {
166+
coverage: {
167+
src: ['test/*/*.js'], // a folder works nicely
168+
options: {
169+
coverage:true, // this will make the grunt.event.on('coverage') event listener to be triggered
170+
mask: '*.js',
171+
excludes: ['bin/*', 'frontend/*', 'extend/*', 'Gruntfile.js', 'test/*'],
172+
mochaOptions: ['--harmony', '--async-only', '--reporter', 'spec', '--timeout', '50000', '--exit'],
173+
nycOptions: ['--harmony', '--clean', 'false'],//,'--include-all-sources' '--all'
174+
reportFormats: ['none']
175+
}
176+
}
177+
},
178+
istanbul_check_coverage: {
179+
default: {
180+
options: {
181+
coverageFolder: 'coverage*', // will check both coverage folders and merge the coverage results
182+
check: {
183+
lines: 80,
184+
statements: 80
185+
}
186+
}
187+
}
188+
}
189+
});
190+
191+
//code coverage
192+
grunt.event.on('coverage', function(lcovFileContents, done){
193+
// Check below on the section "The coverage event"
194+
done();
165195
});
196+
grunt.loadNpmTasks('grunt-mocha-nyc');
197+
grunt.registerTask('coverage', ['mocha_nyc:coverage']);
198+
//-----------code coverage-----------
166199

167200
grunt.loadNpmTasks('grunt-contrib-jshint');
168201
grunt.loadNpmTasks('grunt-contrib-concat');

bin/config/supervisord.conf

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ programs=countly-dashboard, countly-api
2222
[program:countly-dashboard]
2323
environment=NODE_ENV=production
2424
command=node %(here)s/../../frontend/express/app.js
25+
;command=nyc node %(here)s/../../frontend/express/app.js ;replace previous line with this in case you want to run nyc
2526
directory=.
2627
autorestart=true
2728
redirect_stderr=true
@@ -35,6 +36,7 @@ loglevel=warn
3536
[program:countly-api]
3637
environment=NODE_ENV=production
3738
command=node %(here)s/../../api/api.js
39+
;command=nyc --nycrc-path nyc.config node %(here)s/../../api/api.js ;replace previous line with this in case you want to run nyc
3840
directory=%(here)s
3941
autorestart=true
4042
redirect_stderr=true

nyc.config

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"report-dir": "./CoverageReportDir",
3+
"exclude": [
4+
".git/**",
5+
"frontend/**",
6+
"bin/**",
7+
"frontend/**",
8+
"test/**",
9+
"core/**",
10+
"extend/**",
11+
"**/tests/**",
12+
"**/tests.js",
13+
"CodeCoverageResult/**",
14+
"CoverageReportDir/**",
15+
"plugins/*/frontend/**",
16+
"node_modules/**",
17+
"**/node_modules/**"
18+
19+
],
20+
"reporter": [
21+
"html",
22+
"text"
23+
],
24+
"all": true
25+
}

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
"grunt-contrib-cssmin": "2.2.1",
2222
"grunt-contrib-jshint": "1.1.0",
2323
"grunt-contrib-uglify": "3.3.0",
24+
"grunt-mocha-nyc": "^1.0.3",
2425
"grunt-mocha-test": "0.13.3",
2526
"mocha": "^5.1.1",
27+
"nyc": "^13.0.1",
2628
"should": "13.2.1",
2729
"supertest": "3.1.0"
2830
},

0 commit comments

Comments
 (0)