2022-02-12 02:05:31 +01:00
|
|
|
const { execSync } = require('child_process')
|
2022-02-05 06:12:17 +01:00
|
|
|
const fs = require('fs-extra')
|
2021-12-12 05:13:02 +01:00
|
|
|
const path = require('path')
|
2022-02-07 05:00:48 +01:00
|
|
|
const glob = require('glob')
|
2021-12-12 05:13:02 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-02-07 06:43:28 +01:00
|
|
|
fs.emptyDirSync('tests/__data__/output')
|
2022-02-12 02:05:31 +01:00
|
|
|
fs.copyFileSync(
|
|
|
|
'tests/__data__/input/database/playlist_update.streams.db',
|
|
|
|
'tests/__data__/output/streams.db'
|
|
|
|
)
|
2021-12-12 05:13:02 +01:00
|
|
|
|
2022-02-12 02:05:31 +01:00
|
|
|
const stdout = execSync('DB_DIR=tests/__data__/output npm run playlist:update', {
|
2022-02-11 19:07:16 +01:00
|
|
|
encoding: 'utf8'
|
|
|
|
})
|
2021-12-12 05:13:02 +01:00
|
|
|
})
|
|
|
|
|
2022-02-07 05:00:48 +01:00
|
|
|
it('can update playlists', () => {
|
|
|
|
const files = glob
|
|
|
|
.sync('tests/__data__/expected/channels/*.m3u')
|
|
|
|
.map(f => f.replace('tests/__data__/expected/', ''))
|
2022-02-05 06:12:17 +01:00
|
|
|
|
2022-02-07 05:00:48 +01:00
|
|
|
files.forEach(filepath => {
|
|
|
|
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
|
|
|
|
})
|
2021-12-12 05:13:02 +01:00
|
|
|
})
|
2022-02-05 06:12:17 +01:00
|
|
|
|
|
|
|
function content(filepath) {
|
2022-02-07 05:00:48 +01:00
|
|
|
return fs.readFileSync(`tests/__data__/${filepath}`, {
|
2022-02-05 06:12:17 +01:00
|
|
|
encoding: 'utf8'
|
|
|
|
})
|
|
|
|
}
|