Update tests

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

View File

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