Skip to content
This repository has been archived by the owner on May 8, 2020. It is now read-only.

Commit

Permalink
feat(coverage): implemented coverage instrumenting with source remapp…
Browse files Browse the repository at this point in the history
…ing for typescript reporting
  • Loading branch information
zakhenry committed May 20, 2016
1 parent be51855 commit 12842c8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
55 changes: 48 additions & 7 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ let tsc = require('gulp-typescript');
let sourcemaps = require('gulp-sourcemaps');
let tslint = require('gulp-tslint');
let nodemon = require('gulp-nodemon');
var jasmine = require('gulp-jasmine');
var istanbul = require('gulp-istanbul');
let jasmine = require('gulp-jasmine');
let istanbul = require('gulp-istanbul');
let runSequence = require('run-sequence');

var path = require('path');

// /* Variables */
Expand All @@ -27,7 +29,7 @@ let entryPoint = './localhost.js';
* Remove build directory.
*/
gulp.task('clean', function () {
return gulp.src('build', {read: false})
return gulp.src(['build', 'coverage'], {read: false})
.pipe(rimraf())
});

Expand Down Expand Up @@ -80,7 +82,7 @@ gulp.task('compile', ['clean'], () => {
.pipe(sourcemaps.init())
.pipe(tsc(tsProject));
return tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(sourcemaps.write('.', {sourceRoot: __dirname}))
.pipe(gulp.dest(outDir))
});

Expand All @@ -100,7 +102,19 @@ gulp.task('build', ['compile'], () => {
console.log('Building the project ...')
});

gulp.task('test', ['build'], () => {
gulp.task('pre-test', function () {
return gulp.src(['build/api/**/*.js'])
// Covering files
.pipe(istanbul())
// Force `require` to return covered files
.pipe(istanbul.hookRequire());
});

gulp.task('test', [], (callback) => {
runSequence('build', 'pre-test', 'jasmine', 'remap-istanbul', callback);
});

gulp.task('jasmine', [], () => {
Error.stackTraceLimit = Infinity;

require('es6-shim');
Expand All @@ -109,13 +123,40 @@ gulp.task('test', ['build'], () => {

const SpecReporter = require('jasmine-spec-reporter');

return gulp.src(['build/**/*.spec.js'])
return gulp.src(['build/api/**/*.js', '!build/api/api/bootstrap.js'])
.pipe(jasmine({
reporter: new SpecReporter({
displayFailuresSummary: false
})
})
);
)
// Creating the reports after tests ran
.pipe(istanbul.writeReports({
dir: './coverage/api/js',
reporters: [ 'json' ],
}))
// Enforce a coverage of at least 90%
// .pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } }));
});



gulp.task('remap-istanbul', [], () => {

let remapIstanbul = require('remap-istanbul/lib/gulpRemapIstanbul');

return gulp.src('./coverage/api/js/coverage-final.json')
.pipe(remapIstanbul({
options: {
basePath: 'foo',
},
reports: {
'json': './coverage/api/ts/coverage.json',
'html': './coverage/api/ts/html-report',
// 'text-summary': 'text-summary',
'lcovonly': './coverage/api/ts/lcov.info'
}
}));
});

gulp.task('nodemon', ['build'], () => {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
"null-loader": "^0.1.1",
"phantomjs-prebuilt": "^2.1.7",
"raw-loader": "^0.5.1",
"remap-istanbul": "^0.6.4",
"rimraf": "^2.5.2",
"run-sequence": "^1.2.0",
"style-loader": "^0.13.1",
"ts-loader": "^0.8.2",
"tslint": "^3.10.2",
Expand Down

0 comments on commit 12842c8

Please sign in to comment.