You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iptv/tests/commands/playlist/generate.test.ts

33 lines
1.0 KiB
TypeScript

1 year ago
import { execSync } from 'child_process'
import * as fs from 'fs-extra'
import * as glob from 'glob'
3 years ago
beforeEach(() => {
3 years ago
fs.emptyDirSync('tests/__data__/output')
1 year ago
const stdout = execSync(
1 year ago
'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',
3 years ago
{ encoding: 'utf8' }
)
3 years ago
})
it('can generate playlists and logs', () => {
const playlists = glob
3 years ago
.sync('tests/__data__/expected/.gh-pages/**/*.m3u')
1 year ago
.map((file: string) => file.replace('tests/__data__/expected/', ''))
3 years ago
1 year ago
playlists.forEach((filepath: string) => {
3 years ago
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
})
1 year ago
expect(content(`output/logs/generators.log`).split('\n').sort()).toStrictEqual(
content(`expected/logs/generators.log`).split('\n').sort()
)
3 years ago
})
3 years ago
1 year ago
function content(filepath: string) {
3 years ago
return fs.readFileSync(`tests/__data__/${filepath}`, {
encoding: 'utf8'
})
}