A little library to build http verification tests quickly on top of mocha. Testing is a party, and everyone is invited!
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',
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.
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 flowomf(app, function(app) { var credentials = { email: 'test@example.com', 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);
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.