Files
iptv/tests/commands/playlist/format.test.ts

37 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-04-22 23:17:48 +03:00
import { pathToFileURL } from 'node:url'
2023-09-17 04:07:27 +03:00
import { execSync } from 'child_process'
import * as fs from 'fs-extra'
import { glob } from 'glob'
2025-04-22 03:47:28 +03:00
const ENV_VAR = 'cross-env STREAMS_DIR=tests/__data__/output/streams DATA_DIR=tests/__data__/input/data'
2023-09-17 04:07:27 +03:00
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
2025-03-29 11:39:30 +03:00
fs.copySync('tests/__data__/input/playlist_format', 'tests/__data__/output/streams')
2023-09-17 04:07:27 +03:00
})
2025-04-22 03:47:28 +03:00
describe('playlist:format', () => {
it('can format playlists', () => {
const cmd = `${ENV_VAR} npm run playlist:format`
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
2023-09-17 04:07:27 +03:00
2025-04-23 05:42:52 +03:00
const files = glob.sync('tests/__data__/expected/playlist_format/*.m3u').map(filepath => {
const fileUrl = pathToFileURL(filepath).toString()
const pathToRemove = pathToFileURL('tests/__data__/expected/playlist_format/').toString()
return fileUrl.replace(pathToRemove, '')
})
2023-09-17 04:07:27 +03:00
2025-04-22 03:47:28 +03:00
files.forEach(filepath => {
expect(content(`tests/__data__/output/streams/${filepath}`)).toBe(
2025-04-22 23:17:48 +03:00
content(`tests/__data__/expected/playlist_format/${filepath}`)
2025-04-22 03:47:28 +03:00
)
})
2023-09-17 04:07:27 +03:00
})
})
function content(filepath: string) {
2025-04-22 23:17:48 +03:00
return fs.readFileSync(pathToFileURL(filepath), { encoding: 'utf8' })
2023-09-17 04:07:27 +03:00
}