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

test-model-reporter

v0.1.83

Published

Create a pure JavaScript object model based on JUnit methodology

Downloads

118

Readme

Test Model Reporter

JavaScript hierarchical object model Any model type can validate, generate a report and write it to the file system Currently JUnit xml and Jasmine reporters are supported:

  • JUnit Generates JUnit XML files according to the junit.xsd
  • Jasmine Generates spec files

How To

First create a simple model

The model can be crated using an API like so:

 var testcase,
    failure,
    testsuite = jmr.create({
        type: "model.testsuite",
        data: {
            name: "testsuite"
        }
    });
    testcase = jmr.create({
        type: "model.testcase",
        data: {
            time: "now"
        }
    });
    testcase.set("name", "This is the test name");

    failure = jmr.create({
        type: "model.failure",
        data: {
            message: "This is a faulire message",
            type: "failure"
        }
    });

    testcase.add(failure);
    testsuite.add(testcase);

With that:

You can create an HTML site using Ant Reporter.

// write your file to the tests folder
jmr.write("./tests/demoTest.xml", testsuite.compile());

// tell ant where are your tests and where to put your HTML output
// Ant will collect all your *Test.xml files from test folder
jmr.report({
        reportsdir: "tests/reports",
        testsdir: "tests"
    });

Note: Ant dependency is not installed. You can find it in the dev dependency section.

Another example

In case you generates an object with all of your data, much simpler to burst it like so:

var obj = jmr.generate({
    type: "model.testsuites",
    data: {
        disabled: "false",
        name: "test.suites",
        body: [{
            type: "model.testsuite",
            data: {
                id: "$id",
                package: "test.test",
                name: "test.suite.1",
                body: [{
                    type: "model.testcase",
                    data: {
                        classname: "class1",
                        name: "test.case",
                        time: "now",
                        body: [{
                            type: "model.failure",
                            data: {
                                type: "fail",
                                body: "body content in here..."
                            }
                        }]
                    }
                }]
            }
        }]
    }
});

Jasmine example

Note: to be able to test the specs using node run: node installer.js or install jasmine-node module.

tmr.setReporter("jasmine");

var describe = tmr.create({
    type: "model.jas.describe",
    data: {
        title: "A suite is just a function",
        body:[
            {
                type:"model.jas.code",
                data: {
                    body: "var a;"
                }
            },
            {
                type: "model.jas.it",
                data: {
                    title: "and so is a spec",
                    body: [{
                        type:"model.jas.code",
                        data: {
                            body: "a = true; expect(a).toBe(true);"
                        }
                    }]
                }
            }
        ]
    }
});        


Model types: 
* **model.jas.describe** describe method
* **model.jas.it** it method
* **model.jas.code** code snippet 

Note: WIP, other Jasmine functionality will be supported.

Browser Support

Usage

  • AMD

    • See tmrwebRequire-min.js file, as an example of requirejs project style

      define([], function() {

        var jmrOnReady = function (jmr) {
            // use the "jmr" object   
        };
        return jmrOnReady;
              

      });

  • None AMD

      // Use "jmr" or "testModelReporter" objects 
            
            
            

Download

Troubleshooting

  • Ant reporter, issue with MAC
    • After Ant Npm installed edit the ../bin/ant file according to the following fix

Reference

  • create(config)
    • config {Object} The JUnit based configuration model
      • type - The type of the class model.[testsuites | testsuite | testcase | failure | error | skipped | system]
      • data - The class data
        • available specification properties (id, name, disabled, etc...)
        • body - the class children, can be a nested class or a string value
  • generate(config)
    • config {Object} The JUnit based configuration model
      • type - The type of the class model.[testsuites | testsuite | testcase | failure | error | skipped | system]
      • data - The class data
        • available specification properties (id, name, disabled, etc...)
        • body - the class children, can be a nested class or a string value return an object
    • output {String} The generate output model
    • model {Object} The generated object model

JUnit Reporter configuration {reportsdir: "the output report location", testsdir: "the test folder to be scanned"}

Contribute

See ./src/reporter/junit and ./src/reporter/jasmine reporters for more information