mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 08:30:06 -04:00
Create init.test.ts
This commit is contained in:
parent
89bc036b01
commit
6285025a53
1 changed files with 45 additions and 0 deletions
45
tests/commands/sites/init.test.ts
Normal file
45
tests/commands/sites/init.test.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { execSync } from 'child_process'
|
||||
import fs from 'fs-extra'
|
||||
import os from 'os'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
|
||||
let ENV_VAR = 'SITES_DIR=tests/__data__/output/sites'
|
||||
if (os.platform() === 'win32') {
|
||||
ENV_VAR = 'SET "SITES_DIR=tests/__data__/output/sites" &&'
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
fs.mkdirSync('tests/__data__/output/sites')
|
||||
})
|
||||
|
||||
it('can create new site config from template', () => {
|
||||
const cmd = `${ENV_VAR} npm run sites:init --- example.com`
|
||||
|
||||
const stdout = execSync(cmd, { encoding: 'utf8' })
|
||||
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
|
||||
|
||||
expect(exists('tests/__data__/output/sites/example.com')).toBe(true)
|
||||
expect(exists('tests/__data__/output/sites/example.com/example.com.test.js')).toBe(true)
|
||||
expect(exists('tests/__data__/output/sites/example.com/example.com.config.js')).toBe(true)
|
||||
expect(exists('tests/__data__/output/sites/example.com/readme.md')).toBe(true)
|
||||
expect(content('tests/__data__/output/sites/example.com/example.com.test.js')).toEqual(
|
||||
content('tests/__data__/expected/sites/sites-init/example.com.test.js')
|
||||
)
|
||||
expect(content('tests/__data__/output/sites/example.com/example.com.config.js')).toEqual(
|
||||
content('tests/__data__/expected/sites/sites-init/example.com.config.js')
|
||||
)
|
||||
expect(content('tests/__data__/output/sites/example.com/readme.md')).toEqual(
|
||||
content('tests/__data__/expected/sites/sites-init/readme.md')
|
||||
)
|
||||
})
|
||||
|
||||
function content(filepath: string) {
|
||||
return fs.readFileSync(pathToFileURL(filepath), {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
}
|
||||
|
||||
function exists(filepath: string) {
|
||||
return fs.existsSync(pathToFileURL(filepath))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue