Add tests

This also caught a minor bug around error handling: this is masked
by the bin, which throws as soon as the callback returns an error,
but using .json programmatically will trigger a bug in which the
function continues and tries to process the return value of the callback
as a module.