@slothsoft/qunit-reporter

A module to generate reports from QUnit.

Usage no npm install needed!

<script type="module">
  import slothsoftQunitReporter from 'https://cdn.skypack.dev/@slothsoft/qunit-reporter';
</script>

README

QUnit Reporter

MIT Licence Build Status npm version

A module to generate reports from QUnit. Right now this module supports getting test data from multiple sources. Similarly it exports into different formats.

Content of this file:

Getting Started

Installing

This module can be found in the npm software registry:

npm install @slothsoft/qunit-reporter --save

Using the Framework

Creating a test report consists of two parts:

  1. Collecting the test results
  2. Exporting the collected results

The general API to mix and match both parts is:

var sourceConfig = {};
var exportConfig = {};

require("@slothsoft/qunit-reporter")
    .from<Source>(sourceConfig)
    .to<Export>(exportConfig);

You can generally chain multiple exports after each other like this:

require("@slothsoft/qunit-reporter")
    .from<Source>(sourceConfig)
    .to<Export1>(exportConfig)
    .to<Export2>(exportConfig)
    .to<Export3>(exportConfig);

Examples for Sources

QUnit

const QUnit = require("qunit");

QUnit.module("source-qunit", function() {
    QUnit.test("my first test", function(assert) {
        assert.equal(true, true);
    });
});

require("@slothsoft/qunit-reporter").fromQUnit().toLog({ file : "example/output/source-qunit.txt" });

Custom Source

var run = {
    name : "Run",
    suites : [
        {
            name : "source-run",
            tests : [
                { name : "Test 1", time : 123},
                { name : "Test 2", time : 456, error : "Error"},
                { name : "Test 3", time : 789, failure : "Failure"},
            ],
        }
    ],
    total : 3,
    failures : 1,
    errors : 1,
    tile : 1368
};

require("@slothsoft/qunit-reporter").fromRun(run).toLog({ file : "example/output/source-run.txt" });

Examples for Exports

All exports acknowledge the following parameters in their configuration:

  • file - exports directly to file
  • callback - callback function with report content

HTML

Creates an HTML that can be displayed in any browser.

var run = createRun();

require("@slothsoft/qunit-reporter").fromRun(run).toHtml({
    file : "example/output/export-html.html", // exports directly to file
    callback : reportContent => {}, // callback function with report content
    encoding : 'utf-8', // the encoding of the exported file
    xsl : null, // XSL that converts to HTML (or whatever you like)
    xslFile : null, // path to XSL file that converts to HTML
});

To see how the config for XSL might work see this example:

JUnit

Creates standard JUnit XML that should be readable by every program that can handle JUnit as well.

var run = createRun();

require("@slothsoft/qunit-reporter").fromRun(run).toJUnit({
    file : "example/output/export-junit.xml", // exports directly to file
    callback : reportContent => {}, // callback function with report content
    encoding : 'utf-8', // the encoding of the exported file
});

Log

Creates a log similar to what NodeJS does when executing the tests.

var run = createRun();

require("@slothsoft/qunit-reporter").fromRun(run).toLog({
    file : "example/output/export-log.txt", // exports directly to file
    callback : reportContent => {}, // callback function with report content
    encoding : 'utf-8', // the encoding of the exported file
});

Custom Export

Uses a function to export the run.

var run = createRun();

require("@slothsoft/qunit-reporter").fromRun(run).toCustomExport(function(run) {
    // this is a minimalistic report
    return (run.total - run.failures - run.errors) + " / " + run.total + " passed.";
}, {
    file : "example/output/export-custom.txt", // exports directly to file
    callback : reportContent => {}, // callback function with report content
    encoding : 'utf-8', // the encoding of the exported file
});

Versions

Version Release Notes
0.2.0
  • XSL for HTML works correctly now and is customizable
  • bugfixes
  • defensive programming
0.1.0
  • basic functionality
  • sources: QUnit
  • exports: JUnit, HTML

License

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