From 4f45300d91bcedffd3981d7116c3d9ab47180460 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 20 Jul 2023 11:53:19 +0200 Subject: [PATCH] Bug 34319: Upgrade cypress 9.7.0 to 12.17.2 We are currently using 9.7.0. Since 10 the config file structure changed, and has been renamed cypress.json to cypress.config.ts https://docs.cypress.io/guides/references/migration-guide#Migrating-to-Cypress-version-10-0 Also cypress-studio (used for bug 34076) is not working on 9.7.0. Test plan: yarn install yarn build mv /root/.cache/Cypress/12.17.2/ /kohadevbox/Cypress/ perl /kohadevbox/misc4dev/run_tests.pl --run-cypress-tests-only You should not get any failures from the tests. Signed-off-by: Matt Blenkinsop Signed-off-by: Tomas Cohen Arazi --- cypress.config.ts | 22 +++++++++++ cypress.json | 11 ------ package.json | 2 +- t/cypress/support/commands.js | 41 -------------------- t/cypress/support/{index.js => e2e.js} | 53 ++++++++++++++++++-------- 5 files changed, 60 insertions(+), 69 deletions(-) create mode 100644 cypress.config.ts delete mode 100644 cypress.json delete mode 100644 t/cypress/support/commands.js rename t/cypress/support/{index.js => e2e.js} (61%) diff --git a/cypress.config.ts b/cypress.config.ts new file mode 100644 index 0000000000..d6814be6e2 --- /dev/null +++ b/cypress.config.ts @@ -0,0 +1,22 @@ +import { defineConfig } from "cypress"; + +export default defineConfig({ + fixturesFolder: "t/cypress/fixtures", + screenshotsFolder: "t/cypress/screenshots", + videosFolder: "t/cypress/videos", + defaultCommandTimeout: 10000, + + e2e: { + experimentalStudio: true, + baseUrl: "http://localhost:8081", + specPattern: "t/cypress/integration/**/*.*", + supportFile: "t/cypress/support/e2e.js", + }, + + component: { + devServer: { + framework: "vue-cli", + bundler: "webpack", + }, + }, +}); diff --git a/cypress.json b/cypress.json deleted file mode 100644 index e7b86b17d2..0000000000 --- a/cypress.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "baseUrl": "http://kohadev-intra.mydnsname.org:8081", - "fixturesFolder": "t/cypress/fixtures", - "integrationFolder": "t/cypress/integration", - "pluginsFile": "t/cypress/plugins", - "screenshotsFolder": "t/cypress/screenshots", - "supportFile": "t/cypress/support", - "videosFolder": "t/cypress/videos", - "testFiles": "**/*.*", - "defaultCommandTimeout": 10000 -} diff --git a/package.json b/package.json index 1a4d20e98e..5ae1686b26 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "babel-core": "^7.0.0-beta.3", "bootstrap": "^4.5.2", "css-loader": "^6.6.0", - "cypress": "^9.5.2", + "cypress": "^12.17.2", "datatables.net-buttons": "^2.3.4", "datatables.net-vue3": "^2.0.0", "gulp": "^4.0.2", diff --git a/t/cypress/support/commands.js b/t/cypress/support/commands.js deleted file mode 100644 index 60bea1fcb6..0000000000 --- a/t/cypress/support/commands.js +++ /dev/null @@ -1,41 +0,0 @@ -// *********************************************** -// This example commands.js shows you how to -// create various custom commands and overwrite -// existing commands. -// -// For more comprehensive examples of custom -// commands please read more here: -// https://on.cypress.io/custom-commands -// *********************************************** -// -// -// -- This is a parent command -- -// Cypress.Commands.add('login', (email, password) => { ... }) -// -// -// -- 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 will overwrite an existing command -- -// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) - -function get_fallback_login_value(param) { - - var env_var = param == 'username' ? 'KOHA_USER' : 'KOHA_PASS'; - - return typeof Cypress.env(env_var) === 'undefined' ? 'koha' : Cypress.env(env_var); -} - -Cypress.Commands.add('login', (username, password) => { - var user = typeof username === 'undefined' ? get_fallback_login_value('username') : username; - var pass = typeof password === 'undefined' ? get_fallback_login_value('password') : password; - cy.visit('/cgi-bin/koha/mainpage.pl?logout.x=1') - cy.get("#userid").type(user) - cy.get("#password").type(pass) - cy.get("#submit-button").click() -}) diff --git a/t/cypress/support/index.js b/t/cypress/support/e2e.js similarity index 61% rename from t/cypress/support/index.js rename to t/cypress/support/e2e.js index 4040e00547..afb2dfd49d 100644 --- a/t/cypress/support/index.js +++ b/t/cypress/support/e2e.js @@ -1,23 +1,44 @@ -// *********************************************************** -// This example support/index.js is processed and -// loaded automatically before your test files. +// *********************************************** +// This example commands.js shows you how to +// create various custom commands and overwrite +// existing commands. // -// This is a great place to put global configuration and -// behavior that modifies Cypress. +// For more comprehensive examples of custom +// commands please read more here: +// https://on.cypress.io/custom-commands +// *********************************************** // -// 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 -// *********************************************************** +// -- This is a parent command -- +// Cypress.Commands.add('login', (email, password) => { ... }) +// +// +// -- 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 will overwrite an existing command -- +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) -// Import commands.js using ES2015 syntax: -import './commands'; +function get_fallback_login_value(param) { -// Alternatively you can use CommonJS syntax: -// require('./commands') + var env_var = param == 'username' ? 'KOHA_USER' : 'KOHA_PASS'; + + return typeof Cypress.env(env_var) === 'undefined' ? 'koha' : Cypress.env(env_var); +} + +Cypress.Commands.add('login', (username, password) => { + var user = typeof username === 'undefined' ? get_fallback_login_value('username') : username; + var pass = typeof password === 'undefined' ? get_fallback_login_value('password') : password; + cy.visit('/cgi-bin/koha/mainpage.pl?logout.x=1') + cy.get("#userid").type(user) + cy.get("#password").type(pass) + cy.get("#submit-button").click() +}) Cypress.Commands.add('left_menu_active_item_is', (label) => { cy.get("#navmenulist a.current:not(.disabled)").should('have.length',1).contains(label); @@ -90,4 +111,4 @@ cy.get_agreements_to_relate = () => { name: "fourth agreement name" }, ] -} \ No newline at end of file +} -- 2.39.5