Files
iptv/tests/commands/api/generate.test.ts

27 lines
852 B
TypeScript
Raw Normal View History

2025-04-22 23:17:48 +03:00
import { pathToFileURL } from 'node:url'
2023-09-15 18:40:14 +03:00
import { execSync } from 'child_process'
import fs from 'fs-extra'
2025-04-22 03:47:28 +03:00
const ENV_VAR =
'cross-env DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/api_generate API_DIR=tests/__data__/output/.api'
2022-02-13 01:40:45 +03:00
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
2025-03-29 11:39:30 +03:00
})
2022-02-13 01:40:45 +03:00
2025-04-22 03:47:28 +03:00
describe('api:generate', () => {
it('can create streams.json', () => {
const cmd = `${ENV_VAR} npm run api:generate`
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
2022-02-13 01:40:45 +03:00
2025-04-22 23:17:48 +03:00
expect(content('tests/__data__/output/.api/streams.json')).toMatchObject(
content('tests/__data__/expected/api_generate/.api/streams.json')
2025-04-22 03:47:28 +03:00
)
})
2022-02-13 01:40:45 +03:00
})
2023-09-15 18:40:14 +03:00
function content(filepath: string) {
2025-04-22 23:17:48 +03:00
return JSON.parse(fs.readFileSync(pathToFileURL(filepath), { encoding: 'utf8' }))
2022-02-13 01:40:45 +03:00
}