mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update tests
This commit is contained in:
parent
047df3c707
commit
7df6b224d4
8 changed files with 239 additions and 133 deletions
27
tests/commands/channels/editor.test.ts
Normal file
27
tests/commands/channels/editor.test.ts
Normal 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")
|
||||||
|
})
|
||||||
|
})
|
|
@ -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`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
28
tests/commands/channels/lint.test.ts
Normal file
28
tests/commands/channels/lint.test.ts
Normal 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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
|
@ -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'
|
|
||||||
})
|
|
||||||
}
|
|
41
tests/commands/channels/parse.test.ts
Normal file
41
tests/commands/channels/parse.test.ts
Normal 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'
|
||||||
|
})
|
||||||
|
}
|
|
@ -1,49 +1,58 @@
|
||||||
const { execSync } = require('child_process')
|
import { execSync } from 'child_process'
|
||||||
|
|
||||||
it('will show a message if the file contains a duplicate', () => {
|
type ExecError = {
|
||||||
try {
|
status: number
|
||||||
const stdout = execSync(
|
stdout: string
|
||||||
'DATA_DIR=tests/__data__/input/tmp/data npm run channels:validate -- tests/__data__/input/sites/duplicate.channels.xml',
|
}
|
||||||
{
|
|
||||||
encoding: 'utf8'
|
describe('channels:validate', () => {
|
||||||
}
|
it('will show a message if the file contains a duplicate', () => {
|
||||||
)
|
try {
|
||||||
console.log(stdout)
|
const stdout = execSync(
|
||||||
process.exit(1)
|
'DATA_DIR=tests/__data__/input/temp/data npm run channels:validate -- tests/__data__/input/channels-validate/duplicate.channels.xml',
|
||||||
} catch (err) {
|
{
|
||||||
expect(err.status).toBe(1)
|
encoding: 'utf8'
|
||||||
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
|
)
|
||||||
|
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-validate/duplicate.channels.xml
|
||||||
┌─────────┬─────────────┬──────┬────────────────┬─────────┬─────────┐
|
┌─────────┬─────────────┬──────┬────────────────┬─────────┬─────────┐
|
||||||
│ (index) │ type │ lang │ xmltv_id │ site_id │ name │
|
│ (index) │ type │ lang │ xmltv_id │ site_id │ name │
|
||||||
├─────────┼─────────────┼──────┼────────────────┼─────────┼─────────┤
|
├─────────┼─────────────┼──────┼────────────────┼─────────┼─────────┤
|
||||||
│ 0 │ 'duplicate' │ 'en' │ 'BravoEast.us' │ '140' │ 'Bravo' │
|
│ 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', () => {
|
it('will show a message if the file contains a channel with wrong xmltv_id', () => {
|
||||||
try {
|
try {
|
||||||
const stdout = execSync(
|
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'
|
encoding: 'utf8'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
console.log(stdout)
|
console.log(stdout)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
expect(err.status).toBe(1)
|
expect((error as ExecError).status).toBe(1)
|
||||||
expect(err.stdout).toBe(
|
expect(
|
||||||
`\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
|
(error as ExecError).stdout
|
||||||
|
.includes(`tests/__data__/input/channels-validate/wrong_xmltv_id.channels.xml
|
||||||
┌─────────┬──────────────────┬──────┬────────────────────┬─────────┬─────────────────────┐
|
┌─────────┬──────────────────┬──────┬────────────────────┬─────────┬─────────────────────┐
|
||||||
│ (index) │ type │ lang │ xmltv_id │ site_id │ name │
|
│ (index) │ type │ lang │ xmltv_id │ site_id │ name │
|
||||||
├─────────┼──────────────────┼──────┼────────────────────┼─────────┼─────────────────────┤
|
├─────────┼──────────────────┼──────┼────────────────────┼─────────┼─────────────────────┤
|
||||||
│ 0 │ 'wrong_xmltv_id' │ 'en' │ 'CNNInternational' │ '140' │ 'CNN International' │
|
│ 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)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
})
|
})
|
|
@ -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'
|
|
||||||
})
|
|
||||||
}
|
|
98
tests/commands/epg/grab.test.ts
Normal file
98
tests/commands/epg/grab.test.ts
Normal 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'
|
||||||
|
})
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue