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 { execSync } from 'child_process'
import fs from 'fs-extra' import fs from 'fs-extra'
import path from 'path' 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(() => { beforeEach(() => {
fs.emptyDirSync('tests/__data__/output') fs.emptyDirSync('tests/__data__/output')
@ -8,10 +16,8 @@ beforeEach(() => {
describe('epg:grab', () => { describe('epg:grab', () => {
it('can grab epg by site name', () => { it('can grab epg by site name', () => {
execSync( const cmd = `${ENV_VAR} npm run grab -- --site=example.com --output=tests/__data__/output/guide.xml`
'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', execSync(cmd, { encoding: 'utf8' })
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/guide.xml')).toEqual( expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/guide2.xml') content('tests/__data__/expected/guide2.xml')
@ -19,10 +25,8 @@ describe('epg:grab', () => {
}) })
it('can grab epg with multiple channels.xml files', () => { it('can grab epg with multiple channels.xml files', () => {
execSync( const cmd = `${ENV_VAR} npm run grab -- --channels=tests/__data__/input/epg-grab/sites/**/*.channels.xml --output=tests/__data__/output/guide.xml`
'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', execSync(cmd, { encoding: 'utf8' })
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/guide.xml')).toEqual( expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/guide.xml') content('tests/__data__/expected/guide.xml')
@ -30,10 +34,8 @@ describe('epg:grab', () => {
}) })
it('can grab epg with gzip option enabled', () => { it('can grab epg with gzip option enabled', () => {
execSync( const cmd = `${ENV_VAR} npm run grab -- --channels=tests/__data__/input/epg-grab/sites/**/*.channels.xml --output=tests/__data__/output/guide.xml --gzip`
'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', execSync(cmd, { encoding: 'utf8' })
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/guide.xml')).toEqual( expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/guide.xml') content('tests/__data__/expected/guide.xml')
@ -45,10 +47,8 @@ describe('epg:grab', () => {
}) })
it('can grab epg with wildcard as output', () => { it('can grab epg with wildcard as output', () => {
execSync( 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`
'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', execSync(cmd, { encoding: 'utf8' })
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/guides/en/example.com.xml')).toEqual( expect(content('tests/__data__/output/guides/en/example.com.xml')).toEqual(
content('tests/__data__/expected/guides/en/example.com.xml') content('tests/__data__/expected/guides/en/example.com.xml')
@ -60,10 +60,8 @@ describe('epg:grab', () => {
}) })
it('can grab epg then language filter enabled', () => { it('can grab epg then language filter enabled', () => {
execSync( 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`
'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', execSync(cmd, { encoding: 'utf8' })
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/guides/fr/example.com.xml')).toEqual( expect(content('tests/__data__/output/guides/fr/example.com.xml')).toEqual(
content('tests/__data__/expected/guides/fr/example.com.xml') content('tests/__data__/expected/guides/fr/example.com.xml')
@ -71,10 +69,8 @@ describe('epg:grab', () => {
}) })
it('can grab epg using custom channels list', () => { it('can grab epg using custom channels list', () => {
execSync( const cmd = `${ENV_VAR} npm run grab -- --channels=tests/__data__/input/epg-grab/custom.channels.xml --output=tests/__data__/output/guide.xml`
'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', execSync(cmd, { encoding: 'utf8' })
{ encoding: 'utf8' }
)
expect(content('tests/__data__/output/guide.xml')).toEqual( expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/guide.xml') content('tests/__data__/expected/guide.xml')
@ -82,10 +78,8 @@ describe('epg:grab', () => {
}) })
it('it will raise an error if the timeout is exceeded', () => { it('it will raise an error if the timeout is exceeded', () => {
const stdout = execSync( const cmd = `${ENV_VAR} npm run grab -- --channels=tests/__data__/input/epg-grab/custom.channels.xml --output=tests/__data__/output/guide.xml --timeout=0`
'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', const stdout = execSync(cmd, { encoding: 'utf8' })
{ encoding: 'utf8' }
)
expect(stdout).toContain('ERR: Connection timeout') expect(stdout).toContain('ERR: Connection timeout')
}) })