Skip to content

Commit

Permalink
test(coverage): test-coverage task
Browse files Browse the repository at this point in the history
  • Loading branch information
the-darc committed Jul 15, 2015
1 parent 45c687b commit 6274a25
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
npm-debug.log
coverage
60 changes: 43 additions & 17 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ var gulp = require('gulp'),
config: path.join(__dirname, 'package.json')
});

var path = {
var config = {
src: {
files: 'src/**/*.js'
files: 'src/**/*.js',
release: 'releases/br-validations.js'
},
test: {
files: 'test/**/*.test.js'
Expand Down Expand Up @@ -45,11 +46,11 @@ gulp.task('build', function(done) {
' ie: IE,',
' cpf: CPF,',
' cnpj: CNPJ,',
' pis: PIS',
' pis: PIS',
' };',
'}));'].join('\n');

gulp.src(path.src.files)
gulp.src(config.src.files)
.pipe(plugins.concat('br-validations.js'))
.pipe(plugins.header(header, {pkg: pkg}))
.pipe(plugins.footer(footer))
Expand All @@ -63,34 +64,59 @@ gulp.task('build', function(done) {
});

gulp.task('jshint', function(done) {
gulp.src(path.src.files)
gulp.src(config.src.files)
.pipe(plugins.jshint('.jshintrc'))
.pipe(plugins.jshint.reporter(jshintReporter));
done();
});

gulp.task('runtestdot', function() {
gulp.src(path.test.files, {read: false})
.pipe(plugins.mocha({
reporter: 'dot'
}))
function mochaRunnerFactory(reporter) {
return plugins.mocha({
reporter: reporter || 'spec'
});
}

gulp.task('runtestdot', ['jshint', 'build'], function() {
gulp.src(config.test.files, {read: false})
.pipe(mochaRunnerFactory('dot'))
.on('error', console.warn.bind(console));
});

gulp.task('runtest', function() {
gulp.src(path.test.files, {read: false})
.pipe(plugins.mocha({
reporter: 'spec'
}))
gulp.task('runtest', ['jshint', 'build'], function() {
gulp.src(config.test.files, {read: false})
.pipe(mochaRunnerFactory())
.on('error', console.warn.bind(console));
});

gulp.task('default', ['jshint', 'build', 'runtestdot'], function() {
gulp.watch(path.src.files, ['jshint', 'build', 'runtestdot']);
gulp.watch(config.src.files, ['jshint', 'build', 'runtestdot']);
});

gulp.task('test', ['jshint', 'build', 'runtest']);

gulp.task('test-watch', ['jshint', 'build', 'runtest'], function() {
gulp.watch(path.src.files, ['jshint', 'build', 'runtest']);
gulp.watch(config.src.files, ['jshint', 'build', 'runtest']);
});

gulp.task('test-coverage', function(done) {
gulp.src(config.src.release)
.pipe(plugins.istanbul())
.pipe(plugins.istanbul.hookRequire())
.on('finish', function() {
gulp.src(config.test.files, {
cwd: process.env.PWD,
read: false
})
.pipe(mochaRunnerFactory('spec'))
.pipe(plugins.istanbul.writeReports())
.on('end', function() {
if (process.env.TRAVIS) {
gulp.src('./coverage/**/lcov.info')
.pipe(plugins.coveralls())
.on('end', done);
} else {
done();
}
});
});
});
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
"url": "https://github.com/the-darc/br-validations/issues"
},
"scripts": {
"test": "gulp test"
"test": "gulp test-coverage"
},
"keywords": [
"validator",
"validation",
"cpf",
"cnpj",
"inscrição estadual",
"pis pasep"
"pis pasep"
],
"author": {
"name": "Daniel Campos",
Expand All @@ -32,8 +32,10 @@
"devDependencies": {
"gulp": "^3.7.0",
"gulp-concat": "^2.3.4",
"gulp-coveralls": "^0.1.4",
"gulp-footer": "^1.0.5",
"gulp-header": "^1.0.5",
"gulp-istanbul": "^0.10.0",
"gulp-jshint": "^1.6.1",
"gulp-load-plugins": "^0.5.3",
"gulp-mocha": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion test/cnpj.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var should = require('should'),
BrV = require('../releases/br-validations.min');
BrV = require('../releases/br-validations');

describe('br-validations', function(){
describe('CNPJ ', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/cpf.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var should = require('should'),
BrV = require('../releases/br-validations.min');
BrV = require('../releases/br-validations');

describe('br-validations', function(){
describe('CPF ', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/ie.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var should = require('should'),
BrV = require('../releases/br-validations.min');
BrV = require('../releases/br-validations');

describe('br-validations', function(){
describe('I.E. ', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/pis.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var should = require('should'),
BrV = require('../releases/br-validations.min');
BrV = require('../releases/br-validations');

describe('br-validations', function(){
describe('PIS ', function() {
Expand Down

0 comments on commit 6274a25

Please sign in to comment.