From fa9cdcff4864c8304b1ee6a8e30de8e8bfc78e5a Mon Sep 17 00:00:00 2001 From: Christian Dangl Date: Thu, 1 Feb 2024 23:09:13 +0100 Subject: [PATCH] add support for process.env --- CHANGELOG.md | 1 + README.md | 24 +- src/services/ConfigService.js | 15 + tests/Jest/services/ConfigService.spec.js | 1044 ++++++++++++--------- 4 files changed, 606 insertions(+), 478 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eed7140..a9df768 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. - Added description to README how to use an **Api Key** instead of the user password. - Added documentation on how to use **Cucumber** and **Gherkin documents** with the integration. +- Added support for **process.env** variables. All configuration settings will now also consider entries in process.env. ### Fixed diff --git a/README.md b/README.md index 8539bbd..50c12e2 100644 --- a/README.md +++ b/README.md @@ -11,21 +11,23 @@ This integration helps you to automatically send test results to TestRail. And y Add your TestRail credentials in Cypress, decide which test results should be sent to TestRail and you're done! - * [1. Installation](#1-installation) - * [2. Setup Wizard](#2-setup-wizard) - * [3. Execution Modes](#3-execution-modes) + +* [1. Installation](#1-installation) +* [2. Setup Wizard](#2-setup-wizard) +* [3. Execution Modes](#3-execution-modes) * [3.1 Mode A: Send results to one or more runs in TestRail](#31-mode-a-send-results-to-one-or-more-runs-in-testrail) * [3.2 Mode B: Create new Run in TestRail for every Cypress run](#32-mode-b-create-new-run-in-testrail-for-every-cypress-run) - * [4. Register Plugin](#4-register-plugin) - * [5. Map Test Cases](#5-map-test-cases) - * [6. Advanced Features](#6-advanced-features) +* [4. Register Plugin](#4-register-plugin) +* [5. Map Test Cases](#5-map-test-cases) +* [6. Advanced Features](#6-advanced-features) * [6.1 Sending Screenshots on failures](#61-sending-screenshots-on-failures) * [6.2 Using multiple Cypress plugins](#62-using-multiple-cypress-plugins) * [6.3 Cucumber Gherkin Support](#63-cucumber-gherkin-support) - * [7. Variables](#7-variables) +* [7. Variables](#7-variables) * [7.1 Use on CLI](#71-use-on-cli) * [7.2 Use in cypress.env.json](#72-use-in-cypressenvjson) - * [8. Copying / License](#8-copying--license) +* [8. Copying / License](#8-copying--license) + ### 1. Installation @@ -50,7 +52,7 @@ Run it with this command and enter your data: Please copy the displayed JSON structure of that command to your `cypress.env.json` file. -You can of course also build such a JSON manually. In addition to this, you can also use ENV variables. Please see the section on variables below for more. +You can of course also build such a JSON manually. In addition to this, you can also use ENV variables or process.env variables. Please see the section on variables below for more. Here is a sample of a JSON from the CLI command. @@ -192,7 +194,6 @@ This will send all failed screenshots of all attempts in Cypress to TestRail. } ``` - #### 6.2 Using multiple Cypress plugins Let's start with the most important thing: The problem with the Cypress event listeners. @@ -262,7 +263,6 @@ module.exports = defineConfig({ That's it! When you now run tests based on Gherkin documents, the TestRail integration will automatically send the results to TestRail. - ### 7. Variables This is a list of all available variables and their explanation. @@ -272,7 +272,7 @@ You can use all variables in both scopes. Examples on how to use it are below the list. -| ENV | JSON | Required | Description | +| ENV / process.env | JSON | Required | Description | |----------------------------------|-------------------------|-----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | CYPRESS_TESTRAIL_DOMAIN | testrail.domain | yes | TestRail domain | | CYPRESS_TESTRAIL_USERNAME | testrail.username | yes | TestRail username | diff --git a/src/services/ConfigService.js b/src/services/ConfigService.js index caa39cd..98dbd0c 100644 --- a/src/services/ConfigService.js +++ b/src/services/ConfigService.js @@ -229,6 +229,8 @@ class ConfigService { value = this.config[keyCLI]; } else if (this.config.testrail !== undefined && this.config.testrail !== null) { value = this.config.testrail[keyJSON]; + } else if (process.env !== undefined && process.env !== null) { + value = process.env[keyCLI]; } if (value === undefined || value === null || value === '') { @@ -265,6 +267,17 @@ class ConfigService { } } else if (this.config.testrail !== undefined && this.config.testrail !== null) { value = this.config.testrail[keyJSON]; + } else if (process.env !== undefined && process.env !== null) { + const tmpString = process.env[keyCLI]; + + // if we have a value, then try to split it + if (tmpString !== undefined && tmpString !== null && tmpString !== '') { + if (tmpString.toString().indexOf(',') !== -1) { + value = tmpString.split(','); + } else { + value = [tmpString]; + } + } } if (value === undefined || value === null || value === '') { @@ -292,6 +305,8 @@ class ConfigService { value = this.config[keyCLI]; } else if (this.config.testrail !== undefined && this.config.testrail !== null) { value = this.config.testrail[keyJSON]; + } else if (process.env !== undefined && process.env !== null) { + value = process.env[keyCLI]; } if (value === undefined || value === null || value === '') { diff --git a/tests/Jest/services/ConfigService.spec.js b/tests/Jest/services/ConfigService.spec.js index e64eb91..c36b74b 100644 --- a/tests/Jest/services/ConfigService.spec.js +++ b/tests/Jest/services/ConfigService.spec.js @@ -1,665 +1,777 @@ import ConfigService from '../../../src/services/ConfigService'; -describe('TestRail Domain', () => { - describe('.env file', () => { - test('TestRailDomain from .env file with NULL config', () => { - const config = new ConfigService(null); - expect(config.getDomain()).toBe(''); +describe('ConfigService', () => { + beforeEach(() => { + process.env = []; + }); + + describe('TestRail Domain', () => { + describe('.env file', () => { + test('TestRailDomain from .env file with NULL config', () => { + const config = new ConfigService(null); + expect(config.getDomain()).toBe(''); + }); + + test('TestRailDomain from .env file', () => { + const config = new ConfigService({ + testrail: { + domain: 'my-domain', + }, + }); + expect(config.getDomain()).toBe('my-domain'); + }); + + test('TestRailDomain from .env file with NULL domain', () => { + const config = new ConfigService({ + testrail: { + domain: null, + }, + }); + expect(config.getDomain()).toBe(''); + }); + + test('TestRailDomain from .env file not existing', () => { + const config = new ConfigService({ + testrail: {}, + }); + expect(config.getDomain()).toBe(''); + }); }); - test('TestRailDomain from .env file', () => { - const config = new ConfigService({ - testrail: { - domain: 'my-domain', - }, + describe('ENV variable', () => { + test('TestRailDomain from ENV', () => { + const config = new ConfigService({ + TESTRAIL_DOMAIN: 'my-domain', + }); + expect(config.getDomain()).toBe('my-domain'); }); - expect(config.getDomain()).toBe('my-domain'); }); - test('TestRailDomain from .env file with NULL domain', () => { - const config = new ConfigService({ - testrail: { - domain: null, - }, + describe('process.env', () => { + test('TestRailDomain from process.env', () => { + process.env.TESTRAIL_DOMAIN = 'my-domain'; + const config = new ConfigService({}); + expect(config.getDomain()).toBe('my-domain'); }); - expect(config.getDomain()).toBe(''); }); - test('TestRailDomain from .env file not existing', () => { + test('Leading http:// is removed from TestRail domain', () => { const config = new ConfigService({ - testrail: {}, + TESTRAIL_DOMAIN: 'http://my-domain', }); - expect(config.getDomain()).toBe(''); + expect(config.getDomain()).toBe('my-domain'); }); - }); - describe('ENV variable', () => { - test('TestRailDomain from ENV', () => { + test('Leading https:// is removed from TestRail domain', () => { const config = new ConfigService({ - TESTRAIL_DOMAIN: 'my-domain', + TESTRAIL_DOMAIN: 'https://my-domain', }); expect(config.getDomain()).toBe('my-domain'); }); }); - test('Leading http:// is removed from TestRail domain', () => { - const config = new ConfigService({ - TESTRAIL_DOMAIN: 'http://my-domain', - }); - expect(config.getDomain()).toBe('my-domain'); - }); + describe('TestRail Username', () => { + describe('.env file', () => { + test('TestRailUsername from .env file', () => { + const config = new ConfigService({ + testrail: { + username: 'user123', + }, + }); + expect(config.getUsername()).toBe('user123'); + }); - test('Leading https:// is removed from TestRail domain', () => { - const config = new ConfigService({ - TESTRAIL_DOMAIN: 'https://my-domain', - }); - expect(config.getDomain()).toBe('my-domain'); - }); -}); + test('TestRailUsername from ENV with NULL config', () => { + const config = new ConfigService(null); + expect(config.getUsername()).toBe(''); + }); -describe('TestRail Username', () => { - describe('.env file', () => { - test('TestRailUsername from .env file', () => { - const config = new ConfigService({ - testrail: { - username: 'user123', - }, + test('TestRailUsername from .env file not existing', () => { + const config = new ConfigService({ + testrail: {}, + }); + expect(config.getUsername()).toBe(''); }); - expect(config.getUsername()).toBe('user123'); }); - test('TestRailUsername from ENV with NULL config', () => { - const config = new ConfigService(null); - expect(config.getUsername()).toBe(''); + describe('ENV variable', () => { + test('TestRailUsername from ENV', () => { + const config = new ConfigService({ + TESTRAIL_USERNAME: 'user123', + }); + expect(config.getUsername()).toBe('user123'); + }); }); - test('TestRailUsername from .env file not existing', () => { - const config = new ConfigService({ - testrail: {}, + describe('process.env', () => { + test('TestRailUsername from process.env', () => { + process.env.TESTRAIL_USERNAME = 'user123'; + const config = new ConfigService({}); + expect(config.getUsername()).toBe('user123'); }); - expect(config.getUsername()).toBe(''); }); }); - describe('ENV variable', () => { - test('TestRailUsername from ENV', () => { - const config = new ConfigService({ - TESTRAIL_USERNAME: 'user123', + describe('TestRail Password', () => { + describe('.env file', () => { + test('TestRailPassword from .env file', () => { + const config = new ConfigService({ + testrail: { + password: 'P123', + }, + }); + expect(config.getPassword()).toBe('P123'); }); - expect(config.getUsername()).toBe('user123'); - }); - }); -}); -describe('TestRail Password', () => { - describe('.env file', () => { - test('TestRailPassword from .env file', () => { - const config = new ConfigService({ - testrail: { - password: 'P123', - }, + test('TestRailPassword from .env file with NULL config', () => { + const config = new ConfigService(null); + expect(config.getPassword()).toBe(''); }); - expect(config.getPassword()).toBe('P123'); - }); - test('TestRailPassword from .env file with NULL config', () => { - const config = new ConfigService(null); - expect(config.getPassword()).toBe(''); + test('TestRailPassword from .env file not existing', () => { + const config = new ConfigService({ + testrail: {}, + }); + expect(config.getPassword()).toBe(''); + }); }); - test('TestRailPassword from .env file not existing', () => { - const config = new ConfigService({ - testrail: {}, + describe('ENV variable', () => { + test('TestRailPassword from ENV', () => { + const config = new ConfigService({ + TESTRAIL_PASSWORD: 'P123', + }); + expect(config.getPassword()).toBe('P123'); }); - expect(config.getPassword()).toBe(''); }); - }); - describe('ENV variable', () => { - test('TestRailPassword from ENV', () => { - const config = new ConfigService({ - TESTRAIL_PASSWORD: 'P123', + describe('process.env', () => { + test('TestRailPassword from process.env', () => { + process.env.TESTRAIL_PASSWORD = 'P123'; + const config = new ConfigService({}); + expect(config.getPassword()).toBe('P123'); }); - expect(config.getPassword()).toBe('P123'); }); }); -}); -describe('ProjectID', () => { - describe('.env file', () => { - test('ProjectID from .env file', () => { - const config = new ConfigService({ - testrail: { - projectId: '123', - }, + describe('ProjectID', () => { + describe('.env file', () => { + test('ProjectID from .env file', () => { + const config = new ConfigService({ + testrail: { + projectId: '123', + }, + }); + expect(config.getProjectId()).toBe('123'); }); - expect(config.getProjectId()).toBe('123'); - }); - test('ProjectID from .env file with leading P', () => { - const config = new ConfigService({ - testrail: { - projectId: 'P123', - }, + test('ProjectID from .env file with leading P', () => { + const config = new ConfigService({ + testrail: { + projectId: 'P123', + }, + }); + expect(config.getProjectId()).toBe('123'); }); - expect(config.getProjectId()).toBe('123'); - }); - test('ProjectID from .env file with whitespaces', () => { - const config = new ConfigService({ - testrail: { - projectId: ' 123 ', - }, + test('ProjectID from .env file with whitespaces', () => { + const config = new ConfigService({ + testrail: { + projectId: ' 123 ', + }, + }); + expect(config.getProjectId()).toBe('123'); }); - expect(config.getProjectId()).toBe('123'); - }); - test('ProjectID from .env as INT', () => { - const config = new ConfigService({ - testrail: { - projectId: 123, - }, + test('ProjectID from .env as INT', () => { + const config = new ConfigService({ + testrail: { + projectId: 123, + }, + }); + expect(config.getProjectId()).toBe('123'); + }); + + test('ProjectID from .env is not existing', () => { + const config = new ConfigService({ + testrail: {}, + }); + expect(config.getProjectId()).toBe(''); }); - expect(config.getProjectId()).toBe('123'); }); - test('ProjectID from .env is not existing', () => { - const config = new ConfigService({ - testrail: {}, + describe('ENV variable', () => { + test('ProjectID from ENV variable as INT', () => { + const config = new ConfigService({ + TESTRAIL_PROJECT_ID: 45, + }); + expect(config.getProjectId()).toBe('45'); }); - expect(config.getProjectId()).toBe(''); }); - }); - describe('ENV variable', () => { - test('ProjectID from ENV variable as INT', () => { - const config = new ConfigService({ - TESTRAIL_PROJECT_ID: 45, + describe('process.env', () => { + test('ProjectID from process.env', () => { + process.env.TESTRAIL_PROJECT_ID = 45; + const config = new ConfigService({}); + expect(config.getProjectId()).toBe('45'); }); - expect(config.getProjectId()).toBe('45'); }); }); -}); -describe('MilestoneID', () => { - describe('.env file', () => { - test('MilestoneID from .env', () => { - const config = new ConfigService({ - testrail: { - milestoneId: '123', - }, + describe('MilestoneID', () => { + describe('.env file', () => { + test('MilestoneID from .env', () => { + const config = new ConfigService({ + testrail: { + milestoneId: '123', + }, + }); + expect(config.getMilestoneId()).toBe('123'); }); - expect(config.getMilestoneId()).toBe('123'); - }); - test('MilestoneID from .env with leading M', () => { - const config = new ConfigService({ - testrail: { - milestoneId: 'M123', - }, + test('MilestoneID from .env with leading M', () => { + const config = new ConfigService({ + testrail: { + milestoneId: 'M123', + }, + }); + expect(config.getMilestoneId()).toBe('123'); }); - expect(config.getMilestoneId()).toBe('123'); - }); - test('MilestoneID from .env with whitespaces', () => { - const config = new ConfigService({ - testrail: { - milestoneId: ' 123 ', - }, + test('MilestoneID from .env with whitespaces', () => { + const config = new ConfigService({ + testrail: { + milestoneId: ' 123 ', + }, + }); + expect(config.getMilestoneId()).toBe('123'); }); - expect(config.getMilestoneId()).toBe('123'); - }); - test('MilestoneID from .env as INT', () => { - const config = new ConfigService({ - testrail: { - milestoneId: 123, - }, + test('MilestoneID from .env as INT', () => { + const config = new ConfigService({ + testrail: { + milestoneId: 123, + }, + }); + expect(config.getMilestoneId()).toBe('123'); + }); + + test('MilestoneID from .env not existing', () => { + const config = new ConfigService({ + testrail: {}, + }); + expect(config.getMilestoneId()).toBe(''); }); - expect(config.getMilestoneId()).toBe('123'); }); - test('MilestoneID from .env not existing', () => { - const config = new ConfigService({ - testrail: {}, + describe('ENV variable', () => { + test('MilestoneID from ENV variable as INT', () => { + const config = new ConfigService({ + TESTRAIL_MILESTONE_ID: 45, + }); + expect(config.getMilestoneId()).toBe('45'); }); - expect(config.getMilestoneId()).toBe(''); }); - }); - describe('ENV variable', () => { - test('MilestoneID from ENV variable as INT', () => { - const config = new ConfigService({ - TESTRAIL_MILESTONE_ID: 45, + describe('process.env', () => { + test('MilestoneID from process.env', () => { + process.env.TESTRAIL_MILESTONE_ID = 45; + const config = new ConfigService({}); + expect(config.getMilestoneId()).toBe('45'); }); - expect(config.getMilestoneId()).toBe('45'); }); }); -}); -describe('SuiteID', () => { - describe('.env file', () => { - test('SuiteID from .env', () => { - const config = new ConfigService({ - testrail: { - suiteId: '123', - }, + describe('SuiteID', () => { + describe('.env file', () => { + test('SuiteID from .env', () => { + const config = new ConfigService({ + testrail: { + suiteId: '123', + }, + }); + expect(config.getSuiteId()).toBe('123'); }); - expect(config.getSuiteId()).toBe('123'); - }); - test('SuiteID from .env with leading S', () => { - const config = new ConfigService({ - testrail: { - suiteId: 'S123', - }, + test('SuiteID from .env with leading S', () => { + const config = new ConfigService({ + testrail: { + suiteId: 'S123', + }, + }); + expect(config.getSuiteId()).toBe('123'); }); - expect(config.getSuiteId()).toBe('123'); - }); - test('SuiteID from .env with whitespaces', () => { - const config = new ConfigService({ - testrail: { - suiteId: ' 123 ', - }, + test('SuiteID from .env with whitespaces', () => { + const config = new ConfigService({ + testrail: { + suiteId: ' 123 ', + }, + }); + expect(config.getSuiteId()).toBe('123'); }); - expect(config.getSuiteId()).toBe('123'); - }); - test('SuiteID from .env as INT', () => { - const config = new ConfigService({ - testrail: { - suiteId: 123, - }, + test('SuiteID from .env as INT', () => { + const config = new ConfigService({ + testrail: { + suiteId: 123, + }, + }); + expect(config.getSuiteId()).toBe('123'); + }); + + test('SuiteID from .env not existing', () => { + const config = new ConfigService({ + testrail: {}, + }); + expect(config.getSuiteId()).toBe(''); }); - expect(config.getSuiteId()).toBe('123'); }); - test('SuiteID from .env not existing', () => { - const config = new ConfigService({ - testrail: {}, + describe('ENV variable', () => { + test('SuiteID from ENV variable as INT', () => { + const config = new ConfigService({ + TESTRAIL_SUITE_ID: 45, + }); + expect(config.getSuiteId()).toBe('45'); }); - expect(config.getSuiteId()).toBe(''); }); - }); - describe('ENV variable', () => { - test('SuiteID from ENV variable as INT', () => { - const config = new ConfigService({ - TESTRAIL_SUITE_ID: 45, + describe('process.env', () => { + test('SuiteID from process.env', () => { + process.env.TESTRAIL_SUITE_ID = 45; + const config = new ConfigService({}); + expect(config.getSuiteId()).toBe('45'); }); - expect(config.getSuiteId()).toBe('45'); }); }); -}); -describe('RunID', () => { - describe('.env file', () => { - test('RunID from .env file', () => { - const config = new ConfigService({ - testrail: { - runId: '123', - }, + describe('RunID', () => { + describe('.env file', () => { + test('RunID from .env file', () => { + const config = new ConfigService({ + testrail: { + runId: '123', + }, + }); + expect(config.getRunId()).toBe('123'); }); - expect(config.getRunId()).toBe('123'); - }); - test('RunID from .env file with leading R', () => { - const config = new ConfigService({ - testrail: { - runId: 'R123', - }, + test('RunID from .env file with leading R', () => { + const config = new ConfigService({ + testrail: { + runId: 'R123', + }, + }); + expect(config.getRunId()).toBe('123'); }); - expect(config.getRunId()).toBe('123'); - }); - test('RunID from .env file with whitespaces', () => { - const config = new ConfigService({ - testrail: { - runId: ' 123 ', - }, + test('RunID from .env file with whitespaces', () => { + const config = new ConfigService({ + testrail: { + runId: ' 123 ', + }, + }); + expect(config.getRunId()).toBe('123'); }); - expect(config.getRunId()).toBe('123'); - }); - test('RunID from .env as INT', () => { - const config = new ConfigService({ - testrail: { - runId: 123, - }, + test('RunID from .env as INT', () => { + const config = new ConfigService({ + testrail: { + runId: 123, + }, + }); + expect(config.getRunId()).toBe('123'); + }); + + test('RunID from .env not existing', () => { + const config = new ConfigService({ + testrail: {}, + }); + expect(config.getRunId()).toBe(''); }); - expect(config.getRunId()).toBe('123'); }); - test('RunID from .env not existing', () => { - const config = new ConfigService({ - testrail: {}, + describe('ENV variable', () => { + test('RunID from ENV variable as INT', () => { + const config = new ConfigService({ + TESTRAIL_RUN_ID: 455, + }); + expect(config.getRunId()).toBe('455'); }); - expect(config.getRunId()).toBe(''); }); - }); - describe('ENV variable', () => { - test('RunID from ENV variable as INT', () => { - const config = new ConfigService({ - TESTRAIL_RUN_ID: 455, + describe('process.env', () => { + test('RunID from process.env', () => { + process.env.TESTRAIL_RUN_ID = 455; + const config = new ConfigService({}); + expect(config.getRunId()).toBe('455'); }); - expect(config.getRunId()).toBe('455'); }); }); -}); -describe('RunIDs', () => { - describe('.env file', () => { - test('RunIDs from .env file', () => { - const config = new ConfigService({ - testrail: { - runIds: ['123', '456'], - }, + describe('RunIDs', () => { + describe('.env file', () => { + test('RunIDs from .env file', () => { + const config = new ConfigService({ + testrail: { + runIds: ['123', '456'], + }, + }); + expect(config.getRunIds().length).toBe(2); + expect(config.getRunIds()[0]).toBe('123'); + expect(config.getRunIds()[1]).toBe('456'); }); - expect(config.getRunIds().length).toBe(2); - expect(config.getRunIds()[0]).toBe('123'); - expect(config.getRunIds()[1]).toBe('456'); - }); - test('RunIDs from .env file with leading R', () => { - const config = new ConfigService({ - testrail: { - runIds: ['R123', 'R456'], - }, + test('RunIDs from .env file with leading R', () => { + const config = new ConfigService({ + testrail: { + runIds: ['R123', 'R456'], + }, + }); + expect(config.getRunIds().length).toBe(2); + expect(config.getRunIds()[0]).toBe('123'); + expect(config.getRunIds()[1]).toBe('456'); }); - expect(config.getRunIds().length).toBe(2); - expect(config.getRunIds()[0]).toBe('123'); - expect(config.getRunIds()[1]).toBe('456'); - }); - test('RunIDs from .env file with whitespaces', () => { - const config = new ConfigService({ - testrail: { - runIds: [' 123 ', ' 456 '], - }, + test('RunIDs from .env file with whitespaces', () => { + const config = new ConfigService({ + testrail: { + runIds: [' 123 ', ' 456 '], + }, + }); + expect(config.getRunIds().length).toBe(2); + expect(config.getRunIds()[0]).toBe('123'); + expect(config.getRunIds()[1]).toBe('456'); }); - expect(config.getRunIds().length).toBe(2); - expect(config.getRunIds()[0]).toBe('123'); - expect(config.getRunIds()[1]).toBe('456'); - }); - test('RunIDs from .env as INT', () => { - const config = new ConfigService({ - testrail: { - runIds: [123, 456], - }, + test('RunIDs from .env as INT', () => { + const config = new ConfigService({ + testrail: { + runIds: [123, 456], + }, + }); + expect(config.getRunIds().length).toBe(2); + expect(config.getRunIds()[0]).toBe('123'); + expect(config.getRunIds()[1]).toBe('456'); + }); + + test('RunIDs from .env if NULL', () => { + const config = new ConfigService({ + testrail: { + runIds: null, + }, + }); + expect(config.getRunIds().length).toBe(0); + }); + + test('RunIDs from .env if missing', () => { + const config = new ConfigService({ + testrail: {}, + }); + expect(config.getRunIds().length).toBe(0); }); - expect(config.getRunIds().length).toBe(2); - expect(config.getRunIds()[0]).toBe('123'); - expect(config.getRunIds()[1]).toBe('456'); }); - test('RunIDs from .env if NULL', () => { - const config = new ConfigService({ - testrail: { - runIds: null, - }, + describe('ENV variable', () => { + test('RunIDs from ENV variable as STRING', () => { + const config = new ConfigService({ + TESTRAIL_RUN_IDS: '123,456', + }); + expect(config.getRunIds().length).toBe(2); + expect(config.getRunIds()[0]).toBe('123'); + expect(config.getRunIds()[1]).toBe('456'); + }); + + test('RunIDs from ENV variable as STRING with single entry', () => { + const config = new ConfigService({ + TESTRAIL_RUN_IDS: '123', + }); + expect(config.getRunIds().length).toBe(1); + expect(config.getRunIds()[0]).toBe('123'); + }); + + test('RunIDs from ENV variable with NULL', () => { + const config = new ConfigService({ + TESTRAIL_RUN_IDS: null, + }); + expect(config.getRunIds().length).toBe(0); + }); + + test('RunIDs from ENV variable if not provided', () => { + const config = new ConfigService({}); + expect(config.getRunIds().length).toBe(0); }); - expect(config.getRunIds().length).toBe(0); }); - test('RunIDs from .env if missing', () => { - const config = new ConfigService({ - testrail: {}, + describe('process.env', () => { + test('RunIDs from process.env', () => { + process.env.TESTRAIL_RUN_IDS = '123,456'; + const config = new ConfigService({}); + expect(config.getRunIds().length).toBe(2); + expect(config.getRunIds()[0]).toBe('123'); + expect(config.getRunIds()[1]).toBe('456'); }); - expect(config.getRunIds().length).toBe(0); }); }); - describe('ENV variable', () => { - test('RunIDs from ENV variable as STRING', () => { - const config = new ConfigService({ - TESTRAIL_RUN_IDS: '123,456', + describe('RunName', () => { + describe('.env file', () => { + test('RunName from .env file', () => { + const config = new ConfigService({ + testrail: { + runName: 'P123', + }, + }); + expect(config.getRunName()).toBe('P123'); }); - expect(config.getRunIds().length).toBe(2); - expect(config.getRunIds()[0]).toBe('123'); - expect(config.getRunIds()[1]).toBe('456'); }); - test('RunIDs from ENV variable as STRING with single entry', () => { - const config = new ConfigService({ - TESTRAIL_RUN_IDS: '123', + describe('ENV variable', () => { + test('RunName from ENV', () => { + const config = new ConfigService({ + TESTRAIL_RUN_NAME: 'P123', + }); + expect(config.getRunName()).toBe('P123'); }); - expect(config.getRunIds().length).toBe(1); - expect(config.getRunIds()[0]).toBe('123'); }); - test('RunIDs from ENV variable with NULL', () => { - const config = new ConfigService({ - TESTRAIL_RUN_IDS: null, + describe('process.env', () => { + test('RunName from process.env', () => { + process.env.TESTRAIL_RUN_NAME = 'P123'; + const config = new ConfigService({}); + expect(config.getRunName()).toBe('P123'); }); - expect(config.getRunIds().length).toBe(0); }); + }); - test('RunIDs from ENV variable if not provided', () => { - const config = new ConfigService({}); - expect(config.getRunIds().length).toBe(0); + describe('RunIncludeAll', () => { + describe('.env file', () => { + test('RunIncludeAll from .env ON', () => { + const config = new ConfigService({ + testrail: { + runIncludeAll: true, + }, + }); + expect(config.includeAllCasesDuringCreation()).toBe(true); + }); + + test('RunIncludeAll from .env OFF', () => { + const config = new ConfigService({ + testrail: { + runIncludeAll: false, + }, + }); + expect(config.includeAllCasesDuringCreation()).toBe(false); + }); + + test('RunIncludeAll from .env default is OFF', () => { + const config = new ConfigService({ + testrail: {}, + }); + expect(config.includeAllCasesDuringCreation()).toBe(false); + }); }); - }); -}); -describe('RunName', () => { - describe('.env file', () => { - test('RunName from .env file', () => { - const config = new ConfigService({ - testrail: { - runName: 'P123', - }, + describe('ENV variable', () => { + test('RunIncludeAll from ENV variable', () => { + const config = new ConfigService({ + TESTRAIL_RUN_INCLUDE_ALL: true, + }); + expect(config.includeAllCasesDuringCreation()).toBe(true); }); - expect(config.getRunName()).toBe('P123'); }); - }); - describe('ENV variable', () => { - test('RunName from ENV', () => { - const config = new ConfigService({ - TESTRAIL_RUN_NAME: 'P123', + describe('process.env', () => { + test('RunIncludeAll from process.env', () => { + process.env.TESTRAIL_RUN_INCLUDE_ALL = true; + const config = new ConfigService({}); + expect(config.includeAllCasesDuringCreation()).toBe(true); }); - expect(config.getRunName()).toBe('P123'); }); }); -}); -describe('RunIncludeAll', () => { - describe('.env file', () => { - test('RunIncludeAll from .env ON', () => { - const config = new ConfigService({ - testrail: { - runIncludeAll: true, - }, + describe('CloseRun', () => { + describe('.env file', () => { + test('CloseRun from .env file', () => { + const config = new ConfigService({ + testrail: { + closeRun: true, + }, + }); + expect(config.shouldCloseRun()).toBe(true); }); - expect(config.includeAllCasesDuringCreation()).toBe(true); }); - test('RunIncludeAll from .env OFF', () => { - const config = new ConfigService({ - testrail: { - runIncludeAll: false, - }, + describe('ENV variable', () => { + test('CloseRun from ENV', () => { + const config = new ConfigService({ + TESTRAIL_RUN_CLOSE: true, + }); + expect(config.shouldCloseRun()).toBe(true); }); - expect(config.includeAllCasesDuringCreation()).toBe(false); }); - test('RunIncludeAll from .env default is OFF', () => { - const config = new ConfigService({ - testrail: {}, + test('closeRun default is FALSE', () => { + const config = new ConfigService({}); + expect(config.shouldCloseRun()).toBe(false); + }); + + describe('process.env', () => { + test('closeRun from process.env', () => { + process.env.TESTRAIL_RUN_CLOSE = true; + const config = new ConfigService({}); + expect(config.shouldCloseRun()).toBe(true); }); - expect(config.includeAllCasesDuringCreation()).toBe(false); }); }); - describe('ENV variable', () => { - test('RunIncludeAll from ENV variable', () => { - const config = new ConfigService({ - TESTRAIL_RUN_INCLUDE_ALL: true, + describe('Screenshots', () => { + describe('.env file', () => { + test('Screenshots from .env ON', () => { + const config = new ConfigService({ + testrail: { + screenshots: true, + }, + }); + expect(config.isScreenshotsEnabled()).toBe(true); + }); + + test('Screenshots from .env OFF', () => { + const config = new ConfigService({ + testrail: { + screenshots: false, + }, + }); + expect(config.isScreenshotsEnabled()).toBe(false); + }); + + test('Screenshots from .env default is OFF', () => { + const config = new ConfigService({ + testrail: {}, + }); + expect(config.isScreenshotsEnabled()).toBe(false); }); - expect(config.includeAllCasesDuringCreation()).toBe(true); }); - }); -}); -describe('CloseRun', () => { - describe('.env file', () => { - test('CloseRun from .env file', () => { - const config = new ConfigService({ - testrail: { - closeRun: true, - }, + describe('ENV variable', () => { + test('Screenshots from ENV variable', () => { + const config = new ConfigService({ + TESTRAIL_SCREENSHOTS: true, + }); + expect(config.isScreenshotsEnabled()).toBe(true); }); - expect(config.shouldCloseRun()).toBe(true); }); - }); - describe('ENV variable', () => { - test('CloseRun from ENV', () => { - const config = new ConfigService({ - TESTRAIL_RUN_CLOSE: true, + describe('process.env', () => { + test('Screenshots from process.env', () => { + process.env.TESTRAIL_SCREENSHOTS = true; + const config = new ConfigService({}); + expect(config.isScreenshotsEnabled()).toBe(true); }); - expect(config.shouldCloseRun()).toBe(true); }); }); - test('closeRun default is FALSE', () => { - const config = new ConfigService({}); - expect(config.shouldCloseRun()).toBe(false); - }); -}); + describe('Screenshots All', () => { + describe('.env file', () => { + test('ScreenshotsAll from .env ON', () => { + const config = new ConfigService({ + testrail: { + screenshotsAll: true, + }, + }); + expect(config.includeAllFailedScreenshots()).toBe(true); + }); -describe('Screenshots', () => { - describe('.env file', () => { - test('Screenshots from .env ON', () => { - const config = new ConfigService({ - testrail: { - screenshots: true, - }, + test('ScreenshotsAll from .env OFF', () => { + const config = new ConfigService({ + testrail: { + screenshotsAll: false, + }, + }); + expect(config.includeAllFailedScreenshots()).toBe(false); + }); + + test('ScreenshotsAll from .env default is OFF', () => { + const config = new ConfigService({ + testrail: {}, + }); + expect(config.includeAllFailedScreenshots()).toBe(false); }); - expect(config.isScreenshotsEnabled()).toBe(true); }); - test('Screenshots from .env OFF', () => { - const config = new ConfigService({ - testrail: { - screenshots: false, - }, + describe('ENV variable', () => { + test('ScreenshotsAll from ENV variable', () => { + const config = new ConfigService({ + TESTRAIL_SCREENSHOTS_ALL: true, + }); + expect(config.includeAllFailedScreenshots()).toBe(true); }); - expect(config.isScreenshotsEnabled()).toBe(false); }); - test('Screenshots from .env default is OFF', () => { - const config = new ConfigService({ - testrail: {}, + describe('process.env', () => { + test('ScreenshotsAll from process.env', () => { + process.env.TESTRAIL_SCREENSHOTS_ALL = true; + const config = new ConfigService({}); + expect(config.includeAllFailedScreenshots()).toBe(true); }); - expect(config.isScreenshotsEnabled()).toBe(false); }); }); - describe('ENV variable', () => { - test('Screenshots from ENV variable', () => { - const config = new ConfigService({ - TESTRAIL_SCREENSHOTS: true, - }); - expect(config.isScreenshotsEnabled()).toBe(true); + describe('Invalid Configurations', () => { + test('undefined config returns default values', () => { + const config = new ConfigService(undefined); + expect(config.getRunId()).toBe(''); + }); + + test('null config returns default values', () => { + const config = new ConfigService(null); + expect(config.getRunId()).toBe(''); + }); + + test('empty config returns default values', () => { + const config = new ConfigService({}); + expect(config.getRunId()).toBe(''); }); }); -}); -describe('Screenshots All', () => { - describe('.env file', () => { - test('ScreenshotsAll from .env ON', () => { + describe('hasRunID', () => { + test('hasRunID is true on single runs', () => { const config = new ConfigService({ testrail: { - screenshotsAll: true, + runId: '123', }, }); - expect(config.includeAllFailedScreenshots()).toBe(true); + expect(config.hasRunID()).toBe(true); }); - test('ScreenshotsAll from .env OFF', () => { + test('hasRunID is true on multiple runs', () => { const config = new ConfigService({ testrail: { - screenshotsAll: false, + runIds: ['123', '456'], }, }); - expect(config.includeAllFailedScreenshots()).toBe(false); - }); - - test('ScreenshotsAll from .env default is OFF', () => { - const config = new ConfigService({ - testrail: {}, - }); - expect(config.includeAllFailedScreenshots()).toBe(false); + expect(config.hasRunID()).toBe(true); }); - }); - describe('ENV variable', () => { - test('ScreenshotsAll from ENV variable', () => { - const config = new ConfigService({ - TESTRAIL_SCREENSHOTS_ALL: true, - }); - expect(config.includeAllFailedScreenshots()).toBe(true); + test('hasRunID is false if no runs provided', () => { + const config = new ConfigService(null); + expect(config.hasRunID()).toBe(false); }); }); -}); -describe('Invalid Configurations', () => { - test('undefined config returns default values', () => { - const config = new ConfigService(undefined); - expect(config.getRunId()).toBe(''); - }); - - test('null config returns default values', () => { + test('getTestRailStatusPassed', () => { const config = new ConfigService(null); - expect(config.getRunId()).toBe(''); - }); - - test('empty config returns default values', () => { - const config = new ConfigService({}); - expect(config.getRunId()).toBe(''); - }); -}); - -describe('hasRunID', () => { - test('hasRunID is true on single runs', () => { - const config = new ConfigService({ - testrail: { - runId: '123', - }, - }); - expect(config.hasRunID()).toBe(true); + expect(config.getTestRailStatusPassed()).toBe(1); }); - test('hasRunID is true on multiple runs', () => { - const config = new ConfigService({ - testrail: { - runIds: ['123', '456'], - }, - }); - expect(config.hasRunID()).toBe(true); + test('getTestRailStatusSkipped', () => { + const config = new ConfigService(null); + expect(config.getTestRailStatusSkipped()).toBe(2); }); - test('hasRunID is false if no runs provided', () => { + test('getTestRailStatusFailed', () => { const config = new ConfigService(null); - expect(config.hasRunID()).toBe(false); + expect(config.getTestRailStatusFailed()).toBe(5); }); }); - -test('getTestRailStatusPassed', () => { - const config = new ConfigService(null); - expect(config.getTestRailStatusPassed()).toBe(1); -}); - -test('getTestRailStatusSkipped', () => { - const config = new ConfigService(null); - expect(config.getTestRailStatusSkipped()).toBe(2); -}); - -test('getTestRailStatusFailed', () => { - const config = new ConfigService(null); - expect(config.getTestRailStatusFailed()).toBe(5); -});