Testing API Generation Command Implementation in iptv-org/iptv
This test suite validates the API generation functionality in the IPTV project, specifically focusing on the streams.json file creation process. It ensures proper file generation and content matching through automated testing.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
iptv-org/iptv
tests/commands/api/generate.test.ts
import { execSync } from 'child_process'
import fs from 'fs-extra'
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
execSync(
'STREAMS_DIR=tests/__data__/input/streams_generate API_DIR=tests/__data__/output/.api npm run api:generate',
{ encoding: 'utf8' }
)
})
it('can create streams.json', () => {
expect(content('output/.api/streams.json')).toMatchObject(content('expected/.api/streams.json'))
})
function content(filepath: string) {
return JSON.parse(
fs.readFileSync(`tests/__data__/${filepath}`, {
encoding: 'utf8'
})
)
}