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:
chen zhihao
2026-09-03 22:42:56 +02:00
committed by GitHub
parent b618525815
commit 2c21f19496
3 changed files with 25 additions and 8 deletions
+3
View File
@@ -0,0 +1,3 @@
const dns = require('node:dns')
dns.lookup = (_hostname, callback) => callback(new Error('offline'))
+17 -1
View File
@@ -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 { promisify } from 'node:util'
import * as fs from 'fs-extra'
@@ -9,6 +10,7 @@ const exec = promisify(child_process.exec)
type ExecError = {
status: number
stdout: string
stderr: string
}
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) {