diff --git a/CHANGELOG.md b/CHANGELOG.md index 632d3c7..69132f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 31e4dbb..d8527fc 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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. diff --git a/src/Reporter.js b/src/Reporter.js index f03b71b..abd0876 100644 --- a/src/Reporter.js +++ b/src/Reporter.js @@ -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 { /** @@ -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); @@ -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)); }); } diff --git a/src/services/FileWriter.js b/src/services/FileWriter.js new file mode 100644 index 0000000..0565292 --- /dev/null +++ b/src/services/FileWriter.js @@ -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;