eslint-plugin-cypress 3.2.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CONTRIBUTING.md CHANGED
@@ -2,15 +2,49 @@
2
2
 
3
3
  Thanks for taking the time to contribute! :smile:
4
4
 
5
+ ## Preparation
6
+
7
+ * Fork and clone this repository
8
+ * Branch from the default `master` branch using a descriptive new branch name
9
+ * Install dependencies with `npm ci`
10
+
11
+ ## Rule references
12
+
13
+ * Refer to the [ESLint documentation](https://eslint.org/docs/latest/) and the [Custom Rules](https://eslint.org/docs/latest/extend/custom-rules) page
14
+
15
+ ## New rule
16
+
5
17
  To add a new rule:
6
- * Fork and clone this repository
7
- * Generate a new rule (a [yeoman generator](https://github.com/eslint/generator-eslint) is available)
8
- * Write test scenarios then implement logic
9
- * Describe the rule in the generated `docs` file
10
- * Run `npm test` to run [Jest](https://jestjs.io/) or
11
- * Run `npm start` to run [Jest](https://jestjs.io/) in [watchAll](https://jestjs.io/docs/cli#--watchall) mode where it remains active and reruns when source changes are made
12
- * Make sure all tests are passing
13
- * Add the rule to the [README](README.md) file
14
- * Create a PR
15
-
16
- Use the following commit message conventions: https://github.com/semantic-release/semantic-release#commit-message-format
18
+
19
+ * Follow the instructions in the ESLint [generator-eslint](https://www.npmjs.com/package/generator-eslint) documentation to install [Yeoman](https://www.npmjs.com/package/yo) and the generator
20
+ * Run the new rule generator `yo eslint:rule` and answer the questions
21
+ - select "ESLint Plugin"
22
+ - for "Type a short description of this rule" provide text which starts with one of "enforce", "require" or "disallow" (all lower case)
23
+ * Yeoman creates three boilerplate files:
24
+ - `docs/rules/<rule-id>.md`
25
+ - `lib/rules/<rule-id>.js`
26
+ - `test/rules/<rule-id>.js`
27
+ * Run `npm run lint-fix`
28
+ * Address the linting errors by editing `lib/rules/<rule-id>.js`
29
+ - Add a `meta.messages` property (see [MessageIds](https://eslint.org/docs/latest/extend/custom-rules#messageids))
30
+ - Select the appropriate `meta.type` property using `problem`, `suggestion`, or `layout`
31
+ * Complete the new rule by adding content to the three files previously created
32
+ * Run `eslint-doc-generator` to generate automated documentation sections (see [Document generation](#document-generation) below)
33
+ * Review documentation changes
34
+ * Run `npm run lint`
35
+ * Run `npm test` to run [Jest](https://jestjs.io/) (or run `npm start` to run [Jest](https://jestjs.io/) in [watchAll](https://jestjs.io/docs/cli#--watchall) mode where it remains active and reruns when source changes are made)
36
+ * Make sure all tests are passing
37
+ * Add the rule to [legacy.js](https://github.com/cypress-io/eslint-plugin-cypress/blob/master/legacy.js) and to [flat.js](https://github.com/cypress-io/eslint-plugin-cypress/blob/master/lib/flat.js)
38
+ * Create a git commit with a commit message similar to: `feat: add rule <description>` (see [commit message conventions](https://github.com/semantic-release/semantic-release#commit-message-format))
39
+ * Create a PR from your branch
40
+
41
+ ## Document generation
42
+
43
+ This plugin uses the ESLint [eslint-doc-generator](https://www.npmjs.com/package/eslint-doc-generator) to generate consistent documentation.
44
+ * Install with `npm install eslint-doc-generator -g`
45
+ * Run `eslint-doc-generator` in the root directory of the plugin
46
+
47
+ ## Legacy tests
48
+
49
+ * The directory [tests-legacy](https://github.com/cypress-io/eslint-plugin-cypress/tree/master/tests-legacy) contains tests which are compatible with the legacy [ESLint v8 RuleTester](https://eslint.org/docs/v8.x/integrate/nodejs-api#ruletester) utility. It is not expected to add new rules to this set of tests.
50
+ * The directory [tests](https://github.com/cypress-io/eslint-plugin-cypress/tree/master/tests) is for tests compatible with the current [ESLint RuleTester](https://eslint.org/docs/latest/integrate/nodejs-api#ruletester).
package/FLAT-CONFIG.md CHANGED
@@ -10,7 +10,7 @@ Usage with ESLint `8.57.0` and ESLint `9.x` is described.
10
10
 
11
11
  Previously, ESLint had announced in their blog post [Flat config rollout plans](https://eslint.org/blog/2023/10/flat-config-rollout-plans/) in October 2023 that flat config was planned to be the default in ESLint `v9.0.0` and that the eslintrc configuration system is planned to be removed in the future ESLint `v10.0.0`.
12
12
 
13
- The Cypress ESLint Plugin (`eslint-plugin-cypress`) is currently based on ESLint `8.x` and has not yet been migrated to support Flat Config natively. [ESLint's new config system, Part 2: Introduction to flat config](https://eslint.org/blog/2022/08/new-config-system-part-2/) from August 2022 introduced the [Backwards compatibility utility](https://eslint.org/blog/2022/08/new-config-system-part-2/#backwards-compatibility-utility). This gives the capability to use `eslint-plugin-cypress` in an ESLint flat config environment.
13
+ Cypress ESLint Plugin (`eslint-plugin-cypress`) in release [3.2.0](https://github.com/cypress-io/eslint-plugin-cypress/releases/tag/v3.2.0) offered the first support of ESLint `9.x` flat config files using the [Backwards compatibility utility](https://eslint.org/blog/2022/08/new-config-system-part-2/#backwards-compatibility-utility). Current releases have removed the dependency on this utility and the examples in this document have been updated correspondingly.
14
14
 
15
15
  The following information details installation and usage examples for `eslint-plugin-cypress` together with related plugins in an ESLint flat config environment.
16
16
 
@@ -19,60 +19,82 @@ The following information details installation and usage examples for `eslint-pl
19
19
  It is recommended to use a minimum ESLint `8.x` version [eslint@8.57.0](https://github.com/eslint/eslint/releases/tag/v8.57.0) or ESLint `9.x`.
20
20
 
21
21
  ```shell
22
- npm install eslint @eslint/eslintrc eslint-plugin-cypress@^3.1.1 --save-dev
22
+ npm install eslint eslint-plugin-cypress --save-dev
23
23
  ```
24
24
 
25
25
  or
26
26
 
27
27
  ```shell
28
- yarn add eslint @eslint/eslintrc eslint-plugin-cypress@^3.1.1 --dev
28
+ yarn add eslint eslint-plugin-cypress --dev
29
29
  ```
30
30
 
31
31
  ## Usage examples
32
32
 
33
- Add a flat configuration file `eslint.config.mjs` file to the root directory of your Cypress project. In the following sections, different examples of possible configuration file contents are given, together with some brief explanations. Adapt these examples according to your needs.
33
+ Add a flat configuration file `eslint.config.mjs` to the root directory of your Cypress project and include the following instructions to import the available flat configurations using:
34
+
35
+ ```shell
36
+ import pluginCypress from 'eslint-plugin-cypress/flat'
37
+ ```
38
+
39
+ There are two specific flat configurations available:
40
+
41
+ | Configuration | Content |
42
+ | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
43
+ | `configs.globals` | defines globals `cy`, `Cypress`, `expect`, `assert` and `chai` used in Cypress test specs as well as `globals.browser` and `globals.mocha` from [globals](https://www.npmjs.com/package/globals). Additionally, `languageOptions` of `ecmaVersion: 2019` and `sourceType: 'module'` for backwards compatibility with earlier versions of this plugin are defined. There are no default rules enabled in this configuration. |
44
+ | `configs.recommended` | enables [recommended Rules](README.md#rules). It includes also `configs.global` (see above) |
45
+
46
+ In the following sections, different examples of possible configuration file contents are given, together with some brief explanations. Adapt these examples according to your needs.
34
47
 
35
48
  ### Cypress
36
49
 
37
- All rules from `eslint-plugin-cypress` are available through the `FlatCompat` class of [@eslint/eslintrc](https://www.npmjs.com/package/@eslint/eslintrc).
50
+ All rules from `eslint-plugin-cypress` are available through `eslint-plugin-cypress/flat`.
38
51
  - [cypress/unsafe-to-chain-command](https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/unsafe-to-chain-command.md) is active and set to `error`
39
52
 
40
53
  ```js
41
- import { FlatCompat } from '@eslint/eslintrc'
42
- const compat = new FlatCompat()
54
+ import pluginCypress from 'eslint-plugin-cypress/flat'
43
55
  export default [
44
- ...compat.config(
45
- {
46
- plugins: ['cypress'],
47
- rules: {
48
- 'cypress/unsafe-to-chain-command': 'error'
49
- }
50
- })
56
+ {
57
+ plugins: {
58
+ cypress: pluginCypress
59
+ },
60
+ rules: {
61
+ 'cypress/unsafe-to-chain-command': 'error'
62
+ }
63
+ }
51
64
  ]
52
65
  ```
53
66
 
54
67
  ### Cypress recommended
55
68
 
56
- The `eslint-plugin-cypress` [recommended rules](README.md#rules) `plugin:cypress/recommended` are activated, except for
69
+ The `eslint-plugin-cypress` [recommended rules](README.md#rules) `configs.recommended` are activated, except for
57
70
  - [cypress/no-unnecessary-waiting](https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-unnecessary-waiting.md) set to `off`
58
71
 
59
72
  ```js
60
- import { FlatCompat } from '@eslint/eslintrc'
61
- const compat = new FlatCompat()
73
+ import pluginCypress from 'eslint-plugin-cypress/flat'
62
74
  export default [
63
- ...compat.config(
64
- {
65
- extends: ['plugin:cypress/recommended'],
66
- rules: {
67
- 'cypress/no-unnecessary-waiting': 'off'
68
- }
69
- })
75
+ pluginCypress.configs.recommended,
76
+ {
77
+ rules: {
78
+ 'cypress/no-unnecessary-waiting': 'off'
79
+ }
80
+ }
81
+ ]
82
+ ```
83
+
84
+ ### Cypress globals
85
+
86
+ The `configs.globals` are activated.
87
+
88
+ ```js
89
+ import pluginCypress from 'eslint-plugin-cypress/flat'
90
+ export default [
91
+ pluginCypress.configs.globals
70
92
  ]
71
93
  ```
72
94
 
73
95
  ### Cypress and Mocha recommended
74
96
 
75
- [eslint-plugin-mocha](https://www.npmjs.com/package/eslint-plugin-mocha) is added to the previous example. This plugin offers a flat file recommended option `configs.flat.recommended`.
97
+ [eslint-plugin-mocha](https://www.npmjs.com/package/eslint-plugin-mocha) is added to the example [Cypress recommended](#cypress-recommended). This plugin offers a flat file recommended option `configs.flat.recommended`.
76
98
 
77
99
  The settings for individual `mocha` rules from the `configs.flat.recommended` option are changed.
78
100
  - [mocha/no-exclusive-tests](https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-exclusive-tests.md) and [mocha/no-skipped-tests](https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-skipped-tests.md) are set to `error` instead of `warn`
@@ -83,52 +105,42 @@ npm install eslint-plugin-mocha@^10.4.3 --save-dev
83
105
  ```
84
106
 
85
107
  ```js
86
- import { FlatCompat } from '@eslint/eslintrc'
87
- import mochaPlugin from 'eslint-plugin-mocha'
88
- const compat = new FlatCompat()
108
+ import pluginMocha from 'eslint-plugin-mocha'
109
+ import pluginCypress from 'eslint-plugin-cypress/flat'
89
110
  export default [
90
- mochaPlugin.configs.flat.recommended, {
111
+ pluginMocha.configs.flat.recommended,
112
+ pluginCypress.configs.recommended,
113
+ {
91
114
  rules: {
92
- 'mocha/no-exclusive-tests': 'error',
93
- 'mocha/no-skipped-tests': 'error',
94
- 'mocha/no-mocha-arrows': 'off'
115
+ 'mocha/no-exclusive-tests': 'warn',
116
+ 'mocha/no-skipped-tests': 'warn',
117
+ 'mocha/no-mocha-arrows': 'off',
118
+ 'cypress/no-unnecessary-waiting': 'off'
95
119
  }
96
- },
97
- ...compat.config(
98
- {
99
- extends: ['plugin:cypress/recommended'],
100
- rules: {
101
- 'cypress/no-unnecessary-waiting': 'off'
102
- }
103
- })
120
+ }
104
121
  ]
105
122
  ```
106
123
 
107
124
  ### Cypress and Chai recommended
108
125
 
109
- [eslint-plugin-chai-friendly](https://www.npmjs.com/package/eslint-plugin-chai-friendly) is combined with the Cypress plugin `eslint-plugin-cypress`.
126
+ [eslint-plugin-chai-friendly](https://www.npmjs.com/package/eslint-plugin-chai-friendly) (minimum version [eslint-plugin-chai-friendly@0.8.0](https://github.com/ihordiachenko/eslint-plugin-chai-friendly/releases/tag/v0.8.0) required for ESLint v9 support and flat config support) is combined with the Cypress plugin `eslint-plugin-cypress`.
110
127
 
111
- The [eslint-plugin-chai-friendly](https://www.npmjs.com/package/eslint-plugin-chai-friendly) plugin does not currently offer flat config options and so the `FlatCompat` class of [@eslint/eslintrc](https://www.npmjs.com/package/@eslint/eslintrc) enables this plugin to be used too. The recommended rules for both plugins are used: `plugin:cypress/recommended` and `plugin:chai-friendly/recommended`.
128
+ The recommended rules for both plugins are used: `pluginCypress.configs.recommended` and `pluginChaiFriendly.configs.recommended`:
112
129
 
113
130
  ```shell
114
- npm install eslint-plugin-chai-friendly --save-dev
131
+ npm install eslint-plugin-chai-friendly@^0.8.0 --save-dev
115
132
  ```
116
133
 
117
134
  ```js
118
- import { FlatCompat } from '@eslint/eslintrc'
119
- const compat = new FlatCompat()
135
+ import pluginCypress from 'eslint-plugin-cypress/flat'
136
+ import pluginChaiFriendly from 'eslint-plugin-chai-friendly'
120
137
  export default [
121
- ...compat.config(
122
- {
123
- extends: [
124
- 'plugin:cypress/recommended',
125
- 'plugin:chai-friendly/recommended'
126
- ],
127
- rules: {
128
- 'cypress/no-unnecessary-waiting': 'off',
129
- }
130
- })
138
+ pluginCypress.configs.recommended,
139
+ pluginChaiFriendly.configs.recommended,
140
+ {
141
+ rules: {
142
+ 'cypress/no-unnecessary-waiting': 'off',
143
+ },
144
+ }
131
145
  ]
132
146
  ```
133
-
134
- **Pending the resolution of issue https://github.com/ihordiachenko/eslint-plugin-chai-friendly/issues/32 [eslint-plugin-chai-friendly](https://www.npmjs.com/package/eslint-plugin-chai-friendly) cannot be used with ESLint `v9`.**
package/README.md CHANGED
@@ -7,7 +7,7 @@ Note: If you installed ESLint globally then you must also install `eslint-plugin
7
7
  ## Installation
8
8
 
9
9
  Prerequisites: [ESLint](https://www.npmjs.com/package/eslint) `v7`, `v8` or `v9`.
10
- This plugin supports the use of [Flat config files](https://eslint.org/docs/latest/use/configure/configuration-files) with ESLint `8.57.0` and above through [@eslint/eslintrc](https://www.npmjs.com/package/@eslint/eslintrc).
10
+ This plugin supports the use of [Flat config files](https://eslint.org/docs/latest/use/configure/configuration-files) with ESLint `8.57.0` and above.
11
11
 
12
12
  ```sh
13
13
  npm install eslint-plugin-cypress --save-dev
package/circle.yml CHANGED
@@ -7,11 +7,13 @@ workflows:
7
7
  - lint
8
8
  - test-v7
9
9
  - test-v8
10
+ - test-v9
10
11
  - release:
11
12
  requires:
12
13
  - lint
13
14
  - test-v7
14
15
  - test-v8
16
+ - test-v9
15
17
  filters:
16
18
  branches:
17
19
  only:
@@ -52,7 +54,7 @@ jobs:
52
54
  command: npx eslint --version
53
55
  - run:
54
56
  name: Test ESLint 7
55
- command: npm test
57
+ command: npm run test:legacy
56
58
 
57
59
  test-v8:
58
60
  docker:
@@ -70,6 +72,24 @@ jobs:
70
72
  command: npx eslint --version
71
73
  - run:
72
74
  name: Test ESLint 8
75
+ command: npm run test:legacy
76
+
77
+ test-v9:
78
+ docker:
79
+ - image: cimg/node:20.12.2
80
+ steps:
81
+ - checkout
82
+ - run:
83
+ name: Install dependencies
84
+ command: npm ci
85
+ - run:
86
+ name: Install ESLint 9
87
+ command: npm install eslint@9
88
+ - run:
89
+ name: Show ESLint version
90
+ command: npx eslint --version
91
+ - run:
92
+ name: Test ESLint 9
73
93
  command: npm test
74
94
 
75
95
  release:
package/eslint.config.mjs CHANGED
@@ -18,6 +18,8 @@ export default [
18
18
  'eslint-plugin/require-meta-docs-url':
19
19
  ['error', { 'pattern': 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/{{name}}.md' }],
20
20
  'eslint-plugin/require-meta-docs-description': 'error',
21
+ 'eslint-plugin/meta-property-ordering': 'error',
22
+ 'eslint-plugin/test-case-property-ordering': 'error',
21
23
  'n/no-extraneous-require':
22
24
  ['error', { 'allowModules': ['jest-config'] }],
23
25
  'mocha/no-mocha-arrows': 'off',
@@ -0,0 +1,6 @@
1
+ const { defaults } = require('jest-config')
2
+
3
+ module.exports = {
4
+ testMatch: ['**/tests-legacy/**/*.[jt]s?(x)'],
5
+ testPathIgnorePatterns: [...defaults.testPathIgnorePatterns, '.history'],
6
+ }
package/lib/flat.js ADDED
@@ -0,0 +1,66 @@
1
+ const globals = require('globals')
2
+ const { name, version } = require('../package.json')
3
+
4
+ const plugin = {
5
+ meta: { name, version },
6
+ configs: {},
7
+ rules: {
8
+ 'no-assigning-return-values': require('./rules/no-assigning-return-values'),
9
+ 'unsafe-to-chain-command': require('./rules/unsafe-to-chain-command'),
10
+ 'no-unnecessary-waiting': require('./rules/no-unnecessary-waiting'),
11
+ 'no-async-before': require('./rules/no-async-before'),
12
+ 'no-async-tests': require('./rules/no-async-tests'),
13
+ 'assertion-before-screenshot': require('./rules/assertion-before-screenshot'),
14
+ 'require-data-selectors': require('./rules/require-data-selectors'),
15
+ 'no-force': require('./rules/no-force'),
16
+ 'no-pause': require('./rules/no-pause'),
17
+ },
18
+ }
19
+
20
+ const commonGlobals =
21
+ Object.assign({
22
+ cy: false,
23
+ Cypress: false,
24
+ expect: false,
25
+ assert: false,
26
+ chai: false,
27
+ }, globals.browser, globals.mocha)
28
+
29
+ const commonLanguageOptions = {
30
+ ecmaVersion: 2019,
31
+ sourceType: 'module'
32
+ }
33
+
34
+ Object.assign(plugin.configs, {
35
+ globals: {
36
+ plugins: {
37
+ cypress: plugin
38
+ },
39
+ languageOptions: {
40
+ globals:
41
+ commonGlobals,
42
+ ...commonLanguageOptions
43
+ }
44
+ }
45
+ })
46
+
47
+ Object.assign(plugin.configs, {
48
+ recommended: {
49
+ plugins: {
50
+ cypress: plugin
51
+ },
52
+ rules: {
53
+ 'cypress/no-assigning-return-values': 'error',
54
+ 'cypress/no-unnecessary-waiting': 'error',
55
+ 'cypress/no-async-tests': 'error',
56
+ 'cypress/unsafe-to-chain-command': 'error',
57
+ },
58
+ languageOptions: {
59
+ globals:
60
+ commonGlobals,
61
+ ...commonLanguageOptions
62
+ }
63
+ }
64
+ })
65
+
66
+ module.exports = plugin
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "eslint-plugin-cypress",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "An ESLint plugin for projects using Cypress",
5
- "main": "index.js",
5
+ "main": "legacy.js",
6
+ "exports": {
7
+ ".": "./legacy.js",
8
+ "./flat": "./lib/flat.js"
9
+ },
6
10
  "author": "Cypress-io",
7
11
  "license": "MIT",
8
12
  "keywords": [
@@ -25,12 +29,12 @@
25
29
  "globals": "^13.20.0"
26
30
  },
27
31
  "devDependencies": {
28
- "@eslint/eslintrc": "^3.0.2",
29
- "@eslint/js": "^9.2.0",
30
- "eslint": "^8.57.0",
32
+ "@eslint/eslintrc": "^3.1.0",
33
+ "@eslint/js": "^9.3.0",
34
+ "eslint": "^9.3.0",
31
35
  "eslint-plugin-eslint-plugin": "^6.1.0",
32
36
  "eslint-plugin-mocha": "^10.4.3",
33
- "eslint-plugin-n": "^17.4.0",
37
+ "eslint-plugin-n": "^17.7.0",
34
38
  "husky": "^9.0.11",
35
39
  "jest": "^29.7.0",
36
40
  "semantic-release": "23.0.8"
@@ -41,6 +45,7 @@
41
45
  "semantic-release": "semantic-release",
42
46
  "start": "npm run test-watch",
43
47
  "test": "jest",
48
+ "test:legacy": "jest --config jest.config-legacy.js",
44
49
  "test-watch": "jest --watchAll",
45
50
  "prepare": "husky"
46
51
  }
package/tests/config.js CHANGED
@@ -2,10 +2,10 @@
2
2
  'use strict'
3
3
 
4
4
  const globals = require('globals')
5
- const config = require('../index.js')
5
+ const config = require('../lib/flat.js')
6
6
 
7
- describe('environments globals', () => {
8
- const env = config.environments.globals
7
+ describe('globals languageOptions', () => {
8
+ const languageOptions = config.configs.globals.languageOptions
9
9
 
10
10
  it('should not mutate globals', () => {
11
11
  expect(globals.browser).not.toHaveProperty('cy')
@@ -13,12 +13,12 @@ describe('environments globals', () => {
13
13
  })
14
14
 
15
15
  it('should include other globals', () => {
16
- expect(env.globals).toEqual(expect.objectContaining(globals.browser))
17
- expect(env.globals).toEqual(expect.objectContaining(globals.mocha))
16
+ expect(languageOptions.globals).toEqual(expect.objectContaining(globals.browser))
17
+ expect(languageOptions.globals).toEqual(expect.objectContaining(globals.mocha))
18
18
  })
19
19
 
20
20
  it('should include cypress globals', () => {
21
- expect(env.globals).toEqual(expect.objectContaining({
21
+ expect(languageOptions.globals).toEqual(expect.objectContaining({
22
22
  cy: false,
23
23
  Cypress: false,
24
24
  }))
@@ -6,30 +6,29 @@ const RuleTester = require('eslint').RuleTester
6
6
  const ruleTester = new RuleTester()
7
7
 
8
8
  const errors = [{ messageId: 'unexpected' }]
9
- const parserOptions = { ecmaVersion: 6 }
10
9
 
11
10
  ruleTester.run('assertion-before-screenshot', rule, {
12
11
  valid: [
13
- { code: 'cy.get(".some-element"); cy.screenshot();', parserOptions },
14
- { code: 'cy.get(".some-element").should("exist").screenshot();', parserOptions },
15
- { code: 'cy.get(".some-element").should("exist").screenshot().click()', parserOptions, errors },
16
- { code: 'cy.get(".some-element").should("exist"); if(true) cy.screenshot();', parserOptions },
17
- { code: 'if(true) { cy.get(".some-element").should("exist"); cy.screenshot(); }', parserOptions },
18
- { code: 'cy.get(".some-element").should("exist"); if(true) { cy.screenshot(); }', parserOptions },
19
- { code: 'const a = () => { cy.get(".some-element").should("exist"); cy.screenshot(); }', parserOptions, errors },
20
- { code: 'cy.get(".some-element").should("exist").and("be.visible"); cy.screenshot();', parserOptions },
21
- { code: 'cy.get(".some-element").contains("Text"); cy.screenshot();', parserOptions },
12
+ { code: 'cy.get(".some-element"); cy.screenshot();' },
13
+ { code: 'cy.get(".some-element").should("exist").screenshot();' },
14
+ { code: 'cy.get(".some-element").should("exist").screenshot().click()' },
15
+ { code: 'cy.get(".some-element").should("exist"); if(true) cy.screenshot();' },
16
+ { code: 'if(true) { cy.get(".some-element").should("exist"); cy.screenshot(); }' },
17
+ { code: 'cy.get(".some-element").should("exist"); if(true) { cy.screenshot(); }' },
18
+ { code: 'const a = () => { cy.get(".some-element").should("exist"); cy.screenshot(); }' },
19
+ { code: 'cy.get(".some-element").should("exist").and("be.visible"); cy.screenshot();' },
20
+ { code: 'cy.get(".some-element").contains("Text"); cy.screenshot();' },
22
21
  ],
23
22
 
24
23
  invalid: [
25
- { code: 'cy.screenshot()', parserOptions, errors },
26
- { code: 'cy.visit("somepage"); cy.screenshot();', parserOptions, errors },
27
- { code: 'cy.custom(); cy.screenshot()', parserOptions, errors },
28
- { code: 'cy.get(".some-element").click(); cy.screenshot()', parserOptions, errors },
29
- { code: 'cy.get(".some-element").click().screenshot()', parserOptions, errors },
30
- { code: 'if(true) { cy.get(".some-element").click(); cy.screenshot(); }', parserOptions, errors },
31
- { code: 'cy.get(".some-element").click(); if(true) { cy.screenshot(); }', parserOptions, errors },
32
- { code: 'cy.get(".some-element"); function a() { cy.screenshot(); }', parserOptions, errors },
33
- { code: 'cy.get(".some-element"); const a = () => { cy.screenshot(); }', parserOptions, errors },
24
+ { code: 'cy.screenshot()', errors },
25
+ { code: 'cy.visit("somepage"); cy.screenshot();', errors },
26
+ { code: 'cy.custom(); cy.screenshot()', errors },
27
+ { code: 'cy.get(".some-element").click(); cy.screenshot()', errors },
28
+ { code: 'cy.get(".some-element").click().screenshot()', errors },
29
+ { code: 'if(true) { cy.get(".some-element").click(); cy.screenshot(); }', errors },
30
+ { code: 'cy.get(".some-element").click(); if(true) { cy.screenshot(); }', errors },
31
+ { code: 'cy.get(".some-element"); function a() { cy.screenshot(); }', errors },
32
+ { code: 'cy.get(".some-element"); const a = () => { cy.screenshot(); }', errors },
34
33
  ],
35
34
  })
@@ -6,33 +6,32 @@ const RuleTester = require('eslint').RuleTester
6
6
  const ruleTester = new RuleTester()
7
7
 
8
8
  const errors = [{ messageId: 'unexpected' }]
9
- const parserOptions = { ecmaVersion: 6 }
10
9
 
11
10
  ruleTester.run('no-assigning-return-values', rule, {
12
11
  valid: [
13
- { code: 'var foo = true;', parserOptions },
14
- { code: 'let foo = true;', parserOptions },
15
- { code: 'const foo = true;', parserOptions },
16
- { code: 'const foo = bar();', parserOptions },
17
- { code: 'const foo = bar().baz();', parserOptions },
18
- { code: 'const spy = cy.spy();', parserOptions },
19
- { code: 'const spy = cy.spy().as();', parserOptions },
20
- { code: 'const stub = cy.stub();', parserOptions },
21
- { code: 'const result = cy.now();', parserOptions },
22
- { code: 'const state = cy.state();', parserOptions },
23
- { code: 'cy.get("foo");', parserOptions },
24
- { code: 'cy.contains("foo").click();', parserOptions },
12
+ { code: 'var foo = true;' },
13
+ { code: 'let foo = true;' },
14
+ { code: 'const foo = true;' },
15
+ { code: 'const foo = bar();' },
16
+ { code: 'const foo = bar().baz();' },
17
+ { code: 'const spy = cy.spy();' },
18
+ { code: 'const spy = cy.spy().as();' },
19
+ { code: 'const stub = cy.stub();' },
20
+ { code: 'const result = cy.now();' },
21
+ { code: 'const state = cy.state();' },
22
+ { code: 'cy.get("foo");' },
23
+ { code: 'cy.contains("foo").click();' },
25
24
  ],
26
25
 
27
26
  invalid: [
28
- { code: 'let a = cy.get("foo")', parserOptions, errors },
29
- { code: 'const a = cy.get("foo")', parserOptions, errors },
30
- { code: 'var a = cy.get("foo")', parserOptions, errors },
27
+ { code: 'let a = cy.get("foo")', errors },
28
+ { code: 'const a = cy.get("foo")', errors },
29
+ { code: 'var a = cy.get("foo")', errors },
31
30
 
32
- { code: 'let a = cy.contains("foo")', parserOptions, errors },
33
- { code: 'let a = cy.window()', parserOptions, errors },
34
- { code: 'let a = cy.wait("@something")', parserOptions, errors },
31
+ { code: 'let a = cy.contains("foo")', errors },
32
+ { code: 'let a = cy.window()', errors },
33
+ { code: 'let a = cy.wait("@something")', errors },
35
34
 
36
- { code: 'let a = cy.contains("foo").click()', parserOptions, errors },
35
+ { code: 'let a = cy.contains("foo").click()', errors },
37
36
  ],
38
37
  })
@@ -6,20 +6,18 @@ const RuleTester = require('eslint').RuleTester
6
6
  const ruleTester = new RuleTester()
7
7
 
8
8
  const errors = [{ messageId: 'unexpected' }]
9
- // async functions are an ES2017 feature
10
- const parserOptions = { ecmaVersion: 8 }
11
9
 
12
10
  ruleTester.run('no-async-before', rule, {
13
11
  valid: [
14
- { code: 'before(\'a before case\', () => { cy.get(\'.someClass\'); })', parserOptions },
15
- { code: 'before(\'a before case\', async () => { await somethingAsync(); })', parserOptions },
16
- { code: 'async function nonTestFn () { return await somethingAsync(); }', parserOptions },
17
- { code: 'const nonTestArrowFn = async () => { await somethingAsync(); }', parserOptions },
12
+ { code: 'before(\'a before case\', () => { cy.get(\'.someClass\'); })' },
13
+ { code: 'before(\'a before case\', async () => { await somethingAsync(); })' },
14
+ { code: 'async function nonTestFn () { return await somethingAsync(); }' },
15
+ { code: 'const nonTestArrowFn = async () => { await somethingAsync(); }' },
18
16
  ],
19
17
  invalid: [
20
- { code: 'before(\'a test case\', async () => { cy.get(\'.someClass\'); })', parserOptions, errors },
21
- { code: 'beforeEach(\'a test case\', async () => { cy.get(\'.someClass\'); })', parserOptions, errors },
22
- { code: 'before(\'a test case\', async function () { cy.get(\'.someClass\'); })', parserOptions, errors },
23
- { code: 'beforeEach(\'a test case\', async function () { cy.get(\'.someClass\'); })', parserOptions, errors },
18
+ { code: 'before(\'a test case\', async () => { cy.get(\'.someClass\'); })', errors },
19
+ { code: 'beforeEach(\'a test case\', async () => { cy.get(\'.someClass\'); })', errors },
20
+ { code: 'before(\'a test case\', async function () { cy.get(\'.someClass\'); })', errors },
21
+ { code: 'beforeEach(\'a test case\', async function () { cy.get(\'.someClass\'); })', errors },
24
22
  ],
25
23
  })
@@ -6,20 +6,18 @@ const RuleTester = require('eslint').RuleTester
6
6
  const ruleTester = new RuleTester()
7
7
 
8
8
  const errors = [{ messageId: 'unexpected' }]
9
- // async functions are an ES2017 feature
10
- const parserOptions = { ecmaVersion: 8 }
11
9
 
12
10
  ruleTester.run('no-async-tests', rule, {
13
11
  valid: [
14
- { code: 'it(\'a test case\', () => { cy.get(\'.someClass\'); })', parserOptions },
15
- { code: 'it(\'a test case\', async () => { await somethingAsync(); })', parserOptions },
16
- { code: 'async function nonTestFn () { return await somethingAsync(); }', parserOptions },
17
- { code: 'const nonTestArrowFn = async () => { await somethingAsync(); }', parserOptions },
12
+ { code: 'it(\'a test case\', () => { cy.get(\'.someClass\'); })' },
13
+ { code: 'it(\'a test case\', async () => { await somethingAsync(); })' },
14
+ { code: 'async function nonTestFn () { return await somethingAsync(); }' },
15
+ { code: 'const nonTestArrowFn = async () => { await somethingAsync(); }' },
18
16
  ],
19
17
  invalid: [
20
- { code: 'it(\'a test case\', async () => { cy.get(\'.someClass\'); })', parserOptions, errors },
21
- { code: 'test(\'a test case\', async () => { cy.get(\'.someClass\'); })', parserOptions, errors },
22
- { code: 'it(\'a test case\', async function () { cy.get(\'.someClass\'); })', parserOptions, errors },
23
- { code: 'test(\'a test case\', async function () { cy.get(\'.someClass\'); })', parserOptions, errors },
18
+ { code: 'it(\'a test case\', async () => { cy.get(\'.someClass\'); })', errors },
19
+ { code: 'test(\'a test case\', async () => { cy.get(\'.someClass\'); })', errors },
20
+ { code: 'it(\'a test case\', async function () { cy.get(\'.someClass\'); })', errors },
21
+ { code: 'test(\'a test case\', async function () { cy.get(\'.someClass\'); })', errors },
24
22
  ],
25
23
  })