Remap istanbul coverage info at the end of running tests

This commit is contained in:
Alex Dima 2016-08-18 18:31:33 +02:00
parent b72fb76e77
commit 3d0aea0755
2 changed files with 35 additions and 4 deletions

View file

@ -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
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then node_modules/.bin/coveralls < .build/coverage/lcov.info; fi

View file

@ -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']);