diff --git a/tests/commands/channels/editor.test.ts b/tests/commands/channels/editor.test.ts index 8499eb03..2db6ebd3 100644 --- a/tests/commands/channels/editor.test.ts +++ b/tests/commands/channels/editor.test.ts @@ -1,5 +1,6 @@ import fs from 'fs-extra' import { execSync } from 'child_process' +import os from 'os' beforeEach(() => { fs.emptyDirSync('tests/__data__/output') @@ -11,12 +12,13 @@ beforeEach(() => { describe('channels:editor', () => { it('shows list of options for a channel', () => { - const stdout = execSync( - 'DATA_DIR=tests/__data__/input/temp/data npm run channels:editor -- tests/__data__/output/channels.xml', - { - encoding: 'utf8' - } - ) + let ENV_VAR = 'DATA_DIR=tests/__data__/input/temp/data' + if (os.platform() === 'win32') { + ENV_VAR = 'SET "DATA_DIR=tests/__data__/input/temp/data" &&' + } + + const cmd = `${ENV_VAR} npm run channels:editor -- tests/__data__/output/channels.xml` + const stdout = execSync(cmd, { encoding: 'utf8' }) expect(stdout).toContain('CNN International | CNNInternational.us [new]') expect(stdout).toContain('CNN International Europe | CNNInternationalEurope.us [api]') diff --git a/tests/commands/channels/lint.test.ts b/tests/commands/channels/lint.test.ts index 794cad23..0aab10c2 100644 --- a/tests/commands/channels/lint.test.ts +++ b/tests/commands/channels/lint.test.ts @@ -8,13 +8,9 @@ type ExecError = { describe('channels:lint', () => { it('will show a message if the file contains a syntax error', () => { try { - const stdout = execSync( - 'npm run channels:lint -- --channels=tests/__data__/input/channels-lint/channels-lint.channels.xml', - { - encoding: 'utf8' - } - ) - console.log(stdout) + const cmd = + 'npm run channels:lint -- --channels=tests/__data__/input/channels-lint/channels-lint.channels.xml' + execSync(cmd, { encoding: 'utf8' }) 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 3c1aa4e7..83d91d7a 100644 --- a/tests/commands/channels/parse.test.ts +++ b/tests/commands/channels/parse.test.ts @@ -12,10 +12,9 @@ beforeEach(() => { describe('channels:parse', () => { it('can parse channels', () => { - execSync( - 'npm run channels:parse -- --config=tests/__data__/input/channels-parse/channels-parse.config.js --output=tests/__data__/output/channels.xml', - { encoding: 'utf8' } - ) + const cmd = + 'npm run channels:parse -- --config=tests/__data__/input/channels-parse/channels-parse.config.js --output=tests/__data__/output/channels.xml' + execSync(cmd, { encoding: 'utf8' }) expect(content('tests/__data__/output/channels.xml')).toEqual( content('tests/__data__/expected/sites/channels-parse/channels-parse.channels.xml') @@ -23,10 +22,9 @@ describe('channels:parse', () => { }) it('can parse channels with clean flag', () => { - execSync( - 'npm run channels:parse -- --config=tests/__data__/input/channels-parse/channels-parse.config.js --output=tests/__data__/output/channels.xml --clean', - { encoding: 'utf8' } - ) + const cmd = + 'npm run channels:parse -- --config=tests/__data__/input/channels-parse/channels-parse.config.js --output=tests/__data__/output/channels.xml --clean' + execSync(cmd, { encoding: 'utf8' }) expect(content('tests/__data__/output/channels.xml')).toEqual( content('tests/__data__/expected/sites/channels-parse/channels-parse-clean.channels.xml') diff --git a/tests/commands/channels/validate.test.ts b/tests/commands/channels/validate.test.ts index 635e6164..d7a4946f 100644 --- a/tests/commands/channels/validate.test.ts +++ b/tests/commands/channels/validate.test.ts @@ -1,20 +1,21 @@ import { execSync } from 'child_process' +import os from 'os' type ExecError = { status: number 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" &&' +} + describe('channels:validate', () => { it('will show a message if the file contains a duplicate', () => { try { - const stdout = execSync( - 'DATA_DIR=tests/__data__/input/temp/data npm run channels:validate -- --channels=tests/__data__/input/channels-validate/duplicate.channels.xml', - { - encoding: 'utf8' - } - ) - console.log(stdout) + const cmd = `${ENV_VAR} npm run channels:validate -- --channels=tests/__data__/input/channels-validate/duplicate.channels.xml` + execSync(cmd, { encoding: 'utf8' }) process.exit(1) } catch (error) { expect((error as ExecError).status).toBe(1) @@ -33,13 +34,8 @@ describe('channels:validate', () => { it('will show a message if the file contains a channel with wrong xmltv_id', () => { try { - const stdout = execSync( - 'DATA_DIR=tests/__data__/input/temp/data npm run channels:validate -- --channels=tests/__data__/input/channels-validate/wrong_xmltv_id.channels.xml', - { - encoding: 'utf8' - } - ) - console.log(stdout) + const cmd = `${ENV_VAR} npm run channels:validate -- --channels=tests/__data__/input/channels-validate/wrong_xmltv_id.channels.xml` + execSync(cmd, { encoding: 'utf8' }) process.exit(1) } catch (error) { expect((error as ExecError).status).toBe(1)