mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-14 19:10:04 -04:00
Update tests
This commit is contained in:
parent
df365451a9
commit
6543464515
8 changed files with 175 additions and 111 deletions
|
@ -1,19 +1,28 @@
|
|||
import { execSync } from 'child_process'
|
||||
import fs from 'fs-extra'
|
||||
import os from 'os'
|
||||
|
||||
let ENV_VAR =
|
||||
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/api_generate API_DIR=tests/__data__/output/.api'
|
||||
if (os.platform() === 'win32') {
|
||||
ENV_VAR =
|
||||
'SET "DATA_DIR=tests/__data__/input/data" && SET "STREAMS_DIR=tests/__data__/input/api_generate" && SET "API_DIR=tests/__data__/output/.api" &&'
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
})
|
||||
|
||||
it('can create streams.json', () => {
|
||||
execSync(
|
||||
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/api_generate API_DIR=tests/__data__/output/.api npm run api:generate',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
describe('api:generate', () => {
|
||||
it('can create streams.json', () => {
|
||||
const cmd = `${ENV_VAR} npm run api:generate`
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
expect(content('output/.api/streams.json')).toMatchObject(
|
||||
content('expected/api_generate/.api/streams.json')
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
function content(filepath: string) {
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
import { execSync } from 'child_process'
|
||||
import * as fs from 'fs-extra'
|
||||
import { glob } from 'glob'
|
||||
import os from 'os'
|
||||
|
||||
let ENV_VAR = 'STREAMS_DIR=tests/__data__/output/streams'
|
||||
if (os.platform() === 'win32') {
|
||||
ENV_VAR = 'SET "STREAMS_DIR=tests/__data__/output/streams" &&'
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
fs.copySync('tests/__data__/input/playlist_format', 'tests/__data__/output/streams')
|
||||
})
|
||||
|
||||
it('can format playlists', () => {
|
||||
execSync('STREAMS_DIR=tests/__data__/output/streams npm run playlist:format', {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
describe('playlist:format', () => {
|
||||
it('can format playlists', () => {
|
||||
const cmd = `${ENV_VAR} npm run playlist:format`
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
const files = glob
|
||||
.sync('tests/__data__/expected/playlist_format/*.m3u')
|
||||
|
@ -21,6 +28,7 @@ it('can format playlists', () => {
|
|||
content(`expected/playlist_format/${filepath}`)
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
function content(filepath: string) {
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
import { execSync } from 'child_process'
|
||||
import * as fs from 'fs-extra'
|
||||
import * as glob from 'glob'
|
||||
import os from 'os'
|
||||
|
||||
let ENV_VAR =
|
||||
'STREAMS_DIR=tests/__data__/input/playlist_generate DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output/.gh-pages LOGS_DIR=tests/__data__/output/logs'
|
||||
if (os.platform() === 'win32') {
|
||||
ENV_VAR =
|
||||
'SET "STREAMS_DIR=tests/__data__/input/playlist_generate" && SET "DATA_DIR=tests/__data__/input/data" && SET "PUBLIC_DIR=tests/__data__/output/.gh-pages" && SET "LOGS_DIR=tests/__data__/output/logs" &&'
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
})
|
||||
|
||||
it('can generate playlists and logs', () => {
|
||||
const stdout = execSync(
|
||||
'STREAMS_DIR=tests/__data__/input/playlist_generate DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output/.gh-pages LOGS_DIR=tests/__data__/output/logs npm run playlist:generate',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
|
||||
if (process.env.DEBUG === 'true') console.log(stdout)
|
||||
describe('playlist:generate', () => {
|
||||
it('can generate playlists and logs', () => {
|
||||
const cmd = `${ENV_VAR} npm run playlist:generate`
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
const playlists = glob
|
||||
.sync('tests/__data__/expected/playlist_generate/.gh-pages/**/*.m3u')
|
||||
|
@ -27,6 +33,7 @@ it('can generate playlists and logs', () => {
|
|||
expect(content('output/logs/generators.log').split('\n').sort()).toStrictEqual(
|
||||
content('expected/playlist_generate/logs/generators.log').split('\n').sort()
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
function content(filepath: string) {
|
||||
|
|
|
@ -1,19 +1,32 @@
|
|||
import { execSync } from 'child_process'
|
||||
import os from 'os'
|
||||
|
||||
type ExecError = {
|
||||
status: number
|
||||
stdout: string
|
||||
}
|
||||
|
||||
it('shows an error if the playlist contains a broken link', () => {
|
||||
let ENV_VAR = 'ROOT_DIR=tests/__data__/input'
|
||||
if (os.platform() === 'win32') {
|
||||
ENV_VAR = 'SET "ROOT_DIR=tests/__data__/input" &&'
|
||||
}
|
||||
|
||||
describe('playlist:test', () => {
|
||||
it('shows an error if the playlist contains a broken link', () => {
|
||||
const cmd = `${ENV_VAR} npm run playlist:test playlist_test/ag.m3u`
|
||||
try {
|
||||
execSync('ROOT_DIR=tests/__data__/input npm run playlist:test playlist_test/ag.m3u', {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
process.exit(1)
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
checkStdout(stdout)
|
||||
} catch (error) {
|
||||
expect((error as ExecError).status).toBe(1)
|
||||
expect((error as ExecError).stdout).toContain('playlist_test/ag.m3u')
|
||||
expect((error as ExecError).stdout).toContain('2 problems (1 errors, 1 warnings)')
|
||||
// NOTE: for Windows only
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, error)
|
||||
checkStdout((error as ExecError).stdout)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
function checkStdout(stdout: string) {
|
||||
expect(stdout).toContain('playlist_test/ag.m3u')
|
||||
expect(stdout).toContain('2 problems (1 errors, 1 warnings)')
|
||||
}
|
||||
|
|
|
@ -1,19 +1,24 @@
|
|||
import { execSync } from 'child_process'
|
||||
import * as fs from 'fs-extra'
|
||||
import { glob } from 'glob'
|
||||
import os from 'os'
|
||||
|
||||
let ENV_VAR = 'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/output/streams'
|
||||
if (os.platform() === 'win32') {
|
||||
ENV_VAR =
|
||||
'SET "DATA_DIR=tests/__data__/input/data" && SET "STREAMS_DIR=tests/__data__/output/streams" &&'
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
fs.copySync('tests/__data__/input/playlist_update', 'tests/__data__/output/streams')
|
||||
})
|
||||
|
||||
it('can update playlists', () => {
|
||||
const stdout = execSync(
|
||||
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/output/streams npm run playlist:update --silent',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
describe('playlist:update', () => {
|
||||
it('can update playlists', () => {
|
||||
const cmd = `${ENV_VAR} npm run playlist:update --silent`
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
const files = glob
|
||||
.sync('tests/__data__/expected/playlist_update/*.m3u')
|
||||
|
@ -28,6 +33,7 @@ it('can update playlists', () => {
|
|||
expect(stdout).toBe(
|
||||
'OUTPUT=closes #14151, closes #14150, closes #14110, closes #14120, closes #14175, closes #14105, closes #14104, closes #14057, closes #14034, closes #13964, closes #13893, closes #13881, closes #13793, closes #13751, closes #13715\n'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
function content(filepath: string) {
|
||||
|
|
|
@ -1,41 +1,47 @@
|
|||
import { execSync } from 'child_process'
|
||||
import os from 'os'
|
||||
|
||||
type ExecError = {
|
||||
status: number
|
||||
stdout: string
|
||||
}
|
||||
|
||||
it('show an error if channel id in the blocklist', () => {
|
||||
let ENV_VAR =
|
||||
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/playlist_validate'
|
||||
if (os.platform() === 'win32') {
|
||||
ENV_VAR =
|
||||
'SET "DATA_DIR=tests/__data__/input/data" && SET "STREAMS_DIR=tests/__data__/input/playlist_validate" &&'
|
||||
}
|
||||
|
||||
describe('playlist:validate', () => {
|
||||
it('show an error if channel id in the blocklist', () => {
|
||||
const cmd = `${ENV_VAR} npm run playlist:validate -- us_blocked.m3u`
|
||||
try {
|
||||
const stdout = execSync(
|
||||
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/playlist_validate npm run playlist:validate -- us_blocked.m3u',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
if (process.env.DEBUG === 'true') console.log(stdout)
|
||||
process.exit(1)
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
checkStdout(stdout)
|
||||
} catch (error) {
|
||||
if (process.env.DEBUG === 'true') console.log((error as ExecError).stdout)
|
||||
expect((error as ExecError).status).toBe(1)
|
||||
expect((error as ExecError).stdout).toContain(`us_blocked.m3u
|
||||
2 error "FoxSports2.us" is on the blocklist due to claims of copyright holders (https://github.com/iptv-org/iptv/issues/0002)
|
||||
4 error "TVN.pl" is on the blocklist due to NSFW content (https://github.com/iptv-org/iptv/issues/0003)
|
||||
|
||||
2 problems (2 errors, 0 warnings)`)
|
||||
// NOTE: for Windows only
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, error)
|
||||
checkStdout((error as ExecError).stdout)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('show a warning if channel has wrong id', () => {
|
||||
const stdout = execSync(
|
||||
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/playlist_validate npm run playlist:validate -- wrong_id.m3u',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
if (process.env.DEBUG === 'true') console.log(stdout)
|
||||
it('show a warning if channel has wrong id', () => {
|
||||
const cmd = `${ENV_VAR} npm run playlist:validate -- wrong_id.m3u`
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
expect(stdout).toContain(
|
||||
'wrong_id.m3u\n 2 warning "qib22lAq1L.us" is not in the database\n\n1 problems (0 errors, 1 warnings)\n'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
function checkStdout(stdout: string) {
|
||||
expect(stdout).toContain(`us_blocked.m3u
|
||||
2 error "FoxSports2.us" is on the blocklist due to claims of copyright holders (https://github.com/iptv-org/iptv/issues/0002)
|
||||
4 error "TVN.pl" is on the blocklist due to NSFW content (https://github.com/iptv-org/iptv/issues/0003)
|
||||
|
||||
2 problems (2 errors, 0 warnings)`)
|
||||
}
|
||||
|
|
|
@ -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 =
|
||||
'DATA_DIR=tests/__data__/input/data LOGS_DIR=tests/__data__/input/readme_update README_DIR=tests/__data__/output/.readme'
|
||||
if (os.platform() === 'win32') {
|
||||
ENV_VAR =
|
||||
'SET "DATA_DIR=tests/__data__/input/data" && SET "LOGS_DIR=tests/__data__/input/readme_update" && SET "README_DIR=tests/__data__/output/.readme" &&'
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
|
@ -13,17 +21,18 @@ beforeEach(() => {
|
|||
'tests/__data__/input/readme_update/.readme/template.md',
|
||||
'tests/__data__/output/.readme/template.md'
|
||||
)
|
||||
|
||||
execSync(
|
||||
'DATA_DIR=tests/__data__/input/data LOGS_DIR=tests/__data__/input/readme_update README_DIR=tests/__data__/output/.readme npm run readme:update',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
})
|
||||
|
||||
it('can update readme.md', () => {
|
||||
describe('readme:update', () => {
|
||||
it('can update readme.md', () => {
|
||||
const cmd = `${ENV_VAR} npm run readme:update`
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
expect(content('tests/__data__/output/readme.md')).toEqual(
|
||||
content('tests/__data__/expected/readme_update/_readme.md')
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
function content(filepath: string) {
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
import { execSync } from 'child_process'
|
||||
import os from 'os'
|
||||
|
||||
it('can create report', () => {
|
||||
const stdout = execSync(
|
||||
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/report_create npm run report:create',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
let ENV_VAR = 'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/report_create'
|
||||
if (os.platform() === 'win32') {
|
||||
ENV_VAR =
|
||||
'SET "DATA_DIR=tests/__data__/input/data" && SET "STREAMS_DIR=tests/__data__/input/report_create" &&'
|
||||
}
|
||||
|
||||
describe('report:create', () => {
|
||||
it('can create report', () => {
|
||||
const cmd = `${ENV_VAR} npm run report:create`
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
expect(
|
||||
stdout.includes(`
|
||||
|
@ -21,4 +26,5 @@ it('can create report', () => {
|
|||
│ 5 │ 19956 │ 'channel search' │ 'CNBCe.tr' │ undefined │ 'invalid_id' │
|
||||
└─────────┴─────────────┴──────────────────┴─────────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────┴───────────────┘`)
|
||||
).toBe(true)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue