Files
epg/tests/commands/channels/edit.test.ts

57 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-10-15 14:08:23 +03:00
import fs from 'fs-extra'
import { execSync } from 'child_process'
import os from 'os'
import { pathToFileURL } from 'node:url'
2023-10-15 14:08:23 +03:00
2025-01-16 15:53:28 +03:00
type ExecError = {
status: number
stdout: string
}
2025-01-07 19:24:50 +03:00
let ENV_VAR = 'DATA_DIR=tests/__data__/input/temp/data'
if (os.platform() === 'win32') {
ENV_VAR = 'SET "DATA_DIR=tests/__data__/input/temp/data" &&'
}
2023-10-15 14:08:23 +03:00
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
fs.copySync(
'tests/__data__/input/channels-edit/example.com.channels.xml',
2023-10-15 14:08:23 +03:00
'tests/__data__/output/channels.xml'
)
})
describe('channels:edit', () => {
2023-10-15 14:08:23 +03:00
it('shows list of options for a channel', () => {
2025-01-12 23:09:49 +03:00
const cmd = `${ENV_VAR} npm run channels:edit --- tests/__data__/output/channels.xml`
2025-01-16 15:53:28 +03:00
try {
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
2025-01-16 21:33:32 +03:00
checkStdout(stdout)
2025-01-16 22:33:34 +03:00
expect(content('tests/__data__/output/channels.xml')).toEqual(
content('tests/__data__/expected/sites/channels-edit/example.com.channels.xml')
)
2025-01-16 15:53:28 +03:00
} catch (error) {
2025-01-16 21:33:32 +03:00
// NOTE: for Windows only
2025-01-16 15:53:28 +03:00
if (process.env.DEBUG === 'true') console.log(cmd, error)
checkStdout((error as ExecError).stdout)
expect(content('tests/__data__/output/channels.xml')).toEqual(
content('tests/__data__/expected/sites/channels-edit/example.com.channels.xml')
)
}
2023-10-15 14:08:23 +03:00
})
})
2025-01-16 15:53:28 +03:00
function checkStdout(stdout: string) {
expect(stdout).toContain('CNN International Europe | CNNInternationalEurope.us')
expect(stdout).toContain('Type...')
expect(stdout).toContain('Skip')
expect(stdout).toContain("File 'tests/__data__/output/channels.xml' successfully saved")
}
2023-10-15 14:08:23 +03:00
function content(filepath: string) {
return fs.readFileSync(pathToFileURL(filepath), {
2023-10-15 14:08:23 +03:00
encoding: 'utf8'
})
}