Skip to content

Commit

Permalink
create json of new testrail runs
Browse files Browse the repository at this point in the history
  • Loading branch information
boxblinkracer committed Feb 2, 2024
1 parent ee1adce commit bdefaf2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- 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.
- Added new option to **ignore pending tests**. If ignored, these tests will not be sent to TestRail. Please see README for more.
- Added new **created_run.json** file that is created in "Create Run Mode". This allows to immediately read and use data of the created run in other steps of your CI pipeline, while Cypress is running.

### Fixed

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Add your TestRail credentials in Cypress, decide which test results should be se
* [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)
* [6.4 Get data of new TestRail runs](#64-get-data-of-new-testrail-runs)
* [7. Variables](#7-variables)
* [7.1 Use on CLI](#71-use-on-cli)
* [7.2 Use in cypress.env.json](#72-use-in-cypressenvjson)
Expand Down Expand Up @@ -263,6 +264,13 @@ 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.

#### 6.4 Get data of new TestRail runs

When using the "Create Run Mode", the integration will now create a new file called **created_run.json**.
This is immediately created after the run was created in TestRail and contains data such as the ID, name and more.

You can use this file to immediately read and use data of the created run in other steps of your CI pipeline, while Cypress is running.

### 7. Variables

This is a list of all available variables and their explanation.
Expand Down
18 changes: 18 additions & 0 deletions src/Reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const ColorConsole = require('./services/ColorConsole');
const CypressStatusConverter = require('./services/CypressStatusConverter');

const packageData = require('../package.json');
const FileWriter = require('./services/FileWriter');

class Reporter {
/**
Expand All @@ -19,6 +20,7 @@ class Reporter {
this.on = on;

this.testCaseParser = new TestCaseParser();
this.fileWriter = new FileWriter();

/* eslint-disable no-undef */
const configService = new ConfigService(config.env);
Expand Down Expand Up @@ -288,11 +290,27 @@ class Reporter {
description += '\n' + this.customComment;
}

const me = this;

await this.testrail.createRun(this.projectId, this.milestoneId, this.suiteId, runName, description, this.includeAllCasesDuringCreation, (runId) => {
// run created
this.runIds = [runId];
/* eslint-disable no-console */
ColorConsole.debug(' New TestRail Run: R' + runId);

// we need to write the runId to a file
// this allows developers to immediately fetch the new runID and
// use it for their own purposes
const data = {
id: runId,
name: runName,
description: description,
projectId: me.projectId,
milestoneId: me.milestoneId,
suiteId: me.suiteId,
};

me.fileWriter.write('created_run.json', JSON.stringify(data, null, 2));
});
}

Expand Down
20 changes: 20 additions & 0 deletions src/services/FileWriter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fs = require('fs');

class FileWriter {
/**
*
* @param filename
* @param content
*/
write(filename, content) {
fs.writeFile(filename, content, (err) => {
if (err) {
console.error('Error writing to file:', err);
} else {
console.log('File written successfully!');
}
});
}
}

module.exports = FileWriter;

0 comments on commit bdefaf2

Please sign in to comment.