Update tests

This commit is contained in:
freearhey 2023-09-15 18:40:14 +03:00
parent 708744b28f
commit 8a83f23243
10 changed files with 151 additions and 116 deletions

View file

@ -1,5 +1,5 @@
const { execSync } = require('child_process')
const fs = require('fs-extra')
import { execSync } from 'child_process'
import fs from 'fs-extra'
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
@ -10,7 +10,7 @@ beforeEach(() => {
)
const stdout = execSync(
'DB_DIR=tests/__data__/output/database DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output/.api npm run api:generate',
'DB_DIR=tests/__data__/output/database API_DIR=tests/__data__/output/.api npm run api:generate',
{ encoding: 'utf8' }
)
})
@ -19,7 +19,7 @@ it('can create streams.json', () => {
expect(content(`output/.api/streams.json`)).toMatchObject(content(`expected/.api/streams.json`))
})
function content(filepath) {
function content(filepath: string) {
return JSON.parse(
fs.readFileSync(`tests/__data__/${filepath}`, {
encoding: 'utf8'

View file

@ -1,13 +1,14 @@
const fs = require('fs-extra')
const path = require('path')
const { execSync } = require('child_process')
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 npm run db:create -- --input-dir=tests/__data__/input/streams',
'DB_DIR=tests/__data__/output/database DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/streams npm run db:create',
{ encoding: 'utf8' }
)
})
@ -25,10 +26,12 @@ it('can create database', () => {
return i
})
expect(output).toMatchObject(expect.arrayContaining(expected))
expect(_.orderBy(output, 'name')).toMatchObject(
expect.arrayContaining(_.orderBy(expected, 'name'))
)
})
function content(filepath) {
function content(filepath: string) {
const data = fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'
})

View file

@ -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'
})
}

View file

@ -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'
})

View 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'
})
}

View file

@ -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`
)
})

View 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)
})

View file

@ -1,26 +0,0 @@
const { execSync } = require('child_process')
const fs = require('fs-extra')
const path = require('path')
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
const stdout = execSync(
'DATA_DIR=tests/__data__/input/data LOGS_DIR=tests/__data__/input/logs/generators npm run readme:update -- --config=tests/__data__/input/_readme.json',
{ encoding: 'utf8' }
)
})
it('can update readme.md', () => {
expect(content('tests/__data__/output/readme.md')).toEqual(
content('tests/__data__/expected/_readme.md')
)
})
function content(filepath) {
const data = fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'
})
return JSON.stringify(data)
}

View file

@ -0,0 +1,35 @@
import { execSync } from 'child_process'
import fs from 'fs-extra'
import path from 'path'
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
fs.mkdirSync('tests/__data__/output/.readme')
fs.copyFileSync(
'tests/__data__/input/.readme/config.json',
'tests/__data__/output/.readme/config.json'
)
fs.copyFileSync(
'tests/__data__/input/.readme/template.md',
'tests/__data__/output/.readme/template.md'
)
const stdout = execSync(
'DATA_DIR=tests/__data__/input/data LOGS_DIR=tests/__data__/input/logs README_DIR=tests/__data__/output/.readme npm run readme:update',
{ encoding: 'utf8' }
)
})
it('can update readme.md', () => {
expect(content('tests/__data__/output/readme.md')).toEqual(
content('tests/__data__/expected/_readme.md')
)
})
function content(filepath: string) {
const data = fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'
})
return JSON.stringify(data)
}

View file

@ -0,0 +1,20 @@
import { execSync } from 'child_process'
it('can create report', () => {
const stdout = execSync('DATA_DIR=tests/__data__/input/data npm run report:create', {
encoding: 'utf8'
})
expect(
stdout.includes(`
(index) issueNumber channelId status
0 14179 'ManoramaNews.in' 'pending'
1 14178 'TV3.my' 'blocked'
2 14177 'TUTV.us' 'fullfilled'
3 14176 'ManoramaNews.in' 'duplicate'
4 14175 'TFX.fr' 'invalid_id'
`)
).toBe(true)
})