Skip to content

Commit

Permalink
Ignore files that do not exist in convertLcovToCoveralls
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjan Singh committed Sep 14, 2016
1 parent 95c4dfd commit 9933322
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/convertLcovToCoveralls.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ var convertLcovToCoveralls = function(input, options, cb){
postJson.service_pull_request = options.service_pull_request;
}
parsed.forEach(function(file){
postJson.source_files.push(convertLcovFileObject(file, filepath));
var currentFilePath = path.resolve(filepath, file.file);
if (fs.existsSync(currentFilePath)) {
postJson.source_files.push(convertLcovFileObject(file, filepath));
}
});
return cb(null, postJson);
});
Expand Down
34 changes: 34 additions & 0 deletions test/convertLcovToCoveralls.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,46 @@ describe("convertLcovToCoveralls", function(){
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();
});
});

it ("should ignore files that do not exists", function(done){
process.env.TRAVIS_JOB_ID = -1;
var lcovpath = __dirname + "/../fixtures/istanbul.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 false; };

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

should.not.exist(err);
output.source_files.should.be.empty;
done();
});
});

});

0 comments on commit 9933322

Please sign in to comment.