iptv/tests/commands/api/generate.test.js

29 lines
800 B
JavaScript
Raw Normal View History

2022-02-12 23:40:45 +01:00
const { execSync } = require('child_process')
const fs = require('fs-extra')
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
2022-08-15 01:22:01 +02:00
fs.mkdirSync('tests/__data__/output/database')
2022-02-12 23:40:45 +01:00
fs.copyFileSync(
2023-04-28 16:07:32 +02:00
'tests/__data__/input/database/api_generate.streams.db',
2022-08-15 01:22:01 +02:00
'tests/__data__/output/database/streams.db'
2022-02-12 23:40:45 +01:00
)
const stdout = execSync(
2023-04-28 16:07:32 +02:00
'DB_DIR=tests/__data__/output/database DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output/.api npm run api:generate',
2022-02-12 23:40:45 +01:00
{ encoding: 'utf8' }
)
})
it('can create streams.json', () => {
2023-04-27 16:41:38 +02:00
expect(content(`output/.api/streams.json`)).toMatchObject(content(`expected/.api/streams.json`))
2022-02-12 23:40:45 +01:00
})
function content(filepath) {
2022-08-10 02:41:21 +02:00
return JSON.parse(
fs.readFileSync(`tests/__data__/${filepath}`, {
encoding: 'utf8'
})
)
2022-02-12 23:40:45 +01:00
}