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

omf

v1.2.0

Published

ORANGE MOCHA FRAPPUCCINO!!!11

Downloads

10

Readme

ORANGE MOCHA FRAPPUCCINO

Build Status

A little library to build http verification tests quickly on top of mocha. Testing is a party, and everyone is invited!

ORANGE MOCHA FRABBUCCINO

install

npm install omf

use

var omf = require('omf');

var app = require(/*require your express app or http server listener here*/);

omf(app, function(client) {

  client.get('/', function(response) {
    response.has.statusCode(200);
    response.is.html();
    response.has.body('O hai!');
  });

  client.get('/index.js', function(response) {
    response.has.statusCode(200);
    response.has.header('content-type', 'application/javascript');
  });

});

Instead of passing in an express or http server listener as the first parameter, we can pass in the base url of any public website, and all the tests can still run. This way you can swap out your development app for one in production and use the same http tests as a verification tool for your live site.

var omf = require('omf');
var assert = require('assert');

omf('https://github.com', function(client) {
  client.get('/brianc/node-omf', function(response){
    response.has.statusCode(200);
    response.has.body('ORANGE MOCHA FRAPPUCCINO');

    //the full response is available to any custom tests:
    it('has ETag header', function() {
      assert(this.response.headers['etag']).ok();
    });
  });
});

ORANGE MOCHA FRAPPUCCINO just uses a tiny bit of meta-programmy-bla-bla to reduce the boiler plate in set up & tear down of http tests...but you still have the entire mocha framework at your disposal. For example, you can still nest sub-contexts, do more setup/teardown, or whatever!

var omf = require('omf');
var assert = require('assert');

omf('https://github.com', function(client) {
  describe('when not signed in', function() {
    before(function(done) {
      process.nextTick(function() {
        //some sign out logic maybe?
        done();
      });
    });
    
    client.get('/brianc/node-omf', function(response) {
      response.has.statusCode(200);
    });
  });
});

Also, the requests are all sent using the request library. Anything you pass as the optional 2nd parameter will be passed straight into the request module.

omf('https://some-awesome-json-web-service.com', function(client) {
  describe('with json request', function() {
    var options = { json: true };

    get('/user1.json', options, function(res) {
      res.has.statusCode(200);
    });
  });

  describe('with non-json request', function() {
    get('/user1.json', function(res) {
      res.has.statusCode(406); //not acceptable
    });
  });
});

Shorthand to just do the bare minimum sanity checks. These are all equal.

omf(app, function(app) {
  app.get('/', function(res) {
    res.has.statusCode(200);
  });

  app.get('/', 200);

  app.get('/');
});

Sometimes you do not know the url ahead of time. ORANGE MOCHA FRAPPUCCINO supplies you with the same request object used in other tests so you can share a cookie jar and other things. Example:

//test login & post flow
omf(app, function(app) {
  var credentials = {
    email: '[email protected]',
    password: 'pass'
  }

  app.post('/', {json: credentials}, function(res) {
    res.has.statusCode(200);
  });

  //at this point we have a login cookie, so lets create
  //a post for our next test...

  var post = {
    text: 'I love to write posts about things'
  };
  app.post('/posts', {json: postJson}, function(res) {
    res.has.statusCode(201); //created
    it('has post body and id', function() {
      //remember the scope of the 'it' tests have access to the
      //raw response from `request`
      var savedPost = this.response.body;
      assert(savedPost.id, 'created savedPost should have a body');
      assert.equal(savedPost.text, post.text);
      //let's save the posts ID to a place our other test can access it
      post.id = savedPost.id;
    });
  });

  //now lets test the fetching of the newly created post
  //remember, we didn't know the ID beforehand, so we don't know the direct url
  //we're basically dropping out of what ORANGE MOCHA FRAPPUCCINO gives you
  //as helpers and doing it ourselves manually but we still have 
  //our applications life-cycle managed and our urls rooted to our 
  //dynamically hosted app
  describe('getting saved post', function() {
    var optionsBuilder = function() {
      return {
        path: '/posts/' + post.id
      }
    };
    app.get(optionsBuilder, function(res) {
      res.has.statusCode(200);
      it('returns saved post', function() {
        var savedPost = res.body;
        assert.equal(savedPost.text, post.text);
      })
    });
  });
});

license

Copyright (c) 2012 Brian M. Carlson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.