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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mongotape

v1.0.0

Published

Run integration tests using mongoose and tape

Downloads

20

Readme

mongotape

Run integration tests using mongoose and tape

install

npm i mongotape -S

usage

Set up a ./mongotape module as follows.

var mongotape = require('mongotape');
var options = {
  mongoose: require('mongoose'),
  models: 'models/*'
};
module.exports = mongotape(options);

You're all set, your tests should now use that module to access the mongotape API.

mongotape(description?, tests)

The tests callback will receive a test object that matches the API you would expect from tape. The difference is that each test will include a setup and teardown.

setup

  • Database connection is established
  • Database is dropped
  • Database is re-created and models are re-loaded

teardown

  • Database connection is closed

This process ensures each test runs effectively in isolation, which is usually a very painful thing to achieve using plain tape and mongoose.

example

mongotape(function tests (test) {
  test('.recent pulls recent sorted by creation date, descending', function (t) {
    contra.series([
      function (next) {
        new models.Log({ level: 'info', message: 'some foo' }).save(next);
      },
      function (next) {
        new models.Log({ level: 'error', message: 'some bar' }).save(next);
      },
      function (next) {
        logQueryService.recent({}, next);
      }
    ], function (err, results) {
      var logs = results.pop();
      t.equal(err, null);
      t.equal(logs.length, 2);
      t.equal(logs[0].message, 'some bar');
      t.equal(logs[1].message, 'some foo');
      t.end();
    });
  });
});

You can mix mongotape and regular Tape's test statements as you see fit. There's no need to call a special method to signal that you are done, as mongotape will simply yield execution once all your mongoose test handlers have ran to completion.

options

You can set a few options when first configuring mongotape as seen above.

mongoose

Set mongoose to your local mongoose instance so that we have the same exact version

models

Set models to the path to your mongoose models. It can be an string, an array, or a method that returns the models in an object like:

{
  Article: ArticleModel,
  Comment: CommentModel
}

(and so on...)

env

If you use an environment variables manager such as nconf, set options.env to a method that returns an environment configuration value given a key. Here's the default implementation:

function env (key) {
  return process.env[key];
}

license

MIT