Skip to content

Commit 3a44d02

Browse files
igorcostaAutohand Evolve
andcommitted
test(browser): fix flaky native host chunked-input test
Attach child exit/error listeners immediately after spawn so the test cannot miss a fast exit event and hang until timeout in CI. Co-authored-by: Autohand Evolve <code-noreply@autohand.ai>
1 parent 8ce8a33 commit 3a44d02

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

tests/browser/chrome.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ describe('browser/chrome', () => {
135135
const child = spawn(process.execPath, [hostScriptPath], {
136136
stdio: ['pipe', 'pipe', 'pipe'],
137137
});
138+
const exitPromise = new Promise<{ code: number | null; signal: NodeJS.Signals | null }>((resolve, reject) => {
139+
child.once('error', (error) => reject(error));
140+
child.once('exit', (code, signal) => resolve({ code, signal }));
141+
});
138142

139143
const stdoutChunks: Buffer[] = [];
140144
child.stdout.on('data', (chunk) => {
@@ -159,9 +163,7 @@ describe('browser/chrome', () => {
159163
child.stdin.write(Buffer.concat([shutdownHeader, shutdownPayload]));
160164
child.stdin.end();
161165

162-
const exitResult = await new Promise<{ code: number | null; signal: NodeJS.Signals | null }>((resolve) => {
163-
child.on('exit', (code, signal) => resolve({ code, signal }));
164-
});
166+
const exitResult = await exitPromise;
165167

166168
expect(exitResult.code).toBe(0);
167169
expect(exitResult.signal).toBeNull();

0 commit comments

Comments
 (0)