diff --git a/e2e-harness/__tests__/tui-capture.test.ts b/e2e-harness/__tests__/tui-capture.test.ts new file mode 100644 index 000000000..b67bf88b6 --- /dev/null +++ b/e2e-harness/__tests__/tui-capture.test.ts @@ -0,0 +1,20 @@ +import { captureTui } from '../tui-capture'; + +const run = (script: string) => + captureTui({ + cmd: process.execPath, + args: ['-e', script], + cwd: process.cwd(), + env: process.env, + }).exited; + +describe('captureTui', () => { + it('resolves exited with the child exit code', async () => { + expect(await run('process.exit(0)')).toBe(0); + expect(await run('process.exit(3)')).toBe(3); + }); + + it('resolves exited with 128 + signal when a signal ends the child', async () => { + expect(await run("process.kill(process.pid, 'SIGTERM')")).toBe(143); + }); +}); diff --git a/e2e-harness/tui-capture.ts b/e2e-harness/tui-capture.ts index d71d0fa21..d88f22664 100644 --- a/e2e-harness/tui-capture.ts +++ b/e2e-harness/tui-capture.ts @@ -44,8 +44,8 @@ export interface TuiCapture { /** Fires after each chunk of terminal output is applied. */ onData(cb: () => void): void; kill(): void; - /** Resolves when the child exits. */ - exited: Promise; + /** Resolves with the child's exit code, or 128 + signal, when it exits. */ + exited: Promise; } // Serialize one buffer row back to ANSI: re-emit SGR (colors + attributes) each @@ -119,9 +119,11 @@ export function captureTui(opts: { term.write(d); for (const cb of cbs) cb(); }); - let resolveExit!: () => void; - const exited = new Promise((r) => (resolveExit = r)); - child.onExit(() => resolveExit()); + let resolveExit!: (code: number) => void; + const exited = new Promise((r) => (resolveExit = r)); + child.onExit(({ exitCode, signal }) => + resolveExit(signal ? 128 + signal : exitCode), + ); return { frame() { diff --git a/scripts/tui-snapshots.no-jest.ts b/scripts/tui-snapshots.no-jest.ts index 2d791c7bd..211ac4ea9 100644 --- a/scripts/tui-snapshots.no-jest.ts +++ b/scripts/tui-snapshots.no-jest.ts @@ -52,10 +52,10 @@ async function drainCtrl() { } const timer = setInterval(() => void drainCtrl(), 150); -void cap.exited.then(async () => { +void cap.exited.then(async (code) => { await drainCtrl(); clearInterval(timer); // eslint-disable-next-line no-console - console.log(`done; ${seq} snapshots in ${OUT}`); - process.exit(0); + console.log(`done; ${seq} snapshots in ${OUT}; host exited ${code}`); + process.exit(code); });