Skip to content

Commit

Permalink
Merge pull request #144 from a11smiles/master
Browse files Browse the repository at this point in the history
Fixes #143 where .lcov files generated by Angular CLI & Typescript (istanbul.remap) have improper source file name
  • Loading branch information
nickmerwin committed Nov 11, 2016
2 parents cbb1e46 + f9c3697 commit d15a6f8
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 0 deletions.
131 changes: 131 additions & 0 deletions fixtures/istanbul.remap.lcov
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
TN:
SF:/Users/deepsweet/Dropbox/projects/svgo/node_modules/angular2-template-loader/index.js!/Users/deepsweet/Dropbox/projects/svgo/node_modules/tslint-loader/index.js!/Users/deepsweet/Dropbox/projects/svgo/lib/svgo/config.js
FN:14,(anonymous_1)
FN:51,preparePluginsArray
FN:56,(anonymous_3)
FN:101,extendConfig
FN:108,(anonymous_5)
FN:115,(anonymous_6)
FN:161,optimizePluginsArray
FN:165,(anonymous_8)
FN:169,(anonymous_9)
FNF:9
FNH:9
FNDA:87,(anonymous_1)
FNDA:87,preparePluginsArray
FNDA:141,(anonymous_3)
FNDA:1,extendConfig
FNDA:3,(anonymous_5)
FNDA:84,(anonymous_6)
FNDA:87,optimizePluginsArray
FNDA:141,(anonymous_8)
FNDA:141,(anonymous_9)
DA:1,1
DA:3,1
DA:5,1
DA:14,1
DA:16,87
DA:18,87
DA:20,85
DA:22,85
DA:23,85
DA:24,85
DA:29,2
DA:31,2
DA:33,2
DA:34,1
DA:37,2
DA:41,87
DA:51,1
DA:53,87
DA:56,87
DA:59,141
DA:61,85
DA:62,85
DA:65,85
DA:66,0
DA:67,0
DA:70,85
DA:71,0
DA:74,85
DA:75,85
DA:78,85
DA:83,56
DA:84,56
DA:88,141
DA:101,1
DA:103,1
DA:106,1
DA:108,1
DA:111,3
DA:113,3
DA:115,3
DA:117,84
DA:119,3
DA:120,2
DA:121,2
DA:124,1
DA:125,1
DA:128,0
DA:129,0
DA:142,1
DA:143,0
DA:147,1
DA:148,0
DA:151,1
DA:161,1
DA:163,87
DA:165,87
DA:166,141
DA:169,87
DA:171,141
DA:172,44
DA:173,44
DA:176,97
DA:178,97
DA:182,87
LF:64
LH:57
BRDA:18,1,0,85
BRDA:18,1,1,2
BRDA:18,2,0,87
BRDA:18,2,1,86
BRDA:22,3,0,85
BRDA:22,3,1,0
BRDA:33,4,0,1
BRDA:33,4,1,1
BRDA:59,5,0,85
BRDA:59,5,1,56
BRDA:65,6,0,0
BRDA:65,6,1,85
BRDA:66,7,0,0
BRDA:66,7,1,0
BRDA:70,8,0,0
BRDA:70,8,1,85
BRDA:74,9,0,85
BRDA:74,9,1,0
BRDA:106,10,0,1
BRDA:106,10,1,0
BRDA:111,11,0,3
BRDA:111,11,1,0
BRDA:117,12,0,3
BRDA:117,12,1,81
BRDA:119,13,0,2
BRDA:119,13,1,1
BRDA:120,14,0,2
BRDA:120,14,1,1
BRDA:124,15,0,1
BRDA:124,15,1,0
BRDA:128,16,0,0
BRDA:128,16,1,0
BRDA:142,17,0,0
BRDA:142,17,1,1
BRDA:147,18,0,0
BRDA:147,18,1,1
BRDA:171,19,0,44
BRDA:171,19,1,97
BRDA:171,20,0,141
BRDA:171,20,1,54
BRF:40
BRH:27
end_of_record
11 changes: 11 additions & 0 deletions lib/convertLcovToCoveralls.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ var convertLcovFileObject = function(file, filepath){
coverage : coverage };
};

var cleanFilePath = function(file) {
if (file.indexOf('!') > -1) {
var regex = /^(.*!)(.*)$/g;
var matches = regex.exec(file);
return matches[matches.length-1];
}

return file;
};

var convertLcovToCoveralls = function(input, options, cb){
var filepath = options.filepath || '';
logger.debug("in: ", filepath);
Expand Down Expand Up @@ -61,6 +71,7 @@ var convertLcovToCoveralls = function(input, options, cb){
postJson.service_pull_request = options.service_pull_request;
}
parsed.forEach(function(file){
file.file = cleanFilePath(file.file);
var currentFilePath = path.resolve(filepath, file.file);
if (fs.existsSync(currentFilePath)) {
postJson.source_files.push(convertLcovFileObject(file, filepath));
Expand Down
29 changes: 29 additions & 0 deletions test/convertLcovToCoveralls.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,33 @@ describe("convertLcovToCoveralls", function(){
});
});

it ("should parse file paths concatenated by typescript and ng 2", function(done) {
process.env.TRAVIS_JOB_ID = -1;
var lcovpath = __dirname + "/../fixtures/istanbul.remap.lcov";
var input = fs.readFileSync(lcovpath, "utf8");
var libpath = "/Users/deepsweet/Dropbox/projects/svgo/lib";
var sourcepath = path.resolve(libpath, "svgo/config.js");

var originalReadFileSync = fs.readFileSync;
fs.readFileSync = function(filepath) {
if (filepath === sourcepath) {
return '';
}

return originalReadFileSync.apply(fs, arguments);
};

var originalExistsSync = fs.existsSync;
fs.existsSync = function () { return true; };

convertLcovToCoveralls(input, {filepath: libpath}, function(err, output){
fs.readFileSync = originalReadFileSync;
fs.existsSync = originalExistsSync;

should.not.exist(err);
output.source_files[0].name.should.equal(path.join("svgo", "config.js"));
done();
});
});

});

0 comments on commit d15a6f8

Please sign in to comment.