test(create-termui-app): add prompts unit tests#1948
Conversation
📝 WalkthroughWalkthroughThe prompts.test.ts test suite was rewritten to mock readline.createInterface via vi.mocked with explicit stdin/stdout mocks, and test coverage was significantly expanded for textPrompt, selectPrompt, confirmPrompt, and multiSelectPrompt to validate formatting, defaults, clamping, and edge cases. ChangesPrompts test suite expansion
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/create-termui-app/src/prompts.test.ts`:
- Around line 29-39: The mock in prompts.test.ts uses a double type assertion
for createInterface, but it lacks the required inline comment explaining why the
cast is necessary. Update the mockedCreateInterface.mockReturnValue setup near
the Interface assertion to add a brief justification comment consistent with the
existing mock comments, so the use of “as unknown as Interface” is documented
and clearly intentional.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: de06a960-0d07-424c-b6ea-f9572de6752c
📒 Files selected for processing (1)
packages/create-termui-app/src/prompts.test.ts
| mockedCreateInterface.mockReturnValue( | ||
| { | ||
| question: questionMock, | ||
| close: closeMock, | ||
| } as unknown as Interface, | ||
| ); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Missing inline comment on double type assertion.
{ question, close } as unknown as Interface bypasses type-checking for a mock that only implements two of Interface's members, but there's no comment explaining why this cast is safe/necessary, unlike lines 17-18 which have one.
As per coding guidelines, **/*.{ts,tsx}: "No type assertions without an inline comment explaining why."
📝 Proposed fix
+ // Only question/close are exercised by prompts.ts; other Interface
+ // members are unused in these tests.
mockedCreateInterface.mockReturnValue(
{
question: questionMock,
close: closeMock,
} as unknown as Interface,
);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| mockedCreateInterface.mockReturnValue( | |
| { | |
| question: questionMock, | |
| close: closeMock, | |
| } as unknown as Interface, | |
| ); | |
| }); | |
| afterEach(() => { | |
| vi.restoreAllMocks(); | |
| }); | |
| // Only question/close are exercised by prompts.ts; other Interface | |
| // members are unused in these tests. | |
| mockedCreateInterface.mockReturnValue( | |
| { | |
| question: questionMock, | |
| close: closeMock, | |
| } as unknown as Interface, | |
| ); | |
| }); | |
| afterEach(() => { | |
| vi.restoreAllMocks(); | |
| }); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/create-termui-app/src/prompts.test.ts` around lines 29 - 39, The
mock in prompts.test.ts uses a double type assertion for createInterface, but it
lacks the required inline comment explaining why the cast is necessary. Update
the mockedCreateInterface.mockReturnValue setup near the Interface assertion to
add a brief justification comment consistent with the existing mock comments, so
the use of “as unknown as Interface” is documented and clearly intentional.
Source: Coding guidelines
Summary
Adds comprehensive unit tests for the
promptsmodule in@termuijs/create-termui-appto improve test coverage and verify prompt behavior.Changes Made
packages/create-termui-app/src/prompts.test.tsTest Coverage
The test suite includes coverage for:
Validation
Successfully verified with:
All checks pass successfully.
Closes #1321
Summary by CodeRabbit