mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 01:20:08 -04:00
Update tests
This commit is contained in:
parent
510d89c8c8
commit
37664b49b9
8 changed files with 56 additions and 67 deletions
|
@ -1,22 +1,21 @@
|
|||
import fs from 'fs-extra'
|
||||
import { execSync } from 'child_process'
|
||||
import fs from 'fs-extra'
|
||||
import os from 'os'
|
||||
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/__data__'
|
||||
if (os.platform() === 'win32') {
|
||||
ENV_VAR = 'SET "DATA_DIR=tests/__data__/input/temp/data" &&'
|
||||
ENV_VAR = 'SET "DATA_DIR=tests/__data__/input/__data__" &&'
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
fs.copySync(
|
||||
'tests/__data__/input/channels-edit/example.com.channels.xml',
|
||||
'tests/__data__/input/channels_edit/example.com.channels.xml',
|
||||
'tests/__data__/output/channels.xml'
|
||||
)
|
||||
})
|
||||
|
@ -28,29 +27,17 @@ describe('channels:edit', () => {
|
|||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
checkStdout(stdout)
|
||||
expect(content('tests/__data__/output/channels.xml')).toEqual(
|
||||
content('tests/__data__/expected/sites/channels-edit/example.com.channels.xml')
|
||||
)
|
||||
} catch (error) {
|
||||
// NOTE: for Windows only
|
||||
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')
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
function checkStdout(stdout: string) {
|
||||
expect(stdout).toContain('CNN International Europe | CNNInternationalEurope.us')
|
||||
expect(stdout).toContain('CNNInternational.us (CNN International, CNN, CNN Int)')
|
||||
expect(stdout).toContain('Type...')
|
||||
expect(stdout).toContain('Skip')
|
||||
expect(stdout).toContain("File 'tests/__data__/output/channels.xml' successfully saved")
|
||||
}
|
||||
|
||||
function content(filepath: string) {
|
||||
return fs.readFileSync(pathToFileURL(filepath), {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue