ORANGE MOCHA FRAPPUCCINO!!!11
A little library to build http verification tests quickly on top of mocha. Testing is a party, and everyone is invited!
npm install omf
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''clientget'/brianc/node-omf'responsehasstatusCode200;responsehasbody'ORANGE MOCHA FRAPPUCCINO';//the full response is available to any custom tests:it'has ETag header'assertthisresponseheaders'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''describe'when not signed in'beforeprocessnextTick//some sign out logic maybe?done;;;clientget'/brianc/node-omf'responsehasstatusCode200;;;;
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''describe'with json request'var options = json: true ;get'/user1.json' optionsreshasstatusCode200;;;describe'with non-json request'get'/user1.json'reshasstatusCode406; //not acceptable;;;
Shorthand to just do the bare minimum sanity checks. These are all equal.
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 flowomfappvar credentials =email: 'email@example.com'password: 'pass'apppost'/' json: credentialsreshasstatusCode200;;//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';apppost'/posts' json: postJsonreshasstatusCode201; //createdit'has post body and id'//remember the scope of the 'it' tests have access to the//raw response from `request`var savedPost = thisresponsebody;assertsavedPostid 'created savedPost should have a body';assertequalsavedPosttext posttext;//let's save the posts ID to a place our other test can access itpostid = savedPostid;;;//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 appdescribe'getting saved post'varreturnpath: '/posts/' + postid;appgetoptionsBuilderreshasstatusCode200;it'returns saved post'var savedPost = resbody;assertequalsavedPosttext posttext;;;;
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.