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 🙏

© 2026 – Pkg Stats / Ryan Hefner

jazzmine

v1.1.0

Published

jassmine testsuite with support for async and require modules

Readme

JazzmineJS

Jazzmine is an addition to Jasmine, adding and modifying it to work nicer with AMD modules and async code.

Installation

Install Jazzmine using npm

npm install jazzmine

Module loading

Jazzmine is made to test individual AMD modules. This is done by loading the model, and any other dependency, right in the describe. For example:

describe("a test with dependencies", ["myLittleModule"], function(myLittleModue){
  
  it("should be a module", function(){
    expect(myLittleModule).toBeDefine();
  });

});

This way you can load the module you want to test, and any other module needed for the test to run, right in the describe statement.

Jazzmine will wait until all of the dependencies have loaded before it runs the tests.

because

The because function is exactly the same as beforeEach. It is included as it works better with behaviour driven code; the because function describes what triggers what we want to test. For example:

describe("when a variable is set", [], function(){
  
  var variable;

  because(function(){
    variable = "a value";
  });

  it("should have set the variable", function(){
    expect(variable).toBe("a value");
  });

});

Async tests

~~Jasmine has horrible support for async testing~~. Jasmine has adopted the same async support as Jazzmine has had, so continue using it like you always have. The beforeEach, afterEach, because and it functions support async by using a done parameter, like so:

it("should wait until the done function is called", function(done){
  
  done();

});


because(function(done){
  
  setTimeout(function(){
    done();
  }, 1000);

});

Mocking

The module you want to test usually has dependencies to other modules, some of which you might want to replace during testing. Jazzmine lets you mock these dependencies during testing. The test files can mock dependencies independently of each other, which means everything is reset for your next test. This is done using moquire. For example:

describe("mock out a dependency", {
  "someModule": function(){ return 5; }
},[
  "aModuleDependingOnSomeModule"
], function(
  aModule
){
    
  it("should swap out the dependency", function(){
    expect(aMOdule.dependency).toBe(5);
  });

});

Global matchers

Matchers can be added to every test by calling jazzmine.addMatchers(). This method can either take an object of matchers, similar to Jasmine, or it can take a function with a callback for async registering matchers. These functions should be called before calling jazzmine.onReady().

jazzmine.addMatchers({
  toBeSomething: function(){
    return {
      compare: function(actual){
        var result = actual === "something";
        var notText = result ? " not" : "";


        return {
          pass: result,
          message: "expected " + actual + notText + " to be something"
        };
      }
    };
  }
});

jazzmine.addMatchers(function(matchers){
  require(['Matchers/toBeSomethingElse'], function(toBeSomethingElse){
    matchers({
      toBeSomethingElse: toBeSomethingElse
    });
  });
});

Setup with Karma

Jazzmine will work with any test runner, but here is an example of using it with Karma. Install Karma with npm:

npm install karma

Next add a karma.conf.js file with all the files karma should load and make available. Because we are using requireJS, we don't have to load the modules we are testing; they will be loaded by the tests that need them. But karma needs to be told to include them! Here is an example karma.conf.js:

module.exports = function(config){
  config.set({

    frameworks: [
      'jasmine'
    ],

    files: [
      'node_modules/requirejs/require.js',
      'node_modules/jazzmine/bin/jazzmine.min.js',
      'node_modules/karma-requirejs/lib/adapter.js',
      //add other libraries needed for testing here (for example sinon)

      'test/specs-main.js',
      {pattern: 'source/**/*.js', included: false},
      {pattern: 'test/Mocks/**/*.js', included: false},
      {pattern: 'test/Matchers/**/*.js', included: false},
      {pattern: 'test/Given/**/*.js', included: false},
      'test/Modules/**/*.js'
    ],

    exclude: [

    ],

    reporters: ['dots'],

    autoWatch: true

  });
};

This file assumes your project is set up with a source and test folder next to the karma.conf.js file. We need to configure requireJS with the correct paths, baseUrl and any other options needed for your project. This config is usually pretty similar to your main.js config file. The test/specs-main.js contains this configuration. Here is an example of the specs-main.js file:

jazzmine.requireConfig({
  // Karma serves files from '/base'
  baseUrl: '/base',

  paths: {
    "Mocks": "test/Mocks",
    "Given": "test/Given",
    "Matchers": "test/Matchers",
  }
});


jazzmine.onReady(window.__karma__.start);

Notice the last line, which starts the karma test runner once all the tests have loaded.

To start the tests, run karma from the directory with the karma.conf.js file:

karma start