mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
const fs = require('fs')
|
|
const path = require('path')
|
|
const { execSync } = require('child_process')
|
|
|
|
beforeEach(() => {
|
|
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
|
fs.mkdirSync('tests/__data__/output')
|
|
fs.mkdirSync('tests/__data__/temp/database', { recursive: true })
|
|
fs.copyFileSync('tests/__data__/input/database/queue.db', 'tests/__data__/temp/database/queue.db')
|
|
fs.copyFileSync(
|
|
'tests/__data__/input/database/programs.db',
|
|
'tests/__data__/temp/database/programs.db'
|
|
)
|
|
|
|
const stdout = execSync(
|
|
'DB_DIR=tests/__data__/temp/database API_DIR=tests/__data__/output/api node scripts/commands/update-api.js',
|
|
{ encoding: 'utf8' }
|
|
)
|
|
})
|
|
|
|
afterEach(() => {
|
|
fs.rmdirSync('tests/__data__/temp', { recursive: true })
|
|
})
|
|
|
|
it('can generate guides.json', () => {
|
|
const output = content('tests/__data__/output/api/guides.json')
|
|
const expected = content('tests/__data__/expected/api/guides.json')
|
|
|
|
expect(output).toBe(expected)
|
|
})
|
|
|
|
it('can generate programs.json', () => {
|
|
const output = content('tests/__data__/output/api/programs.json')
|
|
const expected = content('tests/__data__/expected/api/programs.json')
|
|
|
|
expect(output).toBe(expected)
|
|
})
|
|
|
|
function content(filepath) {
|
|
const data = fs.readFileSync(path.resolve(filepath), {
|
|
encoding: 'utf8'
|
|
})
|
|
|
|
return JSON.stringify(data)
|
|
}
|