Skip to content

Commit

Permalink
Merge pull request #291 from lo1tuma/no-hooks
Browse files Browse the repository at this point in the history
Improve no-hooks-for-single-case performance
  • Loading branch information
lo1tuma committed May 26, 2021
2 parents 1b73ddb + df73870 commit 8634d89
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/rules/no-hooks-for-single-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ module.exports = {
},
create(context) {
const astUtils = createAstUtils(context.settings);
const isTestCase = astUtils.buildIsTestCaseAnswerer();
const isDescribe = astUtils.buildIsDescribeAnswerer();

const options = context.options[0] || {};
const allowedHooks = options.allow || [];
let layers = [];
Expand All @@ -57,7 +60,7 @@ module.exports = {
.forEach(function (hookNode) {
context.report({
node: hookNode,
message: `Unexpected use of Mocha \`${ hookNode.name }\` hook for a single test case`
message: `Unexpected use of Mocha \`${hookNode.name}\` hook for a single test case`
});
});
}
Expand All @@ -71,13 +74,13 @@ module.exports = {
},

CallExpression(node) {
if (astUtils.isDescribe(node)) {
if (isDescribe(node)) {
increaseTestCount();
layers.push(newDescribeLayer(node));
return;
}

if (astUtils.isTestCase(node)) {
if (isTestCase(node)) {
increaseTestCount();
}

Expand Down

0 comments on commit 8634d89

Please sign in to comment.