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

metamocha

v1.3.2

Published

Metamocha is a test runner based on [Mocha](https://mochajs.org/), which allows you to include metadata with each test and add filters to selectively run certain tests.

Downloads

262

Readme

metamocha

Metamocha is a test runner based on Mocha, which allows you to include metadata with each test and add filters to selectively run certain tests.

Installation

You can install the module from npm

npm install metamocha

Usage

Here's an example of a test runner that uses metamocha. It works in a very similar way to using Mocha programatically.

var Metamocha = require('metamocha');

// Instantiate new Metamocha
var metamocha = new Metamocha();

// Add files from directory
metamocha.addFolder('test/');

// Apply a filter
metamocha.addFilter({
  filter: function(test) {
    return test.hasOwnProperty('metadata');
  }
});

// Set up test configuration

// Useful in situations where configuration is used to set up 
// things before the test run and you would like tests to have 
// reference to this information
var config = { a: 1 };

// Run
metamocha.run(config, function(failures) {
  process.on('exit', function() {
    process.exit(failures);
  });
});

Add metadata to your tests

Metadata, in the form of an object, can be passed to tests themselves in two ways.

// Standard 'it' test, with no metadata
it('should have no metadata', () => {

});

// Test with metadata passed as the second argument
it('should have metadata', { a: 1 }, () => {
    
});

// Test with metadata passed in an alternate object-based syntax
it('should also have metadata', {
    metadata: { a: 1 },

    test: function() {

    }
});

Add metadata to your suites

Metadata can also be passed to tests through the suite level. By default, any tests will inherit their suite's metadata if it's present. If a test has its own metadata, it'll override any metadata passed in through the suite.

// Suite metadata passed as the second argument
describe('a suite with metadata', { a: 1 }, () => {
  it('should pass its metadata on to its tests', () => {
    // This test should have metadata { a : 1 }
  }); 

  it('should have its metadata overriten by test-level metadata', {
    metadata: { a: 2 },

    test: function() {
      // This test should have metadata { a: 2 }
    }
  });
});

// Suite metadata passed in an alternate object-based syntax
describe('another suite with metadata', {
  metadata: { a: 1 },

  tests: function() {
    it('should still pass its metadata along', () => {
      // This test should have metadata { a: 1 }
    });
  }
}); 

Have tests reference their own metadata

A test's metadata is contained within its Context, so you can access it with this.metadata inside the test run.

it('should be able to access its own metadata', {
  metadata: { a: 1 },

  test: function() {
    expect(this.metadata).to.eql({ a: 1 });
  }
});

Configuration is also contained within the Context and can be accessed in a very similar .

// test runner
var config = { a: 1 };

metamocha.run(config, function(failures) {
  process.on('exit', function() {
    process.exit(failures);
  });
});

// test file
it('should be able to access its own configuration' function() {
  expect(test.configuration).to.eql({ c: 1 })
});