Skip to content

Commit

Permalink
Add option to test for methods like fit or xit
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaus Herberth committed Jul 23, 2024
1 parent 709c025 commit 6d48d58
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ This rule supports opt-in autofixing when the `fix` option is set to `true` to a

## Options

Option | Type | Description
---|---|---
`block` | `string[]` | Specify the block names that your testing framework uses. Add a `*` to the end of any string to enable prefix matching (ie. `test*` will match `testExample.only`)<br>Defaults to `["describe", "it", "context", "test", "tape", "fixture", "serial", "Feature", "Scenario", "Given", "And", "When", "Then"]`
`focus` | `string[]` | Specify the focus scope that your testing framework uses.<br>Defaults to `["only"]`
`fix` | `boolean` | Enable this rule to auto-fix violations, useful for a pre-commit hook, not recommended for users with auto-fixing enabled in their editor.<br>Defaults to `false`
| Option | Type | Description |
| ----------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `block` | `string[]` | Specify the block names that your testing framework uses. Add a `*` to the end of any string to enable prefix matching (ie. `test*` will match `testExample.only`)<br>Defaults to `["describe", "it", "context", "test", "tape", "fixture", "serial", "Feature", "Scenario", "Given", "And", "When", "Then"]` |
| `focus` | `string[]` | Specify the focus scope that your testing framework uses.<br>Defaults to `["only"]` |
| `functions` | `string[]` | Specify not permitted functions. Good examples are `fit` or `xit`.<br>Defaults to `[]` (disabled) |
| `fix` | `boolean` | Enable this rule to auto-fix violations, useful for a pre-commit hook, not recommended for users with auto-fixing enabled in their editor.<br>Defaults to `false` |
33 changes: 32 additions & 1 deletion rules/no-only-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,23 @@
//------------------------------------------------------------------------------

const defaultOptions = {
block: ['describe', 'it', 'context', 'test', 'tape', 'fixture', 'serial', 'Feature', 'Scenario', 'Given', 'And', 'When', 'Then'],
block: [
'describe',
'it',
'context',
'test',
'tape',
'fixture',
'serial',
'Feature',
'Scenario',
'Given',
'And',
'When',
'Then',
],
focus: ['only'],
functions: [],
fix: false,
};

Expand Down Expand Up @@ -44,6 +59,14 @@ module.exports = {
uniqueItems: true,
default: defaultOptions.focus,
},
functions: {
type: 'array',
items: {
type: 'string',
},
uniqueItems: true,
default: defaultOptions.functions,
},
fix: {
type: 'boolean',
default: defaultOptions.fix,
Expand All @@ -57,10 +80,18 @@ module.exports = {
const options = Object.assign({}, defaultOptions, context.options[0]);
const blocks = options.block || [];
const focus = options.focus || [];
const functions = options.functions || [];
const fix = !!options.fix;

return {
Identifier(node) {
if (functions.length && functions.indexOf(node.name) > -1) {
context.report({
node,
message: node.name + ' not permitted',
});
}

const parentObject = node.parent && node.parent.object;
if (parentObject == null) return;
if (focus.indexOf(node.name) === -1) return;
Expand Down

0 comments on commit 6d48d58

Please sign in to comment.