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

mocha-repeat

v0.1.0

Published

Loop tests through diferrent variations of data.

Downloads

534

Readme

mocha-repeat

Loop tests through diferrent variations of data in mocha.js. Perfect for testing against multiple versions of 3rd-party libraries.

var mdescribe = require('mocha-repeat');

var libs = {
  'jquery-1.9': require('../vendor/jquery-1.9.js'),
  'jquery-2.0': require('../vendor/jquery-2.0.js'),
  'jquery-2.1': require('../vendor/jquery-2.1.js'),
};

mdescribe("Tests", libs, function (jQuery) {

  /* ..tests.. */

});

This will be expanded to:

describe("Tests (jquery-1.9)", function () {
  var jQuery = require('../vendor/jquery-1.9.js');
  /* ..tests.. */
});

describe("Tests (jquery-2.0)", function () {
  var jQuery = require('../vendor/jquery-2.0.js');
  /* ..tests.. */
});

describe("Tests (jquery-2.1)", function () {
  var jQuery = require('../vendor/jquery-2.0.js');
  /* ..tests.. */
});

Install

$ npm i --save-dev mocha-repeat

Why?

This effect is easily achievable in plain JavaScript, though the resulting code will be more verbose.

libs = { ... };
for (var version in libs) {
  if (libs.hasOwnProperty(version)) {
    var jQuery = libs[version];

    (function (jQuery, version) {
      describe("Test (" + version + ")", function () {
        /* ..tests.. */
      });
    })(jQuery, version);
  }
}

It's easier to write it this way:

libs = { ... };
mdescribe("Test", libs, function (jQuery, version) {
  /* ..tests.. */
});

Splatting

If the values are arrays, they will be spread across the function's arguments. In this example, the function's 2 arguments (jQuery, options) will be populated by the array items.

var libs = {
  'jquery-1.9': [ require('../vendor/jquery-1.9.js'), { legacy: true } ],
  'jquery-2.0': [ require('../vendor/jquery-2.0.js'), { } ],
  'jquery-2.1': [ require('../vendor/jquery-2.1.js'), { future: true } ],
};

mdescribe("Tests", stubs, function (jQuery, options) {

  if (options.legacy) {
  }

});

Permutations

You can nest calls to mocha-repeat. This is great for testing combinations of multiple library versions. In this example, it tests against every possble combination of underscore [1.0..1.2] with backbone [1.0..1.2].

var libs = {
  underscore: {
    '1.0': '../vendor/underscore/1.0.0.js',
    '1.1': '../vendor/underscore/1.1.0.js',
    '1.2': '../vendor/underscore/1.2.0.js',
  },
  backbone: {
    '1.0': '../vendor/backbone/1.0.0.js',
    '1.1': '../vendor/backbone/1.1.0.js',
    '1.2': '../vendor/backbone/1.2.0.js',
  },
};

var _, Backbone;

mdescribe("Underscore", libs.underscore, function (upath) {
  mdescribe("Backbone", libs.backbone, function (bpath) {

    // load the libraries
    // ...tip: https://www.npmjs.org/package/proxyquire
    before(function () {
      _ = require(upath);
      Backbone = proxyquire(bpath, { underscore: _ });
    });

    it ('loads without errors', function () {
      expect(_).is.a('function');
      expect(Backbone).is.a('object');
    });
  });
})

Output:

$ mocha -R list

  . Underscore (1.0) Backbone (1.0) loads without errors
  . Underscore (1.0) Backbone (1.1) loads without errors
  . Underscore (1.0) Backbone (1.2) loads without errors
  . Underscore (1.1) Backbone (1.0) loads without errors
  . Underscore (1.1) Backbone (1.1) loads without errors
  . Underscore (1.1) Backbone (1.2) loads without errors
  . Underscore (1.2) Backbone (1.0) loads without errors
  . Underscore (1.2) Backbone (1.1) loads without errors
  . Underscore (1.2) Backbone (1.2) loads without errors

  9 passing (120ms)

Thanks

mocha-repeat © 2014+, Rico Sta. Cruz. Released under the MIT License. Authored and maintained by Rico Sta. Cruz with help from contributors (list).

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz