epg-grabber/tests/bin.test.js

84 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-10-05 23:39:01 +02:00
const { execSync } = require('child_process')
2022-08-29 03:14:02 +02:00
const fs = require('fs')
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)
})
}
it('can load config', () => {
const result = 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'
}
)
expect(stdoutResultTester(result)).toBe(true)
})
it('can load mini config', () => {
const result = execSync(
`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'
}
)
expect(stdoutResultTester(result)).toBe(true)
2022-08-29 03:14:02 +02:00
expect(result.includes("File 'tests/__data__/output/mini.guide.xml' successfully saved")).toBe(
true
)
2021-10-05 23:39:01 +02:00
})
2022-03-15 12:52:55 +01:00
it('can generate gzip version', () => {
const result = execSync(
`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'
}
)
expect(stdoutResultTester(result)).toBe(true)
2022-08-29 03:14:02 +02:00
expect(result.includes("File 'tests/__data__/output/mini.guide.xml.gz' successfully saved")).toBe(
true
)
})
it('removes duplicates of the program', () => {
const result = execSync(
`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
})