Skip to content

Commit

Permalink
New rule: no-exclusive-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
textbook committed Jun 24, 2019
1 parent e364747 commit fa646ad
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ Then configure the rules you want to use under the rules section.
## Supported Rules

- `no-actor-in-scenario`: Prevents the use of the `actor` in a `Scenario` and delegate to page objects

- `no-exclusive-tests`: Prevents the use of `Scenario.only` to focus tests
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
}
},
rules: {
"no-actor-in-scenario": require("./lib/rules/no-actor-in-scenario")
"no-actor-in-scenario": require("./lib/rules/no-actor-in-scenario"),
"no-exclusive-tests": require("./lib/rules/no-exclusive-tests")
}
}

};
39 changes: 39 additions & 0 deletions lib/rules/no-exclusive-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

function isOnlyMethodCall(callee) {
return callee.type === 'MemberExpression' &&
callee.object.name === 'Scenario' &&
callee.property.name === 'only';
}

module.exports = {
meta: {
docs: {
description: '',
category: 'Best Practices',
recommended: true
},
fixable: 'code',
messages: {
exclusiveTest: 'Unexpected exclusive test'
},
schema: []
},
create: function (context) {
return {
CallExpression: function (node) {
if (isOnlyMethodCall(node.callee)) {
context.report({
node: node,
messageId: 'exclusiveTest',
fix: function (fixer) {
var start = node.callee.object.range[1];
var end = node.callee.range[1];
return fixer.removeRange([start, end])
}
});
}
}
};
},
};
26 changes: 26 additions & 0 deletions tests/lib/rules/no-exclusive-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

var RuleTester = require('eslint').RuleTester;

var rule = require('../../../lib/rules/no-exclusive-tests');

var ruleTester = new RuleTester();

function invalidScenario (code) {
return {
code: code,
parserOptions: { ecmaVersion: 6 },
errors: [
{ message: 'Unexpected exclusive test' }
]
};
}

ruleTester.run('no-exclusive-tests', rule, {
valid: [
'Scenario("this is cool", function () {});'
],
invalid: [
invalidScenario('Scenario.only("this is not", function () {});')
],
});

0 comments on commit fa646ad

Please sign in to comment.