Skip to content
This repository was archived by the owner on Nov 15, 2018. It is now read-only.

Commit 987e782

Browse files
committed
fix: Unused Dependecies was actually an Array of Dep objects if there were unused dependencies. Fixes issue #61
1 parent 81135bb commit 987e782

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/reporter.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,13 @@ function consoleReport (jsonReport, options) {
150150
}
151151

152152
header('[ Unused dependencies ]');
153-
log.red(jsonReport.unused);
153+
if (Array.isArray(jsonReport.unused)) {
154+
jsonReport.unused.forEach(d => {
155+
log.red(d.getName());
156+
});
157+
} else {
158+
log.red(jsonReport.unused);
159+
}
154160

155161
if (jsonReport.devDependencies.length) {
156162
header('[ Dev dependencies ]');

test/szero-api-test.js

+22
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ test('should return some info', (t) => {
3434
});
3535
});
3636

37+
test('should return unused Array with 1 Dep Object', (t) => {
38+
const dir = path.join(__dirname, '../sample_project');
39+
const options = {};
40+
szero.report(dir, options).then((jsonReport) => {
41+
t.true(jsonReport.unused, 'should have a unused object');
42+
t.equal(Array.isArray(jsonReport.unused), true, 'should be an array');
43+
t.equal(jsonReport.unused[0].getName(), 'swapi-node', 'should be an array');
44+
t.end();
45+
});
46+
});
47+
48+
test('should return unused as string', (t) => {
49+
const dir = path.join(__dirname, '../.');
50+
const options = {};
51+
szero.report(dir, options).then((jsonReport) => {
52+
t.true(jsonReport.unused, 'should have a unused object');
53+
t.equal(Array.isArray(jsonReport.unused), false, 'should be an array');
54+
t.equal(jsonReport.unused, 'None.', 'should be an array');
55+
t.end();
56+
});
57+
});
58+
3759
test('should return file info', (t) => {
3860
const dir = path.join(__dirname, '../sample_project');
3961
const options = {};

0 commit comments

Comments
 (0)