iptv/tests/commands/playlist/update.test.js

33 lines
847 B
JavaScript
Raw Normal View History

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