Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix max-top-level-suites to work with ES modules #255

Merged
merged 1 commit into from
May 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/rules/max-top-level-suites.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}
}
Expand Down
27 changes: 26 additions & 1 deletion test/rules/max-top-level-suites.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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 () { });' +
Expand Down