Back to Repositories

Testing Playlist Update Command Functionality in IPTV-org/iptv

This test suite validates the playlist update functionality in the IPTV repository, focusing on proper formatting and content synchronization of M3U playlists. The tests ensure correct file handling, directory management, and output verification against expected results.

Test Coverage Overview

The test suite provides comprehensive coverage of the playlist update command functionality.

Key areas tested include:
  • Directory cleanup and initialization
  • Playlist file formatting and processing
  • Output validation against expected results
  • Command execution and stdout verification
Edge cases covered include file system operations and encoding handling.

Implementation Analysis

The testing approach utilizes Jest’s unit testing framework with file system operations and child process execution. The implementation leverages fs-extra for enhanced file operations and glob for file pattern matching.

Notable patterns include:
  • Beforehook setup for test isolation
  • Directory state management
  • Content comparison utilities
  • Command execution verification

Technical Details

Testing tools and configuration:
  • Jest test runner
  • fs-extra for file operations
  • child_process for command execution
  • glob for file pattern matching
  • TypeScript for type safety
  • UTF-8 encoding handling

Best Practices Demonstrated

The test implementation showcases several testing best practices for maintaining quality and reliability.

Notable practices include:
  • Clean test environment setup
  • Isolated test data management
  • Explicit file path handling
  • Comprehensive output validation
  • Modular helper functions

iptv-org/iptv

tests/commands/playlist/update.test.ts

            
import { execSync } from 'child_process'
import * as fs from 'fs-extra'
import { glob } from 'glob'

beforeEach(() => {
  fs.emptyDirSync('tests/__data__/output')
  fs.copySync('tests/__data__/input/streams_update', 'tests/__data__/output/streams')
})

it('can format playlists', () => {
  const stdout = execSync(
    'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/output/streams npm run playlist:update --silent',
    {
      encoding: 'utf8'
    }
  )

  const files = glob
    .sync('tests/__data__/expected/streams_update/*.m3u')
    .map(f => f.replace('tests/__data__/expected/streams_update/', ''))

  files.forEach(filepath => {
    expect(content(`output/streams/${filepath}`), filepath).toBe(
      content(`expected/streams_update/${filepath}`)
    )
  })

  expect(stdout).toBe('OUTPUT=closes #14151, closes #14140, closes #14110, closes #14178\n')
})

function content(filepath: string) {
  return fs.readFileSync(`tests/__data__/${filepath}`, {
    encoding: 'utf8'
  })
}