Custom Jest reporter for Testrail synchronization
npm install testrail-jest-reporter  
``code`
npm i testrail-jest-reporter --save-dev
As per Jest's documentation,
the Reporter must be specified in the jest-config.js or package.json file as part of the reporters array.suite mode
- This file should be created in your project's root folder.
- Parameter is defined as 'project_id', which is the id of your project on TestRail.
- Specify the TestRail server url as parameter 'baseUrl' _(recommended)_.
- Specify the TestRail Milestones name and description as parameter 'milestone' _(recommended)_.
- Specify the TestRail id as parameter 'suite_mode' _(recommended)_. If that parameter is not specified, the Reporter will get this automatically. suite_mode:1
>single repository for all cases - suite_mode:2
single repository with baseline support - suite_mode:3
multiple test suites to manage cases - `
- There is no 'pending' or 'skipped' test result status in the TestRail results default
statuses.
You can add your custom status to the TestRail and specify it id as parameter
'"statuses":{"pending": "7"}' _(recommended)_.
#### Usagejavascript`
// this is the part of the jest-config.js
module.exports = {
...,
reporters: [
"default",
[
"testrail-jest-reporter",
{ project_id: 1,
baseUrl: 'http://localhost',
milestone: {name:'
suite_mode: 3,
statuses: {pending: 7}
},
]
],
...
};`js`
// this is the "jest" part of the package.json
{
"jest": {
"reporters": [
"default",
[
"testrail-jest-reporter",
{
"project_id": "1",
"baseUrl": 'http://localhost',
"milestone": {"name":'
"suite_mode": "3",
"statuses": {"pending": "7"}
}
]
]
}
}
The testrail.conf.js file needs to be created in your project's root folder.
- It must contain your TestRail username (email address) and password (or API key).
- This file needs to have all 2 parameters correctly filled.
- It may contain the URL of your TestRail server as a baseUrl parameter, or /[C][?\d]{3,6}/gm
it can be specified in
Jest configuration
- You can specify custom regex expresion _(default: )_$3
The first version of the Reporter requires you to use a milestone.
- Use TestRail Milestone to versioning your tests.
- testrail.conf.js file needs to have Milestones name and description filled. Or
it can be specified in
Jest configuration
#### Example
`js`
module.exports = {
'baseUrl': 'http://localhost',
'user': 'user@example.com',
'pass': 'some-password',
'milestone': {'name':'
'regex': /[C][?\d]{3,6}/gm
}`
Or you can use previous variant 'milestone': '`
##### Important: If you use a public repository, please, secure your sensitive data.
The Case ID from TestRail may be added to _it()_ description
each test result you want to push to TestRail.
You can specify several cases in one _it()_ description.
#### Usage
`javascript
describe("Tests suite", () => {
// "C123" this is Case ID from Test Rail
it("C123 test success", async () => {
expect(1).toBe(1);
});
it("Test fail C124 C125", async () => {
expect(1).toBe(0);
});
xit("Another success test", async () => {
expect(1).toBe(1);
});
});
``
Note: The Case ID is a unique and permanent ID of every test case (e.g. C125),
and shouldn't be confused with a Test Case ID,
which is assigned to a test case when a new run is created (e.g. T325).
Note: The first and second _it()_ test result will be reported, and the last - not.
Version 2:
- Add the Reporter CLI.
Version 3:
- Add ability to parse code annotations.
- Add new TestRail testcase if _it()_ description not specified by Case ID.
- Add maintenance the TestRail test Plan and test Configurations.
This project is licensed under the MIT License - see the LICENSE file for details.
