Skip to content

Commit

Permalink
cleaned up some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Jul 14, 2017
1 parent f58b20c commit 051b20b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/index.js
Expand Up @@ -110,9 +110,10 @@ var flatten = function(options) {
}

licenseData = json.license || json.licenses || undefined;

if (json.path && (!json.readme || json.readme.toLowerCase().indexOf('no readme data found') > -1)) {
readmeFile = path.join(json.path, 'README.md');
/*istanbul ignore if*/
if (fs.existsSync(readmeFile)) {
json.readme = fs.readFileSync(readmeFile, 'utf8').toString();
}
Expand Down Expand Up @@ -178,11 +179,13 @@ var flatten = function(options) {
content = fs.readFileSync(lf, { encoding: 'utf8' });
}

/*istanbul ignore else*/
if (include("licenseFile")) {
moduleInfo.licenseFile = options.basePath ? path.relative(options.basePath, licenseFile) : licenseFile;
}

if (include("licenseText") && options.customFormat) {
/*istanbul ignore else*/
if (options._args && !options._args.csv) {
moduleInfo.licenseText = content.trim();
} else {
Expand Down Expand Up @@ -263,18 +266,20 @@ exports.init = function(options, callback) {
inputError = null;

var colorizeString = function(string) {
/*istanbul ignore next*/
return colorize ? chalk.bold.red(string) : string;
};

Object.keys(data).sort().forEach(function(item) {
if(data[item].private) {
data[item].licenses = colorizeString(UNLICENSED);
}
/*istanbul ignore next*/
if (!data[item].licenses) {
/*istanbul ignore next*/
data[item].licenses = colorizeString(UNKNOWN);
}
if (options.unknown) {
/*istanbul ignore else*/
if (data[item].licenses && data[item].licenses !== UNKNOWN) {
if (data[item].licenses.indexOf('*') > -1) {
/*istanbul ignore if*/
Expand Down Expand Up @@ -307,12 +312,14 @@ exports.init = function(options, callback) {

Object.keys(sorted).forEach(function(item) {
var licenses = sorted[item].licenses;
/*istanbul ignore if - just for protection*/
if(!licenses) {
filtered[item] = sorted[item];
} else {
licenses = [].concat(licenses);
var licenseMatch = false;
licenses.forEach(function(license) {
/*istanbul ignore if - just for protection*/
if (license.indexOf(UNKNOWN) >= 0) { // necessary due to colorization
filtered[item] = sorted[item];
} else {
Expand Down Expand Up @@ -379,6 +386,7 @@ exports.asCSV = function(sorted, customFormat, csvComponentPrefix) {
text.push(textArr.join(','));
} else {
textArr = [];
/*istanbul ignore next*/
if (csvComponentPrefix) { textArr.push(prefixName); }
['"module name"','"license"','"repository"'].forEach(function(item) {
textArr.push(item);
Expand All @@ -402,6 +410,7 @@ exports.asCSV = function(sorted, customFormat, csvComponentPrefix) {
});
line = lineArr.join(',');
} else {
/*istanbul ignore next*/
if (csvComponentPrefix) {
lineArr.push('"'+prefix+'"');
}
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/privateModule/README.md
@@ -0,0 +1 @@
Module README

0 comments on commit 051b20b

Please sign in to comment.