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

jstd-mocha

v0.0.8

Published

Run JsTestDriver tests on Mocha.

Downloads

11

Readme

jstd-mocha

Run your JsTestDriver tests directly within Mocha. This project borrows source code from karma-jstd.

Build Status

Usage

After installing with npm install --save-dev jstd-mocha you can run JsTestDriver tests like this:

require('jstd-mocha').installTo(global);

var MyTestCase = TestCase('JsTestDriver (first suite)');

MyTestCase.prototype.setUp = function() {
	this.x = true;
};

MyTestCase.prototype.testThatXIsTrue = function() {
	assertTrue('x should have been set to true in setUp()', this.x);
};

Running The tests

Because JsTestDriver tests are added to the test-case after it's created, jstd-mocha needs to be nudged once all of the tests have been registered, so you can't just run mocha test as you normally might — assuming your tests are all inside a test directory.

Instead, you can either use the --delay flag, as follows:

mocha test --delay

or create a jstd-register.js file in your own project having these contents:

require('jstd-mocha/register');

and then run the tests like this:

mocha test jstd-register

This second way of doing things is particularly useful if you are planning to run your Mocha tests in a browser using the karma-mocha plug-in. Take a look at this project's package.json and karma.conf.js for examples of this.

Migrating to Mocha

Since jstd-mocha is mostly just a thin wrapper around Mocha and expectations, it isn't too hard to permanently change your tests so they run directly in Mocha. Additionally, since Mocha has an identical API to Jasmine for everything but asynchronous tests, and since expectations is a port of the Jasmine assertion API, tests should also be runnable in Jasmine too.

There are some caveats however. The more complex assertions (e.g. assertEquals()) aren't completely compatible with their Jasmine counterparts (e.g. .toEqual()), so we instead map these through to the assertion library that ships with js-test-driver by default.

However, you can migrate your tests over to using 100% Jasmine compatible expectations by using these assertions instead:

  • $assertEquals() instead of assertEquals() (uses the same definition of object equality as .toEqual()).
  • $assertException() instead of assertException() (if an argument is provided, expects that argument to be equal to the error that will be thrown, rather than expecting a string containing only the type of the error that will be thrown).

Once you've done this for all tests, the final conversion can be done completely mechanically.