Testing Hapi Plugins

Recently, I have found myself needing to build out some authorization modules for both Hapi and Express applications. Hapi has become my server of choice, and building some fully testable plugins has been a priority. In the process, I have learned several techniques that have really streamlined my testing.

There are a few tools I’ve settled on for the baseline structure of my testing:

Mocha
Test runner and base framework
Chai (Chai.expect)
Assertion library
Sinon
Mocks, Stubs, Spies and many other useful helpers
Supertest
Simplifies assertions against explicit routes in our server
Nock
Mocks Node’s HTTP request library for injection of responses

Continue reading →