mirror of
https://github.com/iptv-org/epg
synced 2025-12-18 11:27:06 -05:00
Update edit.test.ts
This commit is contained in:
@@ -3,6 +3,11 @@ import { execSync } from 'child_process'
|
|||||||
import os from 'os'
|
import os from 'os'
|
||||||
import { pathToFileURL } from 'node:url'
|
import { pathToFileURL } from 'node:url'
|
||||||
|
|
||||||
|
type ExecError = {
|
||||||
|
status: number
|
||||||
|
stdout: string
|
||||||
|
}
|
||||||
|
|
||||||
let ENV_VAR = 'DATA_DIR=tests/__data__/input/temp/data'
|
let ENV_VAR = 'DATA_DIR=tests/__data__/input/temp/data'
|
||||||
if (os.platform() === 'win32') {
|
if (os.platform() === 'win32') {
|
||||||
ENV_VAR = 'SET "DATA_DIR=tests/__data__/input/temp/data" &&'
|
ENV_VAR = 'SET "DATA_DIR=tests/__data__/input/temp/data" &&'
|
||||||
@@ -19,18 +24,27 @@ beforeEach(() => {
|
|||||||
describe('channels:edit', () => {
|
describe('channels:edit', () => {
|
||||||
it('shows list of options for a channel', () => {
|
it('shows list of options for a channel', () => {
|
||||||
const cmd = `${ENV_VAR} npm run channels:edit --- tests/__data__/output/channels.xml`
|
const cmd = `${ENV_VAR} npm run channels:edit --- tests/__data__/output/channels.xml`
|
||||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
try {
|
||||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||||
expect(stdout).toContain('CNN International Europe | CNNInternationalEurope.us')
|
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||||
expect(stdout).toContain('Type...')
|
checkStdout(stdout) // NOTE: for Windows only
|
||||||
expect(stdout).toContain('Skip')
|
} catch (error) {
|
||||||
expect(stdout).toContain("File 'tests/__data__/output/channels.xml' successfully saved")
|
if (process.env.DEBUG === 'true') console.log(cmd, error)
|
||||||
expect(content('tests/__data__/output/channels.xml')).toEqual(
|
checkStdout((error as ExecError).stdout)
|
||||||
content('tests/__data__/expected/sites/channels-edit/example.com.channels.xml')
|
expect(content('tests/__data__/output/channels.xml')).toEqual(
|
||||||
)
|
content('tests/__data__/expected/sites/channels-edit/example.com.channels.xml')
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
function content(filepath: string) {
|
function content(filepath: string) {
|
||||||
return fs.readFileSync(pathToFileURL(filepath), {
|
return fs.readFileSync(pathToFileURL(filepath), {
|
||||||
encoding: 'utf8'
|
encoding: 'utf8'
|
||||||
|
|||||||
Reference in New Issue
Block a user