New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

coveralls

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coveralls - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

90

lib/fetchGitData.js

@@ -1,5 +0,8 @@

var exec = require("exec-sync");
var exec = require('child_process').exec;
var logger = require('./logger')();
var fetchGitData = function(git) {
var fetchGitData = function(git, cb) {
if (!cb){
throw new Error("fetchGitData requires a callback");
}

@@ -11,19 +14,14 @@ var i;

"format": "'%aN'",
"default": "Unknown Author"
},
"author_email": {
"format": "'%ae'",
"default": ""
},
"committer_name": {
"format": "'%cN'",
"default": "Unknown Committer"
},
"committer_email": {
"format": "'%ce'",
"default" :""
},
"message": {
"format": "'%s'",
"default": "Unknown Commit Message"
}

@@ -35,7 +33,7 @@ };

if ('undefined' === typeof git) {
throw new Error('No options passed');
return cb(new Error('No options passed'));
} else if (!git.hasOwnProperty('head')) {
throw new Error('You must provide the head');
return cb(new Error('You must provide the head'));
} else if (!git.head.hasOwnProperty('id')) {
throw new Error('You must provide the head.id');
return cb(new Error('You must provide the head.id'));
}

@@ -76,35 +74,51 @@

//-- Use git?
try {
exec("git log -1 " + git.head.id + " --pretty=format:'%H'");
} catch (e) {
execGit = false;
}
exec("git log -1 " + git.head.id + " --pretty=format:'%H'", function(err, response){
if (err){
// git is not available...
git.head.author_name = git.head.author_name || "Unknown Author";
git.head.author_email = git.head.author_email || "";
git.head.committer_name = git.head.committer_name || "Unknown Committer";
git.head.committer_email = git.head.committer_email || "";
git.head.message = git.head.message || "Unknown Commit Message";
return cb(null, git);
}
//-- Head
for (i in head) {
if (!git.head.hasOwnProperty(i)) {
if (execGit) {
git.head[i] = exec("git log -1 " + git.head.id + " --pretty=format:" + head[i].format);
} else {
git.head[i] = head[i].default;
}
//-- Head
var commands = [];
var fields = [];
for (var field in head) {
fields.push(field);
var command = "git log -1 " + git.head.id + " --pretty=format:" + head[field].format;
commands.push(command);
}
}
if (execGit) {
//-- Branch
git.branch = exec("git branch").split("\n")[0].replace(/^\*\ /, "").trim();
exec("git remote -v").split("\n").forEach(function(remote) {
remote = remote.split(/\s/);
saveRemote(remote[0], remote[1]);
var i = 0;
var remaining = commands.length;
commands.forEach(function(command){
var field = fields[i];
i++;
exec(command, function(err, response){
if (err) return cb(err);
git.head[field] = response;
remaining--;
if (remaining === 0){
//-- Branch
exec("git branch", function(err, branches){
if (err) return cb(err);
git.branch = branches.split("\n")[0].replace(/^\*\ /, "").trim();
exec("git remote -v", function(err, remotes){
if (err) return cb(err);
remotes.split("\n").forEach(function(remote) {
remote = remote.split(/\s/);
saveRemote(remote[0], remote[1]);
});
return cb(null, git);
});
});
}
});
});
});
};
}
return git;
};
module.exports = fetchGitData;

@@ -5,5 +5,8 @@ var fs = require('fs');

var logger = require('./logger')();
var git = require('./fetchGitData');
var fetchGitData = require('./fetchGitData');
var getOptions = function(){
var getOptions = function(cb){
if (!cb){
throw new Error('getOptions requires a callback');
}
var options = {};

@@ -45,9 +48,7 @@

if (git_commit){
options.git = git({
head: {
id: git_commit
},
branch: git_branch
});
if (process.env.CI_NAME && process.env.CI_NAME === 'codeship'){
options.service_name = 'codeship';
options.service_job_id = process.env.CI_BUILD_NUMBER;
git_commit = process.env.CI_COMMIT_ID;
git_branch = process.env.CI_BRANCH;
}

@@ -78,5 +79,23 @@

}
return options;
if (git_commit){
fetchGitData({
head: {
id: git_commit
},
branch: git_branch
}, function(err, git){
if (err){
logger.warn('there was an error getting git data: ', err);
} else {
options.git = git;
}
return cb(err, options);
});
} else {
return cb(null, options);
}
};
module.exports = getOptions;

@@ -6,20 +6,25 @@ var index = require('../index');

logger.debug(input);
var options = index.getOptions();
logger.debug(options);
index.convertLcovToCoveralls(input, options, function(err, postData){
var options = index.getOptions(function(err, options){
if (err){
logger.error("error from convertLcovToCoveralls");
logger.error("error from getOptions");
throw err;
}
logger.info("sending this to coveralls.io: ", JSON.stringify(postData));
index.sendToCoveralls(postData, function(err, response, body){
logger.debug(options);
index.convertLcovToCoveralls(input, options, function(err, postData){
if (err){
logger.error("error from convertLcovToCoveralls");
throw err;
}
if (response.statusCode >= 400){
throw "Bad response: " + response.statusCode + " " + body;
}
logger.debug(response.statusCode);
logger.debug(body);
logger.info("sending this to coveralls.io: ", JSON.stringify(postData));
index.sendToCoveralls(postData, function(err, response, body){
if (err){
throw err;
}
if (response.statusCode >= 400){
throw "Bad response: " + response.statusCode + " " + body;
}
logger.debug(response.statusCode);
logger.debug(body);
});
});

@@ -26,0 +31,0 @@ });

@@ -8,3 +8,3 @@ {

],
"version": "2.1.0",
"version": "2.2.0",
"bugs": {

@@ -37,4 +37,3 @@ "url": "https://github.com/cainus/node-coveralls/issues"

"lcov-parse": "0.0.4",
"log-driver": "1.2.1",
"exec-sync": "~0.1.6"
"log-driver": "1.2.1"
},

@@ -41,0 +40,0 @@ "devDependencies": {

#node-coveralls
[![Build Status](https://travis-ci.org/cainus/node-coveralls.png?branch=master)](https://travis-ci.org/cainus/node-coveralls)
[![Coverage Status](https://coveralls.io/repos/cainus/node-coveralls/badge.png?branch=master)](https://coveralls.io/r/cainus/node-coveralls?branch=master)
[![Codeship Build Status](https://www.codeship.io/projects/de6fb440-dea9-0130-e7d9-122ca7ee39d3/status)](https://www.codeship.io/projects/5622)
[Coveralls.io](https://coveralls.io/) support for node.js. Get the great coverage reporting of coveralls.io and add a cool coverage button ( like the one above ) to your README.
Supported CI services: [travis-ci](https://travis-ci.org/), [codeship](https://www.codeship.io/), [circle-ci](https://circleci.com/), [jenkins](http://jenkins-ci.org/)
##Installation:

@@ -55,3 +58,5 @@ Add the latest version of `coveralls` to your package.json:

### [Istanbul](https://github.com/gotwarlost/istanbul)
TODO
```sh
istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
```

@@ -58,0 +63,0 @@ ### [Nodeunit](https://github.com/caolan/nodeunit) + [JSCoverage](https://github.com/fishbar/jscoverage)

@@ -9,3 +9,3 @@ var convertLcovToCoveralls = require('../index').convertLcovToCoveralls;

describe("convertLcovToCoveralls", function(){
it ("should convert a simple lcov file", function(){
it ("should convert a simple lcov file", function(done){
process.env.TRAVIS_JOB_ID = -1;

@@ -21,6 +21,7 @@ var path = __dirname + "/../fixtures/onefile.lcov";

output.source_files[0].coverage[60].should.equal(0);
done();
});
});
it ("should pass on all appropriate parameters from the environment", function(){
it ("should pass on all appropriate parameters from the environment", function(done){
process.env.TRAVIS_JOB_ID = -1;

@@ -33,14 +34,15 @@ process.env.COVERALLS_GIT_COMMIT = "GIT_HASH";

var options = getOptions();
var path = __dirname + "/../fixtures/onefile.lcov";
var input = fs.readFileSync(path, "utf8");
var libpath = "fixtures/lib";
options.filepath = libpath;
convertLcovToCoveralls(input, options, function(err, output){
should.not.exist(err);
console.log(output);
//output.git.should.equal("GIT_HASH");
getOptions(function(err, options){
var path = __dirname + "/../fixtures/onefile.lcov";
var input = fs.readFileSync(path, "utf8");
var libpath = "fixtures/lib";
options.filepath = libpath;
convertLcovToCoveralls(input, options, function(err, output){
should.not.exist(err);
//output.git.should.equal("GIT_HASH");
done();
});
});
});
it ("should work with a relative path as well", function(){
it ("should work with a relative path as well", function(done){
process.env.TRAVIS_JOB_ID = -1;

@@ -54,4 +56,5 @@ var path = __dirname + "/../fixtures/onefile.lcov";

output.source_files[0].source.split("\n").length.should.equal(173);
done();
});
});
});
var should = require('should');
var git = require('../lib/fetchGitData');
var fetchGitData = require('../lib/fetchGitData');
var getOptions = require('../index').getOptions;

@@ -10,39 +10,42 @@

it("should throw an error when no data is passed", function() {
git.should.throw(/No options passed/);
fetchGitData.should.throw(/fetchGitData requires a callback/);
});
it("should throw an error if no head is provided", function() {
var fn = function() {
git({});
};
fn.should.throw(/You must provide the head/);
it("should throw an error if no head is provided", function(done) {
fetchGitData({
}, function(err){
err.should.match(/You must provide the head/);
done();
});
});
it("should throw an error if no head.id is provided", function() {
var fn = function() {
git({
head: {}
});
};
fn.should.throw(/You must provide the head.id/);
it("should throw an error if no head.id is provided", function(done) {
fetchGitData({
head: {}
}, function(err){
err.should.match(/You must provide the head.id/);
done();
});
});
it("should return default values", function() {
var options = git({
it("should return default values", function(done) {
var options = fetchGitData({
head: {
id: "COMMIT_HASH"
}
}, function(err, options){
options.should.eql({
"head": {
"id": "COMMIT_HASH",
"author_name": "Unknown Author",
"author_email": "",
"committer_name": "Unknown Committer",
"committer_email": "",
"message": "Unknown Commit Message"
},
"branch": "",
"remotes": []
});
done();
});
options.should.eql({
"head": {
"id": "COMMIT_HASH",
"author_name": "Unknown Author",
"author_email": "",
"committer_name": "Unknown Committer",
"committer_email": "",
"message": "Unknown Commit Message"
},
"branch": "",
"remotes": []
});
});
it("should override default values", function() {
var options = git({
it("should override default values", function(done) {
var options = fetchGitData({
"head": {

@@ -63,23 +66,25 @@ "id": "COMMIT_HASH",

]
}, function(err, options){
options.should.eql({
"head": {
"id": "COMMIT_HASH",
"author_name": "MY AUTHOR",
"author_email": "",
"committer_name": "MY COMMITTER",
"committer_email": "",
"message": "MY COMMIT MESSAGE"
},
"branch": "TEST",
"remotes": [
{
"name": "TEST",
"url": "test-url"
}
]
});
done();
});
options.should.eql({
"head": {
"id": "COMMIT_HASH",
"author_name": "MY AUTHOR",
"author_email": "",
"committer_name": "MY COMMITTER",
"committer_email": "",
"message": "MY COMMIT MESSAGE"
},
"branch": "TEST",
"remotes": [
{
"name": "TEST",
"url": "test-url"
}
]
});
});
it("should convert git.branch to a string", function() {
var objectToString = git({
it("should convert git.branch to a string", function(done) {
fetchGitData({
"head": {

@@ -91,14 +96,17 @@ "id": "COMMIT_HASH"

}
}, function(err, str){
str.branch.should.be.a("string");
fetchGitData({
"head": {
"id": "COMMIT_HASH"
},
"branch": ["convert", "to", "a", "string"]
}, function(err, str){
str.branch.should.be.a("string");
done();
});
});
var arrayToString = git({
"head": {
"id": "COMMIT_HASH"
},
"branch": ["convert", "to", "a", "string"]
});
objectToString.branch.should.be.a("string");
arrayToString.branch.should.be.a("string");
});
it("should convert git.remotes to an array", function() {
var stringToArray = git({
it("should convert git.remotes to an array", function(done) {
fetchGitData({
"head": {

@@ -108,16 +116,19 @@ "id": "COMMIT_HASH"

"remotes": "convert from string to an array"
}, function(err, arr){
arr.remotes.should.be.instanceof(Array);
fetchGitData({
"head": {
"id": "COMMIT_HASH"
},
"remotes": {
"convert": "from object to an array"
}
}, function(err, arr){
arr.remotes.should.be.instanceof(Array);
done();
});
});
var objectToArray = git({
"head": {
"id": "COMMIT_HASH"
},
"remotes": {
"convert": "from object to an array"
}
});
stringToArray.remotes.should.be.instanceof(Array);
objectToArray.remotes.should.be.instanceof(Array);
});
it("should save passed remotes", function() {
var options = git({
it("should save passed remotes", function(done) {
fetchGitData({
"head": {

@@ -132,34 +143,39 @@ "id": "COMMIT_HASH"

]
}, function(err, options){
options.should.eql({
"head": {
"id": "COMMIT_HASH",
"author_name": "Unknown Author",
"author_email": "",
"committer_name": "Unknown Committer",
"committer_email": "",
"message": "Unknown Commit Message"
},
"branch": "",
"remotes": [
{
"name": "test",
"url": "https://my.test.url"
}
]
});
done();
});
options.should.eql({
"head": {
"id": "COMMIT_HASH",
"author_name": "Unknown Author",
"author_email": "",
"committer_name": "Unknown Committer",
"committer_email": "",
"message": "Unknown Commit Message"
},
"branch": "",
"remotes": [
{
"name": "test",
"url": "https://my.test.url"
}
]
});
});
it("should execute git commands when a valid commit hash is given", function() {
it("should execute git commands when a valid commit hash is given", function(done) {
process.env.COVERALLS_GIT_COMMIT = "HEAD";
process.env.COVERALLS_GIT_BRANCH = "master";
var options = getOptions().git;
options.head.should.be.a("object");
options.head.author_name.should.not.equal("Unknown Author");
options.head.committer_name.should.not.equal("Unknown Committer");
options.head.message.should.not.equal("Unknown Commit Message");
options.branch.should.be.a("string");
options.should.have.property("remotes");
options.remotes.should.be.instanceof(Array);
options.remotes.length.should.be.above(0);
getOptions(function(err, options){
options = options.git;
options.head.should.be.a("object");
options.head.author_name.should.not.equal("Unknown Author");
options.head.committer_name.should.not.equal("Unknown Committer");
options.head.message.should.not.equal("Unknown Commit Message");
options.branch.should.be.a("string");
options.should.have.property("remotes");
options.remotes.should.be.instanceof(Array);
options.remotes.length.should.be.above(0);
done();
});
});
});

@@ -8,40 +8,64 @@ var should = require('should');

});
it ("should get a filepath if there is one", function(){
it ("should get a filepath if there is one", function(done){
process.argv[2] = "somepath";
getOptions().filepath.should.equal("somepath");
getOptions(function(err, options){
options.filepath.should.equal("somepath");
done();
});
});
it ("should get a filepath if there is one, even in verbose mode", function(){
it ("should get a filepath if there is one, even in verbose mode", function(done){
process.argv[2] = "--verbose";
process.argv[3] = "somepath";
getOptions().filepath.should.equal("somepath");
getOptions(function(err, options){
options.filepath.should.equal("somepath");
done();
});
});
it ("should set service_job_id if it exists", function(){
it ("should set service_job_id if it exists", function(done){
process.env.COVERALLS_SERVICE_JOB_ID = "SERVICE_JOB_ID";
getOptions().service_job_id.should.equal("SERVICE_JOB_ID");
getOptions(function(err, options){
options.service_job_id.should.equal("SERVICE_JOB_ID");
done();
});
});
it ("should set git hash if it exists", function(){
it ("should set git hash if it exists", function(done){
process.env.COVERALLS_GIT_COMMIT = "e3e3e3e3e3e3e3e3e";
getOptions().git.head.id.should.equal("e3e3e3e3e3e3e3e3e");
getOptions(function(err, options){
options.git.head.id.should.equal("e3e3e3e3e3e3e3e3e");
done();
});
});
it ("should set git hash if it exists", function(){
it ("should set git hash if it exists", function(done){
process.env.COVERALLS_GIT_COMMIT = "e3e3e3e3e3e3e3e3e";
process.env.COVERALLS_GIT_BRANCH = "master";
getOptions().git.branch.should.equal("master");
getOptions(function(err, options){
options.git.branch.should.equal("master");
done();
});
});
it ("should set repo_token if it exists", function(){
it ("should set repo_token if it exists", function(done){
process.env.COVERALLS_REPO_TOKEN = "REPO_TOKEN";
getOptions().repo_token.should.equal("REPO_TOKEN");
getOptions(function(err, options){
options.repo_token.should.equal("REPO_TOKEN");
done();
});
});
it ("should set service_name if it exists", function(){
it ("should set service_name if it exists", function(done){
process.env.COVERALLS_SERVICE_NAME = "SERVICE_NAME";
getOptions().service_name.should.equal("SERVICE_NAME");
getOptions(function(err, options){
options.service_name.should.equal("SERVICE_NAME");
done();
});
});
it ("should set service_name and service_job_id if it's running on travis-ci", function(){
it ("should set service_name and service_job_id if it's running on travis-ci", function(done){
process.env.TRAVIS = "TRUE";
process.env.TRAVIS_JOB_ID = "1234";
getOptions().service_name.should.equal("travis-ci");
getOptions().service_job_id.should.equal("1234");
getOptions(function(err, options){
options.service_name.should.equal("travis-ci");
options.service_job_id.should.equal("1234");
done();
});
});
it ("should set service_name and service_job_id if it's running on jenkins", function(){
it ("should set service_name and service_job_id if it's running on jenkins", function(done){
process.env.JENKINS_URL = "something";

@@ -51,16 +75,18 @@ process.env.BUILD_ID = "1234";

process.env.GIT_BRANCH = "master";
var options = getOptions();
options.service_name.should.equal("jenkins");
options.service_job_id.should.equal("1234");
options.git.should.eql({ head:
{ id: 'a12s2d3df4f435g45g45g67h5g6',
author_name: 'Unknown Author',
author_email: '',
committer_name: 'Unknown Committer',
committer_email: '',
message: 'Unknown Commit Message' },
branch: 'master',
remotes: [] });
getOptions(function(err, options){
options.service_name.should.equal("jenkins");
options.service_job_id.should.equal("1234");
options.git.should.eql({ head:
{ id: 'a12s2d3df4f435g45g45g67h5g6',
author_name: 'Unknown Author',
author_email: '',
committer_name: 'Unknown Committer',
committer_email: '',
message: 'Unknown Commit Message' },
branch: 'master',
remotes: [] });
done();
});
});
it ("should set service_name and service_job_id if it's running on circleci", function(){
it ("should set service_name and service_job_id if it's running on circleci", function(done){
process.env.CIRCLECI = true;

@@ -70,15 +96,17 @@ process.env.CIRCLE_BRANCH = "master";

process.env.CIRCLE_SHA1 = "e3e3e3e3e3e3e3e3e";
var options = getOptions();
options.service_name.should.equal("circleci");
options.service_job_id.should.equal("1234");
options.git.should.eql({ head:
{ id: 'e3e3e3e3e3e3e3e3e',
author_name: 'Unknown Author',
author_email: '',
committer_name: 'Unknown Committer',
committer_email: '',
message: 'Unknown Commit Message' },
branch: 'master',
remotes: [] });
getOptions(function(err, options){
options.service_name.should.equal("circleci");
options.service_job_id.should.equal("1234");
options.git.should.eql({ head:
{ id: 'e3e3e3e3e3e3e3e3e',
author_name: 'Unknown Author',
author_email: '',
committer_name: 'Unknown Committer',
committer_email: '',
message: 'Unknown Commit Message' },
branch: 'master',
remotes: [] });
done();
});
});
});

@@ -12,4 +12,4 @@ var should = require('should');

it ("throws an error when there's an error sending", function(done){
sinon.stub(index, 'getOptions', function(){
return {};
sinon.stub(index, 'getOptions', function(cb){
return cb(null, {});
});

@@ -29,4 +29,4 @@ sinon.stub(index, 'sendToCoveralls', function(postData, cb){

it ("throws an error when there's a bad status code", function(done){
sinon.stub(index, 'getOptions', function(){
return {};
sinon.stub(index, 'getOptions', function(cb){
return cb(null, {});
});

@@ -46,4 +46,4 @@ sinon.stub(index, 'sendToCoveralls', function(postData, cb){

it ("completes successfully when there are now errors", function(done){
sinon.stub(index, 'getOptions', function(){
return {};
sinon.stub(index, 'getOptions', function(cb){
return cb(null, {});
});

@@ -50,0 +50,0 @@ sinon.stub(index, 'sendToCoveralls', function(postData, cb){

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc