Socket
Book a DemoInstallSign in
Socket

junit-xray-cypress-reporter

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

junit-xray-cypress-reporter

The reporter is built on the top of mocha-junit-reporter v2.2.1 so all the configurations in the official doc, are inherited from this npm package. This reporter offers the ability to specify a Jira-Issue for each it{} inside your cypress test and creates

2.0.1
latest
npmnpm
Version published
Weekly downloads
2
-60%
Maintainers
1
Weekly downloads
 
Created
Source

junit-xray-cypress-reporter

This reporter offers the ability to specify a Jira-Issue for each it{} inside your cypress test and creates a custom report that is easy to load into XRAY. The reporter helps you to integrate your Cypress/Mocha test with XRay easily by producing enriched JUnit-style XML test report files which can be uploaded into XRay with API or other tools.

This reporter is built on the top of mocha-junit-reporter v2.2.1 so all the configurations in the official doc, are inherited from this npm package.

JUnit Xray Reporter is a custom reporter for use with:

INSTALLATION

As a dev module:

$ npm install junit-xray-cypress-reporter --save-dev

or as a global module:

$ npm install -g junit-xray-cypress-reporter

CONFIGURATION

Test level

describe('My First Test', () => {
  it('Does not do much!', {jiraKey:"CALC-1234"}, () => {
    or
  it('Does not do much!', {jiraID:"CALC-1234"}, () => {
    expect(true).to.equal(true);
  })
})

Cypress configuration file (cypress.config.js)

Every others {reporterOptions} explained here: mocha-junit-reporter v2.2.1 are availabile.

const { defineConfig } = require("cypress");
module.exports = defineConfig({
  reporter: "junit-xray-cypress-reporter",
  reporterOptions: {
    mochaFile: "cypress/results/my-test-output-[hash].xml"
  },
  e2e: {
    setupNodeEvents(on, config) {
      // implement node event listeners here
    },
  },
});

AN EXAMPLE

  • Install 'junit-xray-cypress-reporter' to the cypress project
$ npm install junit-xray-cypress-reporter --save-dev
  • Configure 'junit-xray-cypress-reporter' as the reporter and do other configurations as necessary. Configurations can be done in the cypress.config.js or in the command line.
    Add this to cypress.config.js
const { defineConfig } = require("cypress");
module.exports = defineConfig({
  reporter: "junit-xray-cypress-reporter",
  reporterOptions: {
    mochaFile: "cypress/results/my-test-output-[hash].xml"
  },
  e2e: {
    setupNodeEvents(on, config) {
      // implement node event listeners here
    },
  },
});

'mochaFile' is the path to the report file. When there are several test files run it will generate a report file for each test file, so in order to generate unique file names and not overwrite the existing ones, the [hash] is added to the name of the report file.

  • Add cypress test with XRay-related elements
describe('My First Test', () => {
  it('Does not do much!', {jiraKey:"CALC-1234"}, () => {
    expect(true).to.equal(true);
  })
})
  • Run tests and generate report
npx cypress run --spec "path/to/file"
  • View report file

Report file generated at '<Cypress_project_root>/cypress/results'.

"my-test-output-828a1c4885dc687b1a19e11e24b9437e.xml"

<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="Mocha Tests" time="0.1070" tests="1" failures="0">
  <testsuite name="Root Suite" timestamp="2023-01-27T13:51:23" tests="0" file="cypress\e2e\test.cy.js" time="0.0000" failures="0">
  </testsuite>
  <testsuite name="My First Test" timestamp="2023-01-27T13:51:23" tests="1" time="0.0700" failures="0">
    <testcase name="My First Test Does not do much!" time="0.0820" classname="Does not do much!">
      <properties>
        <property name="test_key" value="CALC-1234"/>
      </properties>
    </testcase>
  </testsuite>
</testsuites>

As you can see the property has beenn added and now could be readed correctly by XRay.

<properties>
  <property name="test_key" value="CALC-1234"/>
</properties>
  • Now just upload the report to XRay and the card in Jira will be updated automatically

MIGRATION TO NEWEST VERSION:

Reporter outdated configuration!

You just update this repo to the newest version and u get this error? Dont worry, the solution is easy.

The old and deprecated configuration was:

describe('My First Test', () => {
  it('Does not do much!', {xray:{jiraID:"CALC-1234"}}, () => {
    expect(true).to.equal(true);
  })
})

Now I made it more easyer and clean:

describe('My First Test', () => {
  it('Does not do much!', {jiraID:"CALC-1234"}, () => {
    expect(true).to.equal(true);
  })
})

or

describe('My First Test', () => {
  it('Does not do much!', {jiraKey:"CALC-1234"}, () => {
    expect(true).to.equal(true);
  })
})

How to make an easy update of all the outdated configuration? With regex!

In VS code you can search for this string (ATTENTION: spaces and type of quotation marks can change can be single ' or double "):

xray:\{jiraID:"(.*?)"\}

and replace it with

jiraKey:"$1"

THE JOB IS DONE!

Happy testing to everyone!

ALEC-JS

Keywords

xray

FAQs

Package last updated on 13 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.