Skip to content

Commit

Permalink
Merge pull request #215 from lo1tuma/gh-211
Browse files Browse the repository at this point in the history
Fix no-setup-in-describe to allow mocha config calls
  • Loading branch information
lo1tuma committed Oct 28, 2019
2 parents 913015a + 0ff29dc commit 177fa3f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/util/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,28 @@ function isHookCall(node) {
return isCallExpression(node) && isHookIdentifier(node.callee);
}

function isTestCase(node) {
return isCallExpression(node) && testCaseNames.indexOf(getNodeName(node.callee)) > -1;
}

function isSuiteConfigExpression(node) {
return node.type === 'MemberExpression' &&
node.object.type === 'ThisExpression' &&
suiteConfig.indexOf(getPropertyName(node.property)) !== -1;
if (node.type !== 'MemberExpression') {
return false;
}

const usingThis = node.object.type === 'ThisExpression';

if (usingThis || isTestCase(node.object)) {
return suiteConfig.includes(getPropertyName(node.property));
}

return false;
}

function isSuiteConfigCall(node) {
return isCallExpression(node) && isSuiteConfigExpression(node.callee);
}

function isTestCase(node) {
return isCallExpression(node) && testCaseNames.indexOf(getNodeName(node.callee)) > -1;
}

function findReference(scope, node) {
const hasSameRangeAsNode = pathEq([ 'identifier', 'range' ], node.range);

Expand Down
31 changes: 31 additions & 0 deletions test/rules/no-setup-in-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ ruleTester.run('no-setup-in-describe', rule, {
'describe("", function () { it("", function () { a["b"]; }); })',
'describe("", function () { it("", function () { this.slow(1); }); })',
'describe("", function () { it("", function () { this.timeout(1); }); })',
'describe("", function () { it("", function () {}).timeout(1); })',
'describe("", function () { it("", function () {}).slow(1); })',
'describe("", function () { it.only("", function () {}).timeout(1); })',
'describe("", function () { it.skip("", function () {}).timeout(1); })',
'describe("", function () { xspecify("", function () {}).timeout(1); })',
'describe("", function () { it("", function () { this.retries(1); }); })',
'describe("", function () { it("", function () { this["retries"](1); }); })',
'describe("", function () { function a() { b(); }; it(); })',
Expand Down Expand Up @@ -156,6 +161,32 @@ ruleTester.run('no-setup-in-describe', rule, {
line: 1,
column: 23
} ]
}, {
code: 'describe("", function () { it("", function () {}).a(); });',
errors: [ {
message: 'Unexpected function call in describe block.',
line: 1,
column: 28
}, {
message: memberExpressionError,
line: 1,
column: 28
} ]
}, {
code: 'describe("", function () { something("", function () {}).timeout(); });',
errors: [ {
message: 'Unexpected function call in describe block.',
line: 1,
column: 28
}, {
messagee: memberExpressionError,
line: 1,
column: 28
}, {
message: 'Unexpected function call in describe block.',
line: 1,
column: 28
} ]
}
]
});

0 comments on commit 177fa3f

Please sign in to comment.