Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: Adding rule no-only (fixes #11)
- Loading branch information
1 parent
7b6ca3d
commit 8fbdc11
Showing
4 changed files
with
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Forbid the use of QUnit.only (no-only) | ||
|
||
`QUnit.only` is useful for restricting a test run to just one test while developing, but committing a test file using this function to a repository is dangerous because it will ensure that the rest of the test suite is not run. | ||
|
||
## Rule Details | ||
|
||
The following patterns are considered warnings: | ||
|
||
```js | ||
|
||
QUnit.only('Name', function () { }); | ||
|
||
``` | ||
|
||
The following patterns are not considered warnings: | ||
|
||
```js | ||
|
||
QUnit.test('Name', function () { }); | ||
|
||
``` | ||
|
||
## When Not to Use It | ||
|
||
If your development pipeline would make running this rule annoying, it could be safely disabled. However, it would be a good idea to ensure that this rule is run in continuous integration at the very least. | ||
|
||
## Further Reading | ||
|
||
* [QUnit.only](https://api.qunitjs.com/QUnit.only/) |
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,41 @@ | ||
/** | ||
* @fileoverview Forbid the use of QUnit.only. | ||
* @author Kevin Partington | ||
*/ | ||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
var utils = require("../utils"); | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = function (context) { | ||
var MESSAGE = "Unexpected QUnit.only call."; | ||
|
||
function isQUnitOnly (calleeNode) { | ||
return calleeNode && | ||
calleeNode.type === "MemberExpression" && | ||
calleeNode.object && | ||
calleeNode.object.type === "Identifier" && | ||
calleeNode.object.name === "QUnit" && | ||
calleeNode.property && | ||
calleeNode.property.type === "Identifier" && | ||
calleeNode.property.name === "only"; | ||
} | ||
|
||
return { | ||
"CallExpression": function (node) { | ||
if (isQUnitOnly(node.callee)) { | ||
context.report({ | ||
node: node, | ||
message: MESSAGE | ||
}); | ||
} | ||
} | ||
}; | ||
}; |
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,36 @@ | ||
/** | ||
* @fileoverview Forbid the use of QUnit.only. | ||
* @author Kevin Partington | ||
*/ | ||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
var rule = require("../../../lib/rules/no-only"), | ||
RuleTester = require("eslint").RuleTester; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
var ruleTester = new RuleTester(); | ||
|
||
ruleTester.run("no-only", rule, { | ||
valid: [ | ||
"QUnit.test('Name', function() { });", | ||
|
||
// QUnit.only is not exposed globally so this is valid | ||
"only('Name', function() { });" | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: "QUnit.only('Name', function() { });", | ||
errors: [ | ||
"Unexpected QUnit.only call." | ||
] | ||
} | ||
] | ||
}); |