Minor changes to the tests

This commit is contained in:
freearhey 2025-01-07 19:24:50 +03:00
parent e1ffd61618
commit 3c858ecca9
6 changed files with 24 additions and 21 deletions

View file

@ -17,7 +17,7 @@ describe('api:generate', () => {
it('can generate guides.json', () => {
const cmd = `${ENV_VAR} npm run api:generate`
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(stdout)
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
expect(content('tests/__data__/output/guides.json')).toEqual(
content('tests/__data__/expected/guides.json')

View file

@ -8,6 +8,11 @@ type ExecError = {
stdout: string
}
let ENV_VAR = 'DATA_DIR=tests/__data__/input/temp/data'
if (os.platform() === 'win32') {
ENV_VAR = 'SET "DATA_DIR=tests/__data__/input/temp/data" &&'
}
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
fs.copySync(
@ -18,16 +23,12 @@ beforeEach(() => {
describe('channels:editor', () => {
it('shows list of options for a channel', () => {
let ENV_VAR = 'DATA_DIR=tests/__data__/input/temp/data'
if (os.platform() === 'win32') {
ENV_VAR = 'SET "DATA_DIR=tests/__data__/input/temp/data" &&'
}
try {
const cmd = `${ENV_VAR} npm run channels:editor --- tests/__data__/output/channels.xml`
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(stdout)
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
} catch (error) {
if (process.env.DEBUG === 'true') console.log(cmd, error)
expect((error as ExecError).status).toBe(1)
expect((error as ExecError).stdout).toContain('CNN International | CNNInternational.us [new]')
expect((error as ExecError).stdout).toContain(

View file

@ -10,7 +10,7 @@ describe('channels:lint', () => {
try {
const cmd = 'npm run channels:lint --- tests/__data__/input/channels-lint/error.channels.xml'
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(stdout)
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
@ -25,7 +25,7 @@ describe('channels:lint', () => {
const cmd =
'npm run channels:lint --- tests/__data__/input/channels-lint/invalid.channels.xml'
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(stdout)
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
@ -40,7 +40,7 @@ describe('channels:lint', () => {
const cmd =
'npm run channels:lint --- tests/__data__/input/channels-lint/error.channels.xml tests/__data__/input/channels-lint/invalid.channels.xml'
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(stdout)
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)

View file

@ -15,7 +15,7 @@ describe('channels:parse', () => {
const cmd =
'npm run channels:parse --- --config=tests/__data__/input/channels-parse/channels-parse.config.js --output=tests/__data__/output/channels.xml'
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(stdout)
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
expect(content('tests/__data__/output/channels.xml')).toEqual(
content('tests/__data__/expected/sites/channels-parse/channels-parse.channels.xml')

View file

@ -16,7 +16,7 @@ describe('channels:validate', () => {
try {
const cmd = `${ENV_VAR} npm run channels:validate --- --channels=tests/__data__/input/channels-validate/duplicate.channels.xml`
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(stdout)
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
@ -36,7 +36,7 @@ describe('channels:validate', () => {
try {
const cmd = `${ENV_VAR} npm run channels:validate --- --channels=tests/__data__/input/channels-validate/wrong_xmltv_id.channels.xml`
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(stdout)
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)

View file

@ -3,6 +3,13 @@ import fs from 'fs-extra'
import { pathToFileURL } from 'node:url'
import os from 'os'
let ENV_VAR =
'DOT_SITES_DIR=tests/__data__/output/.sites SITES_DIR=tests/__data__/input/sites-update/sites'
if (os.platform() === 'win32') {
ENV_VAR =
'SET "DOT_SITES_DIR=tests/__data__/output/.sites" && SET "SITES_DIR=tests/__data__/input/sites-update/sites" &&'
}
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
fs.mkdirSync('tests/__data__/output/.sites')
@ -17,15 +24,10 @@ beforeEach(() => {
})
it('can update SITES.md', () => {
let ENV_VAR =
'DOT_SITES_DIR=tests/__data__/output/.sites SITES_DIR=tests/__data__/input/sites-update/sites'
if (os.platform() === 'win32') {
ENV_VAR =
'SET "DOT_SITES_DIR=tests/__data__/output/.sites" && SET "SITES_DIR=tests/__data__/input/sites-update/sites" &&'
}
const cmd = `${ENV_VAR} npm run sites:update`
const stdout = execSync(`${ENV_VAR} npm run sites:update`, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(stdout)
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
expect(content('tests/__data__/output/sites.md')).toEqual(
content('tests/__data__/expected/_sites.md')