Jest to TestRail Reporter
This package allows you to use Jest and report your test results to TestRail.
Please use with combination with the default reporter
Install
npm i testrail-jest-reporter --save-dev
Jest configurations
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.
- 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 Milestone name as parameter 'milestone' (recommended).
- 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).
Usage
module.exports = {
...,
reporters: [
"default",
[
"jest-2-testrail",
{ project_id: "1",
baseUrl: 'http://localhost',
milestone: '<milestone_name>',
statuses: {pending: "7"}
},
]
],
...
};
{
"jest": {
"reporters": [
"default",
[
"jest-2-testrail",
{
"project_id": "1",
"baseUrl": 'http://localhost',
"milestone": '<milestone_name>',
"statuses": {"pending": "7"}
}
]
]
}
}
TestRail configurations
The testrail.conf.js file needs to be created in your project's root folder.
- It must contain the URL of your TestRail server, username (email address) and password (or API key).
- This file needs to have all 3 parameters correctly filled.
Use TestRail Milestone
In first version the Reporter needs you to use milestone.
- Use TestRail Milestone to versioning your tests.
- testrail.conf.js file needs to have Milestone name filled. Or
it can be specified in
Jest configuration - You can specify custom regex expresion (default:
/[?\d]{3,6}/gm
)
Example
module.exports = {
'baseUrl': 'http://localhost',
'user': 'user@example.com',
'pass': 'some-password',
'milestone': '<milestone_name>',
'regex': /[?\d]{3,6}/gm
}
Note: If you use a public repository, please, secure your sensitive data.
Enable TestRail API
In order to use TestRail API, it needs to be enabled by an administrator
in your own TestRail Site Settings.
Also, if you want to use API authentication instead of your password,
enable session authentication for API in the TestRail Site Settings,
and add an API key in your User settings (This is recommended).
Add TestRail tests Runs
In first version the Reporter needs you to add tests Runs with all tests you want to automate.
The Reporter parse all TestRail tests Plans
and test Runs of the Milestone to collect testcases.
The Reporter collects only unique testcases,
if you have several tests Runs with one testcase
then The Reporter push the test result only to one of that Runs.
Example tests
The Case ID from TestRail may be added to it() description
each test result you want to push to TestRail.
Usage
describe("Tests suite", () => {
it("C123 test success", async () => {
expect(1).toBe(1);
});
it("Test fail C124", 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.
Roadmap
This version:
- Add new tests Run if there are testcases that are not present in any of the existing TestRail tests Runs.
- Add new test Runs if the Milestone not specified.
- Add new TestRail Milestone if the specified Milestone not present in the Project.
- Also need to write more tests.
Version 2:
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.
License
This project is licensed under the MIT License - see the LICENSE file for details.