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-as-generated

v1.0.4

Published

Adds generator support to the Mocha test runner.

Downloads

3

Readme

Generator Tests for Mocha

So you really like Mocha. But you also really like generators & promises. And you'd like to see support in Mocha for the promise-returning test style found in Buster and others, i.e. stuff like


it("should be fulfilled with 5", function *() {
    var num = yield getNum(5);
    result.should.equal(5);
});

it("should throw an error", function *() {
    try {
        var someError = new TypeError('some error!');
        var result = yield getError(someError);
    } catch (error) {
        error.should.equal(someError);
    }
});

Origin Note

This is a fork of the mocha-as-promised - https://github.com/domenic/mocha-as-promised repo, but extended to also allow the use of generator functions as well.

How to Use

Once you install and set up Mocha as Generated, you now have another way of creating asynchronous tests, besides Mocha's usual done-callback style or Mocha-As-generated's promise style. Just return a generator and use yields like you would expect.

Moch as Generated works with all Mocha interfaces: BDD, TDD, QUnit, whatever. It hooks in at such a low level, the interfaces don't even get involved.

Installation and Usage

Node

Do an npm install mocha-as-generated --save-dev to get up and running. Then:

require("mocha-as-generated")();

You can of course put this code in a common test fixture file.

AMD

Mocha as Generated supports being used as an AMD module, registering itself anonymously. So, assuming you have configured your loader to map the Mocha and Mocha as Generated files to the respective module IDs "mocha" and "mocha-as-generated", you can use them as follows:

define(function (require, exports, module) {
    var mocha = require("mocha");
    var mochaAsGenerated = require("mocha-as-generated");

    mochaAsGenerated([mocha]);
});

<script> tag

If you include Mocha as Generated directly with a <script> tag, after the one for Mocha itself, then it will automatically plug in to Mocha and be ready for use:

<script src="mocha.js"></script>
<script src="mocha-as-generated.js"></script>

Node, the Advanced Version

The require("mocha-as-generated")() above tries to detect which instance of Mocha is being used automatically. This way, Mocha as Generated can plug into either the local Mocha instance installed into your project, or into the global Mocha instance if you're running your tests using the globally-installed command-line runner.

In some cases, if you're doing something weird, this can fall down. In these cases, you can pass an array of Mocha instances into the Mocha as Generated function. For example, if you somehow had your Mocha module as a property of the foo module, instead of it being found in the usual npm directory structures, you would do

require("mocha-as-generated")([require("foo").MyMocha]);