Skip to content

Commit

Permalink
Add additional test
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Tusch committed Sep 7, 2015
1 parent 52fa91c commit 04a2294
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,16 @@ exports.asMarkDown = function(sorted, customFormat) {

exports.parseJson = function(jsonPath) {
if (typeof jsonPath !== 'string') {
return {};
return new Error('did not specify a path');
}

var jsonData = fs.readFileSync(jsonPath, {encoding: 'utf8'});
var jsonData = '';

try {
jsonData = fs.readFileSync(jsonPath, {encoding: 'utf8'});
} catch (err) {
return err;
}

return JSON.parse(jsonData);
};
9 changes: 9 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ var tests = {
assert.notEqual(json, null);
}
},
'should parse json with errors': {
topic: function() {
var path = './NotExitingFile.json';
return path;
},
'and check it': function(path) {
assert.throws(checker.parseJson(path));
}
},
};

vows.describe('license-checker').addBatch(tests).export(module);

0 comments on commit 04a2294

Please sign in to comment.