mirror of
https://github.com/iptv-org/iptv
synced 2025-12-15 09:56:52 -05:00
Update test.test.ts
This commit is contained in:
@@ -1,21 +1,62 @@
|
|||||||
import { execSync } from 'child_process'
|
import child_process from 'node:child_process'
|
||||||
|
import { pathToFileURL } from 'node:url'
|
||||||
|
import { promisify } from 'node:util'
|
||||||
|
import * as fs from 'fs-extra'
|
||||||
|
import { glob } from 'glob'
|
||||||
|
|
||||||
|
const exec = promisify(child_process.exec)
|
||||||
|
|
||||||
type ExecError = {
|
type ExecError = {
|
||||||
status: number
|
status: number
|
||||||
stdout: string
|
stdout: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const ENV_VAR = 'cross-env ROOT_DIR=tests/__data__/input DATA_DIR=tests/__data__/input/data'
|
const ENV_VAR = 'cross-env DATA_DIR=tests/__data__/input/data ROOT_DIR=tests/__data__/output'
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fs.emptyDirSync('tests/__data__/output')
|
||||||
|
fs.copySync('tests/__data__/input/playlist_test/streams', 'tests/__data__/output/streams')
|
||||||
|
})
|
||||||
|
|
||||||
describe('playlist:test', () => {
|
describe('playlist:test', () => {
|
||||||
it('shows an error if the playlist contains a broken link', () => {
|
it('shows an error if the playlist contains a broken link', async () => {
|
||||||
const cmd = `${ENV_VAR} npm run playlist:test playlist_test/ag.m3u`
|
const cmd = `${ENV_VAR} npm run playlist:test streams/ag.m3u`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
execSync(cmd, { encoding: 'utf8' })
|
await exec(cmd, { encoding: 'utf8' })
|
||||||
|
if (process.env.DEBUG === 'true') console.log(cmd)
|
||||||
|
process.exit(0)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (process.env.DEBUG === 'true') console.log(cmd, error)
|
if (process.env.DEBUG === 'true') console.log(cmd, error)
|
||||||
expect((error as ExecError).stdout).toContain('playlist_test/ag.m3u')
|
expect((error as ExecError).stdout).toContain('streams/ag.m3u')
|
||||||
expect((error as ExecError).stdout).toContain('2 problems (1 errors, 1 warnings)')
|
expect((error as ExecError).stdout).toContain('2 problems (1 errors, 1 warnings)')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('it can remove all broken links from the playlist', async () => {
|
||||||
|
const cmd = `${ENV_VAR} npm run playlist:test streams/ag.m3u --- --fix`
|
||||||
|
try {
|
||||||
|
await exec(cmd, { encoding: 'utf8' })
|
||||||
|
if (process.env.DEBUG === 'true') console.log(cmd)
|
||||||
|
process.exit(0)
|
||||||
|
} catch (error) {
|
||||||
|
if (process.env.DEBUG === 'true') console.log(cmd, error)
|
||||||
|
const files = glob.sync('tests/__data__/expected/playlist_test/*.m3u').map(filepath => {
|
||||||
|
const fileUrl = pathToFileURL(filepath).toString()
|
||||||
|
const pathToRemove = pathToFileURL('tests/__data__/expected/playlist_test/').toString()
|
||||||
|
|
||||||
|
return fileUrl.replace(pathToRemove, '')
|
||||||
|
})
|
||||||
|
|
||||||
|
files.forEach(filepath => {
|
||||||
|
expect(content(`tests/__data__/output/streams/${filepath}`)).toBe(
|
||||||
|
content(`tests/__data__/expected/playlist_test/${filepath}`)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function content(filepath: string) {
|
||||||
|
return fs.readFileSync(pathToFileURL(filepath), { encoding: 'utf8' })
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user