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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mocha-testrail-reporter-2

v1.2.1

Published

A testrail reporter for Mocha.js

Readme

mocha-testrail-reporter-2

This library allows to testrail to be integrated to a mocha automation suite as a mocha reporter.

Pre-requisites

  • Requires mochawesome-report-generator to be present on the suite, in which the mochawesome.json file generated will be used to extract testcases to be uploaded to Testrail. ( Extractor tool added to releases. )

  • Using multi-custom-reporter will allow both reporters work together.

Installation

Using NPM:

npm i mocha-testrail-reporter-2

Add reporter to mocha.json

  1. Standalone using mocha-testrail-reporter-2.
{
  ...,
  "reporter": ["mocha-testrail-reporter-2"],
  "reporter-options" : "",
  ...
}
  1. i. Using multi-custom-reporter (Recommended)
{
  ...,
  "reporter": ["mocha-multi-reporters"],
  "reporter-options" : "configFile=config.json",
  ...
}
  1. ii. Add config.json to root directory of your automation suite if using multi-custom-reporter.
{
  "reporterEnabled": "mochawesome, mocha-testrail-reporter-2",
  "mochawesomeReporterOptions": {
      "reportDir": "./artifacts"
  }
}

Note

Do not forget to install mochawesome & mocha-multi-reporters as dependency.

Please read mochawesome & mocha-multi-reporters documentations if anything unclear.

Extracting & uploading testcases to Testrail

On the releases section, there is the "mochawesome extractor tool" attached and has all the steps detailed on how to use the tool.

On testrail, create your project, followed by suite and import testcases using the the "Import using csv" option.

Testrail configuration

Create a 'testrail.json' json file on the root directory of the project with the following:

{
  "host": "https://yourtestrail.domain.here",
  "email": "[email protected]",
  "apikey": "your_testrail_api_key_here",
  "project_name": "Demo Project Name",
  "project_id": 1,
  "suite_id": 1,
  "testrail_enabled": false,
  "mocha": "--optional field", 
  "version": "--optional field" 
}

Configuration options

host: [string] Domain name of the Testrail domain (e.g. domain.testrail.io)

email: [string] Username/Email for the testrail account

apikey: [string] password or API token for user account

project_name: [number] name of project for which the Testrun will be created

projectId: [number] project number where the suite has been added

suite_id: [number] suite number where the tests have been uploaded

testrail_enabled: [boolean] disable/enable testrail for the automation suite

mocha: [string] (optional) set path for the 'mocha.json' file, used to retrieve the grep value. (default path is root directory of project or ./test/mocha.json)

version: [string] (optional) set path where a version function can be defined to return a version of the Automation suite (default path is root directory of project)

Configuration example for the mocha options

Configure mocha path to be present at config/mocha.json. (Not required if file is present at root directory of project or at ./test/mocha.json)

{
  ...,
  "mocha": "config/mocha.json",
}

Configuration example for the version options

Define version.js path to be present at config/version.js. (Not required if file is present at root directory of project)

{
  ...,
  "version": "config/version.js",
}
  1. Returning a static version
exports.version = async () => {
    return "1.0.0";
}
  1. Returning a dynamic version using a request via superagent. Example using https://reqres.in/api/users/1
let request = require("supertest");

exports.version = async () => {
    try
    {
        return request("https://reqres.in")
          .get("/api/users/1")
          .then(async function (response) {
            return response.body['data']['id'] != undefined ? response.body['data']['id'] : 'undefined';
          });
    }
    catch(err)
    {
        return 'Error in code versioning logic';
    };
};

Testail Execution on CLI & Testrail

image

image

image

Failed tests results on Testrail

image

Testrail Run with mocha defined

image

Testrail Run with version defined

image

Testrail Run with mocha & version defined

image