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-exports-ui

v0.0.3

Published

extended built-in exports interface for Mocha

Downloads

2

Readme

mocha-exports-ui

This projects lets you write your Mocha tests in the same way as original exports UI but it adds pending and exclusive tests plus shortcuts like let and const for assigning variables to the context.

Compare BDD interface and mocha-exports-ui interface:

// mocha-exports-ui interface:
module.exports = {
  'User': {
    // will add variables to the context but only once (similar to `beforeAll`)
    const: {
      db: function(done){
        connect('some://connection/string', done);
      },
      User: function(){
        return this.db.model('User', UserSchema);
      }
    },
    // same as `const` but runs before each test like `beforeEach`
    let: {
      user: function(cb){
        new this.User({name: 'joe', password: 'qwerty', email: '[email protected]'}).save(done);
      }
    },
    // a test suite is just an object that can contain other test suites and tests
    '.signup': {
      // a test
      'returns an error if email exists': function(done){
        new this.User({name: 'another_joe', password: 'qwerty', email: '[email protected]'}).save(function(err){
          expect(err.message).to.contain('email exists');
          done(err);  
        });
      }
    },
    '#save': {
      // adding minus sign will skip the test, this is the same as calling `it.skip`
      '- it hashes password': function(){},
      'omits real password': function(){},
      // exclamation point makes a test or a suite exclusive, it is equivalent to  `it.only` or `describe.only`
      '! returns an error if email is changed to existing one': function(){}
    }
  }
}

// the same using regular BDD interface
describe('User', function(){
  before(function(done){
    const _this = this;
    connect('some://connection/string', function(err, db){
      if(err) return done(err);
      _this.db = db;
      _this.user = db.model('User', UserSchema);
    });  
  });  

  beforeEach(function(done){
    const _this = this;
    new this.User({name: 'joe', password: 'qwerty', email: '[email protected]'}).save(function(err, user){
      if(err) return done(err);
      _this.user = user;
      done(err);  
    });
  })
  describe.only('.signup', function(){
    it('returns an error if email exists', function(done){
      new this.User({name: 'another_joe', password: 'qwerty', email: '[email protected]'}).save(function(err){
        expect(err.message).to.contain('email exists');
        done(err);  
      });
    });
  });
  describe('#save', function(){
    it.skip('hashes password', function(){/* some code*/});
    it('doesn\'t save real password',function(){});
    it.only('returns an error if email changed to existing',function(){})
  });
})

See the test/index.js file in this repo for an example

#Usage

  • Install the package: npm install --save-dev mocha-exports-ui
  • Then just provide the UI name and mocha will automatically require mocha-exports-ui: mocha --ui mocha-exports-ui test/index.test.js

###TODO:

  • should add let and const to the error output, for instance instead of "before each" hook for "adds variables to the context" it should say "let" hook for "adds variables to the context"