Skip to content

Commit ad67e00

Browse files
fix(test): start every test without a terminal and never block on a real prompt
Tests that exercise the no-terminal path never forced one. They inherited the runner's stdin, so the suite passed wherever output was redirected, as in CI, and hung in a developer's terminal: the CLI saw a TTY, opened a real prompt, and waited for an answer. Three tests timed out at 15 seconds, the run never exited, and the queued prompts appeared when the terminal was killed. Every test now starts with stdin reporting no terminal, and pretendTerminal still switches one on where a test needs it. A prompt that reaches the real inquire without being mocked fails at once instead of waiting on stdin, so a future test with the same mistake fails loudly rather than hanging. Verified under a real pseudo-terminal: the full suite passes, and with the default reversed the affected tests fail in two seconds rather than hanging. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f77239b commit ad67e00

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎jest.config.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const config = {
44
testEnvironment: 'node',
55
restoreMocks: true,
66
testMatch: ['**/src/**/*.test.ts', '**/test/integration/**/*.test.ts'],
7-
setupFilesAfterEnv: ['<rootDir>/test/credential-guard.setup.ts'],
7+
setupFilesAfterEnv: ['<rootDir>/test/credential-guard.setup.ts', '<rootDir>/test/no-terminal.setup.ts'],
88
moduleNameMapper: {
99
'^uuid$': '<rootDir>/test/uuid-shim.js',
1010
},

‎test/no-terminal.setup.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { cliux } from '@contentstack/cli-utilities';
2+
3+
import { stdinReportingTTY } from './support/terminal';
4+
5+
let restoreTerminal: () => void = () => undefined;
6+
7+
beforeEach(() => {
8+
restoreTerminal = stdinReportingTTY(false);
9+
10+
jest.spyOn(cliux, 'inquire').mockImplementation(async (payload: unknown) => {
11+
const message = String((payload as Record<string, unknown> | undefined)?.message ?? '');
12+
throw new Error(
13+
`A test reached a real interactive prompt ("${message}"). Mock it with answerPrompts, or it would ` +
14+
'block on stdin whenever the suite runs in a real terminal.',
15+
);
16+
});
17+
});
18+
19+
afterEach(() => {
20+
restoreTerminal();
21+
});

0 commit comments

Comments
 (0)