mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-13 02:20:03 -04:00
Update tests
This commit is contained in:
parent
98645d4166
commit
c1a815754e
7 changed files with 49 additions and 71 deletions
|
@ -3,14 +3,9 @@ import fs from 'fs-extra'
|
|||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
fs.mkdirSync('tests/__data__/output/database')
|
||||
fs.copyFileSync(
|
||||
'tests/__data__/input/database/api_generate.streams.db',
|
||||
'tests/__data__/output/database/streams.db'
|
||||
)
|
||||
|
||||
const stdout = execSync(
|
||||
'DB_DIR=tests/__data__/output/database API_DIR=tests/__data__/output/.api npm run api:generate',
|
||||
'STREAMS_DIR=tests/__data__/input/streams_generate API_DIR=tests/__data__/output/.api npm run api:generate',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
})
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
import * as fs from 'fs-extra'
|
||||
import * as path from 'path'
|
||||
import { execSync } from 'child_process'
|
||||
import * as _ from 'lodash'
|
||||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
fs.mkdirSync('tests/__data__/output/database')
|
||||
|
||||
const stdout = execSync(
|
||||
'DB_DIR=tests/__data__/output/database DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/streams npm run db:create',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
})
|
||||
|
||||
it('can create database', () => {
|
||||
let output = content('tests/__data__/output/database/streams.db')
|
||||
let expected = content('tests/__data__/expected/database/db_create.streams.db')
|
||||
|
||||
output = output.map(i => {
|
||||
i._id = null
|
||||
return i
|
||||
})
|
||||
expected = expected.map(i => {
|
||||
i._id = null
|
||||
return i
|
||||
})
|
||||
|
||||
expect(_.orderBy(output, 'name')).toMatchObject(
|
||||
expect.arrayContaining(_.orderBy(expected, 'name'))
|
||||
)
|
||||
})
|
||||
|
||||
function content(filepath: string) {
|
||||
const data = fs.readFileSync(path.resolve(filepath), {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
|
||||
return data
|
||||
.split('\n')
|
||||
.filter(l => l)
|
||||
.map(l => {
|
||||
return JSON.parse(l)
|
||||
})
|
||||
}
|
30
tests/commands/playlist/format.test.ts
Normal file
30
tests/commands/playlist/format.test.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { execSync } from 'child_process'
|
||||
import * as fs from 'fs-extra'
|
||||
import { glob } from 'glob'
|
||||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
fs.copySync('tests/__data__/input/streams_format', 'tests/__data__/output/streams')
|
||||
})
|
||||
|
||||
it('can format playlists', () => {
|
||||
const stdout = execSync('STREAMS_DIR=tests/__data__/output/streams npm run playlist:format', {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
|
||||
const files = glob
|
||||
.sync('tests/__data__/expected/streams_format/*.m3u')
|
||||
.map(f => f.replace('tests/__data__/expected/streams_format/', ''))
|
||||
|
||||
files.forEach(filepath => {
|
||||
expect(content(`output/streams/${filepath}`), filepath).toBe(
|
||||
content(`expected/streams_format/${filepath}`)
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
function content(filepath: string) {
|
||||
return fs.readFileSync(`tests/__data__/${filepath}`, {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
}
|
|
@ -4,13 +4,9 @@ import * as glob from 'glob'
|
|||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
fs.copyFileSync(
|
||||
'tests/__data__/input/database/playlist_generate.streams.db',
|
||||
'tests/__data__/output/streams.db'
|
||||
)
|
||||
|
||||
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',
|
||||
'STREAMS_DIR=tests/__data__/input/streams_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' }
|
||||
)
|
||||
})
|
||||
|
|
|
@ -4,15 +4,12 @@ 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'
|
||||
)
|
||||
fs.copySync('tests/__data__/input/streams_update', 'tests/__data__/output/streams')
|
||||
})
|
||||
|
||||
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',
|
||||
'DEBUG=true DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/output/streams npm run playlist:update --silent',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
|
@ -21,11 +18,13 @@ it('can format playlists', () => {
|
|||
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/', ''))
|
||||
.sync('tests/__data__/expected/streams_update/*.m3u')
|
||||
.map(f => f.replace('tests/__data__/expected/streams_update/', ''))
|
||||
|
||||
files.forEach(filepath => {
|
||||
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
|
||||
expect(content(`output/streams/${filepath}`), filepath).toBe(
|
||||
content(`expected/streams_update/${filepath}`)
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ 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',
|
||||
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/streams_validate npm run playlist:validate -- us_blocked.m3u',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ it('show an error if channel name in the blocklist', () => {
|
|||
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`
|
||||
`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)
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ it('show an error if channel name in the blocklist', () => {
|
|||
|
||||
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',
|
||||
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/streams_validate npm run playlist:validate -- wrong_id.m3u',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ it('show a warning if channel has wrong id', () => {
|
|||
|
||||
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`
|
||||
`wrong_id.m3u\n 2 warning "qib22lAq1L.us" is not in the database\n\n1 problems (0 errors, 1 warnings)\n`
|
||||
)
|
||||
).toBe(true)
|
||||
})
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
import { execSync } from 'child_process'
|
||||
|
||||
it('can create report', () => {
|
||||
const stdout = execSync('DATA_DIR=tests/__data__/input/data npm run report:create', {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
const stdout = execSync(
|
||||
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/streams_report npm run report:create',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
|
||||
expect(
|
||||
stdout.includes(`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue