epg-grabber/tests/bin.test.js

44 lines
1.0 KiB
JavaScript
Raw Normal View History

2021-10-05 23:39:01 +02:00
const { execSync } = require('child_process')
const pwd = `${__dirname}/..`
2021-11-18 15:31:54 +01:00
import axios from 'axios'
jest.mock('axios')
2021-10-05 23:39:01 +02:00
function stdoutResultTester(stdout) {
return [`Finish`].every(val => {
return RegExp(val).test(stdout)
})
}
it('can load config', () => {
const result = execSync(
2021-10-13 21:52:49 +02:00
`node ${pwd}/bin/epg-grabber.js --config=tests/input/example.com.config.js --delay=0`,
2021-10-05 23:39:01 +02:00
{
encoding: 'utf8'
}
)
expect(stdoutResultTester(result)).toBe(true)
})
it('can load mini config', () => {
2021-11-18 15:31:54 +01:00
axios.mockImplementation(() => Promise.resolve({ data: '' }))
2021-10-05 23:39:01 +02:00
const result = execSync(
`node ${pwd}/bin/epg-grabber.js \
--config=tests/input/mini.config.js \
--channels=tests/input/example.com.channels.xml \
--output=tests/output/mini.guide.xml \
--lang=fr \
--days=3 \
2021-11-18 15:31:54 +01:00
--delay=0 \
--timeout=10000`,
2021-10-05 23:39:01 +02:00
{
encoding: 'utf8'
}
)
expect(stdoutResultTester(result)).toBe(true)
expect(result.includes("File 'tests/output/mini.guide.xml' successfully saved")).toBe(true)
})