Skip to content

test(create-termui-app): add prompts unit tests#1948

Merged
Karanjot786 merged 1 commit into
Karanjot786:mainfrom
KrutagyaKaneria:test/create-termui-app-prompts
Jul 3, 2026
Merged

test(create-termui-app): add prompts unit tests#1948
Karanjot786 merged 1 commit into
Karanjot786:mainfrom
KrutagyaKaneria:test/create-termui-app-prompts

Conversation

@KrutagyaKaneria

@KrutagyaKaneria KrutagyaKaneria commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds comprehensive unit tests for the prompts module in @termuijs/create-termui-app to improve test coverage and verify prompt behavior.

Changes Made

  • Added packages/create-termui-app/src/prompts.test.ts
  • Added unit tests for all exported prompt utilities
  • Covered normal execution paths and edge cases
  • Mocked terminal input/output to avoid interactive prompts during testing
  • Verified prompt validation and expected behavior

Test Coverage

The test suite includes coverage for:

  • Prompt rendering and user input handling
  • Default value behavior
  • Input validation
  • Invalid input scenarios
  • Boundary and edge cases
  • Prompt cancellation/termination behavior (where applicable)

Validation

Successfully verified with:

bun vitest run packages/create-termui-app/src/prompts.test.ts
bun run typecheck
bun run build

All checks pass successfully.

Closes #1321

Summary by CodeRabbit

  • Tests
    • Expanded prompt test coverage for the app creator.
    • Added more specific checks for text, selection, confirmation, and multi-select prompt behavior.
    • Verified prompt formatting, default handling, input clamping, invalid input handling, and interface cleanup in more cases.

@github-actions github-actions Bot added the type:testing +10 pts. Tests. label Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Prompts test suite expansion

Layer / File(s) Summary
Test harness and mocking setup
packages/create-termui-app/src/prompts.test.ts
Imports reorganized; readline mock switched to a vi.mock factory exposing createInterface as vi.fn(), with beforeEach/afterEach mocking process.stdin/stdout and stubbing question/close functions.
textPrompt and selectPrompt coverage
packages/create-termui-app/src/prompts.test.ts
Added tests for trimming, default-suffix formatting, whitespace fallback, empty-default suffix skipping, numbered option logging, index clamping (below/above bounds), NaN for non-numeric input, and empty-options handling.
confirmPrompt and multiSelectPrompt coverage
packages/create-termui-app/src/prompts.test.ts
Added tests for Y/n vs y/N prompt formatting, boolean results on empty answers, 'all' selection logging, default retention/fallback, comma-separated parsing with invalid-token skipping, and out-of-range position handling.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

  • Karanjot786/TermUI#1329: Both PRs modify packages/create-termui-app/src/prompts.test.ts to unit test the same prompt helpers by mocking readline.createInterface.

Suggested labels: gssoc:approved, quality:clean, level:intermediate

Suggested reviewers: Karanjot786

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary, scope, linked issue, and validation, but it is missing most required template sections. Fill in the template sections for Description, Related Issue, Which package(s), Type of Change, and Checklist, and complete any required GSSoC or reviewer notes fields.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and accurately describes the addition of prompts unit tests for create-termui-app.
Linked Issues check ✅ Passed The PR adds unit tests for @termuijs/create-termui-app prompts.ts and closes #1321, matching the issue's coverage and validation goals.
Out of Scope Changes check ✅ Passed The changes stay focused on prompts test coverage and mocked prompt behavior, with no unrelated code or public API changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 85e8d36 and cc7f7e5.

📒 Files selected for processing (1)
  • packages/create-termui-app/src/prompts.test.ts

Comment on lines +29 to 39
mockedCreateInterface.mockReturnValue(
{
question: questionMock,
close: closeMock,
} as unknown as Interface,
);
});

afterEach(() => {
vi.restoreAllMocks();
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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.

Suggested change
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

@Karanjot786 Karanjot786 added gssoc:approved Approved PR. Earns +50 base points. quality:clean x 1.2 multiplier. Clean implementation. level:beginner +20 pts. Entry-level task. labels Jul 3, 2026
@Karanjot786 Karanjot786 merged commit 9348b30 into Karanjot786:main Jul 3, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved PR. Earns +50 base points. level:beginner +20 pts. Entry-level task. quality:clean x 1.2 multiplier. Clean implementation. type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Unit Tests for prompts in packages/create-termui-app/src/prompts.ts

2 participants