additional rules for cypress tests
npm install @mmisty/eslint-plugin-cypressAdditional linter rules for cypress tests
1. Installation
1. Recommended settings
2. Setup
3. Rules
- disallow-get-get-chain
- test-title-pattern
- disallow-only
```shell script``
yarn add -D @mmisty/eslint-plugin-cypress
``shell script``
npm i --save-dev @mmisty/eslint-plugin-cypress
Just add the following into .eslintrc.js
``
// .eslintrc.js
extends: ['plugin:@mmisty/cypress/recommended'],
To enable rules add the following to plugins section in your .eslintrc.js:
``
plugins: ['@mmisty/cypress'],
and add rules you want:
``
rules: {
"@mmisty/cypress/test-title-pattern": 'error'
}
Disallows chaining specified commands (default ['get']).
Will warn when user tries to do chains like cy.get('id').get('id2');
``
rules: {
'@mmisty/cypress/disallow-get-get-chain': ['error', { methods: ['qaId', 'get'] }],
}
The rule will check whether test has title matched with pattern - default pattern not allows '.' at the end of test title
Available options:
| Option | Description |
|-------------|----------------------------------|
| pattern | regexp |
| message | string, error message |
| identifiers | test identifiers. ex it/xit |
To configure the rule with options:
``
rules: {
"@mmisty/cypress/test-title-pattern": ["error", {
pattern: /^ID\d+\w+should/i,
message: "Test should have ID",
identifiers: ['it']
}],
},
Disallows .only in tests
To configure the rule:
```
rules: {
"@mmisty/cypress/disallow-only": "error",
},