From dfe9205bf6ec3fa9d85b30ae66cd98ef36960316 Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 8 Apr 2025 22:20:41 +0200 Subject: [PATCH] refactor(other): cleanup cypress configuration (#8345) * cypress:remove redundant comment from command config * cypress: move command and factory imports from global to local * cypress: linting * cypress: set support file to false in config --- cypress/cypress.config.js | 2 +- cypress/support/commands.js | 13 -------- cypress/support/e2e.js | 33 ------------------- .../somebody_reported_the_following_posts.js | 6 ++-- .../common/I_am_logged_in_as_{string}.js | 6 ++-- ..._following_{string}_are_in_the_database.js | 25 +++++++------- .../common/{string}_wrote_a_post_{string}.js | 5 +-- 7 files changed, 24 insertions(+), 66 deletions(-) delete mode 100644 cypress/support/e2e.js diff --git a/cypress/cypress.config.js b/cypress/cypress.config.js index d08749370..52a765bf0 100644 --- a/cypress/cypress.config.js +++ b/cypress/cypress.config.js @@ -44,7 +44,7 @@ module.exports = defineConfig({ chromeWebSecurity: false, baseUrl: 'http://localhost:3000', specPattern: '**/*.feature', - supportFile: 'cypress/support/e2e.js', + supportFile: false, retries: 0, video: false, viewportHeight: 720, diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 92e8bf1f7..f75fe9b6b 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -53,16 +53,3 @@ Cypress.Commands.add( }) }) - -// -// -// -- This is a child command -- -// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) -// -// -// -- This is a dual command -- -// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) -// -// -// -- This is will overwrite an existing command -- -// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js deleted file mode 100644 index 453c8476f..000000000 --- a/cypress/support/e2e.js +++ /dev/null @@ -1,33 +0,0 @@ -// *********************************************************** -// This example support/index.js is processed and -// loaded automatically before your test files. -// -// This is a great place to put global configuration and -// behavior that modifies Cypress. -// -// You can change the location of this file or turn off -// automatically serving support files with the -// 'supportFile' configuration option. -// -// You can read more here: -// https://on.cypress.io/configuration -// *********************************************************** - -// Import commands.js using ES2015 syntax: - -import './commands' -import './factories' - -// intermittent failing tests -// import 'cypress-plugin-retries' - -// Alternatively you can use CommonJS syntax: -// require('./commands') -import { WebSocket } from 'mock-socket' -before(() => { - cy.visit('/', { - onBeforeLoad(win) { - cy.stub(win, "WebSocket", url => new WebSocket(url)) - } - }) -}) diff --git a/cypress/support/step_definitions/Moderation.ReportContent/somebody_reported_the_following_posts.js b/cypress/support/step_definitions/Moderation.ReportContent/somebody_reported_the_following_posts.js index 38cdbee09..e924acdeb 100644 --- a/cypress/support/step_definitions/Moderation.ReportContent/somebody_reported_the_following_posts.js +++ b/cypress/support/step_definitions/Moderation.ReportContent/somebody_reported_the_following_posts.js @@ -1,5 +1,7 @@ -import { Given } from "@badeball/cypress-cucumber-preprocessor"; -import 'cypress-network-idle'; +import { Given } from '@badeball/cypress-cucumber-preprocessor' +import './../../commands' +import './../../factories' +import 'cypress-network-idle' Given('somebody reported the following posts:', table => { const reportIdRegex = /^[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}$/ diff --git a/cypress/support/step_definitions/common/I_am_logged_in_as_{string}.js b/cypress/support/step_definitions/common/I_am_logged_in_as_{string}.js index 1dbaa3d94..833a21c6a 100644 --- a/cypress/support/step_definitions/common/I_am_logged_in_as_{string}.js +++ b/cypress/support/step_definitions/common/I_am_logged_in_as_{string}.js @@ -1,9 +1,9 @@ -import { Given } from "@badeball/cypress-cucumber-preprocessor"; +import { Given } from '@badeball/cypress-cucumber-preprocessor' import encode from '../../../../backend/build/src/jwt/encode' -Given("I am logged in as {string}", slug => { +Given('I am logged in as {string}', slug => { cy.neode() - .firstOf("User", { slug }) + .firstOf('User', { slug }) .then(user => { return new Cypress.Promise((resolve, reject) => { if(!user) { diff --git a/cypress/support/step_definitions/common/the_following_{string}_are_in_the_database.js b/cypress/support/step_definitions/common/the_following_{string}_are_in_the_database.js index 8e41afa2a..066b5ef3d 100644 --- a/cypress/support/step_definitions/common/the_following_{string}_are_in_the_database.js +++ b/cypress/support/step_definitions/common/the_following_{string}_are_in_the_database.js @@ -1,10 +1,11 @@ -import { Given } from "@badeball/cypress-cucumber-preprocessor"; +import { Given } from '@badeball/cypress-cucumber-preprocessor' +import './../../factories' -Given("the following {string} are in the database:", (table,data) => { +Given('the following {string} are in the database:', (table,data) => { switch(table){ - case "posts": + case 'posts': data.hashes().forEach( entry => { - cy.factory().build("post", { + cy.factory().build('post', { ...entry, deleted: Boolean(entry.deleted), disabled: Boolean(entry.disabled), @@ -15,25 +16,25 @@ Given("the following {string} are in the database:", (table,data) => { }); }) break - case "comments": + case 'comments': data.hashes().forEach( entry => { cy.factory() - .build("comment", entry, entry); + .build('comment', entry, entry); }) break - case "users": + case 'users': data.hashes().forEach( entry => { - cy.factory().build("user", entry, entry); + cy.factory().build('user', entry, entry); }); break - case "tags": + case 'tags': data.hashes().forEach( entry => { - cy.factory().build("tag", entry, entry) + cy.factory().build('tag', entry, entry) }); break - case "donations": + case 'donations': data.hashes().forEach( entry => { - cy.factory().build("donations", entry, entry) + cy.factory().build('donations', entry, entry) }); break } diff --git a/cypress/support/step_definitions/common/{string}_wrote_a_post_{string}.js b/cypress/support/step_definitions/common/{string}_wrote_a_post_{string}.js index 0da055951..086432b30 100644 --- a/cypress/support/step_definitions/common/{string}_wrote_a_post_{string}.js +++ b/cypress/support/step_definitions/common/{string}_wrote_a_post_{string}.js @@ -1,8 +1,9 @@ -import { Given } from "@badeball/cypress-cucumber-preprocessor"; +import { Given } from '@badeball/cypress-cucumber-preprocessor' +import './../../factories' Given('{string} wrote a post {string}', (author, title) => { cy.factory() - .build("post", { + .build('post', { title, }, { authorId: author,