Update grab.test.ts

This commit is contained in:
freearhey 2023-10-14 19:01:58 +03:00
parent f7aa8aaab6
commit 0c0cc2af93

View file

@ -1,6 +1,14 @@
import { execSync } from 'child_process'
import fs from 'fs-extra'
import path from 'path'
import os from 'os'
let ENV_VAR =
'SITES_DIR=tests/__data__/input/epg-grab/sites CURR_DATE=2022-10-20 DATA_DIR=tests/__data__/input/temp/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" &&'
}
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
@ -8,10 +16,8 @@ beforeEach(() => {
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' }
)
const cmd = `${ENV_VAR} npm run grab -- --site=example.com --output=tests/__data__/output/guide.xml`
execSync(cmd, { encoding: 'utf8' })
expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/guide2.xml')
@ -19,10 +25,8 @@ describe('epg:grab', () => {
})
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' }
)
const cmd = `${ENV_VAR} npm run grab -- --channels=tests/__data__/input/epg-grab/sites/**/*.channels.xml --output=tests/__data__/output/guide.xml`
execSync(cmd, { encoding: 'utf8' })
expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/guide.xml')
@ -30,10 +34,8 @@ describe('epg:grab', () => {
})
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' }
)
const cmd = `${ENV_VAR} npm run grab -- --channels=tests/__data__/input/epg-grab/sites/**/*.channels.xml --output=tests/__data__/output/guide.xml --gzip`
execSync(cmd, { encoding: 'utf8' })
expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/guide.xml')
@ -45,10 +47,8 @@ describe('epg:grab', () => {
})
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' }
)
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`
execSync(cmd, { encoding: 'utf8' })
expect(content('tests/__data__/output/guides/en/example.com.xml')).toEqual(
content('tests/__data__/expected/guides/en/example.com.xml')
@ -60,10 +60,8 @@ describe('epg:grab', () => {
})
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' }
)
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`
execSync(cmd, { encoding: 'utf8' })
expect(content('tests/__data__/output/guides/fr/example.com.xml')).toEqual(
content('tests/__data__/expected/guides/fr/example.com.xml')
@ -71,10 +69,8 @@ describe('epg:grab', () => {
})
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' }
)
const cmd = `${ENV_VAR} npm run grab -- --channels=tests/__data__/input/epg-grab/custom.channels.xml --output=tests/__data__/output/guide.xml`
execSync(cmd, { encoding: 'utf8' })
expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/guide.xml')
@ -82,10 +78,8 @@ describe('epg:grab', () => {
})
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' }
)
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' })
expect(stdout).toContain('ERR: Connection timeout')
})