Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit 0f87189

Browse files
committed
[cypress] Log timestamp for each line of integration test output
1 parent 59da108 commit 0f87189

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

packages/cypress-plugin/test/integration/src/run-test-case.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ export const runTestCase = async (
888888

889889
const onOutput = (
890890
name: string,
891-
onLine: (line: string) => void,
891+
onLine: (line: string, now: Date) => void,
892892
escapeDebugOutput: boolean
893893
): ((data: Buffer) => void) => {
894894
const debugExt = debug.extend(name);
@@ -899,12 +899,13 @@ export const runTestCase = async (
899899
// Don't eat the last line of output.
900900
cypressChild.on("exit", () => {
901901
if (pending.s !== "") {
902-
onLine(pending.s);
902+
onLine(pending.s, new Date());
903903
debugExt(escapeDebugOutput ? JSON.stringify(pending.s) : pending.s);
904904
}
905905
});
906906

907907
return (data: Buffer): void => {
908+
const now = new Date();
908909
// In case data terminates in the middle of a Unicode sequence, we need to use a stateful
909910
// TextDecoder with `stream: true`. Otherwise, invalid UTF-8 sequences at the end get
910911
// converted to 0xFFFD, which breaks the tests non-deterministically (i.e., makes them flaky).
@@ -914,7 +915,7 @@ export const runTestCase = async (
914915
// partial line that we want to defer until the next call.
915916
lines.slice(0, lines.length - 1).forEach((line, idx) => {
916917
const lineWithPending = idx === 0 ? pending.s + line : line;
917-
onLine(lineWithPending);
918+
onLine(lineWithPending, now);
918919
debugExt(
919920
escapeDebugOutput ? JSON.stringify(lineWithPending) : lineWithPending
920921
);
@@ -931,7 +932,9 @@ export const runTestCase = async (
931932
"data",
932933
onOutput(
933934
"stderr",
934-
combinedLines.push.bind(combinedLines),
935+
(line, now) => {
936+
combinedLines.push(`${now.toISOString()} ${line}`);
937+
},
935938
// Don't escape stderr output since it likely comes from debug output in the subprocess, which
936939
// is intended for human consumption and not for verifying test results.
937940
false
@@ -941,9 +944,9 @@ export const runTestCase = async (
941944
"data",
942945
onOutput(
943946
"stdout",
944-
(line) => {
947+
(line, now) => {
945948
stdoutLines.push(line);
946-
combinedLines.push(line);
949+
combinedLines.push(`${now.toISOString()} ${line}`);
947950
},
948951
// Escape special characters in debug output so that we can more easily understand test
949952
// failures related to unexpected output.

0 commit comments

Comments
 (0)