-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from MikeMcC399/save-legacy-tests
tests: save legacy tests
- Loading branch information
Showing
13 changed files
with
402 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const { defaults } = require('jest-config') | ||
|
||
module.exports = { | ||
testMatch: ['**/tests-legacy/**/*.[jt]s?(x)'], | ||
testPathIgnorePatterns: [...defaults.testPathIgnorePatterns, '.history'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* global describe, it, expect */ | ||
'use strict' | ||
|
||
const globals = require('globals') | ||
const config = require('../index.js') | ||
|
||
describe('environments globals', () => { | ||
const env = config.environments.globals | ||
|
||
it('should not mutate globals', () => { | ||
expect(globals.browser).not.toHaveProperty('cy') | ||
expect(globals.mocha).not.toHaveProperty('cy') | ||
}) | ||
|
||
it('should include other globals', () => { | ||
expect(env.globals).toEqual(expect.objectContaining(globals.browser)) | ||
expect(env.globals).toEqual(expect.objectContaining(globals.mocha)) | ||
}) | ||
|
||
it('should include cypress globals', () => { | ||
expect(env.globals).toEqual(expect.objectContaining({ | ||
cy: false, | ||
Cypress: false, | ||
})) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict' | ||
|
||
const rule = require('../../../lib/rules/assertion-before-screenshot') | ||
const RuleTester = require('eslint').RuleTester | ||
|
||
const ruleTester = new RuleTester() | ||
|
||
const errors = [{ messageId: 'unexpected' }] | ||
const parserOptions = { ecmaVersion: 6 } | ||
|
||
ruleTester.run('assertion-before-screenshot', rule, { | ||
valid: [ | ||
{ code: 'cy.get(".some-element"); cy.screenshot();', parserOptions }, | ||
{ code: 'cy.get(".some-element").should("exist").screenshot();', parserOptions }, | ||
{ code: 'cy.get(".some-element").should("exist").screenshot().click()', parserOptions, errors }, | ||
{ code: 'cy.get(".some-element").should("exist"); if(true) cy.screenshot();', parserOptions }, | ||
{ code: 'if(true) { cy.get(".some-element").should("exist"); cy.screenshot(); }', parserOptions }, | ||
{ code: 'cy.get(".some-element").should("exist"); if(true) { cy.screenshot(); }', parserOptions }, | ||
{ code: 'const a = () => { cy.get(".some-element").should("exist"); cy.screenshot(); }', parserOptions, errors }, | ||
{ code: 'cy.get(".some-element").should("exist").and("be.visible"); cy.screenshot();', parserOptions }, | ||
{ code: 'cy.get(".some-element").contains("Text"); cy.screenshot();', parserOptions }, | ||
], | ||
|
||
invalid: [ | ||
{ code: 'cy.screenshot()', parserOptions, errors }, | ||
{ code: 'cy.visit("somepage"); cy.screenshot();', parserOptions, errors }, | ||
{ code: 'cy.custom(); cy.screenshot()', parserOptions, errors }, | ||
{ code: 'cy.get(".some-element").click(); cy.screenshot()', parserOptions, errors }, | ||
{ code: 'cy.get(".some-element").click().screenshot()', parserOptions, errors }, | ||
{ code: 'if(true) { cy.get(".some-element").click(); cy.screenshot(); }', parserOptions, errors }, | ||
{ code: 'cy.get(".some-element").click(); if(true) { cy.screenshot(); }', parserOptions, errors }, | ||
{ code: 'cy.get(".some-element"); function a() { cy.screenshot(); }', parserOptions, errors }, | ||
{ code: 'cy.get(".some-element"); const a = () => { cy.screenshot(); }', parserOptions, errors }, | ||
], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict' | ||
|
||
const rule = require('../../../lib/rules/no-assigning-return-values') | ||
const RuleTester = require('eslint').RuleTester | ||
|
||
const ruleTester = new RuleTester() | ||
|
||
const errors = [{ messageId: 'unexpected' }] | ||
const parserOptions = { ecmaVersion: 6 } | ||
|
||
ruleTester.run('no-assigning-return-values', rule, { | ||
valid: [ | ||
{ code: 'var foo = true;', parserOptions }, | ||
{ code: 'let foo = true;', parserOptions }, | ||
{ code: 'const foo = true;', parserOptions }, | ||
{ code: 'const foo = bar();', parserOptions }, | ||
{ code: 'const foo = bar().baz();', parserOptions }, | ||
{ code: 'const spy = cy.spy();', parserOptions }, | ||
{ code: 'const spy = cy.spy().as();', parserOptions }, | ||
{ code: 'const stub = cy.stub();', parserOptions }, | ||
{ code: 'const result = cy.now();', parserOptions }, | ||
{ code: 'const state = cy.state();', parserOptions }, | ||
{ code: 'cy.get("foo");', parserOptions }, | ||
{ code: 'cy.contains("foo").click();', parserOptions }, | ||
], | ||
|
||
invalid: [ | ||
{ code: 'let a = cy.get("foo")', parserOptions, errors }, | ||
{ code: 'const a = cy.get("foo")', parserOptions, errors }, | ||
{ code: 'var a = cy.get("foo")', parserOptions, errors }, | ||
|
||
{ code: 'let a = cy.contains("foo")', parserOptions, errors }, | ||
{ code: 'let a = cy.window()', parserOptions, errors }, | ||
{ code: 'let a = cy.wait("@something")', parserOptions, errors }, | ||
|
||
{ code: 'let a = cy.contains("foo").click()', parserOptions, errors }, | ||
], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict' | ||
|
||
const rule = require('../../../lib/rules/no-async-before') | ||
const RuleTester = require('eslint').RuleTester | ||
|
||
const ruleTester = new RuleTester() | ||
|
||
const errors = [{ messageId: 'unexpected' }] | ||
// async functions are an ES2017 feature | ||
const parserOptions = { ecmaVersion: 8 } | ||
|
||
ruleTester.run('no-async-before', rule, { | ||
valid: [ | ||
{ code: 'before(\'a before case\', () => { cy.get(\'.someClass\'); })', parserOptions }, | ||
{ code: 'before(\'a before case\', async () => { await somethingAsync(); })', parserOptions }, | ||
{ code: 'async function nonTestFn () { return await somethingAsync(); }', parserOptions }, | ||
{ code: 'const nonTestArrowFn = async () => { await somethingAsync(); }', parserOptions }, | ||
], | ||
invalid: [ | ||
{ code: 'before(\'a test case\', async () => { cy.get(\'.someClass\'); })', parserOptions, errors }, | ||
{ code: 'beforeEach(\'a test case\', async () => { cy.get(\'.someClass\'); })', parserOptions, errors }, | ||
{ code: 'before(\'a test case\', async function () { cy.get(\'.someClass\'); })', parserOptions, errors }, | ||
{ code: 'beforeEach(\'a test case\', async function () { cy.get(\'.someClass\'); })', parserOptions, errors }, | ||
], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict' | ||
|
||
const rule = require('../../../lib/rules/no-async-tests') | ||
const RuleTester = require('eslint').RuleTester | ||
|
||
const ruleTester = new RuleTester() | ||
|
||
const errors = [{ messageId: 'unexpected' }] | ||
// async functions are an ES2017 feature | ||
const parserOptions = { ecmaVersion: 8 } | ||
|
||
ruleTester.run('no-async-tests', rule, { | ||
valid: [ | ||
{ code: 'it(\'a test case\', () => { cy.get(\'.someClass\'); })', parserOptions }, | ||
{ code: 'it(\'a test case\', async () => { await somethingAsync(); })', parserOptions }, | ||
{ code: 'async function nonTestFn () { return await somethingAsync(); }', parserOptions }, | ||
{ code: 'const nonTestArrowFn = async () => { await somethingAsync(); }', parserOptions }, | ||
], | ||
invalid: [ | ||
{ code: 'it(\'a test case\', async () => { cy.get(\'.someClass\'); })', parserOptions, errors }, | ||
{ code: 'test(\'a test case\', async () => { cy.get(\'.someClass\'); })', parserOptions, errors }, | ||
{ code: 'it(\'a test case\', async function () { cy.get(\'.someClass\'); })', parserOptions, errors }, | ||
{ code: 'test(\'a test case\', async function () { cy.get(\'.someClass\'); })', parserOptions, errors }, | ||
], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict' | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
const rule = require('../../../lib/rules/no-force') | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
|
||
const errors = [{ messageId: 'unexpected' }] | ||
const parserOptions = { ecmaVersion: 2018 } | ||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
let ruleTester = new RuleTester() | ||
|
||
ruleTester.run('no-force', rule, { | ||
|
||
valid: [ | ||
{ code: `cy.get('button').click()`, parserOptions }, | ||
{ code: `cy.get('button').click({multiple: true})`, parserOptions }, | ||
{ code: `cy.get('button').dblclick()`, parserOptions }, | ||
{ code: `cy.get('input').type('somth')`, parserOptions }, | ||
{ code: `cy.get('input').type('somth', {anyoption: true})`, parserOptions }, | ||
{ code: `cy.get('input').trigger('click', {anyoption: true})`, parserOptions }, | ||
{ code: `cy.get('input').rightclick({anyoption: true})`, parserOptions }, | ||
{ code: `cy.get('input').check()`, parserOptions }, | ||
{ code: `cy.get('input').select()`, parserOptions }, | ||
{ code: `cy.get('input').focus()`, parserOptions }, | ||
{ code: `cy.document().trigger("keydown", { ...event })`, parserOptions }, | ||
], | ||
|
||
invalid: [ | ||
{ code: `cy.get('button').click({force: true})`, parserOptions, errors }, | ||
{ code: `cy.get('button').dblclick({force: true})`, parserOptions, errors }, | ||
{ code: `cy.get('input').type('somth', {force: true})`, parserOptions, errors }, | ||
{ code: `cy.get('div').find('.foo').type('somth', {force: true})`, parserOptions, errors }, | ||
{ code: `cy.get('div').find('.foo').find('.bar').click({force: true})`, parserOptions, errors }, | ||
{ code: `cy.get('div').find('.foo').find('.bar').trigger('change', {force: true})`, parserOptions, errors }, | ||
{ code: `cy.get('input').trigger('click', {force: true})`, parserOptions, errors }, | ||
{ code: `cy.get('input').rightclick({force: true})`, parserOptions, errors }, | ||
{ code: `cy.get('input').check({force: true})`, parserOptions, errors }, | ||
{ code: `cy.get('input').select({force: true})`, parserOptions, errors }, | ||
{ code: `cy.get('input').focus({force: true})`, parserOptions, errors }, | ||
], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict' | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
const rule = require('../../../lib/rules/no-pause') | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
|
||
const errors = [{ messageId: 'unexpected' }] | ||
const parserOptions = { ecmaVersion: 2018 } | ||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
const ruleTester = new RuleTester() | ||
|
||
ruleTester.run('no-pause', rule, { | ||
|
||
valid: [ | ||
{ code: `pause()`, parserOptions }, | ||
{ code: `cy.get('button').dblclick()`, parserOptions }, | ||
], | ||
|
||
invalid: [ | ||
{ code: `cy.pause()`, parserOptions, errors }, | ||
{ code: `cy.pause({ log: false })`, parserOptions, errors }, | ||
{ code: `cy.get('button').pause()`, parserOptions, errors }, | ||
{ | ||
code: `cy.get('a').should('have.attr', 'href').and('match', /dashboard/).pause()`, | ||
parserOptions, | ||
errors | ||
} | ||
], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
'use strict' | ||
|
||
const rule = require('../../../lib/rules/no-unnecessary-waiting') | ||
const RuleTester = require('eslint').RuleTester | ||
|
||
const ruleTester = new RuleTester() | ||
|
||
const errors = [{ messageId: 'unexpected' }] | ||
const parserOptions = { ecmaVersion: 6, sourceType: 'module' } | ||
|
||
ruleTester.run('no-unnecessary-waiting', rule, { | ||
valid: [ | ||
{ code: 'foo.wait(10)', parserOptions }, | ||
|
||
{ code: 'cy.wait("@someRequest")', parserOptions }, | ||
{ code: 'cy.wait("@someRequest", { log: false })', parserOptions }, | ||
{ code: 'cy.wait("@someRequest").then((xhr) => xhr)', parserOptions }, | ||
{ code: 'cy.wait(["@someRequest", "@anotherRequest"])', parserOptions }, | ||
|
||
{ code: 'cy.clock(5000)', parserOptions }, | ||
{ code: 'cy.scrollTo(0, 10)', parserOptions }, | ||
{ code: 'cy.tick(500)', parserOptions }, | ||
|
||
{ code: 'const someRequest="@someRequest"; cy.wait(someRequest)', parserOptions, errors }, | ||
{ code: 'function customWait (alias = "@someRequest") { cy.wait(alias) }', parserOptions, errors }, | ||
{ code: 'const customWait = (alias = "@someRequest") => { cy.wait(alias) }', parserOptions, errors }, | ||
{ code: 'function customWait (ms) { cy.wait(ms) }', parserOptions, errors }, | ||
{ code: 'const customWait = (ms) => { cy.wait(ms) }', parserOptions, errors }, | ||
|
||
{ code: 'import BAR_BAZ from "bar-baz"; cy.wait(BAR_BAZ)', parserOptions }, | ||
{ code: 'import { FOO_BAR } from "foo-bar"; cy.wait(FOO_BAR)', parserOptions }, | ||
{ code: 'import * as wildcard from "wildcard"; cy.wait(wildcard.value)', parserOptions }, | ||
{ code: 'import { NAME as OTHER_NAME } from "rename"; cy.wait(OTHER_NAME)', parserOptions }, | ||
|
||
// disable the eslint rule | ||
{ | ||
code: ` | ||
cy.wait(100); // eslint-disable-line no-unnecessary-waiting | ||
`, | ||
parserOptions, | ||
}, | ||
{ | ||
code: ` | ||
/* eslint-disable-next-line no-unnecessary-waiting */ | ||
cy.wait(100) | ||
`, | ||
parserOptions, | ||
}, | ||
{ | ||
code: ` | ||
/* eslint-disable no-unnecessary-waiting */ | ||
cy.wait(100) | ||
/* eslint-enable no-unnecessary-waiting */ | ||
`, | ||
parserOptions, | ||
}, | ||
], | ||
|
||
invalid: [ | ||
{ code: 'cy.wait(0)', parserOptions, errors }, | ||
{ code: 'cy.wait(100)', parserOptions, errors }, | ||
{ code: 'cy.wait(5000)', parserOptions, errors }, | ||
{ code: 'const someNumber=500; cy.wait(someNumber)', parserOptions, errors }, | ||
{ code: 'function customWait (ms = 1) { cy.wait(ms) }', parserOptions, errors }, | ||
{ code: 'const customWait = (ms = 1) => { cy.wait(ms) }', parserOptions, errors }, | ||
|
||
{ code: 'cy.get(".some-element").wait(10)', parserOptions, errors }, | ||
{ code: 'cy.get(".some-element").contains("foo").wait(10)', parserOptions, errors }, | ||
{ code: 'const customWait = (ms = 1) => { cy.get(".some-element").wait(ms) }', parserOptions, errors }, | ||
], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict' | ||
|
||
const rule = require('../../../lib/rules/require-data-selectors') | ||
const RuleTester = require('eslint').RuleTester | ||
|
||
const ruleTester = new RuleTester() | ||
|
||
const errors = [{ messageId: 'unexpected' }] | ||
const parserOptions = { ecmaVersion: 6 } | ||
|
||
ruleTester.run('require-data-selectors', rule, { | ||
valid: [ | ||
{ code: 'cy.get(\'[data-cy=submit]\').click()', parserOptions }, | ||
{ code: 'cy.get(\'[data-QA=submit]\')', parserOptions }, | ||
{ code: 'cy.clock(5000)', parserOptions }, | ||
{ code: 'cy.scrollTo(0, 10)', parserOptions }, | ||
{ code: 'cy.tick(500)', parserOptions }, | ||
{ code: 'cy.get(\`[data-cy=${1}]\`)', parserOptions }, // eslint-disable-line no-useless-escape | ||
{ code: 'cy.get("@my-alias")', parserOptions, errors }, | ||
{ code: 'cy.get(`@my-alias`)', parserOptions, errors }, | ||
], | ||
|
||
invalid: [ | ||
{ code: 'cy.get(\'[daedta-cy=submit]\').click()', parserOptions, errors }, | ||
{ code: 'cy.get(\'[d-cy=submit]\')', parserOptions, errors }, | ||
{ code: 'cy.get(".btn-large").click()', parserOptions, errors }, | ||
{ code: 'cy.get(".btn-.large").click()', parserOptions, errors }, | ||
{ code: 'cy.get(".a")', parserOptions, errors }, | ||
{ code: 'cy.get(\`[daedta-cy=${1}]\`)', parserOptions, errors }, // eslint-disable-line no-useless-escape | ||
], | ||
}) |
Oops, something went wrong.