iptv/tests/commands/generate-playlists.test.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-02-06 22:04:56 +01:00
const fs = require('fs-extra')
2021-12-12 05:13:02 +01:00
const path = require('path')
const { execSync } = require('child_process')
beforeEach(() => {
2022-02-06 22:04:56 +01:00
fs.emptyDirSync('tests/__data__/output')
fs.emptyDirSync('tests/__data__/temp')
fs.copyFileSync(
'tests/__data__/input/database/generate-playlists.streams.db',
'tests/__data__/temp/streams.db'
)
2022-02-06 22:04:56 +01:00
const stdout = execSync(
'DB_DIR=tests/__data__/temp DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output/.gh-pages LOGS_DIR=tests/__data__/output/logs/generators node --trace-warnings scripts/commands/generate-playlists.js',
{ encoding: 'utf8' }
)
2021-12-12 05:13:02 +01:00
2022-02-06 22:04:56 +01:00
console.log(stdout)
2021-12-12 05:13:02 +01:00
})
2022-02-06 22:04:56 +01:00
it.each([
'.gh-pages/categories/general.m3u',
'.gh-pages/categories/legislative.m3u',
'.gh-pages/categories/news.m3u',
'.gh-pages/categories/other.m3u',
'logs/generators/categories.log'
])('can generate %s', filepath => {
expect(content(`output/${filepath}`)).toBe(content(`expected/${filepath}`))
2021-12-12 05:13:02 +01:00
})
2022-02-06 22:04:56 +01:00
it.each(['countries/ru.m3u', 'countries/uk.m3u', 'countries/undefined.m3u'])(
'can generate %s',
filepath => {
expect(content(`output/.gh-pages/${filepath}`)).toBe(content(`expected/.gh-pages/${filepath}`))
}
)
2021-12-12 05:13:02 +01:00
2022-02-06 22:04:56 +01:00
function content(filepath) {
return fs.readFileSync(`tests/__data__/${filepath}`, {
encoding: 'utf8'
})
}