Update tests

This commit is contained in:
freearhey 2023-10-02 05:52:53 +03:00
parent 047df3c707
commit 7df6b224d4
8 changed files with 239 additions and 133 deletions

View file

@ -0,0 +1,27 @@
import fs from 'fs-extra'
import { execSync } from 'child_process'
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
fs.copySync(
'tests/__data__/input/channels-editor/channels-editor.channels.xml',
'tests/__data__/output/channels.xml'
)
})
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'
}
)
expect(stdout).toContain('CNN International | CNNInternational.us [new]')
expect(stdout).toContain('CNN International Europe | CNNInternationalEurope.us [api]')
expect(stdout).toContain('Overwrite')
expect(stdout).toContain('Skip')
expect(stdout).toContain("File 'tests/__data__/output/channels.xml' successfully saved")
})
})

View file

@ -1,19 +0,0 @@
const { execSync } = require('child_process')
it('will show a message if the file contains a syntax error', () => {
try {
const stdout = execSync(
'npm run channels:lint -- tests/__data__/input/sites/lint.channels.xml',
{
encoding: 'utf8'
}
)
console.log(stdout)
process.exit(1)
} catch (err) {
expect(err.status).toBe(1)
expect(err.stdout).toBe(
`\n> channels:lint\n> node scripts/commands/channels/lint.js tests/__data__/input/sites/lint.channels.xml\n\n\ntests/__data__/input/sites/lint.channels.xml\n 4:0 Element 'channel': The attribute 'lang' is required but missing.\n\n1 error(s)\n`
)
}
})

View file

@ -0,0 +1,28 @@
import { execSync } from 'child_process'
type ExecError = {
status: number
stdout: string
}
describe('channels:lint', () => {
it('will show a message if the file contains a syntax error', () => {
try {
const stdout = execSync(
'npm run channels:lint -- tests/__data__/input/channels-lint/channels-lint.channels.xml',
{
encoding: 'utf8'
}
)
console.log(stdout)
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
expect(
(error as ExecError).stdout.includes(
"tests/__data__/input/channels-lint/channels-lint.channels.xml\n\n\ntests/__data__/input/channels-lint/channels-lint.channels.xml\n 3:0 Element 'channel': The attribute 'lang' is required but missing.\n\n1 error(s)\n"
)
).toBe(true)
}
})
})

View file

@ -1,39 +0,0 @@
const { execSync } = require('child_process')
const fs = require('fs-extra')
const path = require('path')
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
fs.copySync(
'tests/__data__/input/sites/parse-channels.channels.xml',
'tests/__data__/output/channels.xml'
)
})
it('can parse channels', () => {
const stdout = execSync(
'npm run channels:parse -- --config=tests/__data__/input/sites/parse-channels.config.js --output=tests/__data__/output/channels.xml',
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/channels.xml')).toEqual(
content('tests/__data__/expected/sites/parse-channels.channels.xml')
)
})
it('can parse channels with clean flag', () => {
const stdout = execSync(
'npm run channels:parse -- --config=tests/__data__/input/sites/parse-channels.config.js --output=tests/__data__/output/channels.xml --clean',
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/channels.xml')).toEqual(
content('tests/__data__/expected/sites/parse-channels-clean.channels.xml')
)
})
function content(filepath) {
return fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'
})
}

View file

@ -0,0 +1,41 @@
import { execSync } from 'child_process'
import fs from 'fs-extra'
import path from 'path'
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
fs.copySync(
'tests/__data__/input/channels-parse/channels-parse.channels.xml',
'tests/__data__/output/channels.xml'
)
})
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' }
)
expect(content('tests/__data__/output/channels.xml')).toEqual(
content('tests/__data__/expected/sites/channels-parse/channels-parse.channels.xml')
)
})
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' }
)
expect(content('tests/__data__/output/channels.xml')).toEqual(
content('tests/__data__/expected/sites/channels-parse/channels-parse-clean.channels.xml')
)
})
})
function content(filepath: string) {
return fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'
})
}

View file

@ -1,49 +1,58 @@
const { execSync } = require('child_process')
import { execSync } from 'child_process'
type ExecError = {
status: number
stdout: string
}
describe('channels:validate', () => {
it('will show a message if the file contains a duplicate', () => {
try {
const stdout = execSync(
'DATA_DIR=tests/__data__/input/tmp/data npm run channels:validate -- tests/__data__/input/sites/duplicate.channels.xml',
'DATA_DIR=tests/__data__/input/temp/data npm run channels:validate -- tests/__data__/input/channels-validate/duplicate.channels.xml',
{
encoding: 'utf8'
}
)
console.log(stdout)
process.exit(1)
} catch (err) {
expect(err.status).toBe(1)
expect(err.stdout).toBe(
`\n> channels:validate\n> node scripts/commands/channels/validate.js tests/__data__/input/sites/duplicate.channels.xml\n\ntests/__data__/input/sites/duplicate.channels.xml
} catch (error) {
expect((error as ExecError).status).toBe(1)
expect(
(error as ExecError).stdout
.includes(`tests/__data__/input/channels-validate/duplicate.channels.xml
(index) type lang xmltv_id site_id name
0 'duplicate' 'en' 'BravoEast.us' '140' 'Bravo'
\n1 error(s) in 1 file(s)\n`
)
\n1 error(s) in 1 file(s)\n`)
).toBe(true)
}
})
it('will show a message if the file contains a channel with wrong xmltv_id', () => {
try {
const stdout = execSync(
'DATA_DIR=tests/__data__/input/tmp/data npm run channels:validate -- tests/__data__/input/sites/wrong_xmltv_id.channels.xml',
'DATA_DIR=tests/__data__/input/temp/data npm run channels:validate -- tests/__data__/input/channels-validate/wrong_xmltv_id.channels.xml',
{
encoding: 'utf8'
}
)
console.log(stdout)
process.exit(1)
} catch (err) {
expect(err.status).toBe(1)
expect(err.stdout).toBe(
`\n> channels:validate\n> node scripts/commands/channels/validate.js tests/__data__/input/sites/wrong_xmltv_id.channels.xml\n\ntests/__data__/input/sites/wrong_xmltv_id.channels.xml
} catch (error) {
expect((error as ExecError).status).toBe(1)
expect(
(error as ExecError).stdout
.includes(`tests/__data__/input/channels-validate/wrong_xmltv_id.channels.xml
(index) type lang xmltv_id site_id name
0 'wrong_xmltv_id' 'en' 'CNNInternational' '140' 'CNN International'
\n1 error(s) in 1 file(s)\n`
)
\n1 error(s) in 1 file(s)\n`)
).toBe(true)
}
})
})

View file

@ -1,39 +0,0 @@
const { execSync } = require('child_process')
const fs = require('fs-extra')
const path = require('path')
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
})
it('can grab epg', () => {
const stdout = execSync(
'BASE_DIR=tests/__data__/input CURR_DATE=2022-10-20 DATA_DIR=tests/__data__/input/tmp/data npm run grab -- --site=epg-grab --output=tests/__data__/output/{lang}/{site}.xml',
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/en/example.com.xml')).toEqual(
content('tests/__data__/expected/guides/en/example.com.xml')
)
expect(content('tests/__data__/output/fr/example.com.xml')).toEqual(
content('tests/__data__/expected/guides/fr/example.com.xml')
)
})
it('can grab epg with language filter enabled', () => {
const stdout = execSync(
'BASE_DIR=tests/__data__/input CURR_DATE=2022-10-20 DATA_DIR=tests/__data__/input/tmp/data npm run grab -- --site=epg-grab --lang=fr --output=tests/__data__/output/fr/guide.xml',
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/fr/guide.xml')).toEqual(
content('tests/__data__/expected/guides/fr/example.com.xml')
)
})
function content(filepath) {
return fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'
})
}

View file

@ -0,0 +1,98 @@
import { execSync } from 'child_process'
import fs from 'fs-extra'
import path from 'path'
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
})
describe('epg:grab', () => {
it('can grab epg by site name', () => {
execSync(
'SITES_DIR=tests/__data__/input/epg-grab/sites CURR_DATE=2022-10-20 DATA_DIR=tests/__data__/input/temp/data npm run grab -- --site=example.com --output=tests/__data__/output/guide.xml',
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/guide2.xml')
)
})
it('can grab epg with multiple channels.xml files', () => {
execSync(
'SITES_DIR=tests/__data__/input/epg-grab/sites CURR_DATE=2022-10-20 DATA_DIR=tests/__data__/input/temp/data npm run grab -- --channels=tests/__data__/input/epg-grab/sites/**/*.channels.xml --output=tests/__data__/output/guide.xml',
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/guide.xml')
)
})
it('can grab epg with gzip option enabled', () => {
execSync(
'SITES_DIR=tests/__data__/input/epg-grab/sites CURR_DATE=2022-10-20 DATA_DIR=tests/__data__/input/temp/data npm run grab -- --channels=tests/__data__/input/epg-grab/sites/**/*.channels.xml --output=tests/__data__/output/guide.xml --gzip',
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/guide.xml')
)
expect(content('tests/__data__/output/guide.xml.gz')).toEqual(
content('tests/__data__/expected/guide.xml.gz')
)
})
it('can grab epg with wildcard as output', () => {
execSync(
'SITES_DIR=tests/__data__/input/epg-grab/sites CURR_DATE=2022-10-20 DATA_DIR=tests/__data__/input/temp/data npm run grab -- --channels=tests/__data__/input/epg-grab/sites/example.com/example.com.channels.xml --output=tests/__data__/output/guides/{lang}/{site}.xml',
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/guides/en/example.com.xml')).toEqual(
content('tests/__data__/expected/guides/en/example.com.xml')
)
expect(content('tests/__data__/output/guides/fr/example.com.xml')).toEqual(
content('tests/__data__/expected/guides/fr/example.com.xml')
)
})
it('can grab epg then language filter enabled', () => {
execSync(
'SITES_DIR=tests/__data__/input/epg-grab/sites CURR_DATE=2022-10-20 DATA_DIR=tests/__data__/input/temp/data npm run grab -- --channels=tests/__data__/input/epg-grab/sites/example.com/example.com.channels.xml --output=tests/__data__/output/guides/{lang}/{site}.xml --lang=fr',
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/guides/fr/example.com.xml')).toEqual(
content('tests/__data__/expected/guides/fr/example.com.xml')
)
})
it('can grab epg using custom channels list', () => {
execSync(
'SITES_DIR=tests/__data__/input/epg-grab/sites CURR_DATE=2022-10-20 DATA_DIR=tests/__data__/input/temp/data npm run grab -- --channels=tests/__data__/input/epg-grab/custom.channels.xml --output=tests/__data__/output/guide.xml',
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/guide.xml')
)
})
it('it will raise an error if the timeout is exceeded', () => {
const stdout = execSync(
'SITES_DIR=tests/__data__/input/epg-grab/sites CURR_DATE=2022-10-20 DATA_DIR=tests/__data__/input/temp/data npm run grab -- --channels=tests/__data__/input/epg-grab/custom.channels.xml --output=tests/__data__/output/guide.xml --timeout=0',
{ encoding: 'utf8' }
)
expect(stdout).toContain('ERR: Connection timeout')
})
})
function content(filepath: string) {
return fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'
})
}