From e4c36d1d1bf44491ffa5b658a2fc10dae93b0aac Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
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.
---
 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} (59%)

diff --git a/cypress.config.ts b/cypress.config.ts
new file mode 100644
index 00000000000..d6814be6e21
--- /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 e7b86b17d20..00000000000
--- 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 1a4d20e98ec..5ae1686b26e 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 60bea1fcb6c..00000000000
--- 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 59%
rename from t/cypress/support/index.js
rename to t/cypress/support/e2e.js
index 5ced7d5f029..d33e66ddfba 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) => { ... })
+
+function get_fallback_login_value(param) {
 
-// Import commands.js using ES2015 syntax:
-import './commands';
+    var env_var = param == 'username' ? 'KOHA_USER' : 'KOHA_PASS';
 
-// Alternatively you can use CommonJS syntax:
-// require('./commands')
+    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()
+})
 
 cy.get_title = () => {
     return {
@@ -86,4 +107,4 @@ cy.get_agreements_to_relate = () => {
             name: "fourth agreement name"
         },
     ]
-}
\ No newline at end of file
+}
-- 
2.25.1