Skip to content

Commit 251ed08

Browse files
committed
test: Suppress intentional log output in AVA 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. Some @ui5/cli tests leaked further output that does not flow through the logger events at all: profile.js logs progress via console.log and the init command writes the generated ui5.yaml via process.stdout.write. Stub those sinks through file-level hooks in the affected test files. Exception for the logger test itself, where the listeners would impact the test expectations. The remaining leaks in @ui5/builder and @ui5/project (JSDoc warnings) originate from a spawned child process whose stderr is inherited on fd 2, so they cannot be suppressed by an in-process stub without changing production logic; they are left as-is.
1 parent 59640d1 commit 251ed08

6 files changed

Lines changed: 54 additions & 2 deletions

File tree

‎ava.common.config.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// Route @ui5/logger's stderr fallback output into ignored no-op listeners so that
2+
// intentional error/build log lines don't clutter the test output (see suppressLog.js).
3+
// Pass a file:// URL (not a filesystem path) to --import: Node's ESM loader treats the
4+
// argument as a module specifier, and on Windows an absolute path like "d:\..." is
5+
// misread as protocol "d:" (ERR_UNSUPPORTED_ESM_URL_SCHEME).
6+
const suppressLog = new URL("./test/suppressLog.js", import.meta.url).href;
7+
18
export default {
29
files: [
310
"test/lib/**/*.js",
@@ -10,7 +17,9 @@ export default {
1017
},
1118
nodeArguments: [
1219
"--loader=esmock",
13-
"--no-warnings"
20+
"--no-warnings",
21+
"--import",
22+
suppressLog
1423
],
1524
workerThreads: false,
1625
};

‎packages/cli/test/lib/cli/commands/init.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import test from "ava";
22
import sinon from "sinon";
33
import esmock from "esmock";
44

5+
test.beforeEach(() => {
6+
// The init command writes the generated ui5.yaml to process.stdout; stub it out
7+
// so this intentional output does not clutter the test output (restored in afterEach).
8+
sinon.stub(process.stdout, "write");
9+
});
10+
511
test.afterEach.always((t) => {
612
sinon.restore();
713
esmock.purge(t.context.initCommand);

‎packages/cli/test/lib/utils/profile.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ function createSessionStubs() {
2121
return {Session, connectStub, postStub};
2222
}
2323

24+
test.beforeEach(() => {
25+
// profile.js logs progress messages via console.log; stub them out so this
26+
// intentional output does not clutter the test output (restored in afterEach).
27+
sinon.stub(console, "log");
28+
});
29+
2430
test.afterEach.always(() => {
2531
sinon.restore();
2632
});

‎packages/logger/ava.config.js‎

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

3-
export default avaCommonConfig;
3+
// The logger tests assert on @ui5/logger's stderr fallback, which only fires when no
4+
// listener is attached to its process events. Drop the suppressLog --import that the
5+
// common config adds, as it would attach exactly those listeners.
6+
const nodeArguments = [];
7+
for (let i = 0; i < avaCommonConfig.nodeArguments.length; i++) {
8+
const arg = avaCommonConfig.nodeArguments[i];
9+
if (arg === "--import" && avaCommonConfig.nodeArguments[i + 1]?.endsWith("suppressLog.js")) {
10+
i++; // Skip both "--import" and the module path
11+
continue;
12+
}
13+
nodeArguments.push(arg);
14+
}
15+
16+
export default {
17+
...avaCommonConfig,
18+
nodeArguments,
19+
};

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

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

20+
2021
test.beforeEach(async (t) => {
2122
t.context.devcertSanscache = sinon.stub();
2223
t.context.mkdir = sinon.stub().resolves();

‎test/suppressLog.js‎

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 tests intentionally exercise error and build
4+
// paths whose logs would otherwise clutter the test output and obscure real failures.
5+
// Attaching a no-op listener to each event with a stderr fallback routes those messages
6+
// 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)