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

44 lines
1.5 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'
2025-04-22 03:47:28 +03:00
import os from 'os'
let ENV_VAR =
'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'
if (os.platform() === 'win32') {
ENV_VAR =
'SET "STREAMS_DIR=tests/__data__/input/playlist_generate" && SET "DATA_DIR=tests/__data__/input/data" && SET "PUBLIC_DIR=tests/__data__/output/.gh-pages" && SET "LOGS_DIR=tests/__data__/output/logs" &&'
}
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-04-22 03:47:28 +03:00
describe('playlist:generate', () => {
it('can generate playlists and logs', () => {
const cmd = `${ENV_VAR} npm run playlist:generate`
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
2021-12-12 07:13:02 +03:00
2025-04-22 03:47:28 +03:00
const playlists = glob
.sync('tests/__data__/expected/playlist_generate/.gh-pages/**/*.m3u')
.map((file: string) => file.replace('tests/__data__/expected/playlist_generate/', ''))
2025-04-16 20:19:31 +03:00
2025-04-22 03:47:28 +03:00
playlists.forEach((filepath: string) => {
expect(content(`output/${filepath}`), filepath).toBe(
content(`expected/playlist_generate/${filepath}`)
)
})
2021-12-12 07:13:02 +03:00
2025-04-22 03:47:28 +03:00
expect(content('output/logs/generators.log').split('\n').sort()).toStrictEqual(
content('expected/playlist_generate/logs/generators.log').split('\n').sort()
2025-03-29 11:39:30 +03:00
)
2022-02-07 02:27:15 +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'
})
}