Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to test for methods like fit or xit #44

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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