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.
@@ -1,49 +1,39 @@
1
1
  'use strict'
2
2
 
3
- //------------------------------------------------------------------------------
4
- // Requirements
5
- //------------------------------------------------------------------------------
6
-
7
3
  const rule = require('../../../lib/rules/no-force')
8
-
9
4
  const RuleTester = require('eslint').RuleTester
10
5
 
11
- const errors = [{ messageId: 'unexpected' }]
12
- const parserOptions = { ecmaVersion: 2018 }
6
+ const ruleTester = new RuleTester()
13
7
 
14
- //------------------------------------------------------------------------------
15
- // Tests
16
- //------------------------------------------------------------------------------
17
-
18
- let ruleTester = new RuleTester()
8
+ const errors = [{ messageId: 'unexpected' }]
19
9
 
20
10
  ruleTester.run('no-force', rule, {
21
11
 
22
12
  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 },
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 })` },
34
24
  ],
35
25
 
36
26
  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 },
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 },
48
38
  ],
49
39
  })
@@ -1,37 +1,23 @@
1
1
  'use strict'
2
2
 
3
- //------------------------------------------------------------------------------
4
- // Requirements
5
- //------------------------------------------------------------------------------
6
-
7
3
  const rule = require('../../../lib/rules/no-pause')
8
-
9
4
  const RuleTester = require('eslint').RuleTester
10
5
 
11
- const errors = [{ messageId: 'unexpected' }]
12
- const parserOptions = { ecmaVersion: 2018 }
13
-
14
- //------------------------------------------------------------------------------
15
- // Tests
16
- //------------------------------------------------------------------------------
17
-
18
6
  const ruleTester = new RuleTester()
19
7
 
8
+ const errors = [{ messageId: 'unexpected' }]
9
+
20
10
  ruleTester.run('no-pause', rule, {
21
11
 
22
12
  valid: [
23
- { code: `pause()`, parserOptions },
24
- { code: `cy.get('button').dblclick()`, parserOptions },
13
+ { code: `pause()` },
14
+ { code: `cy.get('button').dblclick()` },
25
15
  ],
26
-
16
+
27
17
  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
- }
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 }
36
22
  ],
37
23
  })
@@ -6,66 +6,42 @@ const RuleTester = require('eslint').RuleTester
6
6
  const ruleTester = new RuleTester()
7
7
 
8
8
  const errors = [{ messageId: 'unexpected' }]
9
- const parserOptions = { ecmaVersion: 6, sourceType: 'module' }
10
9
 
11
10
  ruleTester.run('no-unnecessary-waiting', rule, {
12
11
  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
- },
12
+ { code: 'foo.wait(10)' },
13
+
14
+ { code: 'cy.wait("@someRequest")' },
15
+ { code: 'cy.wait("@someRequest", { log: false })' },
16
+ { code: 'cy.wait("@someRequest").then((xhr) => xhr)' },
17
+ { code: 'cy.wait(["@someRequest", "@anotherRequest"])' },
18
+
19
+ { code: 'cy.clock(5000)' },
20
+ { code: 'cy.scrollTo(0, 10)' },
21
+ { code: 'cy.tick(500)' },
22
+
23
+ { code: 'const someRequest="@someRequest"; cy.wait(someRequest)' },
24
+ { code: 'function customWait (alias = "@someRequest") { cy.wait(alias) }' },
25
+ { code: 'const customWait = (alias = "@someRequest") => { cy.wait(alias) }' },
26
+ { code: 'function customWait (ms) { cy.wait(ms) }' },
27
+ { code: 'const customWait = (ms) => { cy.wait(ms) }' },
28
+
29
+ { code: 'import BAR_BAZ from "bar-baz"; cy.wait(BAR_BAZ)' },
30
+ { code: 'import { FOO_BAR } from "foo-bar"; cy.wait(FOO_BAR)' },
31
+ { code: 'import * as wildcard from "wildcard"; cy.wait(wildcard.value)' },
32
+ { code: 'import { NAME as OTHER_NAME } from "rename"; cy.wait(OTHER_NAME)' },
57
33
  ],
58
34
 
59
35
  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 },
36
+ { code: 'cy.wait(0)', errors },
37
+ { code: 'cy.wait(100)', errors },
38
+ { code: 'cy.wait(5000)', errors },
39
+ { code: 'const someNumber=500; cy.wait(someNumber)', errors },
40
+ { code: 'function customWait (ms = 1) { cy.wait(ms) }', errors },
41
+ { code: 'const customWait = (ms = 1) => { cy.wait(ms) }', errors },
42
+
43
+ { code: 'cy.get(".some-element").wait(10)', errors },
44
+ { code: 'cy.get(".some-element").contains("foo").wait(10)', errors },
45
+ { code: 'const customWait = (ms = 1) => { cy.get(".some-element").wait(ms) }', errors },
70
46
  ],
71
47
  })
@@ -6,26 +6,25 @@ 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('require-data-selectors', rule, {
12
11
  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 },
12
+ { code: 'cy.get(\'[data-cy=submit]\').click()' },
13
+ { code: 'cy.get(\'[data-QA=submit]\')' },
14
+ { code: 'cy.clock(5000)' },
15
+ { code: 'cy.scrollTo(0, 10)' },
16
+ { code: 'cy.tick(500)' },
17
+ { code: 'cy.get(\`[data-cy=${1}]\`)' }, // eslint-disable-line no-useless-escape
18
+ { code: 'cy.get("@my-alias")' },
19
+ { code: 'cy.get(`@my-alias`)' },
21
20
  ],
22
21
 
23
22
  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
23
+ { code: 'cy.get(\'[daedta-cy=submit]\').click()', errors },
24
+ { code: 'cy.get(\'[d-cy=submit]\')', errors },
25
+ { code: 'cy.get(".btn-large").click()', errors },
26
+ { code: 'cy.get(".btn-.large").click()', errors },
27
+ { code: 'cy.get(".a")', errors },
28
+ { code: 'cy.get(\`[daedta-cy=${1}]\`)', errors }, // eslint-disable-line no-useless-escape
30
29
  ],
31
30
  })
@@ -6,51 +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('action-ends-chain', rule, {
12
11
  valid: [
13
12
  {
14
- 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");',
15
- parserOptions,
16
- },
17
- {
18
- code: 'cy.focused().should("be.visible");',
19
- parserOptions,
20
- },
21
- {
22
- code: 'cy.submitBtn().click();',
23
- parserOptions,
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");'
24
14
  },
15
+ { code: 'cy.focused().should("be.visible");' },
16
+ { code: 'cy.submitBtn().click();' },
25
17
  ],
26
18
 
27
19
  invalid: [
28
- {
29
- code: 'cy.get("new-todo").type("todo A{enter}").should("have.class", "active");',
30
- parserOptions,
31
- errors,
32
- },
33
- {
34
- code: 'cy.get("new-todo").type("todo A{enter}").type("todo B{enter}");',
35
- parserOptions,
36
- errors,
37
- },
38
- {
39
- code: 'cy.get("new-todo").focus().should("have.class", "active");',
40
- parserOptions,
41
- errors,
42
- },
20
+ { code: 'cy.get("new-todo").type("todo A{enter}").should("have.class", "active");', errors },
21
+ { code: 'cy.get("new-todo").type("todo A{enter}").type("todo B{enter}");', errors },
22
+ { code: 'cy.get("new-todo").focus().should("have.class", "active");', errors },
43
23
  {
44
24
  code: 'cy.get("new-todo").customType("todo A{enter}").customClick();',
45
- parserOptions,
46
- errors,
47
25
  options: [{ methods: ['customType', 'customClick'] }],
26
+ errors,
48
27
  },
49
28
  {
50
29
  code: 'cy.get("new-todo").customPress("Enter").customScroll();',
51
- parserOptions,
30
+ options: [{ methods: ['customPress', 'customScroll'] }],
52
31
  errors,
53
- options: [{ methods: [/customPress/, /customScroll/] }],
54
32
  },
55
33
  ],
56
34
  })
@@ -0,0 +1,26 @@
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
+ })
@@ -0,0 +1,35 @@
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
+ })
@@ -0,0 +1,38 @@
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
+ })
@@ -0,0 +1,25 @@
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
+ })
@@ -0,0 +1,25 @@
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
+ })
@@ -0,0 +1,49 @@
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
+ })
@@ -0,0 +1,37 @@
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
+ })
@@ -0,0 +1,71 @@
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
+ })