Skip to content

Commit ab4c19e

Browse files
arepageekAndrés Aguilar
andauthored
fix(test): strip ANSI codes from Ink TUI test assertions (#1301)
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) Co-authored-by: Andrés Aguilar <andiaa@amazon.com>
1 parent 2f3040a commit ab4c19e

5 files changed

Lines changed: 9 additions & 4 deletions

File tree

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
"node-pty": "^1.1.0",
144144
"prettier": "^3.7.4",
145145
"secretlint": "^12.2.0",
146+
"strip-ansi": "^7.2.0",
146147
"tsx": "^4.21.0",
147148
"typescript": "^5",
148149
"typescript-eslint": "^8.50.1",

src/cli/tui/components/__tests__/DeployStatus.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { DeployMessage } from '../../../cdk/toolkit-lib/index.js';
22
import { DeployStatus } from '../DeployStatus.js';
33
import { render } from 'ink-testing-library';
44
import React from 'react';
5+
import stripAnsi from 'strip-ansi';
56
import { describe, expect, it } from 'vitest';
67

78
function makeMsg(
@@ -28,7 +29,7 @@ describe('DeployStatus', () => {
2829
it('shows "Deploying to AWS" when not complete', () => {
2930
const { lastFrame } = render(<DeployStatus messages={[]} isComplete={false} hasError={false} />);
3031

31-
expect(lastFrame()).toContain('Deploying to AWS');
32+
expect(stripAnsi(lastFrame()!)).toContain('Deploying to AWS');
3233
});
3334

3435
it('shows success message when complete without error', () => {
@@ -90,7 +91,7 @@ describe('DeployStatus', () => {
9091
const { lastFrame } = render(<DeployStatus messages={messages} isComplete={false} hasError={false} />);
9192

9293
// Should show deploying text but no resource lines
93-
expect(lastFrame()).toContain('Deploying to AWS');
94+
expect(stripAnsi(lastFrame()!)).toContain('Deploying to AWS');
9495
expect(lastFrame()).not.toContain('Some general info');
9596
});
9697

src/cli/tui/components/__tests__/LogPanel.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { LogEntry } from '../LogPanel.js';
22
import { LogPanel } from '../LogPanel.js';
33
import { render } from 'ink-testing-library';
44
import React from 'react';
5+
import stripAnsi from 'strip-ansi';
56
import { afterEach, describe, expect, it, vi } from 'vitest';
67

78
const UP_ARROW = '\x1B[A';
@@ -19,7 +20,7 @@ describe('LogPanel', () => {
1920
describe('empty state', () => {
2021
it('renders "No output yet" with no other content', () => {
2122
const { lastFrame } = render(<LogPanel logs={[]} />);
22-
expect(lastFrame()).toBe('No output yet');
23+
expect(stripAnsi(lastFrame()!)).toBe('No output yet');
2324
});
2425
});
2526

src/cli/tui/components/__tests__/SecretInput.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ApiKeySecretInput, SecretInput } from '../SecretInput.js';
22
import { render } from 'ink-testing-library';
33
import React from 'react';
4+
import stripAnsi from 'strip-ansi';
45
import { afterEach, describe, expect, it, vi } from 'vitest';
56
import { z } from 'zod';
67

@@ -34,7 +35,7 @@ describe('SecretInput', () => {
3435
<SecretInput prompt="Key" placeholder="sk-..." onSubmit={vi.fn()} onCancel={vi.fn()} />
3536
);
3637

37-
expect(lastFrame()).toContain('sk-...');
38+
expect(stripAnsi(lastFrame()!)).toContain('sk-...');
3839
});
3940

4041
it('masks input with default * character', async () => {

0 commit comments

Comments
 (0)