Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate to RuleTester v9 #207

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ workflows:
- lint
- test-v7
- test-v8
- test-v9
- release:
requires:
- lint
- test-v7
- test-v8
- test-v9
filters:
branches:
only:
Expand Down Expand Up @@ -72,6 +74,24 @@ jobs:
name: Test ESLint 8
command: npm run test:legacy

test-v9:
docker:
- image: cimg/node:20.12.2
steps:
- checkout
- run:
name: Install dependencies
command: npm ci
- run:
name: Install ESLint 9
command: npm install eslint@9
- run:
name: Show ESLint version
command: npx eslint --version
- run:
name: Test ESLint 9
command: npm test

release:
docker:
- image: cimg/node:20.12.2
Expand Down
37 changes: 18 additions & 19 deletions tests/lib/rules/assertion-before-screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,29 @@ 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 },
{ code: 'cy.get(".some-element"); cy.screenshot();' },
{ code: 'cy.get(".some-element").should("exist").screenshot();' },
{ code: 'cy.get(".some-element").should("exist").screenshot().click()' },
{ code: 'cy.get(".some-element").should("exist"); if(true) cy.screenshot();' },
{ code: 'if(true) { cy.get(".some-element").should("exist"); cy.screenshot(); }' },
{ code: 'cy.get(".some-element").should("exist"); if(true) { cy.screenshot(); }' },
{ code: 'const a = () => { cy.get(".some-element").should("exist"); cy.screenshot(); }' },
{ code: 'cy.get(".some-element").should("exist").and("be.visible"); cy.screenshot();' },
{ code: 'cy.get(".some-element").contains("Text"); cy.screenshot();' },
],

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 },
{ code: 'cy.screenshot()', errors },
{ code: 'cy.visit("somepage"); cy.screenshot();', errors },
{ code: 'cy.custom(); cy.screenshot()', errors },
{ code: 'cy.get(".some-element").click(); cy.screenshot()', errors },
{ code: 'cy.get(".some-element").click().screenshot()', errors },
{ code: 'if(true) { cy.get(".some-element").click(); cy.screenshot(); }', errors },
{ code: 'cy.get(".some-element").click(); if(true) { cy.screenshot(); }', errors },
{ code: 'cy.get(".some-element"); function a() { cy.screenshot(); }', errors },
{ code: 'cy.get(".some-element"); const a = () => { cy.screenshot(); }', errors },
],
})
39 changes: 19 additions & 20 deletions tests/lib/rules/no-assigning-return-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,32 @@ 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 },
{ code: 'var foo = true;' },
{ code: 'let foo = true;' },
{ code: 'const foo = true;' },
{ code: 'const foo = bar();' },
{ code: 'const foo = bar().baz();' },
{ code: 'const spy = cy.spy();' },
{ code: 'const spy = cy.spy().as();' },
{ code: 'const stub = cy.stub();' },
{ code: 'const result = cy.now();' },
{ code: 'const state = cy.state();' },
{ code: 'cy.get("foo");' },
{ code: 'cy.contains("foo").click();' },
],

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.get("foo")', errors },
{ code: 'const a = cy.get("foo")', errors },
{ code: 'var a = cy.get("foo")', 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")', errors },
{ code: 'let a = cy.window()', errors },
{ code: 'let a = cy.wait("@something")', errors },

{ code: 'let a = cy.contains("foo").click()', parserOptions, errors },
{ code: 'let a = cy.contains("foo").click()', errors },
],
})
18 changes: 8 additions & 10 deletions tests/lib/rules/no-async-before.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ 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 },
{ code: 'before(\'a before case\', () => { cy.get(\'.someClass\'); })' },
{ code: 'before(\'a before case\', async () => { await somethingAsync(); })' },
{ code: 'async function nonTestFn () { return await somethingAsync(); }' },
{ code: 'const nonTestArrowFn = async () => { await somethingAsync(); }' },
],
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 },
{ code: 'before(\'a test case\', async () => { cy.get(\'.someClass\'); })', errors },
{ code: 'beforeEach(\'a test case\', async () => { cy.get(\'.someClass\'); })', errors },
{ code: 'before(\'a test case\', async function () { cy.get(\'.someClass\'); })', errors },
{ code: 'beforeEach(\'a test case\', async function () { cy.get(\'.someClass\'); })', errors },
],
})
18 changes: 8 additions & 10 deletions tests/lib/rules/no-async-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ 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 },
{ code: 'it(\'a test case\', () => { cy.get(\'.someClass\'); })' },
{ code: 'it(\'a test case\', async () => { await somethingAsync(); })' },
{ code: 'async function nonTestFn () { return await somethingAsync(); }' },
{ code: 'const nonTestArrowFn = async () => { await somethingAsync(); }' },
],
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 },
{ code: 'it(\'a test case\', async () => { cy.get(\'.someClass\'); })', errors },
{ code: 'test(\'a test case\', async () => { cy.get(\'.someClass\'); })', errors },
{ code: 'it(\'a test case\', async function () { cy.get(\'.someClass\'); })', errors },
{ code: 'test(\'a test case\', async function () { cy.get(\'.someClass\'); })', errors },
],
})
58 changes: 24 additions & 34 deletions tests/lib/rules/no-force.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,39 @@
'use strict'

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const rule = require('../../../lib/rules/no-force')

const RuleTester = require('eslint').RuleTester

const errors = [{ messageId: 'unexpected' }]
const parserOptions = { ecmaVersion: 2018 }
const ruleTester = new RuleTester()

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

let ruleTester = new RuleTester()
const errors = [{ messageId: 'unexpected' }]

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 },
{ code: `cy.get('button').click()` },
{ code: `cy.get('button').click({multiple: true})` },
{ code: `cy.get('button').dblclick()` },
{ code: `cy.get('input').type('somth')` },
{ code: `cy.get('input').type('somth', {anyoption: true})` },
{ code: `cy.get('input').trigger('click', {anyoption: true})` },
{ code: `cy.get('input').rightclick({anyoption: true})` },
{ code: `cy.get('input').check()` },
{ code: `cy.get('input').select()` },
{ code: `cy.get('input').focus()` },
{ code: `cy.document().trigger("keydown", { ...event })` },
],

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 },
{ code: `cy.get('button').click({force: true})`, errors },
{ code: `cy.get('button').dblclick({force: true})`, errors },
{ code: `cy.get('input').type('somth', {force: true})`, errors },
{ code: `cy.get('div').find('.foo').type('somth', {force: true})`, errors },
{ code: `cy.get('div').find('.foo').find('.bar').click({force: true})`, errors },
{ code: `cy.get('div').find('.foo').find('.bar').trigger('change', {force: true})`, errors },
{ code: `cy.get('input').trigger('click', {force: true})`, errors },
{ code: `cy.get('input').rightclick({force: true})`, errors },
{ code: `cy.get('input').check({force: true})`, errors },
{ code: `cy.get('input').select({force: true})`, errors },
{ code: `cy.get('input').focus({force: true})`, errors },
],
})
32 changes: 9 additions & 23 deletions tests/lib/rules/no-pause.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
'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()

const errors = [{ messageId: 'unexpected' }]

ruleTester.run('no-pause', rule, {

valid: [
{ code: `pause()`, parserOptions },
{ code: `cy.get('button').dblclick()`, parserOptions },
{ code: `pause()` },
{ code: `cy.get('button').dblclick()` },
],

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
}
{ code: `cy.pause()`, errors },
{ code: `cy.pause({ log: false })`, errors },
{ code: `cy.get('button').pause()`, errors },
{ code: `cy.get('a').should('have.attr', 'href').and('match', /dashboard/).pause()`, errors }
],
})
Loading