I’m learning so many new things at BrightTag! Among them, I’m helping develop a new service in node.js. After piecing together a fewÂ articlesonline about using node for asynchronous testing of REST services, I thought I’d share the testing setup I’d settled on, in case it can help you. The setup is written for vowsjs and can easily be tailored to your situation.Â I’ve tried to make heavy use of asynchronization, macros, and contextualized requests. In the case below, I was integration-testing an oauth security middleware (simplified here for, well, simplicity).

This pattern is nice because adding new tests is a real piece of cake now that we have the contextualized request macro, and this macro pattern is easy to tailor to your situation. It also demonstrates how to set two contexts, which was left “to the reader” on the vows guide. You can even imagine adding more vows and assertions, such as one that checks the body content, into the macro, as I’ve done in the real case.

Can you refactor or modify this to make it cleaner still? Let me know in the comments.

Subscribe

About Cody A. Ray

I’m an inquisitive, tech-savvy, entrepreneurially-spirited dude. Currently, I’m a DevOps engineer at PEAK6, an entrepreneurial investment firm in downtown Chicago. This is my personal blog. Giving true meaning to the origin of the term, my blog is a catalog of my thoughts on various matters, ranging from technology tutorials to social commentary. My goal is to create insightful, […]more →