diff --git a/tests/commands/playlist/edit.test.ts b/tests/commands/playlist/edit.test.ts index 4651e5ef88..3334b6dee5 100644 --- a/tests/commands/playlist/edit.test.ts +++ b/tests/commands/playlist/edit.test.ts @@ -39,5 +39,4 @@ function checkStdout(stdout: string) { expect(stdout).toContain('TF1.fr (TF1, Télévision française 1)') expect(stdout).toContain('Type...') expect(stdout).toContain('Skip') - expect(stdout).toContain("File 'tests/__data__/output/playlist.m3u' successfully saved") } diff --git a/tests/commands/playlist/generate.test.ts b/tests/commands/playlist/generate.test.ts index fa27be5b1f..4e14d0d30b 100644 --- a/tests/commands/playlist/generate.test.ts +++ b/tests/commands/playlist/generate.test.ts @@ -1,8 +1,8 @@ import { pathToFileURL } from 'node:url' import { execSync } from 'child_process' +import os, { EOL } from 'node:os' import * as fs from 'fs-extra' 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' @@ -36,8 +36,8 @@ describe('playlist:generate', () => { ) }) - expect(content('tests/__data__/output/logs/generators.log').split('\n').sort()).toStrictEqual( - content('tests/__data__/expected/playlist_generate/logs/generators.log').split('\n').sort() + expect(content('tests/__data__/output/logs/generators.log').split(EOL).sort()).toStrictEqual( + content('tests/__data__/expected/playlist_generate/logs/generators.log').split(EOL).sort() ) }) }) diff --git a/tests/commands/playlist/test.test.ts b/tests/commands/playlist/test.test.ts index 1b42c3d585..515dbf824c 100644 --- a/tests/commands/playlist/test.test.ts +++ b/tests/commands/playlist/test.test.ts @@ -1,6 +1,6 @@ import { execSync } from 'child_process' import path from 'node:path' -import os from 'os' +import os from 'node:os' type ExecError = { status: number @@ -16,22 +16,15 @@ describe('playlist:test', () => { it('shows an error if the playlist contains a broken link', () => { const cmd = `${ENV_VAR} npm run playlist:test playlist_test/ag.m3u` try { - const stdout = execSync(cmd, { encoding: 'utf8' }) - if (process.env.DEBUG === 'true') console.log(cmd, stdout) - checkStdout(stdout) + execSync(cmd, { encoding: 'utf8' }) } catch (error) { - // NOTE: for Windows only if (process.env.DEBUG === 'true') console.log(cmd, error) - checkStdout((error as ExecError).stdout) + expect((error as ExecError).stdout).toContain(slash('playlist_test/ag.m3u')) + expect((error as ExecError).stdout).toContain('2 problems (1 errors, 1 warnings)') } }) }) -function checkStdout(stdout: string) { - expect(stdout).toContain(slash('playlist_test/ag.m3u')) - expect(stdout).toContain('2 problems (1 errors, 1 warnings)') -} - function slash(filepath: string) { return filepath.split(path.sep).join(path.posix.sep) } diff --git a/tests/commands/playlist/validate.test.ts b/tests/commands/playlist/validate.test.ts index 933099bc9c..feef97bbfa 100644 --- a/tests/commands/playlist/validate.test.ts +++ b/tests/commands/playlist/validate.test.ts @@ -17,31 +17,29 @@ 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) + execSync(cmd, { encoding: 'utf8' }) } catch (error) { - // NOTE: for Windows only if (process.env.DEBUG === 'true') console.log(cmd, error) - checkStdout((error as ExecError).stdout) + expect((error as ExecError).stdout).toContain('us_blocked.m3u') + expect((error as ExecError).stdout).toContain( + '2 error "FoxSports2.us" is on the blocklist due to claims of copyright holders (https://github.com/iptv-org/iptv/issues/0002)' + ) + expect((error as ExecError).stdout).toContain( + '4 error "TVN.pl" is on the blocklist due to NSFW content (https://github.com/iptv-org/iptv/issues/0003)' + ) + expect((error as ExecError).stdout).toContain('2 problems (2 errors, 0 warnings)') } }) 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' - ) + try { + execSync(cmd, { encoding: 'utf8' }) + } catch (error) { + if (process.env.DEBUG === 'true') console.log(cmd, error) + expect((error as ExecError).stdout).toContain( + 'wrong_id.m3u\n 2 warning "qib22lAq1L.us" is not in the database\n\n1 problems (0 errors, 1 warnings)\n' + ) + } }) }) - -function checkStdout(stdout: string) { - expect(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) - 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)`) -}