From f56812b300edcb6ef444ac07f91c1e8dbf411967 Mon Sep 17 00:00:00 2001 From: Douglas Duteil Date: Wed, 14 Aug 2024 16:18:56 +0200 Subject: [PATCH] test(e2e): cypress support typescript (#657) --- .github/workflows/end-to-end.yml | 2 +- cypress.config.js => cypress.config.ts | 10 ++++- cypress/README.md | 2 +- .../{index.cy.js => index.cy.ts} | 0 .../{index.cy.js => index.cy.ts} | 0 .../{index.cy.js => index.cy.ts} | 0 .../delete_totp/{index.cy.js => index.cy.ts} | 0 .../{index.cy.js => index.cy.ts} | 0 .../{index.cy.js => index.cy.ts} | 0 .../{index.cy.js => index.cy.ts} | 0 .../{index.cy.js => index.cy.ts} | 8 +++- .../{index.cy.js => index.cy.ts} | 22 +++++------ .../{index.cy.js => index.cy.ts} | 4 +- .../{index.cy.js => index.cy.ts} | 2 +- .../{index.cy.js => index.cy.ts} | 0 .../{index.cy.js => index.cy.ts} | 8 +++- .../{index.cy.js => index.cy.ts} | 0 .../{index.cy.js => index.cy.ts} | 0 .../{index.cy.js => index.cy.ts} | 4 +- .../{index.cy.js => index.cy.ts} | 2 +- .../{index.cy.js => index.cy.ts} | 0 .../{index.cy.js => index.cy.ts} | 0 .../{index.cy.js => index.cy.ts} | 0 .../{index.cy.js => index.cy.ts} | 2 +- .../{index.cy.js => index.cy.ts} | 2 +- .../{index.cy.js => index.cy.ts} | 0 .../{index.cy.js => index.cy.ts} | 2 +- .../{index.cy.js => index.cy.ts} | 0 .../{index.cy.js => index.cy.ts} | 0 cypress/plugins/index.js | 22 ----------- .../a11y/{checkA11y.js => checkA11y.ts} | 27 ++++++++----- .../{has-page-title.js => has-page-title.ts} | 2 +- .../rules/{page-title.js => page-title.ts} | 2 +- cypress/support/commands.ts | 33 ++++++++++++++++ cypress/support/e2e.js | 39 ------------------- cypress/support/e2e.ts | 19 +++++++++ .../{get-from-email.js => get-from-email.ts} | 18 ++++++--- package.json | 2 +- 38 files changed, 126 insertions(+), 108 deletions(-) rename cypress.config.js => cypress.config.ts (83%) rename cypress/e2e/activate_totp/{index.cy.js => index.cy.ts} (100%) rename cypress/e2e/check_email_deliverability/{index.cy.js => index.cy.ts} (100%) rename cypress/e2e/delete_account/{index.cy.js => index.cy.ts} (100%) rename cypress/e2e/delete_totp/{index.cy.js => index.cy.ts} (100%) rename cypress/e2e/join_collectivite_territoriale_official_contact_domain/{index.cy.js => index.cy.ts} (100%) rename cypress/e2e/join_must_confirm/{index.cy.js => index.cy.ts} (100%) rename cypress/e2e/join_org_with_gouv_fr_domain/{index.cy.js => index.cy.ts} (100%) rename cypress/e2e/join_org_with_trackdechets_domain/{index.cy.js => index.cy.ts} (88%) rename cypress/e2e/join_org_with_verified_domain/{index.cy.js => index.cy.ts} (94%) rename cypress/e2e/join_with_code_sent_to_official_contact_email/{index.cy.js => index.cy.ts} (96%) rename cypress/e2e/join_with_code_sent_to_official_educ_nat_contact_email/{index.cy.js => index.cy.ts} (99%) rename cypress/e2e/join_with_official_contact_email/{index.cy.js => index.cy.ts} (100%) rename cypress/e2e/join_with_sponsorship/{index.cy.js => index.cy.ts} (95%) rename cypress/e2e/reauthenticate_on_admin_page/{index.cy.js => index.cy.ts} (100%) rename cypress/e2e/redirect_after_session_expiration/{index.cy.js => index.cy.ts} (100%) rename cypress/e2e/reset_password/{index.cy.js => index.cy.ts} (98%) rename cypress/e2e/set_info_after_account_provisioning/{index.cy.js => index.cy.ts} (99%) rename cypress/e2e/signin_from_agentconnect_client/{index.cy.js => index.cy.ts} (100%) rename cypress/e2e/signin_from_legacy_client/{index.cy.js => index.cy.ts} (100%) rename cypress/e2e/signin_from_standard_client/{index.cy.js => index.cy.ts} (100%) rename cypress/e2e/signin_with_email_verification_renewal/{index.cy.js => index.cy.ts} (99%) rename cypress/e2e/signin_with_magic_link/{index.cy.js => index.cy.ts} (98%) rename cypress/e2e/signin_with_totp/{index.cy.js => index.cy.ts} (100%) rename cypress/e2e/signup_entreprise_unipersonnelle/{index.cy.js => index.cy.ts} (99%) rename cypress/e2e/update_personal_information/{index.cy.js => index.cy.ts} (100%) rename cypress/e2e/update_totp_application/{index.cy.js => index.cy.ts} (100%) delete mode 100644 cypress/plugins/index.js rename cypress/support/a11y/{checkA11y.js => checkA11y.ts} (90%) rename cypress/support/a11y/checks/{has-page-title.js => has-page-title.ts} (93%) rename cypress/support/a11y/rules/{page-title.js => page-title.ts} (92%) create mode 100644 cypress/support/commands.ts delete mode 100644 cypress/support/e2e.js create mode 100644 cypress/support/e2e.ts rename cypress/support/{get-from-email.js => get-from-email.ts} (71%) diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index 421b84b1..3ea741f8 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -138,7 +138,7 @@ jobs: build: npm run build:assets start: npx dotenvx run -f cypress/e2e/${{ matrix.e2e_test }}/env.conf --overload -- npm start install: false - spec: cypress/e2e/${{ matrix.e2e_test }}/index.cy.js + spec: cypress/e2e/${{ matrix.e2e_test }}/index.cy.ts env: NODE_ENV: production # Store tests runs in case of failure diff --git a/cypress.config.js b/cypress.config.ts similarity index 83% rename from cypress.config.js rename to cypress.config.ts index 16183b66..27eb6cb2 100644 --- a/cypress.config.js +++ b/cypress.config.ts @@ -1,4 +1,10 @@ -export default { +// + +import { defineConfig } from "cypress"; + +// + +export default defineConfig({ chromeWebSecurity: false, defaultCommandTimeout: 60000, pageLoadTimeout: 60000, @@ -17,4 +23,4 @@ export default { return config; }, }, -}; +}); diff --git a/cypress/README.md b/cypress/README.md index a9dffd52..9169c2e5 100644 --- a/cypress/README.md +++ b/cypress/README.md @@ -37,7 +37,7 @@ On your host, run the tests ```bash export CYPRESS_MAILSLURP_API_KEY=ask_a_teammate -npx cypress run --headed --spec "cypress/e2e/redirect_after_session_expiration/index.cy.js" +npx cypress run --headed --spec "cypress/e2e/redirect_after_session_expiration/index.cy.ts" ``` ## About test client used in e2e test diff --git a/cypress/e2e/activate_totp/index.cy.js b/cypress/e2e/activate_totp/index.cy.ts similarity index 100% rename from cypress/e2e/activate_totp/index.cy.js rename to cypress/e2e/activate_totp/index.cy.ts diff --git a/cypress/e2e/check_email_deliverability/index.cy.js b/cypress/e2e/check_email_deliverability/index.cy.ts similarity index 100% rename from cypress/e2e/check_email_deliverability/index.cy.js rename to cypress/e2e/check_email_deliverability/index.cy.ts diff --git a/cypress/e2e/delete_account/index.cy.js b/cypress/e2e/delete_account/index.cy.ts similarity index 100% rename from cypress/e2e/delete_account/index.cy.js rename to cypress/e2e/delete_account/index.cy.ts diff --git a/cypress/e2e/delete_totp/index.cy.js b/cypress/e2e/delete_totp/index.cy.ts similarity index 100% rename from cypress/e2e/delete_totp/index.cy.js rename to cypress/e2e/delete_totp/index.cy.ts diff --git a/cypress/e2e/join_collectivite_territoriale_official_contact_domain/index.cy.js b/cypress/e2e/join_collectivite_territoriale_official_contact_domain/index.cy.ts similarity index 100% rename from cypress/e2e/join_collectivite_territoriale_official_contact_domain/index.cy.js rename to cypress/e2e/join_collectivite_territoriale_official_contact_domain/index.cy.ts diff --git a/cypress/e2e/join_must_confirm/index.cy.js b/cypress/e2e/join_must_confirm/index.cy.ts similarity index 100% rename from cypress/e2e/join_must_confirm/index.cy.js rename to cypress/e2e/join_must_confirm/index.cy.ts diff --git a/cypress/e2e/join_org_with_gouv_fr_domain/index.cy.js b/cypress/e2e/join_org_with_gouv_fr_domain/index.cy.ts similarity index 100% rename from cypress/e2e/join_org_with_gouv_fr_domain/index.cy.js rename to cypress/e2e/join_org_with_gouv_fr_domain/index.cy.ts diff --git a/cypress/e2e/join_org_with_trackdechets_domain/index.cy.js b/cypress/e2e/join_org_with_trackdechets_domain/index.cy.ts similarity index 88% rename from cypress/e2e/join_org_with_trackdechets_domain/index.cy.js rename to cypress/e2e/join_org_with_trackdechets_domain/index.cy.ts index b2600863..50b396bd 100644 --- a/cypress/e2e/join_org_with_trackdechets_domain/index.cy.js +++ b/cypress/e2e/join_org_with_trackdechets_domain/index.cy.ts @@ -1,5 +1,9 @@ // +import { MatchOptionFieldEnum, MatchOptionShouldEnum } from "mailslurp-client"; + +// + describe("join organizations", () => { before(() => { return cy.mailslurp().then((mailslurp) => @@ -38,8 +42,8 @@ describe("join organizations", () => { { matches: [ { - field: "SUBJECT", - should: "EQUAL", + field: MatchOptionFieldEnum.SUBJECT, + should: MatchOptionShouldEnum.EQUAL, value: "Votre compte MonComptePro a bien été créé", }, ], diff --git a/cypress/e2e/join_org_with_verified_domain/index.cy.js b/cypress/e2e/join_org_with_verified_domain/index.cy.ts similarity index 94% rename from cypress/e2e/join_org_with_verified_domain/index.cy.js rename to cypress/e2e/join_org_with_verified_domain/index.cy.ts index 1b2d9049..e65c644f 100644 --- a/cypress/e2e/join_org_with_verified_domain/index.cy.js +++ b/cypress/e2e/join_org_with_verified_domain/index.cy.ts @@ -1,29 +1,27 @@ // +import { MatchOptionFieldEnum, MatchOptionShouldEnum } from "mailslurp-client"; + +// + describe("join organizations", () => { before(() => { - return cy - .mailslurp() - .then((mailslurp) => + return cy.mailslurp().then((mailslurp) => + Promise.all([ mailslurp.inboxController.deleteAllInboxEmails({ inboxId: "c6c64542-5601-43e0-b320-b20da72f6edc", }), - ) - .then((mailslurp) => mailslurp.inboxController.deleteAllInboxEmails({ inboxId: "34c5063f-81c0-4d09-9d0b-a7502f844cdf", }), - ) - .then((mailslurp) => mailslurp.inboxController.deleteAllInboxEmails({ inboxId: "04972db5-2c62-460e-8a88-848317acfe34", }), - ) - .then((mailslurp) => mailslurp.inboxController.deleteAllInboxEmails({ inboxId: "869c78e6-196d-4e95-9662-44d25f801b06", }), - ); + ]), + ); }); beforeEach(() => { cy.login( @@ -69,8 +67,8 @@ describe("join organizations", () => { { matches: [ { - field: "SUBJECT", - should: "EQUAL", + field: MatchOptionFieldEnum.SUBJECT, + should: MatchOptionShouldEnum.EQUAL, value: "Votre organisation sur MonComptePro", }, ], diff --git a/cypress/e2e/join_with_code_sent_to_official_contact_email/index.cy.js b/cypress/e2e/join_with_code_sent_to_official_contact_email/index.cy.ts similarity index 96% rename from cypress/e2e/join_with_code_sent_to_official_contact_email/index.cy.js rename to cypress/e2e/join_with_code_sent_to_official_contact_email/index.cy.ts index a9c59f87..389a9f23 100644 --- a/cypress/e2e/join_with_code_sent_to_official_contact_email/index.cy.js +++ b/cypress/e2e/join_with_code_sent_to_official_contact_email/index.cy.ts @@ -1,6 +1,6 @@ // -import { getVerificationWordsFromEmail } from "#cypress/support/get-from-email.js"; +import { getVerificationWordsFromEmail } from "#cypress/support/get-from-email"; describe("join organizations", () => { before(() => { @@ -44,7 +44,7 @@ describe("join organizations", () => { ), ) // extract the verification code from the email subject - .then(getVerificationWordsFromEmail) + .then((email) => getVerificationWordsFromEmail(email)) // fill out the verification form and submit .then((code) => { cy.get('[name="official_contact_email_verification_token"]').type(code); diff --git a/cypress/e2e/join_with_code_sent_to_official_educ_nat_contact_email/index.cy.js b/cypress/e2e/join_with_code_sent_to_official_educ_nat_contact_email/index.cy.ts similarity index 99% rename from cypress/e2e/join_with_code_sent_to_official_educ_nat_contact_email/index.cy.js rename to cypress/e2e/join_with_code_sent_to_official_educ_nat_contact_email/index.cy.ts index df4115f2..fc087785 100644 --- a/cypress/e2e/join_with_code_sent_to_official_educ_nat_contact_email/index.cy.js +++ b/cypress/e2e/join_with_code_sent_to_official_educ_nat_contact_email/index.cy.ts @@ -1,6 +1,6 @@ // -import { getVerificationWordsFromEmail } from "#cypress/support/get-from-email.js"; +import { getVerificationWordsFromEmail } from "#cypress/support/get-from-email"; describe("join organizations", () => { before(() => { diff --git a/cypress/e2e/join_with_official_contact_email/index.cy.js b/cypress/e2e/join_with_official_contact_email/index.cy.ts similarity index 100% rename from cypress/e2e/join_with_official_contact_email/index.cy.js rename to cypress/e2e/join_with_official_contact_email/index.cy.ts diff --git a/cypress/e2e/join_with_sponsorship/index.cy.js b/cypress/e2e/join_with_sponsorship/index.cy.ts similarity index 95% rename from cypress/e2e/join_with_sponsorship/index.cy.js rename to cypress/e2e/join_with_sponsorship/index.cy.ts index ee9ab241..52bc5b39 100644 --- a/cypress/e2e/join_with_sponsorship/index.cy.js +++ b/cypress/e2e/join_with_sponsorship/index.cy.ts @@ -1,5 +1,9 @@ // +import { MatchOptionFieldEnum, MatchOptionShouldEnum } from "mailslurp-client"; + +// + describe("join organizations", () => { before(() => { cy.mailslurp().then((mailslurp) => @@ -129,8 +133,8 @@ describe("join organizations", () => { { matches: [ { - field: "SUBJECT", - should: "EQUAL", + field: MatchOptionFieldEnum.SUBJECT, + should: MatchOptionShouldEnum.EQUAL, value: "Votre organisation sur MonComptePro", }, ], diff --git a/cypress/e2e/reauthenticate_on_admin_page/index.cy.js b/cypress/e2e/reauthenticate_on_admin_page/index.cy.ts similarity index 100% rename from cypress/e2e/reauthenticate_on_admin_page/index.cy.js rename to cypress/e2e/reauthenticate_on_admin_page/index.cy.ts diff --git a/cypress/e2e/redirect_after_session_expiration/index.cy.js b/cypress/e2e/redirect_after_session_expiration/index.cy.ts similarity index 100% rename from cypress/e2e/redirect_after_session_expiration/index.cy.js rename to cypress/e2e/redirect_after_session_expiration/index.cy.ts diff --git a/cypress/e2e/reset_password/index.cy.js b/cypress/e2e/reset_password/index.cy.ts similarity index 98% rename from cypress/e2e/reset_password/index.cy.js rename to cypress/e2e/reset_password/index.cy.ts index 7a0d8c41..d9f3a190 100644 --- a/cypress/e2e/reset_password/index.cy.js +++ b/cypress/e2e/reset_password/index.cy.ts @@ -49,7 +49,9 @@ describe("sign-in with magic link", () => { // extract the connection link from the email subject .then((email) => { const matches = - /.* 0) { return matches[1]; } diff --git a/cypress/e2e/set_info_after_account_provisioning/index.cy.js b/cypress/e2e/set_info_after_account_provisioning/index.cy.ts similarity index 99% rename from cypress/e2e/set_info_after_account_provisioning/index.cy.js rename to cypress/e2e/set_info_after_account_provisioning/index.cy.ts index f8be34e8..0d901e48 100644 --- a/cypress/e2e/set_info_after_account_provisioning/index.cy.js +++ b/cypress/e2e/set_info_after_account_provisioning/index.cy.ts @@ -1,6 +1,6 @@ // -import { getVerificationCodeFromEmail } from "#cypress/support/get-from-email.js"; +import { getVerificationCodeFromEmail } from "#cypress/support/get-from-email"; describe("set info after account provisioning", () => { before(() => { diff --git a/cypress/e2e/signin_from_agentconnect_client/index.cy.js b/cypress/e2e/signin_from_agentconnect_client/index.cy.ts similarity index 100% rename from cypress/e2e/signin_from_agentconnect_client/index.cy.js rename to cypress/e2e/signin_from_agentconnect_client/index.cy.ts diff --git a/cypress/e2e/signin_from_legacy_client/index.cy.js b/cypress/e2e/signin_from_legacy_client/index.cy.ts similarity index 100% rename from cypress/e2e/signin_from_legacy_client/index.cy.js rename to cypress/e2e/signin_from_legacy_client/index.cy.ts diff --git a/cypress/e2e/signin_from_standard_client/index.cy.js b/cypress/e2e/signin_from_standard_client/index.cy.ts similarity index 100% rename from cypress/e2e/signin_from_standard_client/index.cy.js rename to cypress/e2e/signin_from_standard_client/index.cy.ts diff --git a/cypress/e2e/signin_with_email_verification_renewal/index.cy.js b/cypress/e2e/signin_with_email_verification_renewal/index.cy.ts similarity index 99% rename from cypress/e2e/signin_with_email_verification_renewal/index.cy.js rename to cypress/e2e/signin_with_email_verification_renewal/index.cy.ts index e981daa2..8dabea77 100644 --- a/cypress/e2e/signin_with_email_verification_renewal/index.cy.js +++ b/cypress/e2e/signin_with_email_verification_renewal/index.cy.ts @@ -1,6 +1,6 @@ // -import { getVerificationCodeFromEmail } from "#cypress/support/get-from-email.js"; +import { getVerificationCodeFromEmail } from "#cypress/support/get-from-email"; describe("sign-in with email verification renewal", () => { before(() => { diff --git a/cypress/e2e/signin_with_magic_link/index.cy.js b/cypress/e2e/signin_with_magic_link/index.cy.ts similarity index 98% rename from cypress/e2e/signin_with_magic_link/index.cy.js rename to cypress/e2e/signin_with_magic_link/index.cy.ts index 382d8a7c..ce9822e8 100644 --- a/cypress/e2e/signin_with_magic_link/index.cy.js +++ b/cypress/e2e/signin_with_magic_link/index.cy.ts @@ -3,7 +3,7 @@ import { getMagicLinkFromEmail, getVerificationCodeFromEmail, -} from "#cypress/support/get-from-email.js"; +} from "#cypress/support/get-from-email"; describe("sign-in with magic link", () => { before(() => { diff --git a/cypress/e2e/signin_with_totp/index.cy.js b/cypress/e2e/signin_with_totp/index.cy.ts similarity index 100% rename from cypress/e2e/signin_with_totp/index.cy.js rename to cypress/e2e/signin_with_totp/index.cy.ts diff --git a/cypress/e2e/signup_entreprise_unipersonnelle/index.cy.js b/cypress/e2e/signup_entreprise_unipersonnelle/index.cy.ts similarity index 99% rename from cypress/e2e/signup_entreprise_unipersonnelle/index.cy.js rename to cypress/e2e/signup_entreprise_unipersonnelle/index.cy.ts index e690b16c..333078d3 100644 --- a/cypress/e2e/signup_entreprise_unipersonnelle/index.cy.js +++ b/cypress/e2e/signup_entreprise_unipersonnelle/index.cy.ts @@ -1,6 +1,6 @@ // -import { getVerificationCodeFromEmail } from "#cypress/support/get-from-email.js"; +import { getVerificationCodeFromEmail } from "#cypress/support/get-from-email"; describe("Signup into new entreprise unipersonnelle", () => { before(() => { diff --git a/cypress/e2e/update_personal_information/index.cy.js b/cypress/e2e/update_personal_information/index.cy.ts similarity index 100% rename from cypress/e2e/update_personal_information/index.cy.js rename to cypress/e2e/update_personal_information/index.cy.ts diff --git a/cypress/e2e/update_totp_application/index.cy.js b/cypress/e2e/update_totp_application/index.cy.ts similarity index 100% rename from cypress/e2e/update_totp_application/index.cy.js rename to cypress/e2e/update_totp_application/index.cy.ts diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js deleted file mode 100644 index 8229063a..00000000 --- a/cypress/plugins/index.js +++ /dev/null @@ -1,22 +0,0 @@ -/// -// *********************************************************** -// This example plugins/index.js can be used to load plugins -// -// You can change the location of this file or turn off loading -// the plugins file with the 'pluginsFile' configuration option. -// -// You can read more here: -// https://on.cypress.io/plugins-guide -// *********************************************************** - -// This function is called when a project is opened or re-opened (e.g. due to -// the project's config changing) - -/** - * @type {Cypress.PluginConfig} - */ -// eslint-disable-next-line no-unused-vars -module.exports = (on, config) => { - // `on` is used to hook into various events Cypress emits - // `config` is the resolved Cypress config -}; diff --git a/cypress/support/a11y/checkA11y.js b/cypress/support/a11y/checkA11y.ts similarity index 90% rename from cypress/support/a11y/checkA11y.js rename to cypress/support/a11y/checkA11y.ts index 878a554c..372105ed 100644 --- a/cypress/support/a11y/checkA11y.js +++ b/cypress/support/a11y/checkA11y.ts @@ -1,6 +1,11 @@ +// + +import type { NodeResult, Result, UnlabelledFrameSelector } from "axe-core"; import { config as hasPageTitleCheck } from "./checks/has-page-title"; import { config as pageTitleRule } from "./rules/page-title"; +// + /** * add custom rules to our axe instance * @@ -23,7 +28,9 @@ const configureAxe = (win) => { * - improve both UI logs and console logs * - removes default cypress-axe logs that are not as useful as ours */ -export const checkA11y = ( +export const checkA11y: Parameters< + typeof Cypress.Commands.overwrite<"checkA11y"> +>[1] = ( originalCheckA11y, context, options, @@ -85,7 +92,7 @@ const injectAxeIfNeeded = () => { * @param violations array of results returned by Axe * @link https://github.com/jonoliver/cypress-axe-demo/blob/after-a11y-fixes/cypress/support/commands.js */ -const cypressLog = (violations) => { +const cypressLog = (violations: Result[]) => { violations.forEach((violation) => { const targets = violation.nodes.map(({ target }) => target); const domElements = Cypress.$(targets.join(",")); @@ -104,10 +111,7 @@ const cypressLog = (violations) => { Cypress.log({ $el: el, consoleProps, - message: getElementString( - el.get(0), - Array.isArray(target) ? target[0] : target, - ), + message: getElementString(el.get(0), target), name: "dom element:", }); }); @@ -120,7 +124,7 @@ const cypressLog = (violations) => { * @param violations array of results returned by Axe * @link https://github.com/component-driven/cypress-axe#in-your-spec-file */ -const terminalLog = (violations) => { +const terminalLog = (violations: Result[]) => { if (!violations?.length) { return; } @@ -154,12 +158,12 @@ const terminalLog = (violations) => { * * @param violations array of results returned by Axe */ -const displayViolations = (violations) => { +const displayViolations = (violations: Result[]) => { terminalLog(violations); cypressLog(violations); }; -const getTerminalViolationElements = ({ nodes }) => { +const getTerminalViolationElements = ({ nodes }: { nodes: NodeResult[] }) => { const targets = nodes.map(({ target }) => target); const domElements = Cypress.$(targets.join(",")); return domElements @@ -169,7 +173,10 @@ const getTerminalViolationElements = ({ nodes }) => { .get(); }; -const getElementString = (el, defaultSelector) => { +const getElementString = ( + el: HTMLElement, + defaultSelector: UnlabelledFrameSelector, +) => { const selector = el.id ? `#${el.id}` : defaultSelector; if (el.textContent && !["html", "body"].includes(el.tagName.toLowerCase())) { let content = el.textContent.replace(/\n/g, " ").trim(); diff --git a/cypress/support/a11y/checks/has-page-title.js b/cypress/support/a11y/checks/has-page-title.ts similarity index 93% rename from cypress/support/a11y/checks/has-page-title.js rename to cypress/support/a11y/checks/has-page-title.ts index 241cd8dd..0ddf840a 100644 --- a/cypress/support/a11y/checks/has-page-title.js +++ b/cypress/support/a11y/checks/has-page-title.ts @@ -18,7 +18,7 @@ const hasPageTitle = (ruleNode, { defaultTitle, win }) => { return title !== defaultTitle && title.includes(defaultTitle); }; -export const config = (defaultTitle, win) => ({ +export const config = (defaultTitle: string, win: Window) => ({ id: "mcp-has-page-title", evaluate: hasPageTitle, options: { diff --git a/cypress/support/a11y/rules/page-title.js b/cypress/support/a11y/rules/page-title.ts similarity index 92% rename from cypress/support/a11y/rules/page-title.js rename to cypress/support/a11y/rules/page-title.ts index 80916755..f6a25f1c 100644 --- a/cypress/support/a11y/rules/page-title.js +++ b/cypress/support/a11y/rules/page-title.ts @@ -3,7 +3,7 @@ * * @link https://github.com/dequelabs/axe-core/blob/develop/lib/rules/document-title.json */ -export const config = (defaultTitle) => ({ +export const config = (defaultTitle: string) => ({ id: "mcp-page-title", impact: "serious", selector: "html", diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts new file mode 100644 index 00000000..7dff52c9 --- /dev/null +++ b/cypress/support/commands.ts @@ -0,0 +1,33 @@ +// + +import { checkA11y } from "./a11y/checkA11y"; + +// + +declare global { + namespace Cypress { + interface Chainable { + login(email: string, password: string): Chainable; + } + } +} + +// + +Cypress.Commands.overwrite("checkA11y", checkA11y); + +Cypress.Commands.add("login", (email, password) => { + cy.session([email, password], () => { + // Visit the signup page + cy.visit(`/users/start-sign-in`); + + // Sign in with the existing inbox + cy.get('[name="login"]').type(email); + cy.get('[type="submit"]').click(); + + cy.get('[name="password"]').type(password); + cy.get('[action="/users/sign-in"] [type="submit"]') + .contains("S’identifier") + .click(); + }); +}); diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js deleted file mode 100644 index 02cdf907..00000000 --- a/cypress/support/e2e.js +++ /dev/null @@ -1,39 +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 "cypress-mailslurp"; -import "cypress-axe"; -import { checkA11y } from "./a11y/checkA11y"; - -// - -Cypress.Commands.overwrite("checkA11y", checkA11y); - -Cypress.Commands.add("login", (email, password) => { - cy.session([email, password], () => { - // Visit the signup page - cy.visit(`/users/start-sign-in`); - - // Sign in with the existing inbox - cy.get('[name="login"]').type(email); - cy.get('[type="submit"]').click(); - - cy.get('[name="password"]').type(password); - cy.get('[action="/users/sign-in"] [type="submit"]') - .contains("S’identifier") - .click(); - }); -}); diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts new file mode 100644 index 00000000..a5f76390 --- /dev/null +++ b/cypress/support/e2e.ts @@ -0,0 +1,19 @@ +// *********************************************************** +// 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 "cypress-mailslurp"; +import "cypress-axe"; + +import "./commands"; diff --git a/cypress/support/get-from-email.js b/cypress/support/get-from-email.ts similarity index 71% rename from cypress/support/get-from-email.js rename to cypress/support/get-from-email.ts index d3dc7a28..d7f997fa 100644 --- a/cypress/support/get-from-email.js +++ b/cypress/support/get-from-email.ts @@ -1,7 +1,13 @@ -export const getVerificationCodeFromEmail = (email) => { +// + +import { Email } from "mailslurp-client"; + +// + +export const getVerificationCodeFromEmail = (email: Email) => { const matches = /.*(\s*(?:\d\s*){10})<\/strong><\/span>.*/.exec( - email.body, + email.body ?? "", ); if (matches && matches.length > 0) { return matches[1]; @@ -9,10 +15,10 @@ export const getVerificationCodeFromEmail = (email) => { throw new Error("Could not find verification code in received email"); }; -export const getVerificationWordsFromEmail = (email) => { +export const getVerificationWordsFromEmail = (email: Email) => { const matches = /.*([a-z]{2,25}-[a-z]{2,25})<\/span>.*/.exec( - email.body, + email.body ?? "", ); if (matches && matches.length > 0) { return matches[1]; @@ -20,9 +26,9 @@ export const getVerificationWordsFromEmail = (email) => { throw new Error("Could not find verification code in received email"); }; -export const getMagicLinkFromEmail = (email) => { +export const getMagicLinkFromEmail = (email: Email) => { const matches = /.* 0) { return matches[1]; diff --git a/package.json b/package.json index ee2bf9d5..9d841f4a 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "license": "AGPL-3.0", "type": "module", "imports": { - "#cypress/*": "./cypress/*" + "#cypress/*": "./cypress/*.ts" }, "main": "src/index.js", "scripts": {