mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 08:30:06 -04:00
32 lines
982 B
TypeScript
32 lines
982 B
TypeScript
import { execSync } from 'child_process'
|
|
import fs from 'fs-extra'
|
|
import { pathToFileURL } from 'node:url'
|
|
import os from 'os'
|
|
|
|
let ENV_VAR = 'SITES_DIR=tests/__data__/input/api_generate/sites API_DIR=tests/__data__/output'
|
|
if (os.platform() === 'win32') {
|
|
ENV_VAR =
|
|
'SET "SITES_DIR=tests/__data__/input/api_generate/sites" && SET "API_DIR=tests/__data__/output" &&'
|
|
}
|
|
|
|
beforeEach(() => {
|
|
fs.emptyDirSync('tests/__data__/output')
|
|
})
|
|
|
|
describe('api:generate', () => {
|
|
it('can generate guides.json', () => {
|
|
const cmd = `${ENV_VAR} npm run api:generate`
|
|
const stdout = execSync(cmd, { encoding: 'utf8' })
|
|
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
|
|
|
expect(content('tests/__data__/output/guides.json')).toEqual(
|
|
content('tests/__data__/expected/api_generate/guides.json')
|
|
)
|
|
})
|
|
})
|
|
|
|
function content(filepath: string) {
|
|
return fs.readFileSync(pathToFileURL(filepath), {
|
|
encoding: 'utf8'
|
|
})
|
|
}
|