diff --git a/cypress.config.js b/cypress.config.js deleted file mode 100644 index 6ffcfe33..00000000 --- a/cypress.config.js +++ /dev/null @@ -1,12 +0,0 @@ -// https://on.cypress.io/configuration -const { defineConfig } = require('cypress'); - -module.exports = defineConfig({ - e2e: { - baseUrl: 'http://localhost:8002', - specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}', - }, - video: !!process.env.RUNNER_DEBUG, // only record videos when running github action in debug mode - viewportHeight: 1080, - viewportWidth: 1920, -}); diff --git a/cypress.config.ts b/cypress.config.ts new file mode 100644 index 00000000..384c03c2 --- /dev/null +++ b/cypress.config.ts @@ -0,0 +1,21 @@ +import { defineConfig } from 'cypress'; + +export default defineConfig({ + e2e: { + baseUrl: 'http://localhost:8002', + specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}', + supportFile: 'cypress/support/commands.ts', + }, + // NOTE: Only record videos when running in debug mode + video: !!process.env.RUNNER_DEBUG, + viewportHeight: 1080, + viewportWidth: 1920, + expose: { + apiBasePath: '/pulp/api/v3/', + uiBasePath: '/ui/', + }, + env: { + username: 'admin', + password: 'admin', + }, +}); diff --git a/cypress.env.json b/cypress.env.json deleted file mode 100644 index f3e117e7..00000000 --- a/cypress.env.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "API_BASE_PATH": "/pulp/api/v3/", - "UI_BASE_PATH": "/ui/", - "username": "admin", - "password": "admin" -} diff --git a/cypress/e2e/smoke.js b/cypress/e2e/smoke.js index edeb1806..4a3ee5b1 100644 --- a/cypress/e2e/smoke.js +++ b/cypress/e2e/smoke.js @@ -13,8 +13,10 @@ describe('UI smoke tests', () => { cy.assertTitle('Login'); // fill in form manually, submit - cy.get('#pf-login-username-id').type(Cypress.env('username')); - cy.get('#pf-login-password-id').type(Cypress.env('password')); + cy.env(['username', 'password']).then(({ username, password }) => { + cy.get('#pf-login-username-id').type(username); + cy.get('#pf-login-password-id').type(password); + }); cy.contains('button', 'Log in').click(); // check on Status, logged in diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts new file mode 100644 index 00000000..7cdf118b --- /dev/null +++ b/cypress/support/commands.ts @@ -0,0 +1,42 @@ +declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace Cypress { + interface Chainable { + assertTitle(title: string): Chainable>; + ui(path?: string): Chainable; + login(username?: string, password?: string): Chainable; + } + } +} + +const ui = Cypress.expose('uiBasePath'); + +Cypress.Commands.add('assertTitle', (title) => { + return cy.contains('.pf-v5-c-title', title); +}); + +Cypress.Commands.add('ui', (path = '') => { + return cy.visit(ui + path); +}); + +Cypress.Commands.add('login', (username, password) => { + if (!username || !password) { + return cy.env(['username', 'password']).then(({ username, password }) => { + return cy.session(username, () => { + window.sessionStorage.credentials = JSON.stringify({ + username, + password, + }); + }); + }); + } + + return cy.session(username, () => { + window.sessionStorage.credentials = JSON.stringify({ + username, + password, + }); + }); +}); + +export {}; diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js deleted file mode 100644 index a4479bdf..00000000 --- a/cypress/support/e2e.js +++ /dev/null @@ -1,27 +0,0 @@ -// https://on.cypress.io/custom-commands - -// const api = Cypress.env('API_BASE_PATH'); -const ui = Cypress.env('UI_BASE_PATH'); - -Cypress.Commands.add('assertTitle', {}, (title) => { - cy.contains('.pf-v5-c-title', title); -}); - -Cypress.Commands.add('ui', {}, (path = '') => { - cy.visit(ui + path); -}); - -Cypress.Commands.add('login', {}, (username, password) => { - if (!username && !password) { - // default to admin - username = Cypress.env('username'); - password = Cypress.env('password'); - } - - cy.session(username, () => { - window.sessionStorage.credentials = JSON.stringify({ - username, - password, - }); - }); -}); diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json new file mode 100644 index 00000000..0ac5b21b --- /dev/null +++ b/cypress/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "target": "es2024", + "lib": ["ES2024", "DOM"], + "sourceMap": true, + "types": ["cypress", "node"] + }, + "include": ["**/*.ts", "support/e2e.js"] +} diff --git a/package-lock.json b/package-lock.json index 0a20ae42..1b9b0345 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,7 +43,7 @@ "clean-webpack-plugin": "^4.0.0", "copy-webpack-plugin": "^14.0.0", "css-loader": "^7.1.2", - "cypress": "^15.21.0", + "cypress": "16.0.0", "eslint": "^10.9.1", "eslint-config-prettier": "^10.1.8", "eslint-plugin-cypress": "^7.0.1", @@ -5936,9 +5936,9 @@ "license": "MIT" }, "node_modules/cypress": { - "version": "15.21.0", - "resolved": "https://registry.npmjs.org/cypress/-/cypress-15.21.0.tgz", - "integrity": "sha512-6uPy5GUjao97t/QDIwlPyJz4JUqPpFIPq5lNazN95LSA3ynJoYC1sHZ3W+aj4f+K1OFGbMfno0+OX2Gx0OmlPA==", + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-16.0.0.tgz", + "integrity": "sha512-/H3zsayGwIGboFIiLWaXxy6ADmCdWy5QjjDBZgslCvjIgYAf1DkZerwAM7wXMPSpfpQ4w+lGjFlmwneRBpg27g==", "dev": true, "hasInstallScript": true, "license": "MIT", @@ -5959,7 +5959,7 @@ "cli-table3": "0.6.1", "commander": "^6.2.1", "common-tags": "^1.8.0", - "dayjs": "^1.10.4", + "dayjs": "^1.11.23", "debug": "^4.3.4", "eventemitter2": "6.4.7", "execa": "4.1.0", @@ -5987,7 +5987,7 @@ "cypress": "bin/cypress" }, "engines": { - "node": "^20.1.0 || ^22.0.0 || >=24.0.0" + "node": "^22.0.0 || ^24.0.0 || >=26.0.0" } }, "node_modules/cypress/node_modules/ansi-styles": { @@ -6220,10 +6220,11 @@ } }, "node_modules/dayjs": { - "version": "1.11.11", - "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.11.tgz", - "integrity": "sha512-okzr3f11N6WuqYtZSvm+F776mB41wRZMhKP+hc34YdW+KmtYYK9iqvHSwo2k9FEH3fhGXvOPV6yz2IcSrfRUDg==", - "dev": true + "version": "1.11.23", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.23.tgz", + "integrity": "sha512-QDTCU0M0MxR3hQfnlDJfwekQiaanm1ubOD231u73WBckQ/fsamwRLiE2GBz6D3a/xF1NgfiDLJjXBa1hYOYTtQ==", + "dev": true, + "license": "MIT" }, "node_modules/debug": { "version": "4.4.3", diff --git a/package.json b/package.json index 2bd11621..b1894bdf 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "clean-webpack-plugin": "^4.0.0", "copy-webpack-plugin": "^14.0.0", "css-loader": "^7.1.2", - "cypress": "^15.21.0", + "cypress": "16.0.0", "eslint": "^10.9.1", "eslint-config-prettier": "^10.1.8", "eslint-plugin-cypress": "^7.0.1",