diff --git a/lib/rules/max-top-level-suites.js b/lib/rules/max-top-level-suites.js index 67fb352..ce35b8f 100644 --- a/lib/rules/max-top-level-suites.js +++ b/lib/rules/max-top-level-suites.js @@ -11,6 +11,10 @@ const { additionalSuiteNames } = require('../util/settings'); const defaultSuiteLimit = 1; +function isTopLevelScope(scope) { + return scope.type === 'module' || scope.upper === null; +} + module.exports = { meta: { type: 'suggestion', @@ -43,7 +47,7 @@ module.exports = { if (astUtil.isDescribe(node, additionalSuiteNames(settings))) { const scope = context.getScope(); - if (scope.upper === null) { + if (isTopLevelScope(scope)) { topLevelDescribes.push(node); } } diff --git a/test/rules/max-top-level-suites.js b/test/rules/max-top-level-suites.js index d38bdfd..6ce54df 100644 --- a/test/rules/max-top-level-suites.js +++ b/test/rules/max-top-level-suites.js @@ -54,7 +54,21 @@ ruleTester.run('max-top-level-suites', rules['max-top-level-suites'], { } }, 'someOtherFunction();', - 'describe("top", function () {}); function foo() { describe("not necessarily top", function () {}); }' + 'describe("top", function () {}); function foo() { describe("not necessarily top", function () {}); }', + { + code: 'describe("", function () { });', + parserOptions: { + sourceType: 'module', + ecmaVersion: 2015 + } + }, + { + code: 'describe("", function () { describe("", function () {}); });', + parserOptions: { + sourceType: 'module', + ecmaVersion: 2015 + } + } ], invalid: [ @@ -65,6 +79,17 @@ ruleTester.run('max-top-level-suites', rules['max-top-level-suites'], { { message: 'The number of top-level suites is more than 1.' } ] }, + { + code: 'describe("", function () { });' + + 'describe("", function () { });', + parserOptions: { + sourceType: 'module', + ecmaVersion: 2015 + }, + errors: [ + { message: 'The number of top-level suites is more than 1.' } + ] + }, { code: 'describe("this is a test", function () { });' + 'describe("this is a different test", function () { });' +