hapipal / boilerplate

A friendly, proven starting place for your next hapi plugin or deployment
https://hapipal.com
183 stars 27 forks source link

How to get testing up and working #5

Closed failpunk closed 8 years ago

failpunk commented 8 years ago

I'm new to node and I'm checking out your repo...thanks!! I have everything up and running but I can't see to get testing going.

I'm assuming that since your are exporting the manifest in server.js that you would create the server via Glue in each of your test files. Whenever I do this it never calls the callback passed to Glue.compose

Am I setting this up right?

// test/test.js

var Glue = require('glue');
var Path = require('path');

var manifest = require("../server.js");

Glue.compose(manifest, { relativeTo: Path.join(__dirname, '../node_modules') }, function (err, server) {

   // We never get here..

    if (err) {
        throw err;
    }

    console.log('begin tests');  

});

Test Output:

0 tests complete Test duration: 0 ms No global variable leaks detected

devinivy commented 8 years ago

That is one approach, yes! For a more robust approach, see my gist: https://gist.github.com/devinivy/1e6e71abcb721fa8fee9

Your approach will work with one small change. To keep the testing suite in sync timing-wise, you should put that boilerplate Glue.compose() code into a lab before() call, as demonstrated here: https://github.com/hapijs/lab#usage

failpunk commented 8 years ago

Thanks @devinivy, making it async and putting Glue.compose in the before call works. I'll have to take a bit more time to grok your more robust solution to see how I might use that.

devinivy commented 8 years ago

Yeah, this stuff can be hard. Testing servers is a common pain-point. Feel free to ask questions here and for further topics on the hapijs/discuss repo!

If you're ever able to PR a good testing solution into this repo, I'd love that. The gist I sent above is a little more heavy-duty than I'd like to include in this boilerplate.