Update tests

This commit is contained in:
freearhey committed 2026-09-18 11:30:45 +03:00
1 parent d7f1cdf2c1
commit 9902121ac0
10 files changed
+49 -10

No files matched your search

+15
View File
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from 'vitest'
import issues from '../../__data__/input/issues' import issues from '../../__data__/input/issues'
import { pathToFileURL } from 'node:url' import { pathToFileURL } from 'node:url'
import { execFileSync } from 'child_process' import { execFileSync } from 'child_process'
@@ -57,6 +58,20 @@ describe('issue:validate', () => {
) )
} }
}) })
it('can handle streams:edit request without changes', () => {
const body = issues.find(issue => issue.number === 39098)?.body
try {
const stdout = runIssueValidate(body, 'approved,streams:edit')
if (process.env.DEBUG === 'true') console.log(stdout)
throw new Error('Failed')
} catch {
expect(content('tests/__data__/output/logs/errors.txt')).toBe(
content('tests/__data__/expected/issue_validate/logs/streams_edit_no_changes.txt')
)
}
})
}) })
function runIssueValidate(body: string | undefined, labels: string) { function runIssueValidate(body: string | undefined, labels: string) {
+1
View File
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from 'vitest'
import { execSync } from 'child_process' import { execSync } from 'child_process'
import fs from 'fs-extra' import fs from 'fs-extra'
+1 -1
View File
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from 'vitest'
import { pathToFileURL } from 'node:url' import { pathToFileURL } from 'node:url'
import { execSync } from 'child_process' import { execSync } from 'child_process'
import fs from 'fs-extra' import fs from 'fs-extra'
@@ -19,7 +20,6 @@ describe('playlist:export', () => {
content('tests/__data__/expected/playlist_export/.api/streams.json') content('tests/__data__/expected/playlist_export/.api/streams.json')
) )
}) })
}) })
function content(filepath: string) { function content(filepath: string) {
+1
View File
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from 'vitest'
import { pathToFileURL } from 'node:url' import { pathToFileURL } from 'node:url'
import { execSync } from 'child_process' import { execSync } from 'child_process'
import * as fs from 'fs-extra' import * as fs from 'fs-extra'
+1
View File
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from 'vitest'
import { pathToFileURL } from 'node:url' import { pathToFileURL } from 'node:url'
import { execSync } from 'child_process' import { execSync } from 'child_process'
import { EOL } from 'node:os' import { EOL } from 'node:os'
+2 -2
View File
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from 'vitest'
import child_process, { execSync } from 'node:child_process' import child_process, { execSync } from 'node:child_process'
import path from 'node:path' import path from 'node:path'
import { pathToFileURL } from 'node:url' import { pathToFileURL } from 'node:url'
@@ -60,8 +61,7 @@ describe('playlist:test', () => {
it('fails when the network is unavailable', () => { it('fails when the network is unavailable', () => {
const preload = path.resolve('tests/__data__/input/offline_dns.cjs').replaceAll('\\', '/') const preload = path.resolve('tests/__data__/input/offline_dns.cjs').replaceAll('\\', '/')
const cmd = const cmd = `cross-env NODE_OPTIONS="--require=${preload}" npm run playlist:test -- streams/af.m3u`
`cross-env NODE_OPTIONS="--require=${preload}" npm run playlist:test -- streams/af.m3u`
try { try {
execSync(cmd, { encoding: 'utf8' }) execSync(cmd, { encoding: 'utf8' })
+2 -4
View File
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from 'vitest'
import { pathToFileURL } from 'node:url' import { pathToFileURL } from 'node:url'
import { execSync } from 'child_process' import { execSync } from 'child_process'
import * as fs from 'fs-extra' import * as fs from 'fs-extra'
@@ -12,7 +13,7 @@ beforeEach(() => {
}) })
describe('playlist:update', () => { describe('playlist:update', () => {
it('can update playlists', done => { it('can update playlists', async () => {
let cmd = `${ENV_VAR} npm run playlist:update` let cmd = `${ENV_VAR} npm run playlist:update`
if (!process.env.DEBUG) cmd += ' --silent' if (!process.env.DEBUG) cmd += ' --silent'
try { try {
@@ -39,11 +40,8 @@ describe('playlist:update', () => {
expect(content('tests/__data__/output/logs/playlist_update.log')).toBe( expect(content('tests/__data__/output/logs/playlist_update.log')).toBe(
content('tests/__data__/expected/playlist_update/playlist_update.log') content('tests/__data__/expected/playlist_update/playlist_update.log')
) )
done()
} catch (err) { } catch (err) {
if (process.env.DEBUG === 'true') console.log(cmd, err.stdout) if (process.env.DEBUG === 'true') console.log(cmd, err.stdout)
done(err)
} }
}) })
}) })
+24 -3
View File
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest'
import { execSync } from 'child_process' import { execSync } from 'child_process'
type ExecError = { type ExecError = {
@@ -38,6 +39,7 @@ describe('playlist:validate', () => {
) )
} catch (error) { } catch (error) {
if (process.env.DEBUG === 'true') console.log(cmd, error) if (process.env.DEBUG === 'true') console.log(cmd, error)
process.exit(0)
} }
}) })
@@ -46,11 +48,14 @@ describe('playlist:validate', () => {
try { try {
const stdout = execSync(cmd, { encoding: 'utf8' }) const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout) if (process.env.DEBUG === 'true') console.log(cmd, stdout)
expect(stdout).toContain( expect(stdout).toContain(`wrong_channel_id.m3u
'wrong_channel_id.m3u\n 2 warning "qib22lAq1L.us" is not in the database\n\n1 problems (0 errors, 1 warnings)\n' 2 warning "qib22lAq1L.us@SD" is not in the database
) 2 warning There is no feed with the ID "SD" in the database for the "qib22lAq1L.us" channel
2 problems (0 errors, 2 warnings)`)
} catch (error) { } catch (error) {
if (process.env.DEBUG === 'true') console.log(cmd, error) if (process.env.DEBUG === 'true') console.log(cmd, error)
process.exit(0)
} }
}) })
@@ -64,6 +69,7 @@ describe('playlist:validate', () => {
) )
} catch (error) { } catch (error) {
if (process.env.DEBUG === 'true') console.log(cmd, error) if (process.env.DEBUG === 'true') console.log(cmd, error)
process.exit(0)
} }
}) })
@@ -77,6 +83,7 @@ describe('playlist:validate', () => {
) )
} catch (error) { } catch (error) {
if (process.env.DEBUG === 'true') console.log(cmd, error) if (process.env.DEBUG === 'true') console.log(cmd, error)
process.exit(0)
} }
}) })
@@ -109,4 +116,18 @@ describe('playlist:validate', () => {
expect(stdout).toContain('missing_metadata.m3u') expect(stdout).toContain('missing_metadata.m3u')
expect(stdout).toContain('is missing a channel ID') expect(stdout).toContain('is missing a channel ID')
}) })
it('shows only errors if log level is error', () => {
const cmd = `${ENV_VAR} npm run playlist:validate -- --log-level=error log_level.m3u`
try {
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
process.exit(0)
} catch (error) {
if (process.env.DEBUG === 'true') console.log(cmd, error)
expect((error as ExecError).stdout).toContain(
'log_level.m3u\n 2 error \"new: https://streamer2.nexgen.bz/07-CHANNEL7/index.m3u8\" is not a valid URL\n\n1 problems (1 errors, 0 warnings)\n'
)
}
})
}) })
+1
View File
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from 'vitest'
import { pathToFileURL } from 'node:url' import { pathToFileURL } from 'node:url'
import { execSync } from 'child_process' import { execSync } from 'child_process'
import fs from 'fs-extra' import fs from 'fs-extra'
+1
View File
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest'
import { execSync } from 'child_process' import { execSync } from 'child_process'
const ENV_VAR = const ENV_VAR =