Fixes linter errors

This commit is contained in:
freearhey 2023-10-15 14:08:23 +03:00
parent 57e508fc3b
commit 63c86a2b30
393 changed files with 28447 additions and 28443 deletions

View file

@ -1,21 +1,21 @@
module.exports = {
site: 'parse-channels.com',
url: 'https://parse-channels.com',
parser() {
return []
},
channels() {
return [
{
lang: 'en',
site_id: 140,
name: 'CNN International'
},
{
lang: 'en',
site_id: 240,
name: 'BBC World News'
}
]
}
}
module.exports = {
site: 'parse-channels.com',
url: 'https://parse-channels.com',
parser() {
return []
},
channels() {
return [
{
lang: 'en',
site_id: 140,
name: 'CNN International'
},
{
lang: 'en',
site_id: 240,
name: 'BBC World News'
}
]
}
}

View file

@ -1,28 +1,28 @@
module.exports = {
site: 'example.com',
days: 2,
request: {
timeout: 1000
},
url: 'https://example.com',
parser({ channel, date }) {
if (channel.xmltv_id === 'Channel2.us') return []
else if (channel.xmltv_id === 'Channel1.us' && channel.lang === 'fr') {
return [
{
title: 'Programme1 (example.com)',
start: `${date.format('YYYY-MM-DD')}T04:30:00.000Z`,
stop: `${date.format('YYYY-MM-DD')}T07:10:00.000Z`
}
]
}
return [
{
title: 'Program1 (example.com)',
start: `${date.format('YYYY-MM-DD')}T04:30:00.000Z`,
stop: `${date.format('YYYY-MM-DD')}T07:10:00.000Z`
}
]
}
}
module.exports = {
site: 'example.com',
days: 2,
request: {
timeout: 1000
},
url: 'https://example.com',
parser({ channel, date }) {
if (channel.xmltv_id === 'Channel2.us') return []
else if (channel.xmltv_id === 'Channel1.us' && channel.lang === 'fr') {
return [
{
title: 'Programme1 (example.com)',
start: `${date.format('YYYY-MM-DD')}T04:30:00.000Z`,
stop: `${date.format('YYYY-MM-DD')}T07:10:00.000Z`
}
]
}
return [
{
title: 'Program1 (example.com)',
start: `${date.format('YYYY-MM-DD')}T04:30:00.000Z`,
stop: `${date.format('YYYY-MM-DD')}T07:10:00.000Z`
}
]
}
}

View file

@ -1,23 +1,23 @@
module.exports = {
site: 'example2.com',
url: 'https://example2.com',
parser({ channel, date }) {
if (channel.lang === 'fr') {
return [
{
title: 'Programme1 (example2.com)',
start: `${date.format('YYYY-MM-DD')}T04:40:00.000Z`,
stop: `${date.format('YYYY-MM-DD')}T07:10:00.000Z`
}
]
}
return [
{
title: 'Program1 (example2.com)',
start: `${date.format('YYYY-MM-DD')}T04:30:00.000Z`,
stop: `${date.format('YYYY-MM-DD')}T07:10:00.000Z`
}
]
}
}
module.exports = {
site: 'example2.com',
url: 'https://example2.com',
parser({ channel, date }) {
if (channel.lang === 'fr') {
return [
{
title: 'Programme1 (example2.com)',
start: `${date.format('YYYY-MM-DD')}T04:40:00.000Z`,
stop: `${date.format('YYYY-MM-DD')}T07:10:00.000Z`
}
]
}
return [
{
title: 'Program1 (example2.com)',
start: `${date.format('YYYY-MM-DD')}T04:30:00.000Z`,
stop: `${date.format('YYYY-MM-DD')}T07:10:00.000Z`
}
]
}
}

View file

@ -1,51 +1,51 @@
import fs from 'fs-extra'
import { execSync } from 'child_process'
import os from 'os'
import path from 'path'
type ExecError = {
status: number
stdout: string
}
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', () => {
let ENV_VAR = 'DATA_DIR=tests/__data__/input/temp/data'
if (os.platform() === 'win32') {
ENV_VAR = 'SET "DATA_DIR=tests/__data__/input/temp/data" &&'
}
try {
const cmd = `${ENV_VAR} npm run channels:editor -- tests/__data__/output/channels.xml`
execSync(cmd, { encoding: 'utf8' })
} catch (error) {
expect((error as ExecError).status).toBe(1)
expect((error as ExecError).stdout).toContain('CNN International | CNNInternational.us [new]')
expect((error as ExecError).stdout).toContain(
'CNN International Europe | CNNInternationalEurope.us [api]'
)
expect((error as ExecError).stdout).toContain('Overwrite')
expect((error as ExecError).stdout).toContain('Skip')
expect((error as ExecError).stdout).toContain(
"File 'tests/__data__/output/channels.xml' successfully saved"
)
expect(content('tests/__data__/output/channels.xml')).toEqual(
content('tests/__data__/expected/sites/channels-editor/channels-editor.channels.xml')
)
}
})
})
function content(filepath: string) {
return fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'
})
}
import fs from 'fs-extra'
import { execSync } from 'child_process'
import os from 'os'
import path from 'path'
type ExecError = {
status: number
stdout: string
}
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', () => {
let ENV_VAR = 'DATA_DIR=tests/__data__/input/temp/data'
if (os.platform() === 'win32') {
ENV_VAR = 'SET "DATA_DIR=tests/__data__/input/temp/data" &&'
}
try {
const cmd = `${ENV_VAR} npm run channels:editor -- tests/__data__/output/channels.xml`
execSync(cmd, { encoding: 'utf8' })
} catch (error) {
expect((error as ExecError).status).toBe(1)
expect((error as ExecError).stdout).toContain('CNN International | CNNInternational.us [new]')
expect((error as ExecError).stdout).toContain(
'CNN International Europe | CNNInternationalEurope.us [api]'
)
expect((error as ExecError).stdout).toContain('Overwrite')
expect((error as ExecError).stdout).toContain('Skip')
expect((error as ExecError).stdout).toContain(
"File 'tests/__data__/output/channels.xml' successfully saved"
)
expect(content('tests/__data__/output/channels.xml')).toEqual(
content('tests/__data__/expected/sites/channels-editor/channels-editor.channels.xml')
)
}
})
})
function content(filepath: string) {
return fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'
})
}

View file

@ -1,22 +1,22 @@
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 cmd =
'npm run channels:lint -- --channels=tests/__data__/input/channels-lint/channels-lint.channels.xml'
execSync(cmd, { encoding: 'utf8' })
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
expect((error as ExecError).stdout).toContain(
"channels-lint.channels.xml\n 3:0 Element 'channel': The attribute 'lang' is required but missing.\n\n1 error(s)\n"
)
}
})
})
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 cmd =
'npm run channels:lint -- --channels=tests/__data__/input/channels-lint/channels-lint.channels.xml'
execSync(cmd, { encoding: 'utf8' })
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
expect((error as ExecError).stdout).toContain(
"channels-lint.channels.xml\n 3:0 Element 'channel': The attribute 'lang' is required but missing.\n\n1 error(s)\n"
)
}
})
})

View file

@ -1,39 +1,39 @@
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', () => {
const cmd =
'npm run channels:parse -- --config=tests/__data__/input/channels-parse/channels-parse.config.js --output=tests/__data__/output/channels.xml'
execSync(cmd, { 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', () => {
const cmd =
'npm run channels:parse -- --config=tests/__data__/input/channels-parse/channels-parse.config.js --output=tests/__data__/output/channels.xml --clean'
execSync(cmd, { 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'
})
}
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', () => {
const cmd =
'npm run channels:parse -- --config=tests/__data__/input/channels-parse/channels-parse.config.js --output=tests/__data__/output/channels.xml'
execSync(cmd, { 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', () => {
const cmd =
'npm run channels:parse -- --config=tests/__data__/input/channels-parse/channels-parse.config.js --output=tests/__data__/output/channels.xml --clean'
execSync(cmd, { 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,48 +1,48 @@
import { execSync } from 'child_process'
import os from 'os'
type ExecError = {
status: number
stdout: string
}
let ENV_VAR = 'DATA_DIR=tests/__data__/input/temp/data'
if (os.platform() === 'win32') {
ENV_VAR = 'SET "DATA_DIR=tests/__data__/input/temp/data" &&'
}
describe('channels:validate', () => {
it('will show a message if the file contains a duplicate', () => {
try {
const cmd = `${ENV_VAR} npm run channels:validate -- --channels=tests/__data__/input/channels-validate/duplicate.channels.xml`
execSync(cmd, { encoding: 'utf8' })
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
expect((error as ExecError).stdout).toContain(`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`)
}
})
it('will show a message if the file contains a channel with wrong xmltv_id', () => {
try {
const cmd = `${ENV_VAR} npm run channels:validate -- --channels=tests/__data__/input/channels-validate/wrong_xmltv_id.channels.xml`
execSync(cmd, { encoding: 'utf8' })
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
expect((error as ExecError).stdout).toContain(`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`)
}
})
})
import { execSync } from 'child_process'
import os from 'os'
type ExecError = {
status: number
stdout: string
}
let ENV_VAR = 'DATA_DIR=tests/__data__/input/temp/data'
if (os.platform() === 'win32') {
ENV_VAR = 'SET "DATA_DIR=tests/__data__/input/temp/data" &&'
}
describe('channels:validate', () => {
it('will show a message if the file contains a duplicate', () => {
try {
const cmd = `${ENV_VAR} npm run channels:validate -- --channels=tests/__data__/input/channels-validate/duplicate.channels.xml`
execSync(cmd, { encoding: 'utf8' })
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
expect((error as ExecError).stdout).toContain(`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`)
}
})
it('will show a message if the file contains a channel with wrong xmltv_id', () => {
try {
const cmd = `${ENV_VAR} npm run channels:validate -- --channels=tests/__data__/input/channels-validate/wrong_xmltv_id.channels.xml`
execSync(cmd, { encoding: 'utf8' })
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
expect((error as ExecError).stdout).toContain(`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`)
}
})
})

View file

@ -1,94 +1,94 @@
import { execSync } from 'child_process'
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'
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')
})
describe('epg:grab', () => {
it('can grab epg by site name', () => {
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')
)
})
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`
execSync(cmd, { encoding: 'utf8' })
expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/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=tests/__data__/output/guide.xml --gzip`
execSync(cmd, { encoding: 'utf8' })
expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/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'))
expect(expected).toEqual(result)
})
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`
execSync(cmd, { 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', () => {
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')
)
})
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`
execSync(cmd, { 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 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')
})
})
function content(filepath: string) {
return fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'
})
}
import { execSync } from 'child_process'
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'
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')
})
describe('epg:grab', () => {
it('can grab epg by site name', () => {
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')
)
})
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`
execSync(cmd, { encoding: 'utf8' })
expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/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=tests/__data__/output/guide.xml --gzip`
execSync(cmd, { encoding: 'utf8' })
expect(content('tests/__data__/output/guide.xml')).toEqual(
content('tests/__data__/expected/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'))
expect(expected).toEqual(result)
})
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`
execSync(cmd, { 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', () => {
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')
)
})
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`
execSync(cmd, { 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 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')
})
})
function content(filepath: string) {
return fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'
})
}