Home

Awesome

TestRail v6.7 NPM NPM

Jest to TestRail Reporter

This package allows you to use Jest and report your test results to TestRail. <br>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.

Usage

// this is the part of the jest-config.js
module.exports = {
  ...,
  reporters: [
    "default",
    [
        "testrail-jest-reporter", 
        { project_id: 1, 
            baseUrl: 'http://localhost', 
            milestone: {name:'<milestone_name>', description:'<milestone_description>'},
            suite_mode: 3,
            statuses: {pending: 7}
        },
    ]
  ], 
    ...
};
// this is the "jest" part of the package.json
{
  "jest": {
    "reporters": [
      "default",
        [
            "testrail-jest-reporter",
            { 
                "project_id": "1",
                "baseUrl": 'http://localhost',
                "milestone": {"name":'<milestone_name>', "description":'<milestone_description>'},
                "suite_mode": "3",
                "statuses": {"pending": "7"}
            }
        ]
    ]
  }
}

TestRail configurations

The testrail.conf.js file needs to be created in your project's root folder.

Use TestRail Milestone

The first version of the Reporter requires you to use a milestone.

Example

module.exports = {
    'baseUrl': 'http://localhost',
    'user': 'user@example.com',
    'pass': 'some-password',
    'milestone': {'name':'<milestone_name>', 'description':'<milestone_description>'},
    'regex': /[C][?\d]{3,6}/gm
}

Or you can use previous variant 'milestone': '<milestone_name>'

Important: 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 <br>in your own TestRail Site Settings. Also, if you want to use API authentication instead of your password, <br>enable session authentication for API in the TestRail Site Settings, <br>and add an API key in your User settings (This is recommended).

Add TestRail tests Runs

You can add a TestRail tests Runs or tests Plan with all tests you want to automate.<br> If you don't, the Reporter will publish Jest tests results into the new TestRail test Run.<br> Each time the Jest runs tests the Reporter parse all TestRail tests Plans <br>and tests Runs of the Milestone to collect testcases. The Reporter collects only unique testcases, <br>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. You can specify several cases in one it() description.

Usage

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, <br>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:

<br>Version 2:

<br>Version 3:

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

"Buy Me A Coffee"