Skip to content

Commit 0efe503

Browse files
committed
test(server): Suppress intentional log output in unit tests
Tests that exercise error and build paths leaked log lines into the test output because @ui5/logger writes to process.stderr whenever its process events have no listener attached, obscuring real failures. Attach no-op listeners to every logger event with a stderr fallback via an AVA --import setup module, and stub the raw stderr password prompt in the sslUtil test through file-level hooks.
1 parent d3f5cdb commit 0efe503

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

packages/server/ava.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
import avaCommonConfig from "../../ava.common.config.js";
22

3-
export default avaCommonConfig;
3+
export default {
4+
...avaCommonConfig,
5+
nodeArguments: [
6+
...avaCommonConfig.nodeArguments,
7+
"--import",
8+
"./test/utils/suppressLog.js"
9+
]
10+
};

packages/server/test/lib/server/sslUtil.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ function fileExists(filePath) {
1717
});
1818
}
1919

20+
// Certificate creation prints a "please enter your root password" prompt straight
21+
// to stderr (not via @ui5/logger). No test asserts on stderr, so silence it once for
22+
// the whole file. A file-level hook (rather than beforeEach) avoids concurrent tests
23+
// racing to stub the same global process.stderr.
24+
let stderrWriteStub;
25+
test.before(() => {
26+
stderrWriteStub = sinon.stub(process.stderr, "write");
27+
});
28+
test.after.always(() => {
29+
stderrWriteStub.restore();
30+
});
31+
2032
test.beforeEach(async (t) => {
2133
t.context.yesno = sinon.stub();
2234
t.context.devcertSanscache = sinon.stub();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @ui5/logger writes messages straight to process.stderr whenever the corresponding
2+
// process event has no listener attached (see the fallback branches in the loggers
3+
// under @ui5/logger/lib/loggers). Several server tests intentionally exercise error
4+
// and build paths whose logs would otherwise clutter the test output and obscure real
5+
// failures. Attaching a no-op listener to each event with a stderr fallback routes
6+
// those messages to the (ignored) event instead.
7+
for (const event of [
8+
"ui5.log", // Logger#_emitOrLog
9+
"ui5.build-status", // loggers/Build
10+
"ui5.project-build-status", // loggers/ProjectBuild
11+
"ui5.serve-status", // loggers/Serve
12+
]) {
13+
process.on(event, () => {});
14+
}

0 commit comments

Comments
 (0)