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

38 lines
1.0 KiB
TypeScript
Raw Normal View History

2025-03-15 07:29:59 +03:00
import { execSync } from 'child_process'
2025-04-23 05:42:52 +03:00
import path from 'node:path'
2025-04-22 03:47:28 +03:00
import os from 'os'
2025-03-15 07:29:59 +03:00
type ExecError = {
status: number
stdout: string
}
2025-04-22 03:47:28 +03:00
let ENV_VAR = 'ROOT_DIR=tests/__data__/input'
if (os.platform() === 'win32') {
ENV_VAR = 'SET "ROOT_DIR=tests/__data__/input" &&'
}
describe('playlist:test', () => {
it('shows an error if the playlist contains a broken link', () => {
const cmd = `${ENV_VAR} npm run playlist:test playlist_test/ag.m3u`
try {
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
checkStdout(stdout)
} catch (error) {
// NOTE: for Windows only
if (process.env.DEBUG === 'true') console.log(cmd, error)
checkStdout((error as ExecError).stdout)
}
})
2025-03-15 07:29:59 +03:00
})
2025-04-22 03:47:28 +03:00
function checkStdout(stdout: string) {
2025-04-23 05:42:52 +03:00
expect(stdout).toContain(slash('playlist_test/ag.m3u'))
2025-04-22 03:47:28 +03:00
expect(stdout).toContain('2 problems (1 errors, 1 warnings)')
}
2025-04-23 05:42:52 +03:00
function slash(filepath: string) {
return filepath.split(path.sep).join(path.posix.sep)
}