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

@digitalbazaar/mocha-w3c-interop-reporter

v1.9.0

Published

Mocha reporter that produces reports that can be embedded in specs.

Downloads

490

Readme

Mocha W3C Interop Reporter

Is a mocha reporter that creates interoperability matrices in existing W3C documents with ReSpec.

Installation

Using npm

npm i --save @digitalbazaar/mocha-w3c-interop-reporter

Usage

The reporter wraps around existing Mocha interfaces such as describe and it.

describe('Matrix Test', function() {
  // summaries are displayed in the SOTD section after the results
  const summaries = new Set();
  this.summary = summaries;
  // when the report sees a suite with report true it includes it
  this.report = true;
  // this tells the reporter to use the matrix.hbs template to display the results
  this.matrix = true;
  // this gives the names of the implementations that are being tested
  this.implemented = ['foo'];
  // this gives the names of the implementations that are not being tested
  this.notImplemented = ['bar'];
  // this will give the row label in the matrix
  this.rowLabel = 'Row';
  // this is the column label in the matrix
  this.columnLabel = 'Verifier';
  //this is an array with items in the form {data: 'foo', detail: false, label: 'bar'}
  const reportData = [];
  // reportData is displayed as code examples
  this.reportData = reportData;
  // this is an array with items in the form {src: 'foo', meta: ['bar']}
  // the images will be displayed with the meta under them
  const images = [];
  this.images = images;
  it('should be a cell in the matrix', function() {
    // this tells the reporter which column and row the test result
    // should be placed in
    this.test.cell = {columnId, 'foo', rowId: 'bar'};
  });
  after(function() {
    summaries.add('Test specific summary data here');
  });
})

A helpers file can be specified to add project specific helpers to report templates:

// myproject/projectHelpers.js

const helpers = {
  upperCaseTitle(testTitle) {
    return testTitle.toUpperCase();    
  }
};
export default helpers;

then specify the path to the helpers file in the --reporter-options helpers="$PWD/projectHelpers.js".

Handlebars lets you use the helpers inside of templates like this:

<td class="{{state}} {{getOptional optional}}">{{getStatusMark state}}</td>

If you need to know the data the template is receiving try logging the context passed to the report.

The report consists of a number of different configuration options:

export const getConfig = () => {
  const homePath = homeDir();
  const templatesPath = join(homePath, 'templates');
  return {
    title: 'W3C Interop Test',
    dirs: {
      // where to output the resulting HTML report
      // if null we output to console.log
      report: null
    },
    // where to log the resulting mocha root suite
    // this can be used to generate test data
    suiteLog: null,
    // config options for the w3c respect library
    respecConfig: join(homePath, 'respec.json'),
    // where to find the templates for handlebars
    templates: {
      body: join(templatesPath, 'body.hbs'),
      head: join(templatesPath, 'head.hbs'),
      metrics: join(templatesPath, 'metrics.hbs'),
      table: join(templatesPath, 'table.hbs'),
      matrix: join(templatesPath, 'matrix.hbs')
    }
  };
};

The templates are written in Handlebars.

Most of the configuration options can be specified by command line options:

mocha tests/ --reporter @digitalbazaar/mocha-w3c-interop-reporter --reporter-options body=\"$PWD/body.hbs\",matrix=\"$PWD/matrix.hbs\",reportDir=\"$PWD/reports\",respec=\"$PWD/respecConfig.json\",title=\"Test Interoperability Report 1.0\",helpers=\"$PWD/templateHelpers.js\",suiteLog='./suite.log' --timeout 15000"
  • --reporter - Specifies the reporter and is required.

  • --reporter-options - Passes options to the reporter in the form key=value[,key2=value[,...]].

    • abstract - Is a recommended reporter option that provides the abstract for a report.

    • body - Is an optional reporter option that provides the body of the report. If no body is specified, the default templates/body.hbs file is used.

    • matrix - Is an optional option that allows customization of matrix test results. If no matrix is specified, the default templates/matrix.hbs file is used.

    • reportDir - Is an optional option that tells the reporter where to write the report HTML. If no dir is specified, no HTML is written.

    • respec - Is a recommended reporter option that provides respec config data to respec. If no json file is specified, the default ./respec.json is used.

    • title - Is a recommended reporter option that sets the title of the report. Defaults to: 'W3C Interop Test'

    • helpers - Is an optional reporter option that provides handlebars helpers usable in custom *.hbs files.

    • suiteLog - Is an optional reporter option that dumps the raw mocha test results to a file.

    • templateData - Is an optional reporter option that dumps the data used to make the HTML report as json.

The reporter also has an npx binary for creating test html manually from mocha suites. This can be used to debug results with out having to rerun an entire test suite.

npx interopReporter makeReport --suiteLog=./suite.log --output=./reports/manualReport.html

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.