Skip to content

Commit a64de74

Browse files
committed
[FIX] Fix 'ui5 tree' output
Refactoring in c7c607a broke tree logging and logged the yargs command object instead. Enhanced tests to capture this in the future.
1 parent e947a6c commit a64de74

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

lib/cli/commands/tree.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ tree.handler = async function(argv) {
3737
},
3838
configPath: argv.config
3939
};
40+
let projectTree;
4041
if (argv.full) {
41-
await normalizer.generateProjectTree(options);
42+
projectTree = await normalizer.generateProjectTree(options);
4243
} else {
43-
await normalizer.generateDependencyTree(options);
44+
projectTree = await normalizer.generateDependencyTree(options);
4445
}
4546

46-
const output = argv.json ? JSON.stringify(tree, null, 4) : treeify.asTree(tree, true);
47+
const output = argv.json ? JSON.stringify(projectTree, null, 4) : treeify.asTree(projectTree, true);
4748
console.log(output);
4849
};
4950

test/lib/cli/commands/tree.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,31 @@ test.serial("ui5 tree --full (generates project tree before output)", async (t)
2727

2828
test.serial("ui5 tree --json (output tree in json)", async (t) => {
2929
const jsonStringifySpy = sinon.spy(JSON, "stringify");
30+
const consoleStub = sinon.stub(console, "log");
31+
3032
normalizer.generateDependencyTree.resolves({name: "sample"});
3133
await tree.handler({json: true});
32-
t.is(JSON.stringify.called, true, "retrieves dependency tree as json");
33-
jsonStringifySpy.restore();
34+
35+
// Note: Some versions of Node.js seem to call stringify internally during this test
36+
t.deepEqual(jsonStringifySpy.called, true, "Stringify got called at least once");
37+
t.deepEqual(jsonStringifySpy.getCall(jsonStringifySpy.callCount - 1).args[0], {name: "sample"},
38+
"JSON.stringify called with correct argument");
39+
t.deepEqual(consoleStub.callCount, 1, "console.log was called once");
40+
t.deepEqual(consoleStub.getCall(0).args[0], `{
41+
"name": "sample"
42+
}`, "console.log was called with correct argument");
3443
});
3544

3645
test.serial("ui5 tree (output tree)", async (t) => {
37-
const treeifySpy = sinon.spy(treeify, "asTree");
46+
const treeifySpy = sinon.stub(treeify, "asTree").returns("🌲");
47+
const consoleStub = sinon.stub(console, "log");
3848
normalizer.generateDependencyTree.resolves({name: "sample"});
3949
await tree.handler({});
40-
t.is(treeify.asTree.called, true, "retrieves dependency tree using treeify");
41-
treeifySpy.restore();
50+
51+
t.deepEqual(treeifySpy.callCount, 1, "Treeify called once");
52+
t.deepEqual(treeifySpy.getCall(0).args[0], {name: "sample"}, "Treeify called with correct argument");
53+
t.deepEqual(consoleStub.callCount, 1, "console.log was called once");
54+
t.deepEqual(consoleStub.getCall(0).args[0], "🌲", "console.log was called with correct argument");
4255
});
4356

4457
test.serial("ui5 tree --dedupe=false (default)", async (t) => {

0 commit comments

Comments
 (0)