mirror of
https://github.com/iptv-org/iptv
synced 2026-04-25 12:17:19 -04:00
Update tests
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
const { execSync } = require('child_process')
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
const glob = require('glob')
|
||||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
fs.copyFileSync(
|
||||
'tests/__data__/input/database/playlist_format.streams.db',
|
||||
'tests/__data__/output/streams.db'
|
||||
)
|
||||
|
||||
const stdout = execSync('DB_DIR=tests/__data__/output npm run playlist:format', {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
})
|
||||
|
||||
it('can format playlists', () => {
|
||||
const files = glob
|
||||
.sync('tests/__data__/expected/streams/*.m3u')
|
||||
.map(f => f.replace('tests/__data__/expected/', ''))
|
||||
|
||||
files.forEach(filepath => {
|
||||
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
|
||||
})
|
||||
})
|
||||
|
||||
function content(filepath) {
|
||||
return fs.readFileSync(`tests/__data__/${filepath}`, {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
const { execSync } = require('child_process')
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
const glob = require('glob')
|
||||
import { execSync } from 'child_process'
|
||||
import * as fs from 'fs-extra'
|
||||
import * as glob from 'glob'
|
||||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
@@ -10,8 +9,8 @@ beforeEach(() => {
|
||||
'tests/__data__/output/streams.db'
|
||||
)
|
||||
|
||||
execSync(
|
||||
'DB_DIR=tests/__data__/output DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output/.gh-pages LOGS_DIR=tests/__data__/output/logs/generators npm run playlist:generate',
|
||||
const stdout = execSync(
|
||||
'DB_DIR=tests/__data__/output 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' }
|
||||
)
|
||||
})
|
||||
@@ -19,22 +18,18 @@ beforeEach(() => {
|
||||
it('can generate playlists and logs', () => {
|
||||
const playlists = glob
|
||||
.sync('tests/__data__/expected/.gh-pages/**/*.m3u')
|
||||
.map(f => f.replace('tests/__data__/expected/', ''))
|
||||
.map((file: string) => file.replace('tests/__data__/expected/', ''))
|
||||
|
||||
playlists.forEach(filepath => {
|
||||
playlists.forEach((filepath: string) => {
|
||||
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
|
||||
})
|
||||
|
||||
const logs = glob
|
||||
.sync('tests/__data__/expected/logs/generators/*.log')
|
||||
.map(f => f.replace('tests/__data__/expected/', ''))
|
||||
|
||||
logs.forEach(filepath => {
|
||||
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
|
||||
})
|
||||
expect(content(`output/logs/generators.log`).split('\n').sort()).toStrictEqual(
|
||||
content(`expected/logs/generators.log`).split('\n').sort()
|
||||
)
|
||||
})
|
||||
|
||||
function content(filepath) {
|
||||
function content(filepath: string) {
|
||||
return fs.readFileSync(`tests/__data__/${filepath}`, {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
36
tests/commands/playlist/update.test.ts
Normal file
36
tests/commands/playlist/update.test.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { execSync } from 'child_process'
|
||||
import * as fs from 'fs-extra'
|
||||
import { glob } from 'glob'
|
||||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
fs.copyFileSync(
|
||||
'tests/__data__/input/database/playlist_update.streams.db',
|
||||
'tests/__data__/output/streams.db'
|
||||
)
|
||||
})
|
||||
|
||||
it('can format playlists', () => {
|
||||
const stdout = execSync(
|
||||
'DEBUG=true DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/output/streams DB_DIR=tests/__data__/output npm run playlist:update --silent',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
|
||||
expect(stdout).toBe(`OUTPUT=closes #14151, closes #14110, closes #14179, closes #14178\n`)
|
||||
|
||||
const files = glob
|
||||
.sync('tests/__data__/expected/streams/*.m3u')
|
||||
.map(f => f.replace('tests/__data__/expected/', ''))
|
||||
|
||||
files.forEach(filepath => {
|
||||
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
|
||||
})
|
||||
})
|
||||
|
||||
function content(filepath: string) {
|
||||
return fs.readFileSync(`tests/__data__/${filepath}`, {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
it('show an error if channel name in the blocklist', () => {
|
||||
try {
|
||||
const stdout = execSync(
|
||||
'DATA_DIR=tests/__data__/input/data npm run playlist:validate -- tests/__data__/input/streams/us_blocked.m3u',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
console.log(stdout)
|
||||
process.exit(1)
|
||||
} catch (err) {
|
||||
expect(err.status).toBe(1)
|
||||
expect(err.stdout).toBe(
|
||||
`\n> playlist:validate\n> node scripts/commands/playlist/validate.js tests/__data__/input/streams/us_blocked.m3u\n\nloading blocklist...\nfound 4 records\n\ntests/__data__/input/streams/us_blocked.m3u\n 2 error "Fox Sports 2 Asia" is on the blocklist due to claims of copyright holders (https://github.com/iptv-org/iptv/issues/0000)\n\n1 problems (1 errors, 0 warnings)\n`
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('show a warning if channel has wrong id', () => {
|
||||
const stdout = execSync(
|
||||
'DATA_DIR=tests/__data__/input/data npm run playlist:validate -- tests/__data__/input/streams/wrong_id.m3u',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
|
||||
expect(stdout).toBe(
|
||||
`\n> playlist:validate\n> node scripts/commands/playlist/validate.js tests/__data__/input/streams/wrong_id.m3u\n\nloading blocklist...\nfound 4 records\n\ntests/__data__/input/streams/wrong_id.m3u\n 2 warning "qib22lAq1L.us" is not in the database\n\n1 problems (0 errors, 1 warnings)\n`
|
||||
)
|
||||
})
|
||||
36
tests/commands/playlist/validate.test.ts
Normal file
36
tests/commands/playlist/validate.test.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { execSync } from 'child_process'
|
||||
|
||||
it('show an error if channel name in the blocklist', () => {
|
||||
try {
|
||||
const stdout = execSync(
|
||||
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/streams npm run playlist:validate -- tests/__data__/input/streams/us_blocked.m3u',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
console.log(stdout)
|
||||
process.exit(1)
|
||||
} catch (error: any) {
|
||||
expect(error.status).toBe(1)
|
||||
expect(
|
||||
error.stdout.includes(
|
||||
`loading blocklist...\nfound 4 records\n\ntests/__data__/input/streams/us_blocked.m3u\n 2 error "Fox Sports 2 Asia (Thai)" is on the blocklist due to claims of copyright holders (https://github.com/iptv-org/iptv/issues/0000)\n\n1 problems (1 errors, 0 warnings)\n`
|
||||
)
|
||||
).toBe(true)
|
||||
}
|
||||
})
|
||||
|
||||
it('show a warning if channel has wrong id', () => {
|
||||
const stdout = execSync(
|
||||
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/streams npm run playlist:validate -- tests/__data__/input/streams/wrong_id.m3u',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
|
||||
expect(
|
||||
stdout.includes(
|
||||
`loading blocklist...\nfound 4 records\n\ntests/__data__/input/streams/wrong_id.m3u\n 2 warning "qib22lAq1L.us" is not in the database\n\n1 problems (0 errors, 1 warnings)\n`
|
||||
)
|
||||
).toBe(true)
|
||||
})
|
||||
Reference in New Issue
Block a user