Skip to content

Commit

Permalink
Update: Add and improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Jun 27, 2016
1 parent 6df8df1 commit 0cd5d83
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 16 deletions.
30 changes: 20 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
lib-cov
*.seed
# Logs
logs
*.log
*.csv
*.dat
*.out
*.pid
*.gz

# Runtime data
pids
logs
results
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

npm-debug.log
# Dependency directory
# Deployed apps should consider commenting this line out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules
8 changes: 3 additions & 5 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ function getExtensions(lastArg){
}

function buildOnSettled(done){
done = done || _.noop;

function onSettled(error, result){
var settledErrors = _.where(result, { state: 'error' });
var settledResults = _.where(result, { state: 'success' });
Expand All @@ -28,11 +30,7 @@ function buildOnSettled(done){
}

error = error || errors;
if(error){
return done(error, results);
}

done(undefined, results);
done(error, results);
}

return onSettled;
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"test": "test"
},
"scripts": {
"test": "tap ./test"
"test": "tap ./test/*.js",
"cover": "istanbul cover ./test/cover/index.js"
},
"repository": {
"type": "git",
Expand All @@ -26,6 +27,8 @@
},
"homepage": "https://github.com/phated/bach",
"devDependencies": {
"istanbul": "^0.3.0",
"require-dir": "^0.1.0",
"tap": "~0.4.8"
},
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions test/cover/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

require('require-dir')('../');
17 changes: 17 additions & 0 deletions test/getExtensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

var test = require('tap').test;

var getExtensions = require('../lib/helpers').getExtensions;

test('should return the argument if it is an object', function(t){
var obj = {};
t.equal(getExtensions(obj), obj, 'should be the same object');
t.end();
});

test('should return a new object if argument is not an object', function(t){
var fn = function(){};
t.deepEqual(getExtensions(fn), {}, 'should be an object');
t.end();
});
23 changes: 23 additions & 0 deletions test/onSettled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

var test = require('tap').test;

var onSettled = require('../lib/helpers').onSettled;

var errors = [
{ state: 'error', value: new Error('Error 1') },
{ state: 'error', value: new Error('Error 2') }
];

test('should group all errors', function(t){
onSettled(function(errs, results){
t.equal(errs.length, 2, 'errors should contain both errors');
t.notOk(results, 'results should contain nothing');
t.end();
})(null, errors);
});

test('should handle the no callback case', function(t){
onSettled()(null, errors);
t.end();
});

0 comments on commit 0cd5d83

Please sign in to comment.