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

35 lines
1008 B
TypeScript
Raw Normal View History

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
import os from 'os'
let ENV_VAR =
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/api_generate API_DIR=tests/__data__/output/.api'
if (os.platform() === 'win32') {
ENV_VAR =
'SET "DATA_DIR=tests/__data__/input/data" && SET "STREAMS_DIR=tests/__data__/input/api_generate" && SET "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 03:47:28 +03:00
expect(content('output/.api/streams.json')).toMatchObject(
content('expected/api_generate/.api/streams.json')
)
})
2022-02-13 01:40:45 +03:00
})
2023-09-15 18:40:14 +03:00
function content(filepath: string) {
2022-08-10 03:41:21 +03:00
return JSON.parse(
fs.readFileSync(`tests/__data__/${filepath}`, {
encoding: 'utf8'
})
)
2022-02-13 01:40:45 +03:00
}