npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

testrail-jest-reporter

v1.2.0

Published

Custom Jest reporter for Testrail synchronization

Downloads

6,740

Readme

TestRail v6.7 NPM NPM

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 Milestones name and description as parameter 'milestone' (recommended).
  • Specify the TestRail suite mode id as parameter 'suite_mode' (recommended). If that parameter is not specified, the Reporter will get this automatically.

    single repository for all cases - suite_mode:1 single repository with baseline support - suite_mode:2 multiple test suites to manage cases - suite_mode:3

  • 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

// 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.

  • 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 it can be specified in Jest configuration
  • You can specify custom regex expresion (default: /[C][?\d]{3,6}/gm)

Use TestRail Milestone

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

module.exports = {
    'baseUrl': 'http://localhost',
    'user': '[email protected]',
    '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 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

You can add a TestRail tests Runs or tests Plan with all tests you want to automate. If you don't, the Reporter will publish Jest tests results into the new TestRail test Run. Each time the Jest runs tests the Reporter parse all TestRail tests Plans and tests 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. 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, 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.~~ >> Done in 1.1.0
  • Add new test Runs if the Milestone not specified.
  • ~~Add new TestRail Milestone if the specified Milestone not present in the Project.~~ >> Done in 1.2.0
  • ~~Also need to write more tests.~~ >> Done in 1.0.4
  • ~~Added ability to specify several case_ids in one test description~~ >> Done in 1.0.6
  • ~~Added JSON validator to API interface~~ >> Done in 1.0.7
  • Migrate to GOT

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.

License

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

Support

"Buy Me A Coffee"