Skip to content

Commit

Permalink
Fix max-top-level-suites to ignore generated suites
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1tuma committed Feb 18, 2020
1 parent 1c3a545 commit 2633908
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
11 changes: 2 additions & 9 deletions lib/rules/max-top-level-suites.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module.exports = {
]
},
create(context) {
const stack = [];
const topLevelDescribes = [];
const options = context.options[0] || {};
const settings = context.settings;
Expand All @@ -41,17 +40,11 @@ module.exports = {
return {
CallExpression(node) {
if (astUtil.isDescribe(node, additionalSuiteNames(settings))) {
stack.push(node);
}
},
const scope = context.getScope();

'CallExpression:exit'(node) {
if (astUtil.isDescribe(node, additionalSuiteNames(settings))) {
if (stack.length === 1) {
if (scope.upper === null) {
topLevelDescribes.push(node);
}

stack.pop(node);
}
},

Expand Down
3 changes: 2 additions & 1 deletion test/rules/max-top-level-suites.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ ruleTester.run('max-top-level-suites', rules['max-top-level-suites'], {
}
}
},
'someOtherFunction();'
'someOtherFunction();',
'describe("top", function () {}); function foo() { describe("not necessarily top", function () {}); }'
],

invalid: [
Expand Down

0 comments on commit 2633908

Please sign in to comment.