Skip to content

Commit a958cf0

Browse files
authored
test: fix flaky test (#1331)
1 parent 08c3656 commit a958cf0

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

features/step_definitions/record/common.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,12 @@ When("I type {string}", function (userInput) {
207207

208208
When("I press Enter", function () {
209209
return new Promise<void>((resolve) => {
210-
this.childProcess.stdin.write("\n");
211-
this.childProcess.stdin.end();
212210
this.childProcess.on("close", () => {
213211
resolve();
214212
});
213+
214+
this.childProcess.stdin.write("\n");
215+
this.childProcess.stdin.end();
215216
});
216217
});
217218

features/utils/world.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,27 @@ export class OurWorld extends World {
114114
},
115115
);
116116

117-
let stdout: Buffer;
118-
let stderr: Buffer;
117+
const stdoutChunks: Buffer[] = [];
118+
const stderrChunks: Buffer[] = [];
119119

120120
this.childProcess.stdout.on("data", (data: Buffer) => {
121-
stdout = data;
121+
stdoutChunks.push(data);
122122
});
123123

124124
this.childProcess.stderr.on("data", (data: Buffer) => {
125-
stderr = data;
125+
stderrChunks.push(data);
126126
});
127127

128128
this.childProcess.on("exit", (code: number) => {
129129
this.response = {
130-
stdout: stdout ?? Buffer.from(""),
131-
stderr: stderr ?? Buffer.from(""),
130+
stdout:
131+
stdoutChunks.length > 0
132+
? Buffer.concat(stdoutChunks)
133+
: Buffer.from(""),
134+
stderr:
135+
stderrChunks.length > 0
136+
? Buffer.concat(stderrChunks)
137+
: Buffer.from(""),
132138
status: code,
133139
};
134140
});

0 commit comments

Comments
 (0)