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

48 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-04-22 23:17:48 +03:00
import { pathToFileURL } from 'node:url'
2023-09-15 18:40:14 +03:00
import { execSync } from 'child_process'
2025-04-23 20:56:11 +03:00
import os, { EOL } from 'node:os'
2023-09-15 18:40:14 +03:00
import * as fs from 'fs-extra'
import * as glob from 'glob'
2025-04-22 03:47:28 +03:00
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')
2025-04-23 05:42:52 +03:00
.map(filepath => {
const fileUrl = pathToFileURL(filepath).toString()
const pathToRemove = pathToFileURL('tests/__data__/expected/playlist_generate/').toString()
return fileUrl.replace(pathToRemove, '')
})
2025-04-16 20:19:31 +03:00
2025-04-22 03:47:28 +03:00
playlists.forEach((filepath: string) => {
2025-04-22 23:17:48 +03:00
expect(content(`tests/__data__/output/${filepath}`), filepath).toBe(
content(`tests/__data__/expected/playlist_generate/${filepath}`)
2025-04-22 03:47:28 +03:00
)
})
2021-12-12 07:13:02 +03:00
2025-04-23 20:56:11 +03:00
expect(content('tests/__data__/output/logs/generators.log').split(EOL).sort()).toStrictEqual(
content('tests/__data__/expected/playlist_generate/logs/generators.log').split(EOL).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) {
2025-04-22 23:17:48 +03:00
return fs.readFileSync(pathToFileURL(filepath), { encoding: 'utf8' })
2022-02-07 00:04:56 +03:00
}