Skip to content

Commit b9841eb

Browse files
committed
Fix tests
1 parent ee2941a commit b9841eb

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

bin/ui5.cjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@ const ui5 = {
7777
return false;
7878
}
7979
if (process.argv.includes("--verbose")) {
80-
console.info(`INFO: This project contains an individual ${pkg.name} installation which ` +
80+
process.stderr.write(`INFO: This project contains an individual ${pkg.name} installation which ` +
8181
"will be used over the global one.");
82-
console.info("See https://github.com/SAP/ui5-cli#local-vs-global-installation for details.");
83-
console.info("");
82+
process.stderr.write("\n");
83+
process.stderr.write("See https://github.com/SAP/ui5-cli#local-vs-global-installation for details.");
84+
process.stderr.write("\n\n");
8485
} else {
85-
console.info(`INFO: Using local ${pkg.name} installation`);
86-
console.info("");
86+
process.stderr.write(`INFO: Using local ${pkg.name} installation`);
87+
process.stderr.write("\n\n");
8788
}
8889
return true;
8990
},

test/bin/ui5.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ test.before(() => {
3535
test.beforeEach(async (t) => {
3636
const sinon = t.context.sinon = sinonGlobal.createSandbox();
3737
t.context.processStderrWriteStub = sinon.stub(process.stderr, "write");
38-
t.context.consoleInfoStub = sinon.stub(console, "info");
3938
t.context.originalArgv = process.argv;
4039
process.env.UI5_CLI_TEST_BIN_RUN_MAIN = "false"; // prevent automatic execution of main function
4140

@@ -77,7 +76,7 @@ test.serial("checkRequirements: Using supported Node.js version", (t) => {
7776
});
7877

7978
t.true(returnValue);
80-
t.is(processStderrWriteStub.callCount, 0, "console.log should not be called");
79+
t.is(processStderrWriteStub.callCount, 0, "stderr info should not be provided");
8180
});
8281

8382
test.serial("checkRequirements: Using unsupported Node.js version", (t) => {
@@ -149,7 +148,7 @@ test.serial("checkRequirements: logs warning when using pre-release Node.js vers
149148
});
150149

151150
test.serial("invokeLocalInstallation: Invokes local installation when found", async (t) => {
152-
const {processStderrWriteStub, consoleInfoStub} = t.context;
151+
const {processStderrWriteStub} = t.context;
153152

154153
importLocalStub.returns({});
155154

@@ -159,11 +158,10 @@ test.serial("invokeLocalInstallation: Invokes local installation when found", as
159158

160159
t.true(returnValue);
161160

162-
t.is(processStderrWriteStub.callCount, 0, "console.log should not be called");
163-
t.is(consoleInfoStub.callCount, 2, "console.info should be called 2 times");
161+
t.is(processStderrWriteStub.callCount, 2, "Information messages should be provided");
164162

165-
t.deepEqual(consoleInfoStub.getCall(0).args, ["INFO: Using local ui5-cli-test installation"]);
166-
t.deepEqual(consoleInfoStub.getCall(1).args, [""]);
163+
t.deepEqual(processStderrWriteStub.getCall(0).args, ["INFO: Using local ui5-cli-test installation"]);
164+
t.deepEqual(processStderrWriteStub.getCall(1).args, ["\n\n"]);
167165

168166
t.is(importLocalStub.callCount, 1, "import-local should be called once");
169167
t.is(importLocalStub.getCall(0).args.length, 1);
@@ -173,7 +171,7 @@ test.serial("invokeLocalInstallation: Invokes local installation when found", as
173171
});
174172

175173
test.serial("invokeLocalInstallation: Invokes local installation when found (/w --verbose)", async (t) => {
176-
const {processStderrWriteStub, consoleInfoStub} = t.context;
174+
const {processStderrWriteStub} = t.context;
177175

178176
importLocalStub.returns({});
179177

@@ -186,16 +184,15 @@ test.serial("invokeLocalInstallation: Invokes local installation when found (/w
186184

187185
t.true(returnValue);
188186

189-
t.is(processStderrWriteStub.callCount, 0, "console.log should not be called");
190-
t.is(consoleInfoStub.callCount, 3, "console.info should be called 3 times");
187+
t.is(processStderrWriteStub.callCount, 4, "console.info should be called 3 times");
191188

192-
t.deepEqual(consoleInfoStub.getCall(0).args, [
189+
t.deepEqual(processStderrWriteStub.getCall(0).args, [
193190
"INFO: This project contains an individual ui5-cli-test installation which " +
194191
"will be used over the global one."]);
195-
t.deepEqual(consoleInfoStub.getCall(1).args, [
192+
t.deepEqual(processStderrWriteStub.getCall(2).args, [
196193
"See https://github.com/SAP/ui5-cli#local-vs-global-installation for details."
197194
]);
198-
t.deepEqual(consoleInfoStub.getCall(2).args, [""]);
195+
t.deepEqual(processStderrWriteStub.getCall(3).args, ["\n\n"]);
199196

200197
t.is(importLocalStub.callCount, 1, "import-local should be called once");
201198
t.is(importLocalStub.getCall(0).args.length, 1);
@@ -205,7 +202,7 @@ test.serial("invokeLocalInstallation: Invokes local installation when found (/w
205202
});
206203

207204
test.serial("invokeLocalInstallation: Doesn't invoke local installation when UI5_CLI_NO_LOCAL is set", async (t) => {
208-
const {processStderrWriteStub, consoleInfoStub} = t.context;
205+
const {processStderrWriteStub} = t.context;
209206

210207
process.env.UI5_CLI_NO_LOCAL = "true";
211208

@@ -215,14 +212,13 @@ test.serial("invokeLocalInstallation: Doesn't invoke local installation when UI5
215212

216213
t.false(returnValue);
217214

218-
t.is(processStderrWriteStub.callCount, 0, "console.log should not be called");
219-
t.is(consoleInfoStub.callCount, 0, "console.info should not be called");
215+
t.is(processStderrWriteStub.callCount, 0, "Information messages should be provided");
220216

221217
t.is(importLocalStub.callCount, 0, "import-local should not be called");
222218
});
223219

224220
test.serial("invokeLocalInstallation: Doesn't invoke local installation when it is not found", async (t) => {
225-
const {processStderrWriteStub, consoleInfoStub} = t.context;
221+
const {processStderrWriteStub} = t.context;
226222

227223
importLocalStub.returns(undefined);
228224

@@ -232,8 +228,7 @@ test.serial("invokeLocalInstallation: Doesn't invoke local installation when it
232228

233229
t.false(returnValue);
234230

235-
t.is(processStderrWriteStub.callCount, 0, "console.log should not be called");
236-
t.is(consoleInfoStub.callCount, 0, "console.info should not be called");
231+
t.is(processStderrWriteStub.callCount, 0, "stderr info should not be provided");
237232

238233
t.is(importLocalStub.callCount, 1, "import-local should be called");
239234
});

test/lib/cli/base.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ test.afterEach.always((t) => {
3737
});
3838

3939
test.serial("ui5 --version", async (t) => {
40-
const {stderr: stderr} = await ui5(["--version"]);
41-
t.is(stderr, `${pkg.version} (from ${ui5Cli})`);
40+
const {stdout} = await ui5(["--version"]);
41+
t.is(stdout, `${pkg.version} (from ${ui5Cli})`);
4242
});
4343

4444
test.serial("ui5 -v", async (t) => {
45-
const {stderr} = await ui5(["-v"]);
46-
t.is(stderr, `${pkg.version} (from ${ui5Cli})`);
45+
const {stdout} = await ui5(["-v"]);
46+
t.is(stdout, `${pkg.version} (from ${ui5Cli})`);
4747
});
4848

4949
test.serial("Handle multiple options", async (t) => {
5050
const {stderr} = await ui5(["versions", "--log-level", "silent", "--log-level", "silly"]);
51-
t.regex(stripAnsi(stderr), /^verb/, "Verbose logging got enabled");
51+
t.regex(stripAnsi(stderr), /verb/g, "Verbose logging got enabled");
5252
});
5353

5454
test.serial("Yargs error handling", async (t) => {

0 commit comments

Comments
 (0)