Skip to content

Commit

Permalink
correctly error out when threshold is not met - fixes #48
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 8, 2015
1 parent b6c9b6b commit e85c57e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
};
1 change: 1 addition & 0 deletions lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
6 changes: 6 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit e85c57e

Please sign in to comment.