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

37 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-09-15 18:40:14 +03:00
import { execSync } from 'child_process'
import * as fs from 'fs-extra'
import * as glob from 'glob'
2021-12-12 07:13:02 +03:00
beforeEach(() => {
2022-02-07 00:04:56 +03:00
fs.emptyDirSync('tests/__data__/output')
2025-03-29 11:39:30 +03:00
})
2025-03-29 11:39:30 +03:00
it('can generate playlists and logs', () => {
2025-04-16 20:19:31 +03:00
const stdout = execSync(
2025-03-29 11:39:30 +03:00
'STREAMS_DIR=tests/__data__/input/playlist_generate DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output/.gh-pages LOGS_DIR=tests/__data__/output/logs npm run playlist:generate',
2022-02-07 00:04:56 +03:00
{ encoding: 'utf8' }
)
2021-12-12 07:13:02 +03:00
2025-04-16 20:19:31 +03:00
if (process.env.DEBUG === 'true') console.log(stdout)
2022-02-11 21:07:16 +03:00
const playlists = glob
2025-03-29 11:39:30 +03:00
.sync('tests/__data__/expected/playlist_generate/.gh-pages/**/*.m3u')
.map((file: string) => file.replace('tests/__data__/expected/playlist_generate/', ''))
2021-12-12 07:13:02 +03:00
2023-09-15 18:40:14 +03:00
playlists.forEach((filepath: string) => {
2025-03-29 11:39:30 +03:00
expect(content(`output/${filepath}`), filepath).toBe(
content(`expected/playlist_generate/${filepath}`)
)
2022-02-07 02:27:15 +03:00
})
2023-09-22 06:22:47 +03:00
expect(content('output/logs/generators.log').split('\n').sort()).toStrictEqual(
2025-03-29 11:39:30 +03:00
content('expected/playlist_generate/logs/generators.log').split('\n').sort()
2023-09-15 18:40:14 +03:00
)
2022-02-07 00:19:09 +03:00
})
2021-12-12 07:13:02 +03:00
2023-09-15 18:40:14 +03:00
function content(filepath: string) {
2022-02-07 00:04:56 +03:00
return fs.readFileSync(`tests/__data__/${filepath}`, {
encoding: 'utf8'
})
}