Update tests

This commit is contained in:
freearhey 2025-04-02 07:12:46 +03:00
parent 510d89c8c8
commit 37664b49b9
8 changed files with 56 additions and 67 deletions

View file

@ -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'
})
}

View file

@ -8,7 +8,7 @@ type ExecError = {
describe('channels:lint', () => {
it('will show a message if the file contains a syntax error', () => {
try {
const cmd = 'npm run channels:lint --- tests/__data__/input/channels-lint/error.channels.xml'
const cmd = 'npm run channels:lint --- tests/__data__/input/channels_lint/error.channels.xml'
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
process.exit(1)
@ -23,7 +23,7 @@ describe('channels:lint', () => {
it('will show a message if an error occurred while parsing an xml file', () => {
try {
const cmd =
'npm run channels:lint --- tests/__data__/input/channels-lint/invalid.channels.xml'
'npm run channels:lint --- tests/__data__/input/channels_lint/invalid.channels.xml'
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
process.exit(1)
@ -38,7 +38,7 @@ describe('channels:lint', () => {
it('can test multiple files at ones', () => {
try {
const cmd =
'npm run channels:lint --- tests/__data__/input/channels-lint/error.channels.xml tests/__data__/input/channels-lint/invalid.channels.xml'
'npm run channels:lint --- tests/__data__/input/channels_lint/error.channels.xml tests/__data__/input/channels_lint/invalid.channels.xml'
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
process.exit(1)
@ -57,7 +57,7 @@ describe('channels:lint', () => {
it('will show a message if the file contains single quotes', () => {
try {
const cmd =
'npm run channels:lint --- tests/__data__/input/channels-lint/single_quotes.channels.xml'
'npm run channels:lint --- tests/__data__/input/channels_lint/single_quotes.channels.xml'
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
process.exit(1)
@ -72,7 +72,7 @@ describe('channels:lint', () => {
it('does not display errors if there are none', () => {
try {
const cmd = 'npm run channels:lint --- tests/__data__/input/channels-lint/valid.channels.xml'
const cmd = 'npm run channels:lint --- tests/__data__/input/channels_lint/valid.channels.xml'
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
} catch (error) {

View file

@ -5,20 +5,20 @@ import { pathToFileURL } from 'node:url'
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
fs.copySync(
'tests/__data__/input/channels-parse/channels-parse.channels.xml',
'tests/__data__/output/channels.xml'
'tests/__data__/input/channels_parse/example.com.channels.xml',
'tests/__data__/output/example.com.channels.xml'
)
})
describe('channels:parse', () => {
it('can parse channels', () => {
const cmd =
'npm run channels:parse --- --config=tests/__data__/input/channels-parse/channels-parse.config.js --output=tests/__data__/output/channels.xml'
'npm run channels:parse --- --config=tests/__data__/input/channels_parse/example.com.config.js --output=tests/__data__/output/example.com.channels.xml'
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
expect(content('tests/__data__/output/channels.xml')).toEqual(
content('tests/__data__/expected/sites/channels-parse/channels-parse.channels.xml')
expect(content('tests/__data__/output/example.com.channels.xml')).toEqual(
content('tests/__data__/expected/channels_parse/example.com.channels.xml')
)
})
})

View file

@ -6,26 +6,26 @@ type ExecError = {
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__" &&'
}
describe('channels:validate', () => {
it('will show a message if the file contains a duplicate', () => {
try {
const cmd = `${ENV_VAR} npm run channels:validate --- tests/__data__/input/channels-validate/duplicate.channels.xml`
const cmd = `${ENV_VAR} npm run channels:validate --- tests/__data__/input/channels_validate/duplicate.channels.xml`
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
expect((error as ExecError).stdout).toContain(`
(index) type lang xmltv_id site_id name
0 'duplicate' 'en' 'BravoEast.us' '140' 'Bravo'
(index) type lang xmltv_id site_id name
0 'duplicate' 'en' 'Bravo.us@East' '140' 'Bravo'
1 error(s) in 1 file(s)
`)
@ -34,7 +34,7 @@ describe('channels:validate', () => {
it('will show a message if the file contains a channel with wrong xmltv_id', () => {
try {
const cmd = `${ENV_VAR} npm run channels:validate --- tests/__data__/input/channels-validate/wrong_xmltv_id.channels.xml`
const cmd = `${ENV_VAR} npm run channels:validate --- tests/__data__/input/channels_validate/wrong_xmltv_id.channels.xml`
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
process.exit(1)