diff --git a/index.js b/index.js index f59a314..9c330f0 100755 --- a/index.js +++ b/index.js @@ -51,7 +51,13 @@ module.exports.output = function (url, opts, cb) { return; } - output(handleOpts(url, opts), data); + try { + output(handleOpts(url, opts), data); + } catch (err) { + cb(err); + return; + } + cb(); }); }; diff --git a/lib/output.js b/lib/output.js index b90d026..6d63cd6 100644 --- a/lib/output.js +++ b/lib/output.js @@ -70,5 +70,6 @@ module.exports = function (parameters, response) { if (response.score < threshold) { var err = new Error('Threshold of ' + threshold + ' not met with score of ' + response.score); err.noStack = true; + throw err; } }; diff --git a/test/test.js b/test/test.js index d5d1b0c..03c8b7a 100644 --- a/test/test.js +++ b/test/test.js @@ -35,6 +35,12 @@ describe('Formatting', function () { output({strategy: 'desktop', format: 'json'}, response); assert(/"Score": 88/.test(chalk.stripColor(this.formattedOutput))); }); + + it('should throw when threshold is not met', function () { + assert.throws(function () { + output({threshold: 100}, response); + }); + }); }); describe('API', function () {