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

33 lines
1023 B
TypeScript
Raw Normal View History

2023-09-15 17:40:14 +02:00
import { execSync } from 'child_process'
import * as fs from 'fs-extra'
import * as glob from 'glob'
2021-12-12 05:13:02 +01:00
beforeEach(() => {
2022-02-06 22:04:56 +01:00
fs.emptyDirSync('tests/__data__/output')
2023-09-22 05:22:47 +02:00
execSync(
2023-09-17 03:07:27 +02:00
'STREAMS_DIR=tests/__data__/input/streams_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-06 22:04:56 +01:00
{ encoding: 'utf8' }
)
2021-12-12 05:13:02 +01:00
})
2022-02-11 19:07:16 +01:00
it('can generate playlists and logs', () => {
const playlists = glob
2022-02-07 00:27:15 +01:00
.sync('tests/__data__/expected/.gh-pages/**/*.m3u')
2023-09-15 17:40:14 +02:00
.map((file: string) => file.replace('tests/__data__/expected/', ''))
2021-12-12 05:13:02 +01:00
2023-09-15 17:40:14 +02:00
playlists.forEach((filepath: string) => {
2022-02-07 00:27:15 +01:00
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
})
2023-09-22 05:22:47 +02:00
expect(content('output/logs/generators.log').split('\n').sort()).toStrictEqual(
content('expected/logs/generators.log').split('\n').sort()
2023-09-15 17:40:14 +02:00
)
2022-02-06 22:19:09 +01:00
})
2021-12-12 05:13:02 +01:00
2023-09-15 17:40:14 +02:00
function content(filepath: string) {
2022-02-06 22:04:56 +01:00
return fs.readFileSync(`tests/__data__/${filepath}`, {
encoding: 'utf8'
})
}