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

jest-testrail

v2.2.0

Published

Reporter and transformer for jest reporting

Downloads

31

Readme

Jest TestRail

by Clark Inada

This module is an extention for Jest and provides a transformer and reporter producing a JSON or custom file like an xUnit XML file (when using templates) based on attributes defined in comments.

Example test file with annotations

    // [StoryID('storyID1', 'storyID2')]
    // [CustomAnnotation('value')]
    describe('test group', () => {
        // [StoryID('storyID3')]
        // [StoryID('storyID4')]
        // [AutomationID('autoID1', 'autoID2')]
        test('test case 1', ()=>{
            //...
        });
        // [AutomationID('autoID3')]
        // [AutomationID('autoID4')]
        test('test case 2', ()=>{
            //...
        });
        // [StoryID('storyID5'), StoryID('storyID6')]
        // [AutomationID('autoID5'), AutomationID('autoID6')]
        test('test case 3', ()=>{
            //...
        });
    })

Usage

// this is the "jest" part of the package.json
{
    "jest":{
        ...otherJestOptions,
        "reporters": [
            ["jest-testrail/reporter",{
                // hook can be a file or a package that export event handlers (example given below).
                "hooks": "<rootDir>/hook.js", // optional hooks to inject during runtime.
                // optional regex to use in matching tags
                // default regex is /(\[(.*?)\(['"][\s\S]*?['"]\)\][\s\S]*?)+?(test|describe)[\s\S]*?\(['"][\s\S]*?['"],[\s\S]*?\)/g
                "match": "/validRegex/g",
                "tags": ["AID"], // defaults are StoryID and AutomationID (must only contain alphanumeric or "_" or "$" and can not start with a number)
                // template file (example given below)
                "template": "<rootDir>/template.xml", // optional template file
                "outputFile": "<rootDir>/results.json" // any file name and type when "template" is defined
            }]
        ],
        "transform": {
            ".*test.*": "jest-testrail/transform"
        }
    }
}

Hooks

interface SuiteGroup {
    total: number;
    passed: number;
    failed: number;
    pending: number;
    skipped: number;
    time: number;
    name: string;
    tests: Array<{
        name: string;
        time: number;
        result: string;
        storyId: string;
        automationId: string;
        tags: object; // object with tag as the property name. (ex: if tags:["AID"] was provided in the config, tags = { AID: string })
        custom: object; // object with custom annotation as the property name. From the example test file above, this would be { CustomAnnotation: ["value"] }
        type: 'UnitTest';
    }>;
}
// testResults is the object passed to the template (see below)
module.export.onTestResult = (suiteGroups:SuiteGroup[], testResults) => void
module.export.onRunComplete = (testResults) => void | boolean
//*Note: For onRunComplete - If truthy is returned, the reporter will continue to execute the default behavior of writing to files. If it any falsy is returned, default behavior is not executed.

Templates

// data object passed to the template
{
    suites: [{
        total: number,
        passed: number,
        failed: number,
        skipped: number,
        name: string,
        time: number,
        tests: [{
            name: string,
            time: number,
            result: string,
            storyId: string,
            automationId: string,
            tags: object,
            custom: object,
            type: 'UnitTest'
        }]
    }],
    name: string,
    environment: string,
    framework: string,
    date: string, //today's date in Y-m-d format
    runtime: number,
    config: any, //globalConfig object passed to the Reporter
    options: any, //options object passed to the Reporter
    total: number,
    passed: number,
    failed: number,
    skipped: number,
    time: number,
    errors: number
}
<!-- example xUnit xml template which follows Craydent's fillTemplate syntax-->
<?xml version="1.0" encoding="utf-8"?>
<assemblies>
 <assembly name="SomeName" run-date="${date}" run-time="${runtime}" total="${total}" passed="${passed}" failed="${failed}" skipped="${skipped}" time="time" errors="0">
   <errors />
   ${FOREACH ${suite} in ${suites}}
     <collection total="${suite.total}" passed="${suite.passed}" failed="${suite.failed}" skipped="${suite.skipped}" name="${suite.name}" time="${suite.time}">
       ${FOREACH ${test} in ${suite.tests}}
       <test name="${test.name}" time="${test.time}" result="${test.result}" sid="${test.storyId}" aid="${test.automationId}" type="${test.type}">
         <traits>
           ${if ('${test.storyId}')}<trait name="StoryID" value="${test.storyId}" />${end if}
           ${if ('${test.automationId}')}<trait name="TestID" value="${test.automationId}" />${end if}
           ${if ('${test.custom && test.custom.CustomAnnotation}')}<trait name="Custom" value="${test.custom.CustomAnnotation[0]}" />${end if}
           ${if ('${test.type}')}<trait name="TestType" value="${test.type}" />${end if}
         </traits>
       </test>
       ${END FOREACH}
     </collection>
   ${END FOREACH}
 </assembly>
</assemblies>

Download

Jest TestRail is released under the [licensed under the MIT license].