Create subfolders for commands
This commit is contained in:
41
tests/commands/playlist/generate.test.js
Normal file
41
tests/commands/playlist/generate.test.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const { execSync } = require('child_process')
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
const glob = require('glob')
|
||||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
fs.copyFileSync(
|
||||
'tests/__data__/input/database/playlist-generate.streams.db',
|
||||
'tests/__data__/output/streams.db'
|
||||
)
|
||||
|
||||
const stdout = execSync(
|
||||
'DB_DIR=tests/__data__/output DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output/.gh-pages LOGS_DIR=tests/__data__/output/logs/generators node --trace-warnings scripts/commands/playlist/generate.js',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate playlists and logs', () => {
|
||||
const playlists = glob
|
||||
.sync('tests/__data__/expected/.gh-pages/**/*.m3u')
|
||||
.map(f => f.replace('tests/__data__/expected/', ''))
|
||||
|
||||
playlists.forEach(filepath => {
|
||||
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
|
||||
})
|
||||
|
||||
const logs = glob
|
||||
.sync('tests/__data__/expected/logs/generators/*.log')
|
||||
.map(f => f.replace('tests/__data__/expected/', ''))
|
||||
|
||||
logs.forEach(filepath => {
|
||||
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
|
||||
})
|
||||
})
|
||||
|
||||
function content(filepath) {
|
||||
return fs.readFileSync(`tests/__data__/${filepath}`, {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
}
|
||||
29
tests/commands/playlist/update.test.js
Normal file
29
tests/commands/playlist/update.test.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
const glob = require('glob')
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
fs.copyFileSync('tests/__data__/input/database/streams.db', 'tests/__data__/output/streams.db')
|
||||
|
||||
const stdout = execSync('DB_DIR=tests/__data__/output node scripts/commands/playlist/update.js', {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
})
|
||||
|
||||
it('can update playlists', () => {
|
||||
const files = glob
|
||||
.sync('tests/__data__/expected/channels/*.m3u')
|
||||
.map(f => f.replace('tests/__data__/expected/', ''))
|
||||
|
||||
files.forEach(filepath => {
|
||||
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
|
||||
})
|
||||
})
|
||||
|
||||
function content(filepath) {
|
||||
return fs.readFileSync(`tests/__data__/${filepath}`, {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
}
|
||||
30
tests/commands/playlist/validate.test.js
Normal file
30
tests/commands/playlist/validate.test.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
it('show error if channel name in the blocklist', () => {
|
||||
try {
|
||||
execSync(
|
||||
'DATA_DIR=tests/__data__/input/data node scripts/commands/playlist/validate.js tests/__data__/input/channels/us_blocked.m3u',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
} catch (err) {
|
||||
expect(err.status).toBe(1)
|
||||
expect(err.stdout).toBe(
|
||||
`\ntests/__data__/input/channels/us_blocked.m3u\n 2 error "Fox Sports" is on the blocklist due to claims of copyright holders (https://github.com/github/dmca/blob/master/2020/09/2020-09-16-dfl.md)\n\n1 problems (1 errors, 0 warnings)\n`
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('show warning if channel has wrong id', () => {
|
||||
const stdout = execSync(
|
||||
'DATA_DIR=tests/__data__/input/data node scripts/commands/playlist/validate.js tests/__data__/input/channels/wrong_id.m3u',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
|
||||
expect(stdout).toBe(
|
||||
`\ntests/__data__/input/channels/wrong_id.m3u\n 2 warning "qib22lAq1L.us" is not in the database\n\n1 problems (0 errors, 1 warnings)\n`
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user