Skip to content

Commit

Permalink
Add custom message option for valid-test-description rule
Browse files Browse the repository at this point in the history
  • Loading branch information
BourgoisMickael committed Aug 21, 2019
1 parent 3102e7c commit f1b711d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/rules/valid-test-description.js
Expand Up @@ -9,9 +9,28 @@ const astUtils = require('../util/ast');

const defaultTestNames = [ 'it', 'test', 'specify' ];

module.exports = function (context) {
function inlineOptions(context) {
const pattern = context.options[0] ? new RegExp(context.options[0]) : /^should/;
const testNames = context.options[1] ? context.options[1] : defaultTestNames;
const message = context.options[2];

return { pattern, testNames, message };
}

function objectOptions(options) {
const pattern = options.pattern ? new RegExp(options.pattern) : /^should/;
const testNames = options.testNames ? options.testNames : defaultTestNames;
const message = options.message;

return { pattern, testNames, message };
}

module.exports = function (context) {
const options = context.options[0];

const { pattern, testNames, message } = typeof options === 'object' && !(options instanceof RegExp) ?
objectOptions(options) :
inlineOptions(context);

function isTest(node) {
return node.callee && node.callee.name && testNames.indexOf(node.callee.name) > -1;
Expand Down Expand Up @@ -41,7 +60,7 @@ module.exports = function (context) {

if (isTest(node)) {
if (!hasValidOrNoTestDescription(node)) {
context.report(node, `Invalid "${ callee.name }()" description found.`);
context.report(node, message || `Invalid "${ callee.name }()" description found.`);
}
}
}
Expand Down

0 comments on commit f1b711d

Please sign in to comment.