Skip to content

Commit a980b1f

Browse files
Merge pull request #205 from MikeMcC399/save-legacy-tests
tests: save legacy tests
2 parents c40989d + 00fc7ca commit a980b1f

13 files changed

+402
-2
lines changed

circle.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
command: npx eslint --version
5353
- run:
5454
name: Test ESLint 7
55-
command: npm test
55+
command: npm run test:legacy
5656

5757
test-v8:
5858
docker:
@@ -70,7 +70,7 @@ jobs:
7070
command: npx eslint --version
7171
- run:
7272
name: Test ESLint 8
73-
command: npm test
73+
command: npm run test:legacy
7474

7575
release:
7676
docker:

jest.config-legacy.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"semantic-release": "semantic-release",
4242
"start": "npm run test-watch",
4343
"test": "jest",
44+
"test:legacy": "jest --config jest.config-legacy.js",
4445
"test-watch": "jest --watchAll",
4546
"prepare": "husky"
4647
}

tests-legacy/config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* global describe, it, expect */
2+
'use strict'
3+
4+
const globals = require('globals')
5+
const config = require('../index.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+
})
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
})
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
})

tests-legacy/lib/rules/no-force.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
})

tests-legacy/lib/rules/no-pause.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 commit comments

Comments
 (0)