Update tests

This commit is contained in:
freearhey 2023-10-15 09:27:41 +03:00
parent 0c0cc2af93
commit f3ba9fbcfe
4 changed files with 27 additions and 35 deletions

View file

@ -1,5 +1,6 @@
import fs from 'fs-extra'
import { execSync } from 'child_process'
import os from 'os'
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
@ -11,12 +12,13 @@ beforeEach(() => {
describe('channels:editor', () => {
it('shows list of options for a channel', () => {
const stdout = execSync(
'DATA_DIR=tests/__data__/input/temp/data npm run channels:editor -- tests/__data__/output/channels.xml',
{
encoding: 'utf8'
}
)
let ENV_VAR = 'DATA_DIR=tests/__data__/input/temp/data'
if (os.platform() === 'win32') {
ENV_VAR = 'SET "DATA_DIR=tests/__data__/input/temp/data" &&'
}
const cmd = `${ENV_VAR} npm run channels:editor -- tests/__data__/output/channels.xml`
const stdout = execSync(cmd, { encoding: 'utf8' })
expect(stdout).toContain('CNN International | CNNInternational.us [new]')
expect(stdout).toContain('CNN International Europe | CNNInternationalEurope.us [api]')

View file

@ -8,13 +8,9 @@ type ExecError = {
describe('channels:lint', () => {
it('will show a message if the file contains a syntax error', () => {
try {
const stdout = execSync(
'npm run channels:lint -- --channels=tests/__data__/input/channels-lint/channels-lint.channels.xml',
{
encoding: 'utf8'
}
)
console.log(stdout)
const cmd =
'npm run channels:lint -- --channels=tests/__data__/input/channels-lint/channels-lint.channels.xml'
execSync(cmd, { encoding: 'utf8' })
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)

View file

@ -12,10 +12,9 @@ beforeEach(() => {
describe('channels:parse', () => {
it('can parse channels', () => {
execSync(
'npm run channels:parse -- --config=tests/__data__/input/channels-parse/channels-parse.config.js --output=tests/__data__/output/channels.xml',
{ encoding: 'utf8' }
)
const cmd =
'npm run channels:parse -- --config=tests/__data__/input/channels-parse/channels-parse.config.js --output=tests/__data__/output/channels.xml'
execSync(cmd, { encoding: 'utf8' })
expect(content('tests/__data__/output/channels.xml')).toEqual(
content('tests/__data__/expected/sites/channels-parse/channels-parse.channels.xml')
@ -23,10 +22,9 @@ describe('channels:parse', () => {
})
it('can parse channels with clean flag', () => {
execSync(
'npm run channels:parse -- --config=tests/__data__/input/channels-parse/channels-parse.config.js --output=tests/__data__/output/channels.xml --clean',
{ encoding: 'utf8' }
)
const cmd =
'npm run channels:parse -- --config=tests/__data__/input/channels-parse/channels-parse.config.js --output=tests/__data__/output/channels.xml --clean'
execSync(cmd, { encoding: 'utf8' })
expect(content('tests/__data__/output/channels.xml')).toEqual(
content('tests/__data__/expected/sites/channels-parse/channels-parse-clean.channels.xml')

View file

@ -1,20 +1,21 @@
import { execSync } from 'child_process'
import os from 'os'
type ExecError = {
status: number
stdout: string
}
let ENV_VAR = 'DATA_DIR=tests/__data__/input/temp/data'
if (os.platform() === 'win32') {
ENV_VAR = 'SET "DATA_DIR=tests/__data__/input/temp/data" &&'
}
describe('channels:validate', () => {
it('will show a message if the file contains a duplicate', () => {
try {
const stdout = execSync(
'DATA_DIR=tests/__data__/input/temp/data npm run channels:validate -- --channels=tests/__data__/input/channels-validate/duplicate.channels.xml',
{
encoding: 'utf8'
}
)
console.log(stdout)
const cmd = `${ENV_VAR} npm run channels:validate -- --channels=tests/__data__/input/channels-validate/duplicate.channels.xml`
execSync(cmd, { encoding: 'utf8' })
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
@ -33,13 +34,8 @@ describe('channels:validate', () => {
it('will show a message if the file contains a channel with wrong xmltv_id', () => {
try {
const stdout = execSync(
'DATA_DIR=tests/__data__/input/temp/data npm run channels:validate -- --channels=tests/__data__/input/channels-validate/wrong_xmltv_id.channels.xml',
{
encoding: 'utf8'
}
)
console.log(stdout)
const cmd = `${ENV_VAR} npm run channels:validate -- --channels=tests/__data__/input/channels-validate/wrong_xmltv_id.channels.xml`
execSync(cmd, { encoding: 'utf8' })
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)