2021-10-05 23:39:01 +02:00
|
|
|
const { execSync } = require('child_process')
|
2023-05-11 03:12:44 +02:00
|
|
|
const fs = require('fs-extra')
|
2022-08-29 03:14:02 +02:00
|
|
|
const path = require('path')
|
2022-08-29 03:26:28 +02:00
|
|
|
const epgParser = require('epg-parser')
|
2021-11-18 15:31:54 +01:00
|
|
|
|
2022-01-16 15:34:21 +01:00
|
|
|
const pwd = `${__dirname}/..`
|
2021-10-05 23:39:01 +02:00
|
|
|
|
|
|
|
function stdoutResultTester(stdout) {
|
|
|
|
return [`Finish`].every(val => {
|
|
|
|
return RegExp(val).test(stdout)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-05-11 03:12:44 +02:00
|
|
|
beforeEach(() => {
|
|
|
|
fs.emptyDirSync('tests/__data__/output')
|
|
|
|
})
|
|
|
|
|
2021-10-05 23:39:01 +02:00
|
|
|
it('can load config', () => {
|
2023-01-10 09:20:29 +01:00
|
|
|
const stdout = execSync(
|
2022-08-29 03:14:02 +02:00
|
|
|
`node ${pwd}/bin/epg-grabber.js --config=tests/__data__/input/example.config.js --delay=0`,
|
2021-10-05 23:39:01 +02:00
|
|
|
{
|
|
|
|
encoding: 'utf8'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-01-10 09:20:29 +01:00
|
|
|
expect(stdoutResultTester(stdout)).toBe(true)
|
2021-10-05 23:39:01 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('can load mini config', () => {
|
2023-01-10 09:20:29 +01:00
|
|
|
const stdout = execSync(
|
2021-10-05 23:39:01 +02:00
|
|
|
`node ${pwd}/bin/epg-grabber.js \
|
2022-08-29 03:14:02 +02:00
|
|
|
--config=tests/__data__/input/mini.config.js \
|
|
|
|
--channels=tests/__data__/input/example.channels.xml \
|
|
|
|
--output=tests/__data__/output/mini.guide.xml \
|
2021-10-05 23:39:01 +02:00
|
|
|
--lang=fr \
|
|
|
|
--days=3 \
|
2021-11-18 15:31:54 +01:00
|
|
|
--delay=0 \
|
2022-01-16 15:34:21 +01:00
|
|
|
--debug \
|
|
|
|
--timeout=1`,
|
2021-10-05 23:39:01 +02:00
|
|
|
{
|
|
|
|
encoding: 'utf8'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-01-10 09:20:29 +01:00
|
|
|
expect(stdoutResultTester(stdout)).toBe(true)
|
|
|
|
expect(stdout.includes("File 'tests/__data__/output/mini.guide.xml' successfully saved")).toBe(
|
2022-08-29 03:14:02 +02:00
|
|
|
true
|
|
|
|
)
|
2021-10-05 23:39:01 +02:00
|
|
|
})
|
2022-03-15 12:52:55 +01:00
|
|
|
|
|
|
|
it('can generate gzip version', () => {
|
2023-01-10 09:20:29 +01:00
|
|
|
const stdout = execSync(
|
2022-03-15 12:52:55 +01:00
|
|
|
`node ${pwd}/bin/epg-grabber.js \
|
2022-08-29 03:14:02 +02:00
|
|
|
--config=tests/__data__/input/mini.config.js \
|
|
|
|
--channels=tests/__data__/input/example.channels.xml \
|
|
|
|
--output=tests/__data__/output/mini.guide.xml.gz \
|
2022-03-15 12:52:55 +01:00
|
|
|
--gzip`,
|
|
|
|
{
|
|
|
|
encoding: 'utf8'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-01-10 09:20:29 +01:00
|
|
|
expect(stdoutResultTester(stdout)).toBe(true)
|
|
|
|
expect(stdout.includes("File 'tests/__data__/output/mini.guide.xml.gz' successfully saved")).toBe(
|
2022-08-29 03:14:02 +02:00
|
|
|
true
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2023-05-11 03:12:44 +02:00
|
|
|
it('can produce multiple outputs', () => {
|
|
|
|
const stdout = execSync(
|
|
|
|
`node ${pwd}/bin/epg-grabber.js \
|
|
|
|
--config=tests/__data__/input/mini.config.js \
|
|
|
|
--channels=tests/__data__/input/example.channels.xml \
|
2023-05-11 23:18:58 +02:00
|
|
|
--output=tests/__data__/output/{lang}/{xmltv_id}.xml`,
|
2023-05-11 03:12:44 +02:00
|
|
|
{
|
|
|
|
encoding: 'utf8'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(stdoutResultTester(stdout)).toBe(true)
|
|
|
|
expect(stdout.includes("File 'tests/__data__/output/fr/1TV.com.xml' successfully saved")).toBe(
|
|
|
|
true
|
|
|
|
)
|
|
|
|
expect(
|
|
|
|
stdout.includes("File 'tests/__data__/output/undefined/2TV.com.xml' successfully saved")
|
|
|
|
).toBe(true)
|
|
|
|
})
|
|
|
|
|
2022-08-29 03:14:02 +02:00
|
|
|
it('removes duplicates of the program', () => {
|
2023-01-10 09:20:29 +01:00
|
|
|
const stdout = execSync(
|
2022-08-29 03:14:02 +02:00
|
|
|
`node ${pwd}/bin/epg-grabber.js \
|
|
|
|
--config=tests/__data__/input/duplicates.config.js \
|
|
|
|
--channels=tests/__data__/input/example.channels.xml \
|
2022-08-29 03:26:28 +02:00
|
|
|
--output=tests/__data__/output/duplicates.guide.xml`,
|
2022-08-29 03:14:02 +02:00
|
|
|
{
|
|
|
|
encoding: 'utf8'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2022-08-29 03:26:28 +02:00
|
|
|
let output = fs.readFileSync(path.resolve(__dirname, '__data__/output/duplicates.guide.xml'))
|
|
|
|
let expected = fs.readFileSync(path.resolve(__dirname, '__data__/expected/duplicates.guide.xml'))
|
|
|
|
|
|
|
|
output = epgParser.parse(output)
|
|
|
|
expected = epgParser.parse(expected)
|
|
|
|
|
|
|
|
expect(output.programs).toEqual(expected.programs)
|
2022-03-15 12:52:55 +01:00
|
|
|
})
|
2023-07-09 15:30:50 +02:00
|
|
|
|
|
|
|
it('can load multiple "channels.xml" files at once', () => {
|
|
|
|
const stdout = execSync(
|
|
|
|
`node ${pwd}/bin/epg-grabber.js --config=tests/__data__/input/example.config.js --channels=tests/__data__/input/example*.channels.xml --timeout=1`,
|
|
|
|
{
|
|
|
|
encoding: 'utf8'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(stdoutResultTester(stdout)).toBe(true)
|
|
|
|
})
|
2023-07-09 15:49:45 +02:00
|
|
|
|
|
|
|
it('can parse list of "channels.xml" from array', () => {
|
|
|
|
const stdout = execSync(
|
|
|
|
`node ${pwd}/bin/epg-grabber.js --config=tests/__data__/input/example_channels.config.js --timeout=1`,
|
|
|
|
{
|
|
|
|
encoding: 'utf8'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(stdoutResultTester(stdout)).toBe(true)
|
|
|
|
})
|