Skip to content

Commit 6602969

Browse files
committed
Drop the timing-dependent test of a plain exit listener
Whether Ink's final render erases a plain 'exit' listener's text, or prints the frame below it, depends on a render being pending at exit. On Linux CI the frame came after the message, so the test failed. The test checked Ink, not onFinalExit, so it is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016QnBk5WpNZf6mJ3NrGJME3
1 parent e3bcaed commit 6602969

2 files changed

Lines changed: 11 additions & 18 deletions

File tree

‎test/utils/fixtures/final-exit-app.tsx‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
// Renders an Ink app that keeps re-rendering, with an exit message registered by onFinalExit (or a plain 'exit'
2-
// listener with `plain`), then ends with process.exit() while mounted, process.exit() after unmounting, or naturally.
1+
// Renders an Ink app that keeps re-rendering, with an exit message registered by onFinalExit, then ends with
2+
// process.exit() while mounted, process.exit() after unmounting, or naturally.
33
import { Box, Text, render } from 'ink';
44
import React, { useEffect, useState } from 'react';
55

66
import { onFinalExit } from '../../../src/utils/on-final-exit.js';
77

8-
const [mode, ending] = process.argv.slice(2);
9-
const message = () => process.stderr.write('\nEXIT MESSAGE\n');
10-
if (mode === 'plain') {
11-
process.once('exit', message);
12-
} else {
13-
onFinalExit(message);
14-
}
8+
const [ending] = process.argv.slice(2);
9+
onFinalExit(() => process.stderr.write('\nEXIT MESSAGE\n'));
1510

1611
function App() {
1712
const [n, setN] = useState(0);

‎test/utils/on-final-exit.test.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..')
88
const APP = path.join(ROOT, 'test/utils/fixtures/final-exit-app.tsx');
99

1010
/** Runs the fixture in a terminal and returns the screen once it exits */
11-
async function runApp(mode: string, ending: string): Promise<string> {
11+
async function runApp(ending: string): Promise<string> {
1212
const term = new xterm.Terminal({ allowProposedApi: true, cols: 60, rows: 20 });
13-
const child = pty.spawn(path.join(ROOT, 'node_modules/.bin/tsx'), ['--no-warnings=ExperimentalWarning', APP, mode, ending], {
13+
const child = pty.spawn(path.join(ROOT, 'node_modules/.bin/tsx'), ['--no-warnings=ExperimentalWarning', APP, ending], {
1414
cols: 60, cwd: ROOT, env: { ...process.env, FORCE_COLOR: '0' } as Record<string, string>, rows: 20,
1515
});
1616
child.onData((data) => term.write(data));
@@ -28,18 +28,16 @@ async function runApp(mode: string, ending: string): Promise<string> {
2828
return lines.join('\n').trim();
2929
}
3030

31+
// A plain process.on('exit') listener can't be tested the same way: whether Ink's final render erases or reorders its
32+
// text depends on a render being pending at exit, so the result depends on timing.
3133
describe('onFinalExit', () => {
3234
it('writes after the final render of a mounted Ink app', async () => {
33-
const screen = await runApp('final', 'exit');
35+
const screen = await runApp('exit');
3436
expect(screen).toMatch(/^render \d+\nline 2\nline 3\n\nEXIT MESSAGE$/);
3537
});
3638

3739
it('writes on exit after Ink unmounted, and when the process ends on its own', async () => {
38-
expect(await runApp('final', 'unmount')).toMatch(/^render \d+\nline 2\nline 3\n\nEXIT MESSAGE$/);
39-
expect(await runApp('final', 'natural')).toMatch(/^render \d+\nline 2\nline 3\n\nEXIT MESSAGE$/);
40-
});
41-
42-
it('is needed: a plain exit listener is erased by the final render', async () => {
43-
expect(await runApp('plain', 'exit')).not.toContain('EXIT MESSAGE');
40+
expect(await runApp('unmount')).toMatch(/^render \d+\nline 2\nline 3\n\nEXIT MESSAGE$/);
41+
expect(await runApp('natural')).toMatch(/^render \d+\nline 2\nline 3\n\nEXIT MESSAGE$/);
4442
});
4543
});

0 commit comments

Comments
 (0)