Skip to content

Commit 572225b

Browse files
committed
Fix E2E tests for stderr status messages and NDJSON output
- Check stderr (not stdout) for status messages like "Entered presence", "Location set in space:", and "Waiting for" - Parse NDJSON correctly: find type "result" line for history, first line for list (completed status signal is appended as last line)
1 parent f96f30d commit 572225b

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

test/e2e/channels/channel-presence-e2e.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ describe("Channel Presence E2E Tests", () => {
8282
},
8383
);
8484

85-
console.log(`Presence enter output: ${enterResult.stdout}`);
85+
console.log(`Presence enter stdout: ${enterResult.stdout}`);
86+
console.log(`Presence enter stderr: ${enterResult.stderr}`);
8687
expect(enterResult.exitCode).toBe(0);
87-
expect(enterResult.stdout).toContain("Entered presence on channel");
88-
expect(enterResult.stdout).toContain(
89-
"Duration elapsed – command finished cleanly",
90-
);
88+
// Status messages go to stderr
89+
const allOutput = enterResult.stdout + enterResult.stderr;
90+
expect(allOutput).toContain("Entered presence on channel");
91+
expect(allOutput).toContain("Duration elapsed – command finished cleanly");
9192
});
9293
});

test/e2e/channels/channels-e2e.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ describe("Channel E2E Tests", () => {
181181

182182
let result;
183183
try {
184-
result = JSON.parse(listResult.stdout);
184+
// JSON output may contain multiple NDJSON lines (result + completed status).
185+
// Parse the first non-empty line which contains the result data.
186+
const line = listResult.stdout.trim().split("\n").find(Boolean);
187+
result = JSON.parse(line);
185188
} catch (parseError) {
186189
throw new Error(
187190
`Failed to parse JSON output. Parse error: ${String(parseError)}. Exit code: ${listResult.exitCode}, Stderr: ${listResult.stderr}, Stdout: ${listResult.stdout}`,
@@ -339,10 +342,13 @@ describe("Channel E2E Tests", () => {
339342

340343
let result;
341344
try {
342-
// The --json output is NDJSON (one event line + one result line).
343-
// Parse the last non-empty line which contains the result.
345+
// The --json output is NDJSON: event lines, then a result line, then a completed status.
346+
// Find the line with type "result" which contains the history data.
344347
const lines = historyResult.stdout.trim().split("\n").filter(Boolean);
345-
result = JSON.parse(lines.at(-1));
348+
const resultLine = lines
349+
.map((l) => JSON.parse(l))
350+
.find((obj) => obj.type === "result");
351+
result = resultLine;
346352
} catch (parseError) {
347353
throw new Error(
348354
`Failed to parse JSON history output. Parse error: ${String(parseError)}. Exit code: ${historyResult.exitCode}, Stderr: ${historyResult.stderr}, Stdout: ${historyResult.stdout}`,

test/e2e/interactive/ctrl-c-behavior.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,10 @@ describe("E2E: Interactive Mode - Ctrl+C Behavior", () => {
357357
}, 100);
358358
});
359359

360-
// Wait for command to start
360+
// Wait for command to start (status messages go to stderr)
361361
await new Promise<void>((resolve) => {
362362
const checkForWaiting = setInterval(() => {
363-
if (output.includes("Waiting for")) {
363+
if (errorOutput.includes("Waiting for")) {
364364
clearInterval(checkForWaiting);
365365
resolve();
366366
}
@@ -435,10 +435,10 @@ describe("E2E: Interactive Mode - Ctrl+C Behavior", () => {
435435
}, 100);
436436
});
437437

438-
// Wait for command to start
438+
// Wait for command to start (status messages go to stderr)
439439
await new Promise<void>((resolve) => {
440440
const checkInterval = setInterval(() => {
441-
if (output.includes("Waiting for")) {
441+
if (errorOutput.includes("Waiting for")) {
442442
clearInterval(checkInterval);
443443
resolve();
444444
}

test/e2e/spaces/spaces-e2e.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,13 @@ describe("Spaces E2E Tests", () => {
217217
);
218218

219219
// Check for success - either exit code 0 or successful output (even if process was killed after success)
220+
// Status messages go to stderr
221+
const allOutput = setLocationResult.stdout + setLocationResult.stderr;
220222
const isLocationSetSuccessful =
221223
setLocationResult.exitCode === 0 ||
222-
setLocationResult.stdout.includes("Location set in space:");
224+
allOutput.includes("Location set in space:");
223225
expect(isLocationSetSuccessful).toBe(true);
224-
expect(setLocationResult.stdout).toContain("Location set in space:");
226+
expect(allOutput).toContain("Location set in space:");
225227

226228
// Wait for location update to be received by client1
227229
let locationUpdateReceived = false;

0 commit comments

Comments
 (0)