Back to Repositories

Testing Stream Report Generation Workflow in IPTV Repository

This test suite validates the report creation functionality in the IPTV repository, specifically focusing on stream status reporting and issue tracking. The test ensures proper formatting and content of generated reports for stream-related issues including edits, additions, and error states.

Test Coverage Overview

The test suite provides comprehensive coverage of the report creation command functionality.

Key areas tested include:
  • Report generation with multiple stream statuses
  • Issue number tracking
  • Various stream operation types (add, edit)
  • Different error states (invalid_link, invalid_id, duplicate)
  • Edge cases like undefined channel IDs

Implementation Analysis

The testing approach utilizes Jest’s execution context to validate command line output. The implementation leverages Node’s child_process.execSync to simulate CLI execution, with specific focus on output validation through string matching.

Technical patterns include:
  • Direct command execution with environment variable configuration
  • Output capture and validation
  • Tabular data structure verification

Technical Details

Testing tools and configuration:
  • Jest testing framework
  • child_process module for command execution
  • Environment variables for test data directory configuration
  • UTF-8 encoding for output processing
  • Custom data directories for isolated testing

Best Practices Demonstrated

The test implementation showcases several testing best practices for command-line tools.

Notable practices include:
  • Isolated test data management
  • Environment variable configuration for test contexts
  • Comprehensive output validation
  • Clear test case organization
  • Explicit encoding specifications

iptv-org/iptv

tests/commands/report/create.test.ts

            
import { execSync } from 'child_process'

it('can create report', () => {
  const stdout = execSync(
    'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/streams_report npm run report:create',
    {
      encoding: 'utf8'
    }
  )

  expect(
    stdout.includes(`
┌─────────┬─────────────┬─────────────────┬─────────────────────┬────────────────┐
│ (index) │ issueNumber │ type            │ channelId           │ status         │
├─────────┼─────────────┼─────────────────┼─────────────────────┼────────────────┤
│ 0       │ 14110       │ 'streams:edit'  │ 'BBCAmericaEast.us' │ 'invalid_link' │
│ 1       │ 14120       │ 'streams:edit'  │ 'boo.us'            │ 'invalid_id'   │
│ 2       │ 14140       │ 'broken stream' │ undefined           │ 'invalid_link' │
│ 3       │ 14175       │ 'streams:add'   │ 'TFX.fr'            │ 'invalid_id'   │
│ 4       │ 14176       │ 'streams:add'   │ 'ManoramaNews.in'   │ 'duplicate'    │
│ 5       │ 14177       │ 'streams:add'   │ 'TUTV.us'           │ 'fullfilled'   │
│ 6       │ 14178       │ 'streams:add'   │ 'TV3.my'            │ 'blocked'      │
│ 7       │ 14179       │ 'streams:add'   │ 'ManoramaNews.in'   │ 'pending'      │
└─────────┴─────────────┴─────────────────┴─────────────────────┴────────────────┘`)
  ).toBe(true)
})