-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df50de1
commit a315b00
Showing
5 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Disallow Pending Tests (no-pending-tests) | ||
|
||
Mocha allows specification of pending tests, which represent tests that aren't yet implemented, but are intended to be implemented eventually. These are designated like a normal mocha test or suite, but with only the first argument provided (no callback for the actual implementation). For example: `describe('unimplemented bdd suite');` | ||
|
||
This rule allows you to raise ESLint warnings or errors on pending tests. This can be useful, for example, for reminding developers that pending tests exist in the repository, so they're more likely to get implemented. | ||
|
||
## Rule Details | ||
|
||
This rule looks for `describe`, `it`, `suite`, `test`, `context`, and `specify` function calls with only one argument, where the argument is a string literal. | ||
|
||
The following patterns are considered warnings: | ||
|
||
```js | ||
// bdd | ||
describe("foo"); | ||
it("foo"); | ||
|
||
// tdd | ||
suite("foo"); | ||
test("foo"); | ||
suite("bar"); | ||
test("bar"); | ||
``` | ||
|
||
These patterns are not considered warnings: | ||
|
||
```js | ||
// bdd | ||
describe("foo", function () {}); | ||
it("foo", function () {}); | ||
|
||
// tdd | ||
suite("foo", function () {}); | ||
test("foo", function () {}); | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
* If the existence of pending/unimplemented tests isn't considered important enough to warrant raising lint warnings/errors. | ||
|
||
## Further Reading | ||
|
||
* [Pending Tests](http://mochajs.org/#pending-tests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
module.exports = function (context) { | ||
var mochaTestFunctionNames = [ | ||
'it', | ||
'describe', | ||
'suite', | ||
'test', | ||
'context', | ||
'specify' | ||
]; | ||
|
||
function isMochaTest(callee) { | ||
return callee.type === 'Identifier' && | ||
mochaTestFunctionNames.indexOf(callee.name) !== -1; | ||
} | ||
|
||
function isPendingMochaTest(node) { | ||
return isMochaTest(node.callee) && | ||
node.arguments.length === 1 && | ||
node.arguments[0].type === 'Literal'; | ||
} | ||
|
||
return { | ||
CallExpression: function (node) { | ||
if (node.callee && isPendingMochaTest(node)) { | ||
context.report({ | ||
node: node, | ||
message: 'Unexpected pending mocha test.' | ||
}); | ||
} | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
var RuleTester = require('eslint').RuleTester, | ||
rules = require('../../').rules, | ||
ruleTester = new RuleTester(), | ||
expectedErrorMessage = 'Unexpected pending mocha test.'; | ||
|
||
ruleTester.run('no-pending-tests', rules['no-pending-tests'], { | ||
|
||
valid: [ | ||
'describe("test", function() { return true; })', | ||
'it("should be false", function() { assert(something, false); })', | ||
'something.describe()', | ||
'something.describe("test")', | ||
'something.it()', | ||
'something.it("test")' | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: 'describe("this is pending")', | ||
errors: [ { message: expectedErrorMessage, column: 1, line: 1 } ] | ||
}, | ||
{ | ||
code: 'it("is pending")', | ||
errors: [ { message: expectedErrorMessage, column: 1, line: 1 } ] | ||
}, | ||
{ | ||
code: 'suite("this is pending")', | ||
errors: [ { message: expectedErrorMessage, column: 1, line: 1 } ] | ||
}, | ||
{ | ||
code: 'test("is pending")', | ||
errors: [ { message: expectedErrorMessage, column: 1, line: 1 } ] | ||
}, | ||
{ | ||
code: 'context("this is pending")', | ||
errors: [ { message: expectedErrorMessage, column: 1, line: 1 } ] | ||
}, | ||
{ | ||
code: 'specify("is pending")', | ||
errors: [ { message: expectedErrorMessage, column: 1, line: 1 } ] | ||
} | ||
] | ||
|
||
}); |