Skip to content

Commit

Permalink
Add tests for customFormat
Browse files Browse the repository at this point in the history
Also minor tweaks for the usability (no explicit json call)
  • Loading branch information
Philipp Tusch committed Sep 7, 2015
1 parent 6fa44ef commit 4aa7065
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
4 changes: 0 additions & 4 deletions bin/license-checker
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ if (!args.color && (args.json || args.csv || args.out)) {
args.color = false;
}

args.customFormat = checker.parseJson(args.customPath);

checker.init(args, function(json) {

console.log(args.customFormat);

var formattedOutput = '';
if (args.json) {
formattedOutput = JSON.stringify(json, null, 2);
Expand Down
8 changes: 6 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,17 @@ var flatten = function(options) {
exports.init = function(options, callback) {
console.error('scanning' , options.start);

if (options.customPath) {
options.customFormat = parseJson(options.customPath);
}

read(options.start, { dev: true }, function(err, json) {
var data = flatten({
deps: json,
data: {},
color: options.color,
unknown: options.unknown,
customFormat: options.customFormat
customFormat: options.customFormat,
filter: options.filter
}),
colorize = options.color,
Expand Down Expand Up @@ -263,7 +267,7 @@ exports.asMarkDown = function(sorted, customFormat) {
return text;
};

exports.parseJson = function(jsonPath) {
parseJson = function(jsonPath) {
if (typeof jsonPath !== 'string') {
return {};
}
Expand Down
62 changes: 61 additions & 1 deletion tests/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var vows = require('vows'),
assert = require('assert'),
path = require('path'),
checker = require('../lib/index');
checker = require('../lib/index'),
args = require('../lib/args'),
fs = require('fs');

var tests = {
loading: {
Expand Down Expand Up @@ -85,6 +87,64 @@ var tests = {
'on undefined': function (d) {
assert.equal(d, 'Undefined');
}
},
'should create a custom format using customFormat': {
topic: function () {
var self = this;

checker.init({
start: path.join(__dirname, '../'),
exclude: "MIT, ISC",
customFormat: {
'name': '<<Default Name>>',
'description': '<<Default Description>>',
'pewpew': '<<Should Never be set>>'
}
}, function (filtered) {
self.callback(null, filtered);
});
},
'create custom format with name, description and pewpew (customFormat manipulation)': function (d) {
Object.keys(d).forEach(function(item) {
assert.notEqual(d[item].name, undefined);
assert.notEqual(d[item].description, undefined);
assert.notEqual(d[item].pewpew, undefined);
assert.equal(d[item].pewpew, '<<Should Never be set>>');
});
}
},
'should create a custom format using customPath': {
topic: function () {
var self = this;

process.argv.push('--customPath');
process.argv.push('./customFormatExample.json');

args = args.parse();
args.start = path.join(__dirname, '../');

process.argv.pop();
process.argv.pop();

checker.init(args, function (filtered) {
self.callback(null, filtered);
});
},
'create custom format with contents of customFormatExample': function (d) {
var customFormatContent = fs.readFileSync(path.join(__dirname, './../customFormatExample.json'), 'utf8');

assert.notEqual(customFormatContent, undefined);
assert.notEqual(customFormatContent, null);

var customJson = JSON.parse(customFormatContent);

//Test dynamically with the file directly
Object.keys(d).forEach(function(licenseItem) {
Object.keys(customJson).forEach(function(definedItem) {
assert.notEqual(d[licenseItem][definedItem], undefined);
});
});
}
}
};

Expand Down

0 comments on commit 4aa7065

Please sign in to comment.