mirror of
https://github.com/iptv-org/iptv
synced 2026-04-29 22:27:05 -04:00
Update tests
This commit is contained in:
@@ -1,25 +1,33 @@
|
||||
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')
|
||||
.map(f => f.replace('tests/__data__/expected/playlist_format/', ''))
|
||||
const files = glob
|
||||
.sync('tests/__data__/expected/playlist_format/*.m3u')
|
||||
.map(f => f.replace('tests/__data__/expected/playlist_format/', ''))
|
||||
|
||||
files.forEach(filepath => {
|
||||
expect(content(`output/streams/${filepath}`), filepath).toBe(
|
||||
content(`expected/playlist_format/${filepath}`)
|
||||
)
|
||||
files.forEach(filepath => {
|
||||
expect(content(`output/streams/${filepath}`), filepath).toBe(
|
||||
content(`expected/playlist_format/${filepath}`)
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,32 +1,39 @@
|
||||
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' }
|
||||
)
|
||||
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)
|
||||
|
||||
if (process.env.DEBUG === 'true') console.log(stdout)
|
||||
const playlists = glob
|
||||
.sync('tests/__data__/expected/playlist_generate/.gh-pages/**/*.m3u')
|
||||
.map((file: string) => file.replace('tests/__data__/expected/playlist_generate/', ''))
|
||||
|
||||
const playlists = glob
|
||||
.sync('tests/__data__/expected/playlist_generate/.gh-pages/**/*.m3u')
|
||||
.map((file: string) => file.replace('tests/__data__/expected/playlist_generate/', ''))
|
||||
playlists.forEach((filepath: string) => {
|
||||
expect(content(`output/${filepath}`), filepath).toBe(
|
||||
content(`expected/playlist_generate/${filepath}`)
|
||||
)
|
||||
})
|
||||
|
||||
playlists.forEach((filepath: string) => {
|
||||
expect(content(`output/${filepath}`), filepath).toBe(
|
||||
content(`expected/playlist_generate/${filepath}`)
|
||||
expect(content('output/logs/generators.log').split('\n').sort()).toStrictEqual(
|
||||
content('expected/playlist_generate/logs/generators.log').split('\n').sort()
|
||||
)
|
||||
})
|
||||
|
||||
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', () => {
|
||||
try {
|
||||
execSync('ROOT_DIR=tests/__data__/input npm run playlist:test playlist_test/ag.m3u', {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
process.exit(1)
|
||||
} 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)')
|
||||
}
|
||||
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 {
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
checkStdout(stdout)
|
||||
} catch (error) {
|
||||
// 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,33 +1,39 @@
|
||||
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')
|
||||
.map(f => f.replace('tests/__data__/expected/playlist_update/', ''))
|
||||
const files = glob
|
||||
.sync('tests/__data__/expected/playlist_update/*.m3u')
|
||||
.map(f => f.replace('tests/__data__/expected/playlist_update/', ''))
|
||||
|
||||
files.forEach(filepath => {
|
||||
expect(content(`output/streams/${filepath}`), filepath).toBe(
|
||||
content(`expected/playlist_update/${filepath}`)
|
||||
files.forEach(filepath => {
|
||||
expect(content(`output/streams/${filepath}`), filepath).toBe(
|
||||
content(`expected/playlist_update/${filepath}`)
|
||||
)
|
||||
})
|
||||
|
||||
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'
|
||||
)
|
||||
})
|
||||
|
||||
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', () => {
|
||||
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'
|
||||
}
|
||||
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(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
checkStdout(stdout)
|
||||
} catch (error) {
|
||||
// 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 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'
|
||||
)
|
||||
if (process.env.DEBUG === 'true') console.log(stdout)
|
||||
process.exit(1)
|
||||
} 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
|
||||
})
|
||||
})
|
||||
|
||||
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)`)
|
||||
}
|
||||
})
|
||||
|
||||
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)
|
||||
|
||||
expect(stdout).toContain(
|
||||
'wrong_id.m3u\n 2 warning "qib22lAq1L.us" is not in the database\n\n1 problems (0 errors, 1 warnings)\n'
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user