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-promise

v0.1.19

Published

TestRail API wrapper using promises

Downloads

4,208

Readme

testrail-promise

TestRail wrapper using promises

"npm badge"

Promise implementation of the TestRail API that returns JSON

http://docs.gurock.com/testrail-api2/start

Setup

var TestRail = require("testrail-promise");
var tr = new TestRail("<url>", "<user email>", "<password/apikey>");

Simple Use Cases

//Getting all Projects
tr.getProjects()
    .then(function(projects) { ... })
    .catch(function(err) { ... });

//Getting a specific project
tr.getProject({"project_id":6})
    .then(function(project) { ... })
    .catch(function(err) { ... });

//Getting test cases
tr.getCases({"project_id":"6", "suite_id":"6", "section_id":"173"})
    .then(function(case) { ... })
    .catch(function(err) { ... });

Automation Use Case

If automated test (Protractor/Karma/...) results are wanted in TestRail use this function.

var obj = {
    "project_name":"<project name>",
    "plan_name":"<test plan>",
    "section_name":"<section/test case folder>",
    "title":"<title of test case>",
    "status_name":"<passed/failed/retest/blocked>"
};
tr.ifNeededCreateThenAddResultForCase(obj)
    .then(function (result) { ... })
    .catch(function (err) { ... });

This will create a test case under the specific section if one does not exist, then update the result to the most recent run of a test plan. It will query using the API to get IDs hence names can be used as long as they are unique. The only required information is: project (project_id/project_name), plan(plan_id/plan_name),section(section_id/section_name), title(can use case_id if case already exists) and status(status_id/status_name).

Jasmine considers showing results within a tests a leak, so we have to use a custom reporter to get results. Usually, we would send the results in a specDone function, but it is not asynchronous therefore I suggest adding an object onto the jasmine var. Here is an example of how to report tests in Protractor:

resultLeaker = {
  suiteStarted: function(result){ jasmine.results = {suite:result}; },
  specStarted: function(result){ jasmine.results.spec = result; }
};
jasmine.getEnv().addReporter(resultLeaker);

describe('TestRail Reporter', function(){
    it('Passing', function(){
        expect(true).toBeTruthy();
    });
    it('Failing', function(){
        expect(false).toBeTruthy();
    });

    var TestRail = require("testrail-promise");
    var tr = new TestRail("<url>", "<user email>", "<password/apikey>");

    afterEach(function(done){
        var obj = {
            "project_name":"<project name>",
            "plan_name":"<test plan>",
            "section_name":"<section/test case folder>",
            "title":jasmine.results.spec.fullName,
            "status_name":(jasmine.results.spec.failedExpectations.length === 0 ? "passed" : "failed")
        };
        tr.ifNeededCreateThenAddResultForCase(obj).finally(function(){
            done();
        });
    });
});

Additional Information

All functions that need input take just one object. It uses what is needed for the API URI then sends the object to the API. This means you should be able to use any field available in the API documentation.

var object = {
    "section_id":173,
    "title":"testrail-promise",
    "type_id":3,
    "project_id":6,
    "estimate":1,
    "milestone_id":3,
    "refs":""
};
tr.addCase(object);

If for some reason the cert on TestRail is not trusted, this function can be called to ignore that error.

tr.allowUntrustedCertificate();

If you want to get errors on non-200 responses change to simple requests.

tr.simpleRequests();

The functions that allow filters ( get_cases , get_milestones , get_plans , get_projects , get_results , get_results_for_case , get_results_for_run , get_runs , get_tests ) can have as part of their parameter object a filters object.

tr.getPlans({
    project_id : 1,
    filters: {
        is_completed : 0
    }
})