From c8055f10d609b3e20e8afdd9ead008696ab05339 Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Sun, 5 Jan 2025 19:02:24 +0300 Subject: [PATCH] Add "debug" mode to tests --- tests/commands/api/generate.test.ts | 3 ++- tests/commands/channels/editor.test.ts | 3 ++- tests/commands/channels/lint.test.ts | 9 ++++++--- tests/commands/channels/parse.test.ts | 3 ++- tests/commands/channels/validate.test.ts | 18 ++++-------------- tests/commands/epg/grab.test.ts | 19 +++++++++++++------ tests/commands/sites/update.test.ts | 3 ++- 7 files changed, 31 insertions(+), 27 deletions(-) diff --git a/tests/commands/api/generate.test.ts b/tests/commands/api/generate.test.ts index ab6a3ee7..b1fbb67d 100644 --- a/tests/commands/api/generate.test.ts +++ b/tests/commands/api/generate.test.ts @@ -16,7 +16,8 @@ beforeEach(() => { describe('api:generate', () => { it('can generate guides.json', () => { const cmd = `${ENV_VAR} npm run api:generate` - execSync(cmd, { encoding: 'utf8' }) + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(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 271014f0..9c03ba6d 100644 --- a/tests/commands/channels/editor.test.ts +++ b/tests/commands/channels/editor.test.ts @@ -25,7 +25,8 @@ describe('channels:editor', () => { try { const cmd = `${ENV_VAR} npm run channels:editor --- tests/__data__/output/channels.xml` - execSync(cmd, { encoding: 'utf8' }) + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(stdout) } catch (error) { expect((error as ExecError).status).toBe(1) expect((error as ExecError).stdout).toContain('CNN International | CNNInternational.us [new]') diff --git a/tests/commands/channels/lint.test.ts b/tests/commands/channels/lint.test.ts index d7d8e2c0..0c2ace78 100644 --- a/tests/commands/channels/lint.test.ts +++ b/tests/commands/channels/lint.test.ts @@ -9,7 +9,8 @@ describe('channels:lint', () => { it('will show a message if the file contains a syntax error', () => { try { const cmd = 'npm run channels:lint --- tests/__data__/input/channels-lint/error.channels.xml' - execSync(cmd, { encoding: 'utf8' }) + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(stdout) process.exit(1) } catch (error) { expect((error as ExecError).status).toBe(1) @@ -23,7 +24,8 @@ describe('channels:lint', () => { try { const cmd = 'npm run channels:lint --- tests/__data__/input/channels-lint/invalid.channels.xml' - execSync(cmd, { encoding: 'utf8' }) + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(stdout) process.exit(1) } catch (error) { expect((error as ExecError).status).toBe(1) @@ -37,7 +39,8 @@ describe('channels:lint', () => { try { const cmd = 'npm run channels:lint --- tests/__data__/input/channels-lint/error.channels.xml tests/__data__/input/channels-lint/invalid.channels.xml' - execSync(cmd, { encoding: 'utf8' }) + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(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 5ca5ad87..3f52de37 100644 --- a/tests/commands/channels/parse.test.ts +++ b/tests/commands/channels/parse.test.ts @@ -14,7 +14,8 @@ describe('channels:parse', () => { it('can parse channels', () => { 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' }) + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(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 dfb1e907..b12cc317 100644 --- a/tests/commands/channels/validate.test.ts +++ b/tests/commands/channels/validate.test.ts @@ -15,17 +15,12 @@ describe('channels:validate', () => { it('will show a message if the file contains a duplicate', () => { try { const cmd = `${ENV_VAR} npm run channels:validate --- --channels=tests/__data__/input/channels-validate/duplicate.channels.xml` - execSync(cmd, { encoding: 'utf8' }) + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(stdout) process.exit(1) } catch (error) { expect((error as ExecError).status).toBe(1) expect((error as ExecError).stdout).toContain(` -> channels:validate -> npx tsx scripts/commands/channels/validate.ts --channels=tests/__data__/input/channels-validate/duplicate.channels.xml - -options: - channels: tests/__data__/input/channels-validate/duplicate.channels.xml -tests/__data__/input/channels-validate/duplicate.channels.xml ┌─────────┬─────────────┬──────┬────────────────┬─────────┬─────────┐ │ (index) │ type │ lang │ xmltv_id │ site_id │ name │ ├─────────┼─────────────┼──────┼────────────────┼─────────┼─────────┤ @@ -40,17 +35,12 @@ tests/__data__/input/channels-validate/duplicate.channels.xml it('will show a message if the file contains a channel with wrong xmltv_id', () => { try { const cmd = `${ENV_VAR} npm run channels:validate --- --channels=tests/__data__/input/channels-validate/wrong_xmltv_id.channels.xml` - execSync(cmd, { encoding: 'utf8' }) + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(stdout) process.exit(1) } catch (error) { expect((error as ExecError).status).toBe(1) expect((error as ExecError).stdout).toContain(` -> channels:validate -> npx tsx scripts/commands/channels/validate.ts --channels=tests/__data__/input/channels-validate/wrong_xmltv_id.channels.xml - -options: - channels: tests/__data__/input/channels-validate/wrong_xmltv_id.channels.xml -tests/__data__/input/channels-validate/wrong_xmltv_id.channels.xml ┌─────────┬──────────────────┬──────┬────────────────────┬─────────┬─────────────────────┐ │ (index) │ type │ lang │ xmltv_id │ site_id │ name │ ├─────────┼──────────────────┼──────┼────────────────────┼─────────┼─────────────────────┤ diff --git a/tests/commands/epg/grab.test.ts b/tests/commands/epg/grab.test.ts index 1c5be77e..c28257f9 100644 --- a/tests/commands/epg/grab.test.ts +++ b/tests/commands/epg/grab.test.ts @@ -20,7 +20,8 @@ describe('epg:grab', () => { const cmd = `${ENV_VAR} npm run grab --- --site=example.com --output=${path.resolve( 'tests/__data__/output/guide.xml' )}` - execSync(cmd, { encoding: 'utf8' }) + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(stdout) expect(content('tests/__data__/output/guide.xml')).toEqual( content('tests/__data__/expected/guide2.xml') @@ -29,7 +30,8 @@ describe('epg:grab', () => { it('can grab epg with multiple channels.xml files', () => { const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg-grab/sites/**/*.channels.xml --output=tests/__data__/output/guide.xml` - execSync(cmd, { encoding: 'utf8' }) + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(stdout) expect(content('tests/__data__/output/guide.xml')).toEqual( content('tests/__data__/expected/guide.xml') @@ -40,7 +42,8 @@ describe('epg:grab', () => { const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg-grab/sites/**/*.channels.xml --output=${path.resolve( 'tests/__data__/output/guide.xml' )} --gzip` - execSync(cmd, { encoding: 'utf8' }) + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(stdout) expect(content('tests/__data__/output/guide.xml')).toEqual( content('tests/__data__/expected/guide.xml') @@ -54,7 +57,8 @@ describe('epg:grab', () => { it('can grab epg with wildcard as output', () => { const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg-grab/sites/example.com/example.com.channels.xml --output=tests/__data__/output/guides/{lang}/{site}.xml` - execSync(cmd, { encoding: 'utf8' }) + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(stdout) expect(content('tests/__data__/output/guides/en/example.com.xml')).toEqual( content('tests/__data__/expected/guides/en/example.com.xml') @@ -67,7 +71,8 @@ describe('epg:grab', () => { it('can grab epg then language filter enabled', () => { const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg-grab/sites/example.com/example.com.channels.xml --output=tests/__data__/output/guides/{lang}/{site}.xml --lang=fr` - execSync(cmd, { encoding: 'utf8' }) + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(stdout) expect(content('tests/__data__/output/guides/fr/example.com.xml')).toEqual( content('tests/__data__/expected/guides/fr/example.com.xml') @@ -76,7 +81,8 @@ describe('epg:grab', () => { it('can grab epg using custom channels list', () => { const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg-grab/custom.channels.xml --output=tests/__data__/output/guide.xml` - execSync(cmd, { encoding: 'utf8' }) + const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(stdout) expect(content('tests/__data__/output/guide.xml')).toEqual( content('tests/__data__/expected/guide.xml') @@ -86,6 +92,7 @@ describe('epg:grab', () => { it('it will raise an error if the timeout is exceeded', () => { const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg-grab/custom.channels.xml --output=tests/__data__/output/guide.xml --timeout=0` const stdout = execSync(cmd, { encoding: 'utf8' }) + if (process.env.DEBUG === 'true') console.log(stdout) expect(stdout).toContain('ERR: Connection timeout') }) diff --git a/tests/commands/sites/update.test.ts b/tests/commands/sites/update.test.ts index 2ecbea5e..ee8ad331 100644 --- a/tests/commands/sites/update.test.ts +++ b/tests/commands/sites/update.test.ts @@ -16,12 +16,13 @@ beforeEach(() => { }) it('can update SITES.md', () => { - execSync( + const stdout = execSync( 'DOT_SITES_DIR=tests/__data__/output/.sites SITES_DIR=tests/__data__/input/sites-update/sites npm run sites:update', { encoding: 'utf8' } ) + if (process.env.DEBUG === 'true') console.log(stdout) expect(content('tests/__data__/output/sites.md')).toEqual( content('tests/__data__/expected/_sites.md')