mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 00:20:08 -04:00
Update tests
This commit is contained in:
parent
510d89c8c8
commit
37664b49b9
8 changed files with 56 additions and 67 deletions
|
@ -3,10 +3,10 @@ import fs from 'fs-extra'
|
|||
import { pathToFileURL } from 'node:url'
|
||||
import os from 'os'
|
||||
|
||||
let ENV_VAR = 'SITES_DIR=tests/__data__/input/epg-grab/sites API_DIR=tests/__data__/output'
|
||||
let ENV_VAR = 'SITES_DIR=tests/__data__/input/api_generate/sites API_DIR=tests/__data__/output'
|
||||
if (os.platform() === 'win32') {
|
||||
ENV_VAR =
|
||||
'SET "SITES_DIR=tests/__data__/input/epg-grab/sites" && SET "API_DIR=tests/__data__/output" &&'
|
||||
'SET "SITES_DIR=tests/__data__/input/api_generate/sites" && SET "API_DIR=tests/__data__/output" &&'
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -20,7 +20,7 @@ describe('api:generate', () => {
|
|||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
expect(content('tests/__data__/output/guides.json')).toEqual(
|
||||
content('tests/__data__/expected/guides.json')
|
||||
content('tests/__data__/expected/api_generate/guides.json')
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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'
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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')
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import { execSync } from 'child_process'
|
||||
import fs from 'fs-extra'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import { execSync } from 'child_process'
|
||||
import { Zip } from '@freearhey/core'
|
||||
import fs from 'fs-extra'
|
||||
import path from 'path'
|
||||
import os from 'os'
|
||||
import { Zip } from '@freearhey/core'
|
||||
|
||||
let ENV_VAR =
|
||||
'SITES_DIR=tests/__data__/input/epg-grab/sites CURR_DATE=2022-10-20 DATA_DIR=tests/__data__/input/temp/data'
|
||||
'SITES_DIR=tests/__data__/input/epg_grab/sites CURR_DATE=2022-10-20 DATA_DIR=tests/__data__/input/__data__'
|
||||
if (os.platform() === 'win32') {
|
||||
ENV_VAR =
|
||||
'SET "SITES_DIR=tests/__data__/input/epg-grab/sites" && SET "CURR_DATE=2022-10-20" && SET "DATA_DIR=tests/__data__/input/temp/data" &&'
|
||||
'SET "SITES_DIR=tests/__data__/input/epg_grab/sites" && SET "CURR_DATE=2022-10-20" && SET "DATA_DIR=tests/__data__/input/__data__" &&'
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -25,73 +25,75 @@ describe('epg:grab', () => {
|
|||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
expect(content('tests/__data__/output/guide.xml')).toEqual(
|
||||
content('tests/__data__/expected/guide2.xml')
|
||||
content('tests/__data__/expected/epg_grab/guide_2.xml')
|
||||
)
|
||||
})
|
||||
|
||||
it('can grab epg with multiple channels.xml files', () => {
|
||||
const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg-grab/sites/**/*.channels.xml --output=tests/__data__/output/guide.xml`
|
||||
const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg_grab/sites/**/*.channels.xml --output=tests/__data__/output/guide.xml`
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
expect(content('tests/__data__/output/guide.xml')).toEqual(
|
||||
content('tests/__data__/expected/guide.xml')
|
||||
content('tests/__data__/expected/epg_grab/guide.xml')
|
||||
)
|
||||
})
|
||||
|
||||
it('can grab epg with gzip option enabled', async () => {
|
||||
const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg-grab/sites/**/*.channels.xml --output="${path.resolve(
|
||||
const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg_grab/sites/**/*.channels.xml --output="${path.resolve(
|
||||
'tests/__data__/output/guide.xml'
|
||||
)}" --gzip`
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
expect(content('tests/__data__/output/guide.xml')).toEqual(
|
||||
content('tests/__data__/expected/guide.xml')
|
||||
content('tests/__data__/expected/epg_grab/guide.xml')
|
||||
)
|
||||
|
||||
const zip = new Zip()
|
||||
const expected = await zip.decompress(fs.readFileSync('tests/__data__/output/guide.xml.gz'))
|
||||
const result = await zip.decompress(fs.readFileSync('tests/__data__/expected/guide.xml.gz'))
|
||||
const result = await zip.decompress(
|
||||
fs.readFileSync('tests/__data__/expected/epg_grab/guide.xml.gz')
|
||||
)
|
||||
expect(expected).toEqual(result)
|
||||
}, 30000)
|
||||
|
||||
it('can grab epg with wildcard as output', () => {
|
||||
const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg-grab/sites/example.com/example.com.channels.xml --output=tests/__data__/output/guides/{lang}/{site}.xml`
|
||||
const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg_grab/sites/example.com/example.com.channels.xml --output=tests/__data__/output/guides/{lang}/{site}.xml`
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
expect(content('tests/__data__/output/guides/en/example.com.xml')).toEqual(
|
||||
content('tests/__data__/expected/guides/en/example.com.xml')
|
||||
content('tests/__data__/expected/epg_grab/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')
|
||||
content('tests/__data__/expected/epg_grab/guides/fr/example.com.xml')
|
||||
)
|
||||
})
|
||||
|
||||
it('can grab epg then language filter enabled', () => {
|
||||
const cmd = `${ENV_VAR} 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`
|
||||
const cmd = `${ENV_VAR} 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`
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
expect(content('tests/__data__/output/guides/fr/example.com.xml')).toEqual(
|
||||
content('tests/__data__/expected/guides/fr/example.com.xml')
|
||||
content('tests/__data__/expected/epg_grab/guides/fr/example.com.xml')
|
||||
)
|
||||
})
|
||||
|
||||
it('can grab epg using custom channels list', () => {
|
||||
const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg-grab/custom.channels.xml --output=tests/__data__/output/guide.xml`
|
||||
const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg_grab/custom.channels.xml --output=tests/__data__/output/guide.xml`
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
expect(content('tests/__data__/output/guide.xml')).toEqual(
|
||||
content('tests/__data__/expected/custom_guide.xml')
|
||||
content('tests/__data__/expected/epg_grab/guide_3.xml')
|
||||
)
|
||||
})
|
||||
|
||||
it('it will raise an error if the timeout is exceeded', () => {
|
||||
const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg-grab/custom.channels.xml --output=tests/__data__/output/guide.xml --timeout=0`
|
||||
const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg_grab/custom.channels.xml --output=tests/__data__/output/guide.xml --timeout=0`
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
|
@ -106,7 +108,7 @@ describe('epg:grab', () => {
|
|||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
expect(content('tests/__data__/output/guide.xml')).toEqual(
|
||||
content('tests/__data__/expected/guide2.xml')
|
||||
content('tests/__data__/expected/epg_grab/guide_2.xml')
|
||||
)
|
||||
})
|
||||
|
||||
|
@ -118,7 +120,7 @@ describe('epg:grab', () => {
|
|||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
expect(content('tests/__data__/output/guide.xml')).toEqual(
|
||||
content('tests/__data__/expected/guide2.xml')
|
||||
content('tests/__data__/expected/epg_grab/guide_2.xml')
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -24,13 +24,13 @@ it('can create new site config from template', () => {
|
|||
expect(exists('tests/__data__/output/sites/example.com/example.com.config.js')).toBe(true)
|
||||
expect(exists('tests/__data__/output/sites/example.com/readme.md')).toBe(true)
|
||||
expect(content('tests/__data__/output/sites/example.com/example.com.test.js')).toEqual(
|
||||
content('tests/__data__/expected/sites/sites-init/example.com.test.js')
|
||||
content('tests/__data__/expected/sites_init/example.com.test.js')
|
||||
)
|
||||
expect(content('tests/__data__/output/sites/example.com/example.com.config.js')).toEqual(
|
||||
content('tests/__data__/expected/sites/sites-init/example.com.config.js')
|
||||
content('tests/__data__/expected/sites_init/example.com.config.js')
|
||||
)
|
||||
expect(content('tests/__data__/output/sites/example.com/readme.md')).toEqual(
|
||||
content('tests/__data__/expected/sites/sites-init/readme.md')
|
||||
content('tests/__data__/expected/sites_init/readme.md')
|
||||
)
|
||||
})
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@ import fs from 'fs-extra'
|
|||
import { pathToFileURL } from 'node:url'
|
||||
import os from 'os'
|
||||
|
||||
let ENV_VAR = 'SITES_DIR=tests/__data__/input/sites-update/sites ROOT_DIR=tests/__data__/output'
|
||||
let ENV_VAR = 'SITES_DIR=tests/__data__/input/sites_update/sites ROOT_DIR=tests/__data__/output'
|
||||
if (os.platform() === 'win32') {
|
||||
ENV_VAR =
|
||||
'SET "SITES_DIR=tests/__data__/input/sites-update/sites" && SET "ROOT_DIR=tests/__data__/output" &&'
|
||||
'SET "SITES_DIR=tests/__data__/input/sites_update/sites" && SET "ROOT_DIR=tests/__data__/output" &&'
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -20,7 +20,7 @@ it('can update SITES.md', () => {
|
|||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
expect(content('tests/__data__/output/SITES.md')).toEqual(
|
||||
content('tests/__data__/expected/SITES.md')
|
||||
content('tests/__data__/expected/sites_update/SITES.md')
|
||||
)
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue