cypress-junit-xml-mocha-reporter
v1.0.2
Published
A JUnit XML reporter for cypress and allows you to split the same test into different test cases by jira id.
Downloads
190
Maintainers
Readme
cypress-junit-xml-mocha-reporter
This is a cypress reporter that produces JUnit style XML test results and allows to split the same test in different test cases by jira id, this improves performance and avoids reloading the page in each test if we want to group different tests in the same test case.
Table of Contents
Installation
pnpm install cypress-junit-xml-mocha-reporter --save-dev
npm install cypress-junit-xml-mocha-reporter --save-dev
Usage
Run mocha with cypress-junit-xml-mocha-reporter
:
mocha test --reporter cypress-junit-xml-mocha-reporter
This will output a results file at ./results.xml
.
You may optionally declare an alternate location for results XML file by setting
the environment variable MOCHA_FILE
or specifying mochaFile
in reporterOptions
:
MOCHA_FILE=./path_to_your/file.xml mocha test --reporter cypress-junit-xml-mocha-reporter
or
mocha test --reporter cypress-junit-xml-mocha-reporter --reporter-options mochaFile=./path_to_your/file.xml
or
const mocha = new Mocha({
reporter: 'cypress-junit-xml-mocha-reporter',
reporterOptions: {
mochaFile: './path_to_your/file-results.xml'
}
});
Split the same test case by id of jira
You can add jira keys in the testConfig
options of a test case to split the same test into different test cases. These keys should be provided in an array of objects, e.g:
it(
"testcase",
{
jiraIds: [
{ id: "JIRA.KEY.1" },
{ id: "JIRA.KEY.2" },
{ id: "JIRA.KEY.3" },
],
},
() => {
expect(2).to.be.greaterThan(1);
}
);
This is useful if you want to test different tests on the same test in Cypress without affecting performance. If you want to provide a different title to the test case you can add the testTitle
property to each of the keys in the test case.
[!IMPORTANT] If the
testTitle
property is not provided, the title will be the title of the test case.
If the test case it's this:
describe("test", () => {
it(
"testcase",
{
jiraIds: [
{ id: "JIRA.KEY.1", testTitle: "should display test 1" },
{ id: "JIRA.KEY.2", testTitle: "should display test 2" },
{ id: "JIRA.KEY.3" },
],
},
() => {
expect(2).to.be.greaterThan(1);
}
);
});
the result it's this:
<testsuites>
<testsuite>
<testcase name="should display test 1 JIRA.KEY.1" time="0.034" classname="should display test 1 JIRA.KEY.1">
</testcase>
<testcase name="should display test 2 JIRA.KEY.2" time="0.034" classname="should display test 2 JIRA.KEY.2">
</testcase>
<testcase name="test testcase JIRA.KEY.3" time="0.034" classname="testcase JIRA.KEY.3">
</testcase>
</testsuite>
</testsuites>
Append properties to testsuite
You can also add properties to the report under testsuite
. This is useful if you want your CI environment to add extra build props to the report for analytics purposes
<testsuites>
<testsuite>
<properties>
<property name="PROPERTY_ID" value="12345"/>
</properties>
<testcase/>
</testsuite>
</testsuites>
To do so pass them in via env variable:
PROPERTIES=PROPERTY_ID:12345 mocha test --reporter cypress-junit-xml-mocha-reporter
or
const mocha = new Mocha({
reporter: 'cypress-junit-xml-mocha-reporter',
reporterOptions: {
properties: {
PROPERTY_ID: 12345
}
}
})
Results Report
Results XML filename can contain [hash]
, e.g. ./path_to_your/results.[hash].xml
. [hash]
is replaced by MD5 hash of test results XML. This enables support of parallel execution of multiple cypress-junit-xml-mocha-reporter
's writing test results in separate files. In addition to this these placeholders can also be used:
| placeholder | output |
| ------------------- | ------------------------------------------------- |
| [testSuitesTitle]
| will be replaced by the testSuitesTitle
setting |
| [rootSuiteTitle]
| will be replaced by the rootSuiteTitle
setting |
| [suiteFilename]
| will be replaced by the filename of the spec file |
| [suiteName]
| will be replaced by the name the first test suite |
In order to display full suite title (including parents) just specify testSuitesTitle
option
const mocha = new Mocha({
reporter: 'cypress-junit-xml-mocha-reporter',
reporterOptions: {
testSuitesTitle: true,
}
});
You can also configure the testsuites.name
attribute by setting reporterOptions.testSuitesTitle
and the root suite's name
attribute by setting reporterOptions.rootSuiteTitle
.
Configuration options
| Parameter | Default | Effect |
| ------------------------------ | ---------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| mochaFile | results.xml
| Configures the file to write reports to |
| properties | null
| A hash of additional properties to add to each test suite |
| rootSuiteTitle | Root Suite
| The name for the root suite. (defaults to 'Root Suite') |
| testSuitesTitle | Mocha Tests
| The name for the testsuites
tag (defaults to 'Mocha Tests') |
Debug mode
If you need see the log when it's executed you can provide the DEBUG
envionment variable.
DEBUG=true
License
MIT, see LICENSE for details.