Update tests

This commit is contained in:
freearhey 2025-04-22 03:47:28 +03:00
parent df365451a9
commit 6543464515
8 changed files with 175 additions and 111 deletions

View file

@ -1,19 +1,28 @@
import { execSync } from 'child_process' import { execSync } from 'child_process'
import fs from 'fs-extra' 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(() => { beforeEach(() => {
fs.emptyDirSync('tests/__data__/output') fs.emptyDirSync('tests/__data__/output')
}) })
it('can create streams.json', () => { describe('api:generate', () => {
execSync( it('can create streams.json', () => {
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/api_generate API_DIR=tests/__data__/output/.api npm run api:generate', const cmd = `${ENV_VAR} npm run api:generate`
{ encoding: 'utf8' } const stdout = execSync(cmd, { encoding: 'utf8' })
) if (process.env.DEBUG === 'true') console.log(cmd, stdout)
expect(content('output/.api/streams.json')).toMatchObject( expect(content('output/.api/streams.json')).toMatchObject(
content('expected/api_generate/.api/streams.json') content('expected/api_generate/.api/streams.json')
) )
})
}) })
function content(filepath: string) { function content(filepath: string) {

View file

@ -1,25 +1,33 @@
import { execSync } from 'child_process' import { execSync } from 'child_process'
import * as fs from 'fs-extra' import * as fs from 'fs-extra'
import { glob } from 'glob' 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(() => { beforeEach(() => {
fs.emptyDirSync('tests/__data__/output') fs.emptyDirSync('tests/__data__/output')
fs.copySync('tests/__data__/input/playlist_format', 'tests/__data__/output/streams') fs.copySync('tests/__data__/input/playlist_format', 'tests/__data__/output/streams')
}) })
it('can format playlists', () => { describe('playlist:format', () => {
execSync('STREAMS_DIR=tests/__data__/output/streams npm run playlist:format', { it('can format playlists', () => {
encoding: 'utf8' 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 const files = glob
.sync('tests/__data__/expected/playlist_format/*.m3u') .sync('tests/__data__/expected/playlist_format/*.m3u')
.map(f => f.replace('tests/__data__/expected/playlist_format/', '')) .map(f => f.replace('tests/__data__/expected/playlist_format/', ''))
files.forEach(filepath => { files.forEach(filepath => {
expect(content(`output/streams/${filepath}`), filepath).toBe( expect(content(`output/streams/${filepath}`), filepath).toBe(
content(`expected/playlist_format/${filepath}`) content(`expected/playlist_format/${filepath}`)
) )
})
}) })
}) })

View file

@ -1,32 +1,39 @@
import { execSync } from 'child_process' import { execSync } from 'child_process'
import * as fs from 'fs-extra' import * as fs from 'fs-extra'
import * as glob from 'glob' 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(() => { beforeEach(() => {
fs.emptyDirSync('tests/__data__/output') fs.emptyDirSync('tests/__data__/output')
}) })
it('can generate playlists and logs', () => { describe('playlist:generate', () => {
const stdout = execSync( it('can generate playlists and logs', () => {
'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', const cmd = `${ENV_VAR} npm run playlist:generate`
{ encoding: 'utf8' } 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 playlists.forEach((filepath: string) => {
.sync('tests/__data__/expected/playlist_generate/.gh-pages/**/*.m3u') expect(content(`output/${filepath}`), filepath).toBe(
.map((file: string) => file.replace('tests/__data__/expected/playlist_generate/', '')) content(`expected/playlist_generate/${filepath}`)
)
})
playlists.forEach((filepath: string) => { expect(content('output/logs/generators.log').split('\n').sort()).toStrictEqual(
expect(content(`output/${filepath}`), filepath).toBe( content('expected/playlist_generate/logs/generators.log').split('\n').sort()
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()
)
}) })
function content(filepath: string) { function content(filepath: string) {

View file

@ -1,19 +1,32 @@
import { execSync } from 'child_process' import { execSync } from 'child_process'
import os from 'os'
type ExecError = { type ExecError = {
status: number status: number
stdout: string stdout: string
} }
it('shows an error if the playlist contains a broken link', () => { let ENV_VAR = 'ROOT_DIR=tests/__data__/input'
try { if (os.platform() === 'win32') {
execSync('ROOT_DIR=tests/__data__/input npm run playlist:test playlist_test/ag.m3u', { ENV_VAR = 'SET "ROOT_DIR=tests/__data__/input" &&'
encoding: 'utf8' }
})
process.exit(1) describe('playlist:test', () => {
} catch (error) { it('shows an error if the playlist contains a broken link', () => {
expect((error as ExecError).status).toBe(1) const cmd = `${ENV_VAR} npm run playlist:test playlist_test/ag.m3u`
expect((error as ExecError).stdout).toContain('playlist_test/ag.m3u') try {
expect((error as ExecError).stdout).toContain('2 problems (1 errors, 1 warnings)') 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)')
}

View file

@ -1,33 +1,39 @@
import { execSync } from 'child_process' import { execSync } from 'child_process'
import * as fs from 'fs-extra' import * as fs from 'fs-extra'
import { glob } from 'glob' 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(() => { beforeEach(() => {
fs.emptyDirSync('tests/__data__/output') fs.emptyDirSync('tests/__data__/output')
fs.copySync('tests/__data__/input/playlist_update', 'tests/__data__/output/streams') fs.copySync('tests/__data__/input/playlist_update', 'tests/__data__/output/streams')
}) })
it('can update playlists', () => { describe('playlist:update', () => {
const stdout = execSync( it('can update playlists', () => {
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/output/streams npm run playlist:update --silent', const cmd = `${ENV_VAR} npm run playlist:update --silent`
{ const stdout = execSync(cmd, { encoding: 'utf8' })
encoding: 'utf8' if (process.env.DEBUG === 'true') console.log(cmd, stdout)
}
)
const files = glob const files = glob
.sync('tests/__data__/expected/playlist_update/*.m3u') .sync('tests/__data__/expected/playlist_update/*.m3u')
.map(f => f.replace('tests/__data__/expected/playlist_update/', '')) .map(f => f.replace('tests/__data__/expected/playlist_update/', ''))
files.forEach(filepath => { files.forEach(filepath => {
expect(content(`output/streams/${filepath}`), filepath).toBe( expect(content(`output/streams/${filepath}`), filepath).toBe(
content(`expected/playlist_update/${filepath}`) 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) { function content(filepath: string) {

View file

@ -1,41 +1,47 @@
import { execSync } from 'child_process' import { execSync } from 'child_process'
import os from 'os'
type ExecError = { type ExecError = {
status: number status: number
stdout: string stdout: string
} }
it('show an error if channel id in the blocklist', () => { let ENV_VAR =
try { 'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/playlist_validate'
const stdout = execSync( if (os.platform() === 'win32') {
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/playlist_validate npm run playlist:validate -- us_blocked.m3u', ENV_VAR =
{ 'SET "DATA_DIR=tests/__data__/input/data" && SET "STREAMS_DIR=tests/__data__/input/playlist_validate" &&'
encoding: 'utf8' }
}
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) function checkStdout(stdout: string) {
expect((error as ExecError).status).toBe(1) expect(stdout).toContain(`us_blocked.m3u
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) 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) 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)`) 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'
)
})

View file

@ -1,6 +1,14 @@
import { execSync } from 'child_process' import { execSync } from 'child_process'
import fs from 'fs-extra' import fs from 'fs-extra'
import path from 'path' 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(() => { beforeEach(() => {
fs.emptyDirSync('tests/__data__/output') fs.emptyDirSync('tests/__data__/output')
@ -13,17 +21,18 @@ beforeEach(() => {
'tests/__data__/input/readme_update/.readme/template.md', 'tests/__data__/input/readme_update/.readme/template.md',
'tests/__data__/output/.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', () => {
expect(content('tests/__data__/output/readme.md')).toEqual( it('can update readme.md', () => {
content('tests/__data__/expected/readme_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) { function content(filepath: string) {

View file

@ -1,15 +1,20 @@
import { execSync } from 'child_process' import { execSync } from 'child_process'
import os from 'os'
it('can create report', () => { let ENV_VAR = 'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/report_create'
const stdout = execSync( if (os.platform() === 'win32') {
'DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/report_create npm run report:create', ENV_VAR =
{ 'SET "DATA_DIR=tests/__data__/input/data" && SET "STREAMS_DIR=tests/__data__/input/report_create" &&'
encoding: 'utf8' }
}
)
expect( describe('report:create', () => {
stdout.includes(` 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(`
(index) issueNumber type streamId streamUrl status (index) issueNumber type streamId streamUrl status
@ -20,5 +25,6 @@ it('can create report', () => {
4 16120 'broken stream' undefined 'http://190.61.102.67:2000/play/a038/index.m3u8' 'wrong_link' 4 16120 'broken stream' undefined 'http://190.61.102.67:2000/play/a038/index.m3u8' 'wrong_link'
5 19956 'channel search' 'CNBCe.tr' undefined 'invalid_id' 5 19956 'channel search' 'CNBCe.tr' undefined 'invalid_id'
`) `)
).toBe(true) ).toBe(true)
})
}) })