From c1a815754e488bc9780026bd626ff173d6653c71 Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Sun, 17 Sep 2023 04:07:27 +0300 Subject: [PATCH] Update tests --- tests/commands/api/generate.test.ts | 7 +--- tests/commands/database/create.test.ts | 45 ------------------------ tests/commands/playlist/format.test.ts | 30 ++++++++++++++++ tests/commands/playlist/generate.test.ts | 6 +--- tests/commands/playlist/update.test.ts | 15 ++++---- tests/commands/playlist/validate.test.ts | 8 ++--- tests/commands/report/create.test.ts | 9 +++-- 7 files changed, 49 insertions(+), 71 deletions(-) delete mode 100644 tests/commands/database/create.test.ts create mode 100644 tests/commands/playlist/format.test.ts diff --git a/tests/commands/api/generate.test.ts b/tests/commands/api/generate.test.ts index 74a70e11d..fe3c1215d 100644 --- a/tests/commands/api/generate.test.ts +++ b/tests/commands/api/generate.test.ts @@ -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' } ) }) diff --git a/tests/commands/database/create.test.ts b/tests/commands/database/create.test.ts deleted file mode 100644 index 4ca4d4023..000000000 --- a/tests/commands/database/create.test.ts +++ /dev/null @@ -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) - }) -} diff --git a/tests/commands/playlist/format.test.ts b/tests/commands/playlist/format.test.ts new file mode 100644 index 000000000..0c867dd36 --- /dev/null +++ b/tests/commands/playlist/format.test.ts @@ -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' + }) +} diff --git a/tests/commands/playlist/generate.test.ts b/tests/commands/playlist/generate.test.ts index 1e2d38abe..8c6d80d6a 100644 --- a/tests/commands/playlist/generate.test.ts +++ b/tests/commands/playlist/generate.test.ts @@ -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' } ) }) diff --git a/tests/commands/playlist/update.test.ts b/tests/commands/playlist/update.test.ts index 01cad1b84..4670b9452 100644 --- a/tests/commands/playlist/update.test.ts +++ b/tests/commands/playlist/update.test.ts @@ -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}`) + ) }) }) diff --git a/tests/commands/playlist/validate.test.ts b/tests/commands/playlist/validate.test.ts index 7f702bb36..d0c6d1396 100644 --- a/tests/commands/playlist/validate.test.ts +++ b/tests/commands/playlist/validate.test.ts @@ -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) }) diff --git a/tests/commands/report/create.test.ts b/tests/commands/report/create.test.ts index b6002eeba..55199f81c 100644 --- a/tests/commands/report/create.test.ts +++ b/tests/commands/report/create.test.ts @@ -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(`