From 3c858ecca9c47589fc7f5ed689de97efbf46fcd0 Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:24:50 +0300 Subject: [PATCH] Minor changes to the tests --- tests/commands/api/generate.test.ts | 2 +- tests/commands/channels/editor.test.ts | 13 +++++++------ tests/commands/channels/lint.test.ts | 6 +++--- tests/commands/channels/parse.test.ts | 2 +- tests/commands/channels/validate.test.ts | 4 ++-- tests/commands/sites/update.test.ts | 18 ++++++++++-------- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/tests/commands/api/generate.test.ts b/tests/commands/api/generate.test.ts index f37d16a0..1480ac59 100644 --- a/tests/commands/api/generate.test.ts +++ b/tests/commands/api/generate.test.ts @@ -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') diff --git a/tests/commands/channels/editor.test.ts b/tests/commands/channels/editor.test.ts index 3d5ab81a..0c001df5 100644 --- a/tests/commands/channels/editor.test.ts +++ b/tests/commands/channels/editor.test.ts @@ -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( diff --git a/tests/commands/channels/lint.test.ts b/tests/commands/channels/lint.test.ts index 0c2ace78..2ba65d80 100644 --- a/tests/commands/channels/lint.test.ts +++ b/tests/commands/channels/lint.test.ts @@ -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) diff --git a/tests/commands/channels/parse.test.ts b/tests/commands/channels/parse.test.ts index 24ed5a22..6c9fa113 100644 --- a/tests/commands/channels/parse.test.ts +++ b/tests/commands/channels/parse.test.ts @@ -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') diff --git a/tests/commands/channels/validate.test.ts b/tests/commands/channels/validate.test.ts index b12cc317..d4d3b039 100644 --- a/tests/commands/channels/validate.test.ts +++ b/tests/commands/channels/validate.test.ts @@ -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) diff --git a/tests/commands/sites/update.test.ts b/tests/commands/sites/update.test.ts index 3446e28d..0af18d4c 100644 --- a/tests/commands/sites/update.test.ts +++ b/tests/commands/sites/update.test.ts @@ -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')