Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions e2e-harness/__tests__/tui-capture.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
12 changes: 7 additions & 5 deletions e2e-harness/tui-capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
/** Resolves with the child's exit code, or 128 + signal, when it exits. */
exited: Promise<number>;
}

// Serialize one buffer row back to ANSI: re-emit SGR (colors + attributes) each
Expand Down Expand Up @@ -119,9 +119,11 @@ export function captureTui(opts: {
term.write(d);
for (const cb of cbs) cb();
});
let resolveExit!: () => void;
const exited = new Promise<void>((r) => (resolveExit = r));
child.onExit(() => resolveExit());
let resolveExit!: (code: number) => void;
const exited = new Promise<number>((r) => (resolveExit = r));
child.onExit(({ exitCode, signal }) =>
resolveExit(signal ? 128 + signal : exitCode),
);

return {
frame() {
Expand Down
6 changes: 3 additions & 3 deletions scripts/tui-snapshots.no-jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Loading