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
|
|
|
const { execSync } = require('child_process')
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-02-07 06:43:28 +01:00
|
|
|
fs.emptyDirSync('tests/__data__/output')
|
|
|
|
fs.copyFileSync('tests/__data__/input/database/streams.db', 'tests/__data__/output/streams.db')
|
2021-12-12 05:13:02 +01:00
|
|
|
|
2022-02-07 06:43:28 +01:00
|
|
|
const stdout = execSync(
|
|
|
|
'DB_DIR=tests/__data__/output node scripts/commands/update-playlists.js',
|
|
|
|
{
|
|
|
|
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'
|
|
|
|
})
|
|
|
|
}
|