From 3d0aea0755c0ba0e3e64250670cd297ebd84d4a2 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 18 Aug 2016 18:31:33 +0200 Subject: [PATCH] Remap istanbul coverage info at the end of running tests --- .travis.yml | 4 +--- test/all.js | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0aa4bb48ada..a542976b975 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,6 +49,4 @@ script: - ./scripts/test-integration.sh after_success: - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then node_modules/.bin/remap-istanbul -i ./.build/coverage/coverage-final.json -t lcovonly > ./.build/coverage/lcov-remap.info; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sed <./.build/coverage/lcov-remap.info >./.build/coverage/lcov-remap-clean.info -e 's/^SF:.*:\(.*\)$/SF:\1/g'; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then node_modules/.bin/coveralls < .build/coverage/lcov-remap-clean.info; fi \ No newline at end of file + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then node_modules/.bin/coveralls < .build/coverage/lcov.info; fi \ No newline at end of file diff --git a/test/all.js b/test/all.js index d68d193b882..d3b0125e582 100644 --- a/test/all.js +++ b/test/all.js @@ -10,6 +10,7 @@ var assert = require('assert'); var path = require('path'); var glob = require('glob'); var istanbul = require('istanbul'); +var i_remap = require('remap-istanbul/lib/remap'); var jsdom = require('jsdom-no-contextify'); var minimatch = require('minimatch'); var async = require('async'); @@ -140,8 +141,40 @@ function main() { }); } + var remappedCoverage = i_remap(global.__coverage__).getFinalCoverage(); + + // The remapped coverage comes out with broken paths + var toUpperDriveLetter = function(str) { + if (/^[a-z]:/.test(str)) { + return str.charAt(0).toUpperCase() + str.substr(1); + } + return str; + }; + var toLowerDriveLetter = function(str) { + if (/^[A-Z]:/.test(str)) { + return str.charAt(0).toLowerCase() + str.substr(1); + } + return str; + }; + + var REPO_PATH = toUpperDriveLetter(path.join(__dirname, '..')); + var fixPath = function(brokenPath) { + var startIndex = brokenPath.indexOf(REPO_PATH); + if (startIndex === -1) { + return toLowerDriveLetter(brokenPath); + } + return toLowerDriveLetter(brokenPath.substr(startIndex)); + }; + + var finalCoverage = {}; + for (var entryKey in remappedCoverage) { + var entry = remappedCoverage[entryKey]; + entry.path = fixPath(entry.path); + finalCoverage[fixPath(entryKey)] = entry; + } + var collector = new istanbul.Collector(); - collector.add(global.__coverage__); + collector.add(finalCoverage); var reporter = new istanbul.Reporter(null, path.join(path.dirname(__dirname), '.build', 'coverage')); reporter.addAll(['json', 'lcov', 'html']);