Skip to content

Commit

Permalink
Strip 'build' dir from source maps in coverage file
Browse files Browse the repository at this point in the history
  • Loading branch information
bingenito committed Jul 9, 2019
1 parent 842f6cc commit 09b2366
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions .gulp/tasks/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var jasmine = require('gulp-jasmine'),
istanbul = require('gulp-istanbul'),
replace = require('gulp-replace'),
remap = require('remap-istanbul/lib/gulpRemapIstanbul'),
instanbulEnforcer = require('gulp-istanbul-enforcer');

Expand All @@ -10,16 +11,40 @@ module.exports = function (gulp, config) {
return gulp.src(config.test.coverage.src)
.pipe(istanbul({ includeUntested: true }))
.pipe(istanbul.hookRequire())
.on('finish', function () {
.on('finish', () => {

// Run jasmine under istanbul
gulp.src(config.test.src)
.pipe(jasmine({ verbose: true, errorOnFail: true, includeStackTrace: false }))
.pipe(istanbul.writeReports({
dir: config.test.coverage.dest,
reporters: ['json']
}))
//.on('end', remapCoverageFiles)

// Take js coverage json and remap to typescript. Output html and text
.on('end', () => {
return gulp.src(config.test.coverage.coverageFile)
.pipe(remap({
reports: {
'json': config.test.coverage.coverageFile, // overwrite js based json with ts remapped version
'html': config.test.coverage.dest,
'lcovonly': config.test.coverage.lcovFile,
'text': null
}
}));
})

// Remove staging build directory in code coverage for correct file mapping
.on('finish', function () {
return gulp.src(config.test.coverage.coverageFile)
.pipe(replace(/\\\\build\\\\src/mg, '\\\\src')) // windows
.pipe(replace(/\/build\/src/mg, '/src')) // unix)
.pipe(gulp.dest(config.test.coverage.dest));
})

// Enforce statement coverage threshold based on config or if not defined 80%
.on('finish', function () {
gulp.src('.')
return gulp.src('.')
.pipe(instanbulEnforcer({
coverageDirectory: config.test.coverage.dest,
rootDirectory: '',
Expand All @@ -29,19 +54,6 @@ module.exports = function (gulp, config) {
}));
});
});

/** Take js coverage json and remap to typescript. Output html and text */
function remapCoverageFiles() {
return gulp.src(config.test.coverage.coverageFile)
.pipe(remap({
reports: {
'json': config.test.coverage.coverageFile, // overwrite js based json with ts remapped version
'html': config.test.coverage.dest,
'lcovonly': config.test.coverage.lcovFile,
'text': null
}
}));
};
};
}

0 comments on commit 09b2366

Please sign in to comment.