9. Testing Stack
• Turbo – test runner
• Istanbul – code coverage
• Proxyquire – mock your require‟s
• Grunt – ties it all together
• See FeedHenry Node.js Cloud Testing Guide
9
10. Testing Stack - Turbo
• Turbo
• Test runner burn out – tight coupling of test running and code coverage
• No fluff, no nuff, just executes exported functions in your test files
• Per-file and global setUp and tearDown
• Parallel by default – encourages stateless tests
10
11. Testing - Istanbul
• Code coverage with Istanbul
11
• Jenkins/CI integration
• Express Middleware – dynamic code coverage
12. Testing - Proxyquire
• Proxyquire: “Proxies nodejs require in order to allow overriding of
dependencies during testing”
12
var request = require('request');
exports.search = function(params, cb) {
request('https://www.google.ie/?q=foo#q=foo', function(err, res, body) {
if (err) return cb(err);
return cb(null, body);
});
};
exports.it_should_test_search = function(finish) {
var mockRequest = function(url, cb) {
console.log("in mock call to request!");
return cb(null, {}, 'Sample data!!');
};
var main = proxyquire('lib/foo.js', {request: mockRequest});
main.search(null, function(err, data) {
assert.ok(!err, 'Unexpected error: ' + util.inspect(err));
console.log("got data from search: ", data);
finish();
});
};
13. Testing – unit vs acceptance
• Eyes on code!
• unit tests should require no external dependencies, external services should
be mocked out (e.g. internet access, writing to file/database, etc)
• unit tests should be super quick to run
• unit tests should be reliable as no external dependencies
• unit tests should just test your own logic
• acceptance tests can require external dependencies, which do require
setup (which should be well documented!)
• as such they can take longer to run
• acceptance tests are a more 'end to end' philosophy
13
15. Mirco Services
• Mix of Message Bus and API
• API - JSON in JSON out (robustness principal)
• Message Bus – Rabbit MQ
• Not just node.js, DropWizard for Java
• Continuous Integration - Small Production Deploys
• Operations – monitor all the things
• Dedicated Ops and Support teams
15
16. Mirco Services – complexity
• Not a silver bullet – but does help with complexity
• Still deal with lots of business rules, moving parts, etc
• Easy !== Simple
• Work at simplicity
• Need Master Builders to keep all the balls in the air
• Boxology
16
17. Misc
• Private NPM Registry: npm delegate (may move to Kappa)
• Docker – container awesomeness
• API Blueprint – readme on steroids
17