mirror of
https://github.com/iptv-org/iptv
synced 2026-09-09 13:27:58 -04:00
Return failure status when playlist checks are offline (#49872)
* fix: fail playlist tests when offline * test: move offline playlist check into test suite
This commit is contained in:
@@ -58,6 +58,7 @@ const rootStorage = new Storage(ROOT_DIR)
|
|||||||
async function main() {
|
async function main() {
|
||||||
if (await isOffline()) {
|
if (await isOffline()) {
|
||||||
logger.error(chalk.red('Internet connection is required for the script to work'))
|
logger.error(chalk.red('Internet connection is required for the script to work'))
|
||||||
|
process.exitCode = 1
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,13 +196,10 @@ async function onFinish(error: Error | null | undefined) {
|
|||||||
process.exit(0)
|
process.exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function isOffline() {
|
async function isOffline(): Promise<boolean> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(resolve => {
|
||||||
dns.lookup('info.cern.ch', err => {
|
dns.lookup('info.cern.ch', err => resolve(Boolean(err)))
|
||||||
if (err) resolve(true)
|
|
||||||
reject(false)
|
|
||||||
})
|
})
|
||||||
}).catch(() => {})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getColor(stream: Stream): string {
|
function getColor(stream: Stream): string {
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
const dns = require('node:dns')
|
||||||
|
|
||||||
|
dns.lookup = (_hostname, callback) => callback(new Error('offline'))
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import child_process from 'node:child_process'
|
import child_process, { execSync } from 'node:child_process'
|
||||||
|
import path from 'node:path'
|
||||||
import { pathToFileURL } from 'node:url'
|
import { pathToFileURL } from 'node:url'
|
||||||
import { promisify } from 'node:util'
|
import { promisify } from 'node:util'
|
||||||
import * as fs from 'fs-extra'
|
import * as fs from 'fs-extra'
|
||||||
@@ -9,6 +10,7 @@ const exec = promisify(child_process.exec)
|
|||||||
type ExecError = {
|
type ExecError = {
|
||||||
status: number
|
status: number
|
||||||
stdout: string
|
stdout: string
|
||||||
|
stderr: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const ENV_VAR = 'cross-env DATA_DIR=tests/__data__/input/data ROOT_DIR=tests/__data__/output'
|
const ENV_VAR = 'cross-env DATA_DIR=tests/__data__/input/data ROOT_DIR=tests/__data__/output'
|
||||||
@@ -55,6 +57,20 @@ describe('playlist:test', () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('fails when the network is unavailable', () => {
|
||||||
|
const preload = path.resolve('tests/__data__/input/offline_dns.cjs').replaceAll('\\', '/')
|
||||||
|
const cmd =
|
||||||
|
`cross-env NODE_OPTIONS="--require=${preload}" npm run playlist:test -- streams/af.m3u`
|
||||||
|
|
||||||
|
try {
|
||||||
|
execSync(cmd, { encoding: 'utf8' })
|
||||||
|
throw new Error('Expected playlist:test to fail offline')
|
||||||
|
} catch (error) {
|
||||||
|
const output = `${(error as ExecError).stdout || ''}${(error as ExecError).stderr || ''}`
|
||||||
|
expect(output).toContain('Internet connection is required for the script to work')
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
function content(filepath: string) {
|
function content(filepath: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user