Skip to content

Commit ac7128b

Browse files
author
Hovhannes Babayan
committed
added coverage and reporting to coveralls.io
1 parent dc215c7 commit ac7128b

3 files changed

Lines changed: 39 additions & 10 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ node_modules
55
# IntelliJ IDEA settings
66
.idea
77
*.iml
8+
9+
# coverage reporter output
10+
coverage

gulpfile.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
var gulp = require('gulp');
2-
var browserify = require('browserify');
3-
var source = require('vinyl-source-stream');
4-
var del = require('del');
5-
var mocha = require('gulp-mocha');
6-
var webserver = require('gulp-webserver');
72

83
const BUILD_DIR = './dist/';
9-
4+
const COVERAGE_DIR = 'coverage';
105

116
gulp.task('default', ['clean', 'build']);
127

138
/**
14-
* Empties BUILD_DIR
9+
* Empties BUILD_DIR and all generated files
1510
*/
1611
gulp.task('clean', function(cb) {
17-
del([BUILD_DIR + '*'], cb);
12+
var del = require('del');
13+
del([BUILD_DIR + '*', COVERAGE_DIR], cb);
1814
});
1915

2016
/**
2117
* Generates browser-ready version for API in BUILD_DIR
2218
* File will be named as api.js
2319
*/
2420
gulp.task('build', function() {
21+
var browserify = require('browserify');
22+
var source = require('vinyl-source-stream');
2523
return browserify(
2624
'./src/api.js',
2725
{
@@ -35,6 +33,7 @@ gulp.task('build', function() {
3533

3634

3735
gulp.task('serve', function() {
36+
var webserver = require('gulp-webserver');
3837
gulp.src('./')
3938
.pipe(webserver({
4039
hostname: 'localhost',
@@ -46,7 +45,32 @@ gulp.task('serve', function() {
4645
});
4746

4847

49-
gulp.task('test', function() {
48+
var runMocha = function() {
49+
var mocha = require('gulp-mocha');
5050
return gulp.src('test/**/*Spec.js', {read: false})
5151
.pipe(mocha({}));
52+
};
53+
54+
gulp.task('test', runMocha);
55+
56+
gulp.task('test-coverage', function(cb) {
57+
var mocha = require('gulp-mocha');
58+
var istanbul = require('gulp-istanbul');
59+
60+
gulp.src(['src/**/*.js'])
61+
.pipe(istanbul()) // Covering files
62+
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
63+
.on('finish', function () {
64+
runMocha()
65+
.pipe(istanbul.writeReports()) // Creating the reports after tests runned
66+
.on('end', cb);
67+
});
5268
});
69+
70+
gulp.task('test-coveralls', function() {
71+
var coveralls = require('gulp-coveralls');
72+
return gulp.src(COVERAGE_DIR + '/lcov.info')
73+
.pipe(coveralls());
74+
});
75+
76+
gulp.task('test-ci', ['clean', 'test-coverage', 'test-coveralls']);

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
"chai": "^1.10.0",
1212
"del": "^1.1.0",
1313
"gulp": "^3.8.10",
14+
"gulp-coveralls": "^0.1.3",
15+
"gulp-istanbul": "^0.5.0",
1416
"gulp-mocha": "^2.0.0",
1517
"gulp-webserver": "^0.9.0",
1618
"vinyl-source-stream": "^1.0.0"
1719
},
1820
"scripts": {
19-
"test": "gulp test"
21+
"test": "gulp test-ci"
2022
},
2123
"repository": {
2224
"type": "git",

0 commit comments

Comments
 (0)