2023-09-15 18:40:14 +03:00
|
|
|
import { execSync } from 'child_process'
|
|
|
|
|
import * as fs from 'fs-extra'
|
|
|
|
|
import * as glob from 'glob'
|
2021-12-12 07:13:02 +03:00
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-02-07 00:04:56 +03:00
|
|
|
fs.emptyDirSync('tests/__data__/output')
|
2021-12-31 11:28:22 +03:00
|
|
|
|
2023-09-22 06:22:47 +03:00
|
|
|
execSync(
|
2023-09-17 04:07:27 +03:00
|
|
|
'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',
|
2022-02-07 00:04:56 +03:00
|
|
|
{ encoding: 'utf8' }
|
2022-01-12 20:35:02 +03:00
|
|
|
)
|
2021-12-12 07:13:02 +03:00
|
|
|
})
|
|
|
|
|
|
2022-02-11 21:07:16 +03:00
|
|
|
it('can generate playlists and logs', () => {
|
|
|
|
|
const playlists = glob
|
2022-02-07 02:27:15 +03:00
|
|
|
.sync('tests/__data__/expected/.gh-pages/**/*.m3u')
|
2023-09-15 18:40:14 +03:00
|
|
|
.map((file: string) => file.replace('tests/__data__/expected/', ''))
|
2021-12-12 07:13:02 +03:00
|
|
|
|
2023-09-15 18:40:14 +03:00
|
|
|
playlists.forEach((filepath: string) => {
|
2022-02-07 02:27:15 +03:00
|
|
|
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
|
|
|
|
|
})
|
|
|
|
|
|
2023-09-22 06:22:47 +03:00
|
|
|
expect(content('output/logs/generators.log').split('\n').sort()).toStrictEqual(
|
|
|
|
|
content('expected/logs/generators.log').split('\n').sort()
|
2023-09-15 18:40:14 +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) {
|
2022-02-07 00:04:56 +03:00
|
|
|
return fs.readFileSync(`tests/__data__/${filepath}`, {
|
|
|
|
|
encoding: 'utf8'
|
|
|
|
|
})
|
|
|
|
|
}
|