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

node-mimejs

v0.0.11

Published

Mock, Spy and Argument Captor module for Node.js TDD

Downloads

6

Readme

#Mime (npm node-mimejs)

Mime (npm node-mimejs module) is a capturing mock library for Node.js. It uses harmony-reflect Proxy objects (part of the ES 6 JavaScript standard) to allow for very simple capturing mock objects and capturing callbacks to be created and used within an automated test framework such as Mocha.

##Example

Assuming you have the following Mongoose code in a file called "mySrcFile.js"

var Cat = mongoose.model('Cat', { name: String }),
    kitty = new Cat({ name: 'Zildjian' });

kitty.save(function (err) {
    if (err) {
        console.log('meow');
    }
});

And you want to not only test the arguments that are passed to mongoose.model, but also to the constructor for the call to make the kitty instance of Cat and then also to make sure that save was called on that instance, you simply do:

var assert = require('assert'),
    Mime = require('../../mime/mime').Mime,
    mongoose;

mongoose = global.mongoose = new Mime();
mongoose._spy('model', function() {
    return this._createClass(function () {
    });
  });
require('./mySrcFile.js');

describe('mongooseExample.js', function () {
    it('Should have created the model', function () {
        assert.ok(mongoose._wasCalledWithArguments('model', 'Cat', { name : String }),
          'Should have called model');
    });

    it('Should have called the "Cat" constructor', function () {
        assert.equal(mongoose._getCallArguments('Class', 0)[0].name, 'Zildjian',
          'Should have created a Zildjian cat');
    });

    it('Should have called the "save" method', function () {
        assert.equal(typeof mongoose._getCallArguments('save', 0)[0], 'function',
          'Should have called with a callback');
    });
});

##Documentation Documentation can be found in the docs folder. Also available with additional information here: http://dylanb.github.io/mime/overview.html.

##Use

NPM install node-mimejs

Then in your test files

require('node-mimejs');

##Environment

Then ensure that grunt/gulp starts node with the -harmony flag set. I did this by creating a shell script in my PATH (cunningly called "node"), that comes before the actual node executable that then calls the real node executable with the -harmony flag.

Here is the source code of that shell script for you to copy/modify

#!/bin/bash
echo $*
/usr/local/bin/node -harmony $*

##Develop

All you need to do is git clone [email protected]:dylanb/mime.git and then npm install to get everything installed.

##Known Issues and Workarounds

###Grunt connect watch Proxy not defined error

There is currently a bug when using Mime in tests that run continually using grunt connect watch. Due to the need to start node with the -harmony flag and the fact that watch always spawns a new instance of node, the -harmony flag is lost by the auto spawns.

This issue does not exist when using gulp.watch - maybe you want to use gulp instead of grunt.

There is a fix that is currently in a pull request to fix this https://github.com/gruntjs/grunt/pull/877

If you must use Grunt, you can get around this by fixing the bug in util.spawn that causes this. Here is the change

in the node_modules/grunt/lib/grunt/util.js file, look for this section of code:

if (opts.grunt) {
    cmd = process.argv[0];
    args = [process.argv[1]].concat(opts.args);
} else {

And change this line:

    args = [process.argv[1]].concat(opts.args);

To

    args = process.execArgv.concat([process.argv[1]].concat(opts.args));