eslint-plugin-cypress 4.3.0 → 5.0.1

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.
Files changed (46) hide show
  1. package/.node-version +1 -1
  2. package/.nvmrc +1 -1
  3. package/CONTRIBUTING.md +2 -7
  4. package/ESLINTRC-CONFIG.md +3 -143
  5. package/FLAT-CONFIG.md +1 -3
  6. package/README.md +25 -19
  7. package/circle.yml +2 -20
  8. package/eslint.config.mjs +13 -6
  9. package/lib/flat.js +14 -14
  10. package/lib/rules/assertion-before-screenshot.js +21 -21
  11. package/lib/rules/no-assigning-return-values.js +4 -4
  12. package/lib/rules/no-async-before.js +10 -10
  13. package/lib/rules/no-async-tests.js +10 -10
  14. package/lib/rules/no-chained-get.js +32 -32
  15. package/lib/rules/no-debug.js +18 -19
  16. package/lib/rules/no-force.js +21 -24
  17. package/lib/rules/no-pause.js +18 -19
  18. package/lib/rules/no-unnecessary-waiting.js +13 -13
  19. package/lib/rules/no-xpath.js +10 -10
  20. package/lib/rules/require-data-selectors.js +14 -14
  21. package/lib/rules/unsafe-to-chain-command.js +13 -13
  22. package/package.json +12 -14
  23. package/test-project/eslint-configs/eslint.default-deprecated.mjs +11 -0
  24. package/test-project/eslint-configs/eslint.default.mjs +1 -1
  25. package/test-project/eslint-configs/eslint.globals.mjs +1 -1
  26. package/test-project/eslint-configs/eslint.recommended.mjs +1 -1
  27. package/tests/lib/rules/no-chained-get.js +15 -15
  28. package/tests/lib/rules/no-debug.js +6 -6
  29. package/tests/lib/rules/no-force.js +22 -22
  30. package/tests/lib/rules/no-pause.js +6 -6
  31. package/tests/lib/rules/no-xpath.js +15 -15
  32. package/tests/lib/rules/unsafe-to-chain-command.js +1 -1
  33. package/vitest.config.mts +8 -0
  34. package/jest.config-legacy.js +0 -6
  35. package/jest.config.js +0 -6
  36. package/legacy.js +0 -36
  37. package/tests-legacy/config.js +0 -26
  38. package/tests-legacy/lib/rules/assertion-before-screenshot.js +0 -35
  39. package/tests-legacy/lib/rules/no-assigning-return-values.js +0 -38
  40. package/tests-legacy/lib/rules/no-async-before.js +0 -25
  41. package/tests-legacy/lib/rules/no-async-tests.js +0 -25
  42. package/tests-legacy/lib/rules/no-force.js +0 -49
  43. package/tests-legacy/lib/rules/no-pause.js +0 -37
  44. package/tests-legacy/lib/rules/no-unnecessary-waiting.js +0 -71
  45. package/tests-legacy/lib/rules/require-data-selectors.js +0 -31
  46. package/tests-legacy/lib/rules/unsafe-to-chain-command.js +0 -56
@@ -2,30 +2,30 @@
2
2
  * @fileoverview disallow chain of `cy.get()` calls
3
3
  * @author benoit
4
4
  */
5
- "use strict";
5
+ 'use strict'
6
6
 
7
- //------------------------------------------------------------------------------
7
+ // ------------------------------------------------------------------------------
8
8
  // Requirements
9
- //------------------------------------------------------------------------------
9
+ // ------------------------------------------------------------------------------
10
10
 
11
- const rule = require("../../../lib/rules/no-chained-get"),
12
- RuleTester = require("eslint").RuleTester;
11
+ const rule = require('../../../lib/rules/no-chained-get'),
12
+ RuleTester = require('eslint').RuleTester
13
13
 
14
- //------------------------------------------------------------------------------
14
+ // ------------------------------------------------------------------------------
15
15
  // Tests
16
- //------------------------------------------------------------------------------
16
+ // ------------------------------------------------------------------------------
17
17
 
18
- const ruleTester = new RuleTester();
19
- ruleTester.run("no-chained-get", rule, {
18
+ const ruleTester = new RuleTester()
19
+ ruleTester.run('no-chained-get', rule, {
20
20
  valid: [
21
- { code: "cy.get('div')" },
22
- { code: "cy.get('.div').find().get()" },
23
- { code: "cy.get('input').should('be.disabled')" },
21
+ { code: 'cy.get(\'div\')' },
22
+ { code: 'cy.get(\'.div\').find().get()' },
23
+ { code: 'cy.get(\'input\').should(\'be.disabled\')' },
24
24
  ],
25
25
  invalid: [
26
26
  {
27
- code: "cy.get('div').get('div')",
28
- errors: [{ messageId: "unexpected" }],
27
+ code: 'cy.get(\'div\').get(\'div\')',
28
+ errors: [{ messageId: 'unexpected' }],
29
29
  },
30
30
  ],
31
- });
31
+ })
@@ -10,14 +10,14 @@ const errors = [{ messageId: 'unexpected' }]
10
10
  ruleTester.run('no-debug', rule, {
11
11
 
12
12
  valid: [
13
- { code: `debug()` },
14
- { code: `cy.get('button').dblclick()` },
13
+ { code: 'debug()' },
14
+ { code: 'cy.get(\'button\').dblclick()' },
15
15
  ],
16
16
 
17
17
  invalid: [
18
- { code: `cy.debug()`, errors },
19
- { code: `cy.debug({ log: false })`, errors },
20
- { code: `cy.get('button').debug()`, errors },
21
- { code: `cy.get('a').should('have.attr', 'href').and('match', /dashboard/).debug()`, errors }
18
+ { code: 'cy.debug()', errors },
19
+ { code: 'cy.debug({ log: false })', errors },
20
+ { code: 'cy.get(\'button\').debug()', errors },
21
+ { code: 'cy.get(\'a\').should(\'have.attr\', \'href\').and(\'match\', /dashboard/).debug()', errors },
22
22
  ],
23
23
  })
@@ -10,30 +10,30 @@ const errors = [{ messageId: 'unexpected' }]
10
10
  ruleTester.run('no-force', rule, {
11
11
 
12
12
  valid: [
13
- { code: `cy.get('button').click()` },
14
- { code: `cy.get('button').click({multiple: true})` },
15
- { code: `cy.get('button').dblclick()` },
16
- { code: `cy.get('input').type('somth')` },
17
- { code: `cy.get('input').type('somth', {anyoption: true})` },
18
- { code: `cy.get('input').trigger('click', {anyoption: true})` },
19
- { code: `cy.get('input').rightclick({anyoption: true})` },
20
- { code: `cy.get('input').check()` },
21
- { code: `cy.get('input').select()` },
22
- { code: `cy.get('input').focus()` },
23
- { code: `cy.document().trigger("keydown", { ...event })` },
13
+ { code: 'cy.get(\'button\').click()' },
14
+ { code: 'cy.get(\'button\').click({multiple: true})' },
15
+ { code: 'cy.get(\'button\').dblclick()' },
16
+ { code: 'cy.get(\'input\').type(\'somth\')' },
17
+ { code: 'cy.get(\'input\').type(\'somth\', {anyoption: true})' },
18
+ { code: 'cy.get(\'input\').trigger(\'click\', {anyoption: true})' },
19
+ { code: 'cy.get(\'input\').rightclick({anyoption: true})' },
20
+ { code: 'cy.get(\'input\').check()' },
21
+ { code: 'cy.get(\'input\').select()' },
22
+ { code: 'cy.get(\'input\').focus()' },
23
+ { code: 'cy.document().trigger("keydown", { ...event })' },
24
24
  ],
25
25
 
26
26
  invalid: [
27
- { code: `cy.get('button').click({force: true})`, errors },
28
- { code: `cy.get('button').dblclick({force: true})`, errors },
29
- { code: `cy.get('input').type('somth', {force: true})`, errors },
30
- { code: `cy.get('div').find('.foo').type('somth', {force: true})`, errors },
31
- { code: `cy.get('div').find('.foo').find('.bar').click({force: true})`, errors },
32
- { code: `cy.get('div').find('.foo').find('.bar').trigger('change', {force: true})`, errors },
33
- { code: `cy.get('input').trigger('click', {force: true})`, errors },
34
- { code: `cy.get('input').rightclick({force: true})`, errors },
35
- { code: `cy.get('input').check({force: true})`, errors },
36
- { code: `cy.get('input').select({force: true})`, errors },
37
- { code: `cy.get('input').focus({force: true})`, errors },
27
+ { code: 'cy.get(\'button\').click({force: true})', errors },
28
+ { code: 'cy.get(\'button\').dblclick({force: true})', errors },
29
+ { code: 'cy.get(\'input\').type(\'somth\', {force: true})', errors },
30
+ { code: 'cy.get(\'div\').find(\'.foo\').type(\'somth\', {force: true})', errors },
31
+ { code: 'cy.get(\'div\').find(\'.foo\').find(\'.bar\').click({force: true})', errors },
32
+ { code: 'cy.get(\'div\').find(\'.foo\').find(\'.bar\').trigger(\'change\', {force: true})', errors },
33
+ { code: 'cy.get(\'input\').trigger(\'click\', {force: true})', errors },
34
+ { code: 'cy.get(\'input\').rightclick({force: true})', errors },
35
+ { code: 'cy.get(\'input\').check({force: true})', errors },
36
+ { code: 'cy.get(\'input\').select({force: true})', errors },
37
+ { code: 'cy.get(\'input\').focus({force: true})', errors },
38
38
  ],
39
39
  })
@@ -10,14 +10,14 @@ const errors = [{ messageId: 'unexpected' }]
10
10
  ruleTester.run('no-pause', rule, {
11
11
 
12
12
  valid: [
13
- { code: `pause()` },
14
- { code: `cy.get('button').dblclick()` },
13
+ { code: 'pause()' },
14
+ { code: 'cy.get(\'button\').dblclick()' },
15
15
  ],
16
16
 
17
17
  invalid: [
18
- { code: `cy.pause()`, errors },
19
- { code: `cy.pause({ log: false })`, errors },
20
- { code: `cy.get('button').pause()`, errors },
21
- { code: `cy.get('a').should('have.attr', 'href').and('match', /dashboard/).pause()`, errors }
18
+ { code: 'cy.pause()', errors },
19
+ { code: 'cy.pause({ log: false })', errors },
20
+ { code: 'cy.get(\'button\').pause()', errors },
21
+ { code: 'cy.get(\'a\').should(\'have.attr\', \'href\').and(\'match\', /dashboard/).pause()', errors },
22
22
  ],
23
23
  })
@@ -1,30 +1,30 @@
1
- "use strict";
1
+ 'use strict'
2
2
 
3
- //------------------------------------------------------------------------------
3
+ // ------------------------------------------------------------------------------
4
4
  // Requirements
5
- //------------------------------------------------------------------------------
5
+ // ------------------------------------------------------------------------------
6
6
 
7
- const rule = require("../../../lib/rules/no-xpath"),
8
- RuleTester = require("eslint").RuleTester;
7
+ const rule = require('../../../lib/rules/no-xpath'),
8
+ RuleTester = require('eslint').RuleTester
9
9
 
10
- //------------------------------------------------------------------------------
10
+ // ------------------------------------------------------------------------------
11
11
  // Tests
12
- //------------------------------------------------------------------------------
12
+ // ------------------------------------------------------------------------------
13
13
 
14
- const ruleTester = new RuleTester();
15
- ruleTester.run("no-xpath", rule, {
14
+ const ruleTester = new RuleTester()
15
+ ruleTester.run('no-xpath', rule, {
16
16
  valid: [
17
17
  { code: 'cy.get("button").click({force: true})' },
18
18
  ],
19
19
 
20
20
  invalid: [
21
21
  {
22
- code: "cy.xpath('//div[@class=\"container\"]/p[1]').click()",
23
- errors: [{ messageId: "unexpected" }],
22
+ code: 'cy.xpath(\'//div[@class="container"]/p[1]\').click()',
23
+ errors: [{ messageId: 'unexpected' }],
24
24
  },
25
25
  {
26
- code: "cy.xpath('//p[1]').should('exist')",
27
- errors: [{ messageId: "unexpected" }]
28
- }
26
+ code: 'cy.xpath(\'//p[1]\').should(\'exist\')',
27
+ errors: [{ messageId: 'unexpected' }],
28
+ },
29
29
  ],
30
- });
30
+ })
@@ -10,7 +10,7 @@ const errors = [{ messageId: 'unexpected' }]
10
10
  ruleTester.run('action-ends-chain', rule, {
11
11
  valid: [
12
12
  {
13
- code: 'cy.get("new-todo").type("todo A{enter}"); cy.get("new-todo").type("todo B{enter}"); cy.get("new-todo").should("have.class", "active");'
13
+ code: 'cy.get("new-todo").type("todo A{enter}"); cy.get("new-todo").type("todo B{enter}"); cy.get("new-todo").should("have.class", "active");',
14
14
  },
15
15
  { code: 'cy.focused().should("be.visible");' },
16
16
  { code: 'cy.submitBtn().click();' },
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from 'vitest/config'
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ include: ['**/tests/**/*.[jt]s?(x)'],
6
+ globals: true
7
+ },
8
+ })
@@ -1,6 +0,0 @@
1
- const { defaults } = require('jest-config')
2
-
3
- module.exports = {
4
- testMatch: ['**/tests-legacy/**/*.[jt]s?(x)'],
5
- testPathIgnorePatterns: [...defaults.testPathIgnorePatterns, '.history'],
6
- }
package/jest.config.js DELETED
@@ -1,6 +0,0 @@
1
- const { defaults } = require('jest-config')
2
-
3
- module.exports = {
4
- testMatch: ['**/tests/**/*.[jt]s?(x)'],
5
- testPathIgnorePatterns: [...defaults.testPathIgnorePatterns, '.history'],
6
- }
package/legacy.js DELETED
@@ -1,36 +0,0 @@
1
- const globals = require('globals')
2
-
3
- module.exports = {
4
- rules: {
5
- 'no-assigning-return-values': require('./lib/rules/no-assigning-return-values'),
6
- 'unsafe-to-chain-command': require('./lib/rules/unsafe-to-chain-command'),
7
- 'no-unnecessary-waiting': require('./lib/rules/no-unnecessary-waiting'),
8
- 'no-async-before': require('./lib/rules/no-async-before'),
9
- 'no-async-tests': require('./lib/rules/no-async-tests'),
10
- 'assertion-before-screenshot': require('./lib/rules/assertion-before-screenshot'),
11
- 'require-data-selectors': require('./lib/rules/require-data-selectors'),
12
- 'no-force': require('./lib/rules/no-force'),
13
- 'no-pause': require('./lib/rules/no-pause'),
14
- 'no-debug': require('./lib/rules/no-debug'),
15
- 'no-xpath': require('./lib/rules/no-xpath'),
16
- 'no-chained-get': require('./lib/rules/no-chained-get'),
17
- },
18
- configs: {
19
- recommended: require('./lib/config/recommended'),
20
- },
21
- environments: {
22
- globals: {
23
- globals: Object.assign({
24
- cy: false,
25
- Cypress: false,
26
- expect: false,
27
- assert: false,
28
- chai: false,
29
- }, globals.browser, globals.mocha),
30
- parserOptions: {
31
- ecmaVersion: 2019,
32
- sourceType: 'module',
33
- },
34
- },
35
- },
36
- }
@@ -1,26 +0,0 @@
1
- /* global describe, it, expect */
2
- 'use strict'
3
-
4
- const globals = require('globals')
5
- const config = require('../legacy.js')
6
-
7
- describe('environments globals', () => {
8
- const env = config.environments.globals
9
-
10
- it('should not mutate globals', () => {
11
- expect(globals.browser).not.toHaveProperty('cy')
12
- expect(globals.mocha).not.toHaveProperty('cy')
13
- })
14
-
15
- it('should include other globals', () => {
16
- expect(env.globals).toEqual(expect.objectContaining(globals.browser))
17
- expect(env.globals).toEqual(expect.objectContaining(globals.mocha))
18
- })
19
-
20
- it('should include cypress globals', () => {
21
- expect(env.globals).toEqual(expect.objectContaining({
22
- cy: false,
23
- Cypress: false,
24
- }))
25
- })
26
- })
@@ -1,35 +0,0 @@
1
- 'use strict'
2
-
3
- const rule = require('../../../lib/rules/assertion-before-screenshot')
4
- const RuleTester = require('eslint').RuleTester
5
-
6
- const ruleTester = new RuleTester()
7
-
8
- const errors = [{ messageId: 'unexpected' }]
9
- const parserOptions = { ecmaVersion: 6 }
10
-
11
- ruleTester.run('assertion-before-screenshot', rule, {
12
- 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 },
22
- ],
23
-
24
- 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 },
34
- ],
35
- })
@@ -1,38 +0,0 @@
1
- 'use strict'
2
-
3
- const rule = require('../../../lib/rules/no-assigning-return-values')
4
- const RuleTester = require('eslint').RuleTester
5
-
6
- const ruleTester = new RuleTester()
7
-
8
- const errors = [{ messageId: 'unexpected' }]
9
- const parserOptions = { ecmaVersion: 6 }
10
-
11
- ruleTester.run('no-assigning-return-values', rule, {
12
- 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 },
25
- ],
26
-
27
- 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 },
31
-
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 },
35
-
36
- { code: 'let a = cy.contains("foo").click()', parserOptions, errors },
37
- ],
38
- })
@@ -1,25 +0,0 @@
1
- 'use strict'
2
-
3
- const rule = require('../../../lib/rules/no-async-before')
4
- const RuleTester = require('eslint').RuleTester
5
-
6
- const ruleTester = new RuleTester()
7
-
8
- const errors = [{ messageId: 'unexpected' }]
9
- // async functions are an ES2017 feature
10
- const parserOptions = { ecmaVersion: 8 }
11
-
12
- ruleTester.run('no-async-before', rule, {
13
- 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 },
18
- ],
19
- 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 },
24
- ],
25
- })
@@ -1,25 +0,0 @@
1
- 'use strict'
2
-
3
- const rule = require('../../../lib/rules/no-async-tests')
4
- const RuleTester = require('eslint').RuleTester
5
-
6
- const ruleTester = new RuleTester()
7
-
8
- const errors = [{ messageId: 'unexpected' }]
9
- // async functions are an ES2017 feature
10
- const parserOptions = { ecmaVersion: 8 }
11
-
12
- ruleTester.run('no-async-tests', rule, {
13
- 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 },
18
- ],
19
- 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 },
24
- ],
25
- })
@@ -1,49 +0,0 @@
1
- 'use strict'
2
-
3
- //------------------------------------------------------------------------------
4
- // Requirements
5
- //------------------------------------------------------------------------------
6
-
7
- const rule = require('../../../lib/rules/no-force')
8
-
9
- const RuleTester = require('eslint').RuleTester
10
-
11
- const errors = [{ messageId: 'unexpected' }]
12
- const parserOptions = { ecmaVersion: 2018 }
13
-
14
- //------------------------------------------------------------------------------
15
- // Tests
16
- //------------------------------------------------------------------------------
17
-
18
- let ruleTester = new RuleTester()
19
-
20
- ruleTester.run('no-force', rule, {
21
-
22
- valid: [
23
- { code: `cy.get('button').click()`, parserOptions },
24
- { code: `cy.get('button').click({multiple: true})`, parserOptions },
25
- { code: `cy.get('button').dblclick()`, parserOptions },
26
- { code: `cy.get('input').type('somth')`, parserOptions },
27
- { code: `cy.get('input').type('somth', {anyoption: true})`, parserOptions },
28
- { code: `cy.get('input').trigger('click', {anyoption: true})`, parserOptions },
29
- { code: `cy.get('input').rightclick({anyoption: true})`, parserOptions },
30
- { code: `cy.get('input').check()`, parserOptions },
31
- { code: `cy.get('input').select()`, parserOptions },
32
- { code: `cy.get('input').focus()`, parserOptions },
33
- { code: `cy.document().trigger("keydown", { ...event })`, parserOptions },
34
- ],
35
-
36
- invalid: [
37
- { code: `cy.get('button').click({force: true})`, parserOptions, errors },
38
- { code: `cy.get('button').dblclick({force: true})`, parserOptions, errors },
39
- { code: `cy.get('input').type('somth', {force: true})`, parserOptions, errors },
40
- { code: `cy.get('div').find('.foo').type('somth', {force: true})`, parserOptions, errors },
41
- { code: `cy.get('div').find('.foo').find('.bar').click({force: true})`, parserOptions, errors },
42
- { code: `cy.get('div').find('.foo').find('.bar').trigger('change', {force: true})`, parserOptions, errors },
43
- { code: `cy.get('input').trigger('click', {force: true})`, parserOptions, errors },
44
- { code: `cy.get('input').rightclick({force: true})`, parserOptions, errors },
45
- { code: `cy.get('input').check({force: true})`, parserOptions, errors },
46
- { code: `cy.get('input').select({force: true})`, parserOptions, errors },
47
- { code: `cy.get('input').focus({force: true})`, parserOptions, errors },
48
- ],
49
- })
@@ -1,37 +0,0 @@
1
- 'use strict'
2
-
3
- //------------------------------------------------------------------------------
4
- // Requirements
5
- //------------------------------------------------------------------------------
6
-
7
- const rule = require('../../../lib/rules/no-pause')
8
-
9
- const RuleTester = require('eslint').RuleTester
10
-
11
- const errors = [{ messageId: 'unexpected' }]
12
- const parserOptions = { ecmaVersion: 2018 }
13
-
14
- //------------------------------------------------------------------------------
15
- // Tests
16
- //------------------------------------------------------------------------------
17
-
18
- const ruleTester = new RuleTester()
19
-
20
- ruleTester.run('no-pause', rule, {
21
-
22
- valid: [
23
- { code: `pause()`, parserOptions },
24
- { code: `cy.get('button').dblclick()`, parserOptions },
25
- ],
26
-
27
- invalid: [
28
- { code: `cy.pause()`, parserOptions, errors },
29
- { code: `cy.pause({ log: false })`, parserOptions, errors },
30
- { code: `cy.get('button').pause()`, parserOptions, errors },
31
- {
32
- code: `cy.get('a').should('have.attr', 'href').and('match', /dashboard/).pause()`,
33
- parserOptions,
34
- errors
35
- }
36
- ],
37
- })
@@ -1,71 +0,0 @@
1
- 'use strict'
2
-
3
- const rule = require('../../../lib/rules/no-unnecessary-waiting')
4
- const RuleTester = require('eslint').RuleTester
5
-
6
- const ruleTester = new RuleTester()
7
-
8
- const errors = [{ messageId: 'unexpected' }]
9
- const parserOptions = { ecmaVersion: 6, sourceType: 'module' }
10
-
11
- ruleTester.run('no-unnecessary-waiting', rule, {
12
- valid: [
13
- { code: 'foo.wait(10)', parserOptions },
14
-
15
- { code: 'cy.wait("@someRequest")', parserOptions },
16
- { code: 'cy.wait("@someRequest", { log: false })', parserOptions },
17
- { code: 'cy.wait("@someRequest").then((xhr) => xhr)', parserOptions },
18
- { code: 'cy.wait(["@someRequest", "@anotherRequest"])', parserOptions },
19
-
20
- { code: 'cy.clock(5000)', parserOptions },
21
- { code: 'cy.scrollTo(0, 10)', parserOptions },
22
- { code: 'cy.tick(500)', parserOptions },
23
-
24
- { code: 'const someRequest="@someRequest"; cy.wait(someRequest)', parserOptions, errors },
25
- { code: 'function customWait (alias = "@someRequest") { cy.wait(alias) }', parserOptions, errors },
26
- { code: 'const customWait = (alias = "@someRequest") => { cy.wait(alias) }', parserOptions, errors },
27
- { code: 'function customWait (ms) { cy.wait(ms) }', parserOptions, errors },
28
- { code: 'const customWait = (ms) => { cy.wait(ms) }', parserOptions, errors },
29
-
30
- { code: 'import BAR_BAZ from "bar-baz"; cy.wait(BAR_BAZ)', parserOptions },
31
- { code: 'import { FOO_BAR } from "foo-bar"; cy.wait(FOO_BAR)', parserOptions },
32
- { code: 'import * as wildcard from "wildcard"; cy.wait(wildcard.value)', parserOptions },
33
- { code: 'import { NAME as OTHER_NAME } from "rename"; cy.wait(OTHER_NAME)', parserOptions },
34
-
35
- // disable the eslint rule
36
- {
37
- code: `
38
- cy.wait(100); // eslint-disable-line no-unnecessary-waiting
39
- `,
40
- parserOptions,
41
- },
42
- {
43
- code: `
44
- /* eslint-disable-next-line no-unnecessary-waiting */
45
- cy.wait(100)
46
- `,
47
- parserOptions,
48
- },
49
- {
50
- code: `
51
- /* eslint-disable no-unnecessary-waiting */
52
- cy.wait(100)
53
- /* eslint-enable no-unnecessary-waiting */
54
- `,
55
- parserOptions,
56
- },
57
- ],
58
-
59
- invalid: [
60
- { code: 'cy.wait(0)', parserOptions, errors },
61
- { code: 'cy.wait(100)', parserOptions, errors },
62
- { code: 'cy.wait(5000)', parserOptions, errors },
63
- { code: 'const someNumber=500; cy.wait(someNumber)', parserOptions, errors },
64
- { code: 'function customWait (ms = 1) { cy.wait(ms) }', parserOptions, errors },
65
- { code: 'const customWait = (ms = 1) => { cy.wait(ms) }', parserOptions, errors },
66
-
67
- { code: 'cy.get(".some-element").wait(10)', parserOptions, errors },
68
- { code: 'cy.get(".some-element").contains("foo").wait(10)', parserOptions, errors },
69
- { code: 'const customWait = (ms = 1) => { cy.get(".some-element").wait(ms) }', parserOptions, errors },
70
- ],
71
- })
@@ -1,31 +0,0 @@
1
- 'use strict'
2
-
3
- const rule = require('../../../lib/rules/require-data-selectors')
4
- const RuleTester = require('eslint').RuleTester
5
-
6
- const ruleTester = new RuleTester()
7
-
8
- const errors = [{ messageId: 'unexpected' }]
9
- const parserOptions = { ecmaVersion: 6 }
10
-
11
- ruleTester.run('require-data-selectors', rule, {
12
- valid: [
13
- { code: 'cy.get(\'[data-cy=submit]\').click()', parserOptions },
14
- { code: 'cy.get(\'[data-QA=submit]\')', parserOptions },
15
- { code: 'cy.clock(5000)', parserOptions },
16
- { code: 'cy.scrollTo(0, 10)', parserOptions },
17
- { code: 'cy.tick(500)', parserOptions },
18
- { code: 'cy.get(\`[data-cy=${1}]\`)', parserOptions }, // eslint-disable-line no-useless-escape
19
- { code: 'cy.get("@my-alias")', parserOptions, errors },
20
- { code: 'cy.get(`@my-alias`)', parserOptions, errors },
21
- ],
22
-
23
- invalid: [
24
- { code: 'cy.get(\'[daedta-cy=submit]\').click()', parserOptions, errors },
25
- { code: 'cy.get(\'[d-cy=submit]\')', parserOptions, errors },
26
- { code: 'cy.get(".btn-large").click()', parserOptions, errors },
27
- { code: 'cy.get(".btn-.large").click()', parserOptions, errors },
28
- { code: 'cy.get(".a")', parserOptions, errors },
29
- { code: 'cy.get(\`[daedta-cy=${1}]\`)', parserOptions, errors }, // eslint-disable-line no-useless-escape
30
- ],
31
- })