Skip to content

Commit

Permalink
add support for process.env
Browse files Browse the repository at this point in the history
  • Loading branch information
boxblinkracer committed Feb 1, 2024
1 parent 640cff3 commit fa9cdcf
Show file tree
Hide file tree
Showing 4 changed files with 606 additions and 478 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

<!-- TOC -->
* [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)

<!-- TOC -->

### 1. Installation
Expand All @@ -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.

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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 |
Expand Down
15 changes: 15 additions & 0 deletions src/services/ConfigService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 === '') {
Expand Down Expand Up @@ -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 === '') {
Expand Down Expand Up @@ -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 === '') {
Expand Down
Loading

0 comments on commit fa9cdcf

Please sign in to comment.