From 013dd060a557fd6d28b933ed1c3c53f9f3f1c069 Mon Sep 17 00:00:00 2001 From: Mike McCready <66998419+MikeMcC399@users.noreply.github.com> Date: Wed, 26 Feb 2025 14:19:49 +0100 Subject: [PATCH] chore: extend linting to cypress examples (#1373) * chore: add examples linting * remove unused setupnodeevents or parameters * selective disable cypress/no-unnecessary-waiting --- eslint.config.mjs | 9 +++++-- examples/basic-pnpm/cypress.config.js | 1 - examples/basic/cypress.config.js | 1 - examples/browser/cypress.config.js | 2 +- examples/config/cypress.config-alternate.js | 2 +- examples/config/cypress.config.js | 1 - examples/custom-command/cypress.config.js | 1 - examples/install-command/cypress.config.js | 1 - examples/install-only/cypress.config.js | 1 - examples/node-versions/cypress.config.js | 1 - examples/quiet/cypress.config.js | 2 +- examples/recording/cypress.config.js | 1 - examples/recording/cypress/e2e/spec-a.cy.js | 1 + examples/recording/cypress/e2e/spec-b.cy.js | 1 + examples/recording/cypress/e2e/spec-c.cy.js | 1 + examples/recording/cypress/e2e/spec-d.cy.js | 1 + .../packages/workspace-1/cypress.config.js | 1 - .../packages/workspace-2/cypress.config.js | 1 - .../workspace-1/cypress.config.js | 1 - .../workspace-2/cypress.config.js | 1 - examples/start/cypress.config.js | 1 - examples/wait-on-vite/cypress.config.js | 1 - examples/wait-on/cypress.config.js | 1 - examples/webpack/cypress.config.js | 1 - examples/yarn-classic/cypress.config.js | 1 - examples/yarn-modern-pnp/cypress.config.js | 1 - examples/yarn-modern/cypress.config.js | 1 - package-lock.json | 27 +++++++++++++++++++ package.json | 1 + 29 files changed, 42 insertions(+), 24 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 6f48164b4..1de26e1ac 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,11 +1,16 @@ import globals from 'globals' import pluginJs from '@eslint/js' +import pluginCypress from 'eslint-plugin-cypress/flat' export default [ pluginJs.configs.recommended, - { name: 'global-ignores', ignores: ['dist/', 'examples/'] }, + pluginCypress.configs.recommended, { - name: `all-js`, + name: 'global-ignores', + ignores: ['dist/', 'examples/nextjs/src/app/'] + }, + { + name: 'all-js', languageOptions: { globals: { ...globals.browser, diff --git a/examples/basic-pnpm/cypress.config.js b/examples/basic-pnpm/cypress.config.js index ec2107cb1..4415f5033 100644 --- a/examples/basic-pnpm/cypress.config.js +++ b/examples/basic-pnpm/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, }, }) diff --git a/examples/basic/cypress.config.js b/examples/basic/cypress.config.js index ec2107cb1..4415f5033 100644 --- a/examples/basic/cypress.config.js +++ b/examples/basic/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, }, }) diff --git a/examples/browser/cypress.config.js b/examples/browser/cypress.config.js index 7779a82b3..489af0fcd 100644 --- a/examples/browser/cypress.config.js +++ b/examples/browser/cypress.config.js @@ -4,7 +4,7 @@ const os = require('os') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) { + setupNodeEvents(on) { on('before:browser:launch', (browser, launchOptions) => { console.log('before launching browser') console.log(browser) diff --git a/examples/config/cypress.config-alternate.js b/examples/config/cypress.config-alternate.js index ef2ccc5b0..8d60d0ecf 100644 --- a/examples/config/cypress.config-alternate.js +++ b/examples/config/cypress.config-alternate.js @@ -4,7 +4,7 @@ module.exports = defineConfig({ fixturesFolder: false, e2e: { baseUrl: 'http://localhost:3333', - setupNodeEvents(on, config) { + setupNodeEvents() { console.log('\nUsing cypress.config-alternate.js config-file') }, supportFile: false diff --git a/examples/config/cypress.config.js b/examples/config/cypress.config.js index ec2107cb1..4415f5033 100644 --- a/examples/config/cypress.config.js +++ b/examples/config/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, }, }) diff --git a/examples/custom-command/cypress.config.js b/examples/custom-command/cypress.config.js index ec2107cb1..4415f5033 100644 --- a/examples/custom-command/cypress.config.js +++ b/examples/custom-command/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, }, }) diff --git a/examples/install-command/cypress.config.js b/examples/install-command/cypress.config.js index 895c686b6..f12244d8f 100644 --- a/examples/install-command/cypress.config.js +++ b/examples/install-command/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, baseUrl: 'https://example.cypress.io/', }, diff --git a/examples/install-only/cypress.config.js b/examples/install-only/cypress.config.js index 895c686b6..f12244d8f 100644 --- a/examples/install-only/cypress.config.js +++ b/examples/install-only/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, baseUrl: 'https://example.cypress.io/', }, diff --git a/examples/node-versions/cypress.config.js b/examples/node-versions/cypress.config.js index ec2107cb1..4415f5033 100644 --- a/examples/node-versions/cypress.config.js +++ b/examples/node-versions/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, }, }) diff --git a/examples/quiet/cypress.config.js b/examples/quiet/cypress.config.js index d771b3a8c..1edefb61c 100644 --- a/examples/quiet/cypress.config.js +++ b/examples/quiet/cypress.config.js @@ -3,7 +3,7 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) { + setupNodeEvents(on) { on('task', { log(message) { console.log(message) diff --git a/examples/recording/cypress.config.js b/examples/recording/cypress.config.js index dc402aa0a..01f7f05c5 100644 --- a/examples/recording/cypress.config.js +++ b/examples/recording/cypress.config.js @@ -4,7 +4,6 @@ module.exports = defineConfig({ fixturesFolder: false, projectId: '3tb7jn', e2e: { - setupNodeEvents(on, config) {}, supportFile: false, }, }) diff --git a/examples/recording/cypress/e2e/spec-a.cy.js b/examples/recording/cypress/e2e/spec-a.cy.js index 48ac31856..5ccd89b0c 100644 --- a/examples/recording/cypress/e2e/spec-a.cy.js +++ b/examples/recording/cypress/e2e/spec-a.cy.js @@ -1,4 +1,5 @@ it('spec-A works', () => { expect(42).to.equal(21 + 21) + // eslint-disable-next-line cypress/no-unnecessary-waiting cy.visit('https://example.cypress.io').wait(2000) }) diff --git a/examples/recording/cypress/e2e/spec-b.cy.js b/examples/recording/cypress/e2e/spec-b.cy.js index 2e540892e..f57ff1fe3 100644 --- a/examples/recording/cypress/e2e/spec-b.cy.js +++ b/examples/recording/cypress/e2e/spec-b.cy.js @@ -1,4 +1,5 @@ it('spec-B works', () => { expect(42).to.equal(21 + 21) + // eslint-disable-next-line cypress/no-unnecessary-waiting cy.visit('https://example.cypress.io').wait(5000) }) diff --git a/examples/recording/cypress/e2e/spec-c.cy.js b/examples/recording/cypress/e2e/spec-c.cy.js index 31d2b670a..03ba9af46 100644 --- a/examples/recording/cypress/e2e/spec-c.cy.js +++ b/examples/recording/cypress/e2e/spec-c.cy.js @@ -1,4 +1,5 @@ it('spec-C works', () => { expect(42).to.equal(21 + 21) + // eslint-disable-next-line cypress/no-unnecessary-waiting cy.visit('https://example.cypress.io').wait(4000) }) diff --git a/examples/recording/cypress/e2e/spec-d.cy.js b/examples/recording/cypress/e2e/spec-d.cy.js index c8c1af21c..48041fe5e 100644 --- a/examples/recording/cypress/e2e/spec-d.cy.js +++ b/examples/recording/cypress/e2e/spec-d.cy.js @@ -1,4 +1,5 @@ it('spec-D works', () => { expect(42).to.equal(21 + 21) + // eslint-disable-next-line cypress/no-unnecessary-waiting cy.visit('https://example.cypress.io').wait(3600) }) diff --git a/examples/start-and-pnpm-workspaces/packages/workspace-1/cypress.config.js b/examples/start-and-pnpm-workspaces/packages/workspace-1/cypress.config.js index 147210eeb..b9801901e 100644 --- a/examples/start-and-pnpm-workspaces/packages/workspace-1/cypress.config.js +++ b/examples/start-and-pnpm-workspaces/packages/workspace-1/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, baseUrl: 'http://localhost:5000', }, diff --git a/examples/start-and-pnpm-workspaces/packages/workspace-2/cypress.config.js b/examples/start-and-pnpm-workspaces/packages/workspace-2/cypress.config.js index 147210eeb..b9801901e 100644 --- a/examples/start-and-pnpm-workspaces/packages/workspace-2/cypress.config.js +++ b/examples/start-and-pnpm-workspaces/packages/workspace-2/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, baseUrl: 'http://localhost:5000', }, diff --git a/examples/start-and-yarn-workspaces/workspace-1/cypress.config.js b/examples/start-and-yarn-workspaces/workspace-1/cypress.config.js index 147210eeb..b9801901e 100644 --- a/examples/start-and-yarn-workspaces/workspace-1/cypress.config.js +++ b/examples/start-and-yarn-workspaces/workspace-1/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, baseUrl: 'http://localhost:5000', }, diff --git a/examples/start-and-yarn-workspaces/workspace-2/cypress.config.js b/examples/start-and-yarn-workspaces/workspace-2/cypress.config.js index 147210eeb..b9801901e 100644 --- a/examples/start-and-yarn-workspaces/workspace-2/cypress.config.js +++ b/examples/start-and-yarn-workspaces/workspace-2/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, baseUrl: 'http://localhost:5000', }, diff --git a/examples/start/cypress.config.js b/examples/start/cypress.config.js index f8d5dd4bd..b518679b7 100644 --- a/examples/start/cypress.config.js +++ b/examples/start/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, baseUrl: 'http://localhost:3000', }, diff --git a/examples/wait-on-vite/cypress.config.js b/examples/wait-on-vite/cypress.config.js index 5ac655721..a858e6176 100644 --- a/examples/wait-on-vite/cypress.config.js +++ b/examples/wait-on-vite/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, baseUrl: 'http://localhost:5173', }, diff --git a/examples/wait-on/cypress.config.js b/examples/wait-on/cypress.config.js index 8396d026a..3c56c67a7 100644 --- a/examples/wait-on/cypress.config.js +++ b/examples/wait-on/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, baseUrl: 'http://localhost:3050', }, diff --git a/examples/webpack/cypress.config.js b/examples/webpack/cypress.config.js index bb85bb8a2..b8ee5eb94 100644 --- a/examples/webpack/cypress.config.js +++ b/examples/webpack/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, baseUrl: 'http://localhost:8080', }, diff --git a/examples/yarn-classic/cypress.config.js b/examples/yarn-classic/cypress.config.js index 895c686b6..f12244d8f 100644 --- a/examples/yarn-classic/cypress.config.js +++ b/examples/yarn-classic/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, baseUrl: 'https://example.cypress.io/', }, diff --git a/examples/yarn-modern-pnp/cypress.config.js b/examples/yarn-modern-pnp/cypress.config.js index 895c686b6..f12244d8f 100644 --- a/examples/yarn-modern-pnp/cypress.config.js +++ b/examples/yarn-modern-pnp/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, baseUrl: 'https://example.cypress.io/', }, diff --git a/examples/yarn-modern/cypress.config.js b/examples/yarn-modern/cypress.config.js index 895c686b6..f12244d8f 100644 --- a/examples/yarn-modern/cypress.config.js +++ b/examples/yarn-modern/cypress.config.js @@ -3,7 +3,6 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ fixturesFolder: false, e2e: { - setupNodeEvents(on, config) {}, supportFile: false, baseUrl: 'https://example.cypress.io/', }, diff --git a/package-lock.json b/package-lock.json index d757f974b..aacf57748 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ "@types/node": "22.13.5", "@vercel/ncc": "0.38.1", "eslint": "9.21.0", + "eslint-plugin-cypress": "4.1.0", "globals": "16.0.0", "husky": "9.1.7", "markdown-link-check": "3.13.6", @@ -1676,6 +1677,32 @@ } } }, + "node_modules/eslint-plugin-cypress": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-cypress/-/eslint-plugin-cypress-4.1.0.tgz", + "integrity": "sha512-JhqkMY02mw74USwK9OFhectx3YSj6Co1NgWBxlGdKvlqiAp9vdEuQqt33DKGQFvvGS/NWtduuhWXWNnU29xDSg==", + "dev": true, + "license": "MIT", + "dependencies": { + "globals": "^15.11.0" + }, + "peerDependencies": { + "eslint": ">=9" + } + }, + "node_modules/eslint-plugin-cypress/node_modules/globals": { + "version": "15.15.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.15.0.tgz", + "integrity": "sha512-7ACyT3wmyp3I61S4fG682L0VA2RGD9otkqGJIwNUMF1SWUombIIk+af1unuDYgMm082aHYwD+mzJvv9Iu8dsgg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/eslint-scope": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.2.0.tgz", diff --git a/package.json b/package.json index 787aa084a..c46b70c5b 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "@types/node": "22.13.5", "@vercel/ncc": "0.38.1", "eslint": "9.21.0", + "eslint-plugin-cypress": "4.1.0", "globals": "16.0.0", "husky": "9.1.7", "markdown-link-check": "3.13.6",