Skip to content

Commit

Permalink
increased code coverage and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
hortinstein committed Oct 17, 2015
1 parent 925caf9 commit 06a1f34
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
11 changes: 4 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ var int_array_to_hex = function (int_array) {
var hex = "";
for (var i in int_array){
var h = int_array[i].toString(16); // converting to hex
if (h.length < 2) h = '0' + h; //adding a 0 for non 2 digit numbers
if (i !== int_array.length) hex+=":"; //adding a : for all but the last group
if (h.length < 2) {h = '0' + h}; //adding a 0 for non 2 digit numbers
if (i !== int_array.length) {hex+=":"}; //adding a : for all but the last group
hex += h;
}
return hex.slice(1);//slice is to get rid of the leading :
Expand All @@ -37,11 +37,8 @@ var create_session = function () {
var session = pcap.createSession();
} catch (err) {
console.error(err);
if (err == "Error: pcap_findalldevs didn't find any devs") {
console.log("Failed to create pcap session: couldn't find devices to listen on.\n" +
"Try running with elevated privileges via 'sudo'");
}
process.exit(1);
console.error("Failed to create pcap session: couldn't find devices to listen on.\n" + "Try running with elevated privileges via 'sudo'");
throw new Error('Error: No devices to listen');
}
return session;
};
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"livetest": "istanbul cover ./node_modules/mocha/bin/_mocha test/test-live.js --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha test/test.js --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},
"bin":{
"bin": {
"findbutton": "./bin/findbutton"
},
"repository": {
Expand All @@ -33,12 +33,11 @@
},
"devDependencies": {
"arpjs": "^1.0.0",
"coveralls": "^2.11.4",
"istanbul": "0.3.22",
"mocha": "^2.3.0",
"should": "^7.1.0",
"sinon": "^1.17.1",
"mockery": "^1.4.0",
"istanbul": "0.3.22",
"coveralls": "^2.11.4"
"should": "^7.1.0",
"sinon": "^1.17.1"
}

}
14 changes: 13 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var mock_pcap = {
},
decode: {
packet: function(packet) {
mock_packet = {
var mock_packet = {
"payload": {
"ethertype": packet.packet_payload_ethertype,
"payload": {
Expand All @@ -48,6 +48,8 @@ var mock_pcap = {
}
}
};
var pcap = ""; //for linting purps
var dash_button = ""; //for linting purps
startTests = function() {
before(function() {
mockery.enable({
Expand Down Expand Up @@ -102,5 +104,15 @@ startTests = function() {
});
fake_session.emit('packet', packet3);
});
it('should throw an error if no interfaces are available', function(done) {
mock_pcap.createSession = function() {
throw new Error("Error: pcap_findalldevs didn't find any devs");
};
try {
dash_button.register('bullshit');
} catch(err) {
done()
}
});
};
startTests();

0 comments on commit 06a1f34

Please sign in to comment.