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')
|
2022-02-07 00:27:15 +01:00
|
|
|
const glob = require('glob')
|
2021-12-12 05:13:02 +01:00
|
|
|
const { execSync } = require('child_process')
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-02-06 22:04:56 +01:00
|
|
|
fs.emptyDirSync('tests/__data__/output')
|
|
|
|
fs.copyFileSync(
|
|
|
|
'tests/__data__/input/database/generate-playlists.streams.db',
|
2022-02-07 06:42:35 +01:00
|
|
|
'tests/__data__/output/streams.db'
|
2022-01-12 18:35:02 +01:00
|
|
|
)
|
2021-12-31 09:28:22 +01:00
|
|
|
|
2022-02-06 22:04:56 +01:00
|
|
|
const stdout = execSync(
|
2022-02-07 06:42:35 +01:00
|
|
|
'DB_DIR=tests/__data__/output 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',
|
2022-02-06 22:04:56 +01:00
|
|
|
{ encoding: 'utf8' }
|
2022-01-12 18:35:02 +01:00
|
|
|
)
|
2021-12-12 05:13:02 +01:00
|
|
|
})
|
|
|
|
|
2022-02-06 23:22:20 +01:00
|
|
|
it('can generate playlists', () => {
|
2022-02-07 00:27:15 +01:00
|
|
|
const files = glob
|
|
|
|
.sync('tests/__data__/expected/.gh-pages/**/*.m3u')
|
|
|
|
.map(f => f.replace('tests/__data__/expected/', ''))
|
2021-12-12 05:13:02 +01:00
|
|
|
|
2022-02-06 23:22:20 +01:00
|
|
|
files.forEach(filepath => {
|
2022-02-07 00:27:15 +01:00
|
|
|
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can generate logs', () => {
|
|
|
|
const files = glob
|
|
|
|
.sync('tests/__data__/expected/logs/generators/*.log')
|
|
|
|
.map(f => f.replace('tests/__data__/expected/', ''))
|
|
|
|
|
|
|
|
files.forEach(filepath => {
|
|
|
|
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
|
2022-02-06 23:22:20 +01:00
|
|
|
})
|
2022-02-06 22:19:09 +01:00
|
|
|
})
|
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'
|
|
|
|
})
|
|
|
|
}
|