Created
July 21, 2016 16:26
-
-
Save Ygg01/5d83296e160bdff8b6e43e11ea58d97b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'), | |
mocha = require('gulp-mocha'), | |
istanbul = require('gulp-istanbul'); | |
var src_path = 'src/*.js'; | |
var test_path = 'test/*.js'; | |
gulp.task('pre-test', function () { | |
return gulp.src([src_path]) | |
// Covering files | |
.pipe(istanbul()) | |
// Force `require` to return covered files | |
.pipe(istanbul.hookRequire()); | |
}); | |
gulp.task('test', ['pre-test'], function () { | |
return gulp.src([test_path]) | |
.pipe(mocha()) | |
// Creating the reports after tests ran | |
.pipe(istanbul.writeReports()) | |
// Enforce a coverage of at least 90% | |
.pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } })) | |
; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "testing-test", | |
"version": "1.0.0", | |
"description": "Testing istanbul", | |
"main": "src/index.js", | |
"scripts": { | |
"test": "gulp test" | |
}, | |
"author": "Daniel Fath <daniel.fath7@gmail.com>", | |
"license": "ISC", | |
"devDependencies": { | |
"gulp": "^3.9.1", | |
"gulp-istanbul": "^1.0.0", | |
"gulp-mocha": "^2.2.0" | |
}, | |
"dependencies": { | |
"chai": "^3.5.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(exports) { | |
'use strict'; | |
exports.testing = function() { | |
if (arguments[0] !== null) { | |
return arguments[0]; | |
} else { | |
return -1; | |
} | |
}; | |
}(typeof exports === 'object' && exports || this)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var chai = require('chai'); | |
var lib = require('../src/index.js').testing; | |
var should = chai.should(); | |
describe('#test', function() { | |
it('test', function(){ | |
lib("x"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment