I’m working on a personal project that makes uses of Hapi for its API layer.
I’ve managed to go about in a mostly test driven fashion and worked from the
bottom up (from data modeling up to the route definition). Whilst working on
the ability to test the response states of routes, I noticed a few problems when
using the Chai plugin for HTTP testing, chai-http. For
completeness, here is what I’m working with1:
That TODO part tripped me up. Checking Hapi’s documentation, I noticed that
Hapi exposed a HTTP server object via server.listener. This gave me the
idea of doing this:
Definitely not what I was looking for. And to be honest, I feel like this
requires me to get closer into how this works and I plan to make a follow-up
post to do this. In the interim, I’ve resorted to using server.inject to
Boom. This kind of sucks. I really like the tools from Hapi and friends but
this little barrier of interoperability between libraries and larger projects
sucks. Again, since I found a working solution, there’s no heavy need for me
to get this working with chai-http at the moment. But if I or anyone else
figure this out, I’ll be sure to provide a new blog post.
For compatibility information, this is me testing this on Hapi 9.3.0, but
this’ll apply for older versions of Hapi (tested on 8.8.1, the version I’m using
in my project).
I make use of ES6 keywords a lot and I don’t use semicolons, we don’t need them. ↩
For reference, this failed with node 0.12.0 and io.js 3.0.0 as well. ↩