fix(test): strip ANSI codes from Ink TUI test assertions#1301
Merged
Conversation
Three TUI component tests were broken on main because Ink 6.8.0
emits ANSI escape codes from `<Text dimColor>`, `<Text color=...>`,
and `<GradientText>` even when the renderer is not attached to a TTY.
The affected assertions compare `lastFrame()` against plain strings,
so the ANSI bytes inside the frame caused these to fail:
src/cli/tui/components/__tests__/DeployStatus.test.tsx:
- 'shows "Deploying to AWS" when not complete'
- 'ignores non-resource-event messages (non-I5502 codes)'
(frame contains `\u001b[90m╭…` from <GradientText> + bordered <Box>)
src/cli/tui/components/__tests__/LogPanel.test.tsx:
- 'renders "No output yet" with no other content'
(frame is `\u001b[2mNo output yet\u001b[22m` from <Text dimColor>)
src/cli/tui/components/__tests__/SecretInput.test.tsx:
- 'renders placeholder when value is empty'
(placeholder is split into <Cursor> + <Text dimColor>, so the
literal substring 'sk-...' has ANSI codes between 's' and 'k-...')
Fix: import `strip-ansi` (already a transitive dep, now declared as a
devDependency) and apply it to `lastFrame()` in the four affected
assertions. Other assertions in the same files were left untouched
because they pass through plain log lines / system messages that are
already ANSI-free.
Verified locally:
Before: Test Files 3 failed | 270 passed (273) | Tests 4 failed | 3912 passed (3916)
After: Test Files 273 passed (273) | Tests 3916 passed (3916)
15 tasks
Contributor
|
Claude Security Review: no high-confidence findings. (run) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Three TUI component test files have failing assertions on
mainbecause Ink 6.8.0 emits ANSI escape codes from styled<Text>and gradient components even when the renderer is not attached to a TTY. The assertions comparelastFrame()against plain strings, so the ANSI bytes inside the frame cause them to fail.What's failing on
mainFix
Import
strip-ansi(already a transitive dep, now declared as a top-leveldevDependency) and apply it tolastFrame()in the four affected assertions only. Other assertions in the same files were left untouched because they pass through plain log lines / system messages that are already ANSI-free in their substrings.Why
strip-ansirather than rewriting the componentsThe components (
<Text dimColor>,<GradientText>,<Cursor>) are intentionally styled — that styling is part of the actual UX. The bug is in the test assertions assuminglastFrame()is plain text, which is fragile any time Ink's rendering behavior changes. Stripping ANSI in the assertion is the minimal, low-risk change and matches the standard pattern used by other Ink-based projects.Files changed
package.json—strip-ansi ^7.2.0added underdevDependencies(was already pulled in transitively via Vitest / ESLint)package-lock.json— regeneratedsrc/cli/tui/components/__tests__/DeployStatus.test.tsx— 2 assertionssrc/cli/tui/components/__tests__/LogPanel.test.tsx— 1 assertionsrc/cli/tui/components/__tests__/SecretInput.test.tsx— 1 assertion5 files, +9 / -4 lines total.
Before / After
Related Issue
Closes #
Documentation PR
N/A — test-only change.
Type of Change
Testing
How have you tested the change?
npm run test:unitandnpm run test:integ(unit: 3916/3916 — was 3912/3916 before this PR)npm run typechecknpm run lint(0 errors; 29 preexisting warnings, none in files touched by this PR)src/assets/, I rannpm run test:update-snapshotsand committed the updated snapshots (N/A — no asset changes)Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.