Skip to content

Add golden file tests for Markdown formatter variants #20

@gregpriday

Description

@gregpriday

Summary

The Markdown formatter supports multiple output variants (line numbers, only-tree, git status) but lacks regression tests using golden files to verify stable output across changes.

Problem Statement

The src/services/formatters/MarkdownFormatter.js implements various output modes and flags, but without golden file tests we cannot:

  • Verify that output format remains consistent after code changes
  • Catch unintended formatting regressions
  • Validate that fence language detection works correctly
  • Ensure begin/end markers are properly placed
  • Test interaction between multiple flags

This affects users who rely on consistent Markdown output for documentation generation, AI tool integration, and automated workflows.

Current State

Formatter Capabilities (Implemented but Untested):

  • Base Markdown formatting with code fences
  • --with-line-numbers - Line-numbered content
  • --only-tree - Tree structure without file contents
  • --with-git-status - Git status annotations
  • Language detection for syntax highlighting
  • Begin/end markers for file boundaries

Existing Test Coverage:

  • Unit tests may exist for individual methods
  • No golden file tests for integrated output
  • No tests for flag combinations

Affected Components

Implementation Approach

  1. Create golden files in tests/fixtures/goldens/markdown/:

    • base.md - Default markdown output
    • with-line-numbers.md - With line numbers
    • only-tree.md - Tree structure only
    • with-git-status.md - With git annotations
    • combined-flags.md - Multiple flags together
  2. Create test file tests/e2e/markdown-formatter.test.js:

    • Test each variant against golden files
    • Use normalizeForGolden() for deterministic comparison
    • Test flag combinations
    • Verify fence language detection
  3. Follow existing golden file workflow:

    • Initial generation with UPDATE_GOLDEN=true
    • Subsequent runs compare against baselines
    • Git tracks changes to golden files

Tasks

  • Create tests/fixtures/goldens/markdown/ directory
  • Create tests/e2e/markdown-formatter.test.js with variant tests
  • Add test for base Markdown output (no flags)
  • Add test for --with-line-numbers output
  • Add test for --only-tree output
  • Add test for --with-git-status output
  • Add test for combined flags (e.g., line numbers + git status)
  • Generate initial golden files with UPDATE_GOLDEN=true npm run test:e2e
  • Verify fence language detection for various file types (.js, .py, .md, etc.)
  • Verify begin/end markers are correctly placed
  • Ensure tests pass on CI across different platforms

Acceptance Criteria

  • At least 6 golden file tests for Markdown formatter variants
  • Tests pass consistently without UPDATE_GOLDEN flag
  • Golden files are committed and tracked in git
  • Tests fail when formatter output changes
  • Language detection verified for common file extensions
  • All flag combinations produce deterministic output
  • README examples match actual output from golden files
  • No test flakiness or platform-specific failures

Additional Context

This issue is a subset of #19 (E2E golden tests) but focuses specifically on the Markdown formatter, which is commonly used for AI tool integration and documentation generation.

README Examples to Verify:

Related Testing Infrastructure:

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority-2 ⚙️Planned/normal priority. Product work or quality improvements to schedule this cycle.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions