Skip to content

Implement Visual Regression Testing for Ink UI Components to Prevent CLI Display Issues #3938

@hoteye

Description

@hoteye

Overview

Terraform CDK CLI has multiple UI rendering issues that could be prevented with automated visual regression testing. Since CDKTF already uses Ink framework and has , implementing visual regression testing would be a natural next step to ensure consistent CLI experience.

Evidence of Current UI Problems

Multiple open issues demonstrate recurring UI rendering problems:

Animation & Display Issues

Technical Context

CDKTF CLI already uses rich Ink ecosystem:

  • (v3.2.0) - Main UI framework
  • (v4.0.3) - Loading animations
  • (v4.2.2) - Selection components
  • (v3.1.0) - Table displays
  • (v2.1.0) - Existing testing foundation

Proposed Solution: Enhanced Visual Testing

I recommend implementing ink-visual-testing alongside the existing for comprehensive UI testing.

Why ink-visual-testing for CDKTF?

  • Perfect compatibility: Works with Ink v3+ (CDKTF uses v3.2.0)
  • CI-focused: Specifically designed to solve CI animation issues like cdktf-cli: disable animations via flag #2951
  • Easy integration: Complements existing setup
  • Cross-platform consistency: Bundled fonts ensure identical rendering across environments
  • Real terminal rendering: Uses node-pty for accurate CLI simulation

Implementation Benefits

  1. Solve CI animation issues (cdktf-cli: disable animations via flag #2951) - Detect broken spinner rendering automatically
  2. Prevent layout problems (CLI: Fixed width output on deploy is unusable #3503) - Catch width/wrapping issues before release
  3. Ensure component stability - Verify ink-table, ink-select-input display correctly
  4. Cross-platform consistency - Identical rendering on Mac/Linux/Windows/CI
  5. Release confidence - Visual baselines prevent UI regressions

Example Implementation

import { fixedPtyRender, getCIOptimizedConfig } from 'ink-visual-testing';

// Test main CDKTF CLI commands
describe('CDKTF CLI Visual Tests', () => {
  it('should render help command correctly', async () => {
    await fixedPtyRender(
      './dist/bin/cdktf.js',
      './tests/__output__/help-command.png',
      {
        ...getCIOptimizedConfig(), // Solves CI animation issues
        args: ['--help'],
        cols: 120,
        rows: 40
      }
    );
  });

  it('should handle synth output properly', async () => {
    await fixedPtyRender(
      './dist/bin/cdktf.js', 
      './tests/__output__/synth-command.png',
      {
        ...getCIOptimizedConfig(),
        args: ['synth'],
        cols: 100,
        rows: 30
      }
    );
  });
});

Recommended Test Coverage

  1. Core commands: cdktf deploy, cdktf synth, cdktf init
  2. Interactive components: Selection prompts, confirmation dialogs
  3. Progress displays: Spinners, progress bars, status tables
  4. Error states: Error messages, warnings, validation output
  5. Different terminal sizes: Narrow (80 cols) to wide (120+ cols)
  6. CI environment: Animation-free rendering for automation

Integration with Existing Testing

Visual testing would complement existing tools:

  • ink-testing-library: Continue for unit/component testing
  • ink-visual-testing: Add for integration/regression testing
  • Jest: Orchestrate both types of tests
// Existing unit test (keep these)
import { render } from 'ink-testing-library';

// New visual test (add these)
import { visualTest } from 'ink-visual-testing';

describe('Deploy Command', () => {
  // Unit test - fast, logic verification
  it('should render deploy status', () => {
    const { lastFrame } = render(<DeployStatus status="deploying" />);
    expect(lastFrame()).toContain('Deploying');
  });

  // Visual test - end-to-end, regression protection  
  it('should display deploy output correctly', async () => {
    await visualTest('deploy-output', './fixtures/deploy-command.tsx', {
      cols: 100,
      rows: 25
    });
  });
});

Technical Support Offer

I'm the author of ink-visual-testing and would be happy to provide comprehensive technical support for implementing visual regression testing in CDKTF:

  1. Integration guidance - Help set up visual tests alongside existing ink-testing-library
  2. CI optimization - Specifically address cdktf-cli: disable animations via flag #2951 animation issues in CI environments
  3. Baseline establishment - Assist with creating initial visual baselines for key commands
  4. Performance optimization - Ensure tests run efficiently in CI/CD pipelines
  5. Component-specific testing - Handle complex Ink components like tables and spinners

Expected Impact

Next Steps

If you're interested in exploring this approach, I'm available for:

  • Technical discussion on integration strategy
  • Demo/proof of concept implementation
  • Documentation and best practices guidance
  • Long-term maintenance and support

This would significantly enhance CDKTF's reliability and solve existing UI pain points while building on your current testing infrastructure.


Note: ink-visual-testing successfully prevents similar UI issues in other Ink-based CLIs. It's specifically designed to work alongside ink-testing-library for comprehensive testing coverage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions