From 09b23661cee80d5d5724e30868a6b6fbd8f0d5b1 Mon Sep 17 00:00:00 2001 From: Brian Ingenito <28159742+bingenito@users.noreply.github.com> Date: Tue, 9 Jul 2019 15:28:53 +0000 Subject: [PATCH] Strip 'build' dir from source maps in coverage file --- .gulp/tasks/tests.js | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/.gulp/tasks/tests.js b/.gulp/tasks/tests.js index ed9ca5e1a..cb0192026 100644 --- a/.gulp/tasks/tests.js +++ b/.gulp/tasks/tests.js @@ -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'); @@ -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: '', @@ -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 - } - })); - }; }; }