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 ced9ce2
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 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,38 +11,49 @@ 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)
.on('finish', function () {
gulp.src('.')
.pipe(instanbulEnforcer({
coverageDirectory: config.test.coverage.dest,
rootDirectory: '',
thresholds: {
statements: config.test.coverage.threshold || 80

// 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
}
}));
});
});
}))

/** 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
}
}));
};
// 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 () {
return gulp.src('.')
.pipe(instanbulEnforcer({
coverageDirectory: config.test.coverage.dest,
rootDirectory: '',
thresholds: {
statements: config.test.coverage.threshold || 80
}
}));
});
})
})
});
};
}

0 comments on commit ced9ce2

Please sign in to comment.