diff --git a/docs/rules/no-exclusive-tests.md b/docs/rules/no-exclusive-tests.md index 9508b4b..89329d6 100644 --- a/docs/rules/no-exclusive-tests.md +++ b/docs/rules/no-exclusive-tests.md @@ -8,7 +8,7 @@ This rule reminds you to remove `.only` from your tests by raising a warning whe ## Rule Details -This rule looks for every `describe.only` and `it.only` occurrences within the source code. +This rule looks for every `describe.only`, `it.only`, `suite.only` and `test.only` occurrences within the source code. Of course there are some edge-cases which can’t be detected by this rule e.g.: ```js @@ -18,33 +18,41 @@ describeOnly.apply(describe); The following patterns are considered warnings: -```js +```js` +// bdd describe.only("foo", function () {}); - it.only("foo", function () {}); - describe["only"]("bar", function () {}); - it["only"]("bar", function () {}); +// tdd +suite.only("foo", function () {}); +test.only("foo", function () {}); +suite["only"]("bar", function () {}); +test["only"]("bar", function () {}); + ``` These patterns would not be considered warnings: ```js +// bdd describe("foo", function () {}); - it("foo", function () {}); - describe.skip("bar", function () {}); - it.skip("bar", function () {}); + +// tdd +suite("foo", function () {}); +test("foo", function () {}); +suite.skip("bar", function () {}); +test.skip("bar", function () {}); ``` ## When Not To Use It * If you really want to execute only one test-suite or test-case because all other tests should not be executed, turn this rule off. -* If you use another library which exposes a similar API as mocha (`describe.only` or `it.only`), you should turn this rule off, because it would raise warnings. +* If you use another library which exposes a similar API as mocha (e.g. `describe.only`), you should turn this rule off, because it would raise warnings. ## Further Reading diff --git a/lib/rules/no-exclusive-tests.js b/lib/rules/no-exclusive-tests.js index bf07386..3c9035d 100644 --- a/lib/rules/no-exclusive-tests.js +++ b/lib/rules/no-exclusive-tests.js @@ -1,14 +1,21 @@ module.exports = function (context) { 'use strict'; + var mochaTestFunctions = [ + 'it', + 'describe', + 'suite', + 'test' + ]; + function isCallToMochasOnlyFunction(callee) { return callee.type === 'MemberExpression' && - isObjectNamedItOrDescribe(callee.object) && - isPropertyNamedOnly(callee.property); + matchesMochaTestFunction(callee.object) && + isPropertyNamedOnly(callee.property); } - function isObjectNamedItOrDescribe(object) { - return object && (object.name === 'it' || object.name === 'describe'); + function matchesMochaTestFunction(object) { + return object && mochaTestFunctions.indexOf(object.name) !== -1; } function isPropertyNamedOnly(property) { diff --git a/test/rules/no-exclusive-tests.js b/test/rules/no-exclusive-tests.js index 52254a2..3afd4af 100644 --- a/test/rules/no-exclusive-tests.js +++ b/test/rules/no-exclusive-tests.js @@ -12,9 +12,13 @@ eslintTester.addRuleTest('lib/rules/no-exclusive-tests', { 'it()', 'describe.skip()', 'it.skip()', + 'suite()', + 'test()', + 'suite.skip()', + 'test.skip()', 'var appliedOnly = describe.only; appliedOnly.apply(describe)', 'var calledOnly = it.only; calledOnly.call(it)', - 'var computedOnly = "only"; describe[computedOnly]()' + 'var dynamicOnly = "only"; suite[dynamicOnly]()' ], invalid: [ @@ -33,6 +37,22 @@ eslintTester.addRuleTest('lib/rules/no-exclusive-tests', { { code: 'it["only"]()', errors: [ { message: expectedErrorMessage, column: 3, line: 1 } ] + }, + { + code: 'suite.only()', + errors: [ { message: expectedErrorMessage, column: 6, line: 1 } ] + }, + { + code: 'suite["only"]()', + errors: [ { message: expectedErrorMessage, column: 6, line: 1 } ] + }, + { + code: 'test.only()', + errors: [ { message: expectedErrorMessage, column: 5, line: 1 } ] + }, + { + code: 'test["only"]()', + errors: [ { message: expectedErrorMessage, column: 5, line: 1 } ] } ]