Update tests

This commit is contained in:
freearhey
2025-03-29 11:39:30 +03:00
parent 3c46b2b3d0
commit 6d9ee99848
8 changed files with 49 additions and 48 deletions

View File

@@ -4,7 +4,7 @@ import { glob } from 'glob'
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
fs.copySync('tests/__data__/input/streams_format', 'tests/__data__/output/streams')
fs.copySync('tests/__data__/input/playlist_format', 'tests/__data__/output/streams')
})
it('can format playlists', () => {
@@ -13,12 +13,12 @@ it('can format playlists', () => {
})
const files = glob
.sync('tests/__data__/expected/streams_format/*.m3u')
.map(f => f.replace('tests/__data__/expected/streams_format/', ''))
.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/streams_format/${filepath}`)
content(`expected/playlist_format/${filepath}`)
)
})
})

View File

@@ -4,24 +4,26 @@ import * as glob from 'glob'
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
execSync(
'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' }
)
})
it('can generate playlists and logs', () => {
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' }
)
const playlists = glob
.sync('tests/__data__/expected/.gh-pages/**/*.m3u')
.map((file: string) => file.replace('tests/__data__/expected/', ''))
.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/${filepath}`))
expect(content(`output/${filepath}`), filepath).toBe(
content(`expected/playlist_generate/${filepath}`)
)
})
expect(content('output/logs/generators.log').split('\n').sort()).toStrictEqual(
content('expected/logs/generators.log').split('\n').sort()
content('expected/playlist_generate/logs/generators.log').split('\n').sort()
)
})

View File

@@ -7,13 +7,13 @@ type ExecError = {
it('shows an error if the playlist contains a broken link', () => {
try {
execSync('ROOT_DIR=tests/__data__/input npm run playlist:test streams_test/ag.m3u', {
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('streams_test/ag.m3u')
expect((error as ExecError).stdout).toContain('playlist_test/ag.m3u')
expect((error as ExecError).stdout).toContain('2 problems (1 errors, 1 warnings)')
}
})

View File

@@ -4,10 +4,10 @@ import { glob } from 'glob'
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
fs.copySync('tests/__data__/input/streams_update', 'tests/__data__/output/streams')
fs.copySync('tests/__data__/input/playlist_update', 'tests/__data__/output/streams')
})
it('can format playlists', () => {
it('can update playlists', () => {
const stdout = execSync(
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/output/streams npm run playlist:update --silent',
{
@@ -16,17 +16,17 @@ it('can format playlists', () => {
)
const files = glob
.sync('tests/__data__/expected/streams_update/*.m3u')
.map(f => f.replace('tests/__data__/expected/streams_update/', ''))
.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/streams_update/${filepath}`)
content(`expected/playlist_update/${filepath}`)
)
})
expect(stdout).toBe(
'OUTPUT=closes #14151, closes #14140, 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'
'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'
)
})

View File

@@ -8,7 +8,7 @@ type ExecError = {
it('show an error if channel id in the blocklist', () => {
try {
execSync(
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/streams_validate npm run playlist:validate -- us_blocked.m3u',
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/playlist_validate npm run playlist:validate -- us_blocked.m3u',
{
encoding: 'utf8'
}
@@ -17,7 +17,7 @@ it('show an error if channel id in the blocklist', () => {
} catch (error) {
expect((error as ExecError).status).toBe(1)
expect((error as ExecError).stdout).toContain(`us_blocked.m3u
2 error "FoxSports2Asia.us" is on the blocklist due to claims of copyright holders (https://github.com/iptv-org/iptv/issues/0002)
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)`)
@@ -26,7 +26,7 @@ it('show an error if channel id 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_validate npm run playlist:validate -- wrong_id.m3u',
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/playlist_validate npm run playlist:validate -- wrong_id.m3u',
{
encoding: 'utf8'
}