From d7bb6c88d3e4878486fb1f4d1655379896a5d976 Mon Sep 17 00:00:00 2001 From: Gianni Ceccarelli Date: Wed, 20 Mar 2024 02:25:49 +0000 Subject: [PATCH] Cypress typescript (#13591) * convert Cypress tests to TypeScript this work was done by @lunaisnotaboy https://github.com/lunaisnotaboy for their fork https://github.com/cutiekey/cutiekey/pull/7 I just repacked their changes into a minimal set * fix call to `window` in cypress tests this error was spotted thanks to the TypeScript compiler: ``` support/commands.ts:33:12 - error TS2559: Type '(win: any) => void' has no properties in common with type 'Partial'. 33 cy.window(win => { ~~~~~~~~ Found 1 error in support/commands.ts:33 ``` (again, @lunaisnotaboy did the actual work) --- cypress/e2e/{basic.cy.js => basic.cy.ts} | 0 cypress/e2e/{router.cy.js => router.cy.ts} | 0 cypress/e2e/{widgets.cy.js => widgets.cy.ts} | 0 cypress/support/{commands.js => commands.ts} | 2 +- cypress/support/{e2e.js => e2e.ts} | 0 cypress/support/index.ts | 19 +++++++++++++++++++ cypress/tsconfig.json | 8 ++++++++ package.json | 1 + pnpm-lock.yaml | 9 +++++++++ 9 files changed, 38 insertions(+), 1 deletion(-) rename cypress/e2e/{basic.cy.js => basic.cy.ts} (100%) rename cypress/e2e/{router.cy.js => router.cy.ts} (100%) rename cypress/e2e/{widgets.cy.js => widgets.cy.ts} (100%) rename cypress/support/{commands.js => commands.ts} (98%) rename cypress/support/{e2e.js => e2e.ts} (100%) create mode 100644 cypress/support/index.ts create mode 100644 cypress/tsconfig.json diff --git a/cypress/e2e/basic.cy.js b/cypress/e2e/basic.cy.ts similarity index 100% rename from cypress/e2e/basic.cy.js rename to cypress/e2e/basic.cy.ts diff --git a/cypress/e2e/router.cy.js b/cypress/e2e/router.cy.ts similarity index 100% rename from cypress/e2e/router.cy.js rename to cypress/e2e/router.cy.ts diff --git a/cypress/e2e/widgets.cy.js b/cypress/e2e/widgets.cy.ts similarity index 100% rename from cypress/e2e/widgets.cy.js rename to cypress/e2e/widgets.cy.ts diff --git a/cypress/support/commands.js b/cypress/support/commands.ts similarity index 98% rename from cypress/support/commands.js rename to cypress/support/commands.ts index 91a4d7abe6..c2d92e1663 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.ts @@ -30,7 +30,7 @@ Cypress.Commands.add('visitHome', () => { }) Cypress.Commands.add('resetState', () => { - cy.window(win => { + cy.window().then(win => { win.indexedDB.deleteDatabase('keyval-store'); }); cy.request('POST', '/api/reset-db', {}).as('reset'); diff --git a/cypress/support/e2e.js b/cypress/support/e2e.ts similarity index 100% rename from cypress/support/e2e.js rename to cypress/support/e2e.ts diff --git a/cypress/support/index.ts b/cypress/support/index.ts new file mode 100644 index 0000000000..c1bed21979 --- /dev/null +++ b/cypress/support/index.ts @@ -0,0 +1,19 @@ +declare global { + namespace Cypress { + interface Chainable { + login(username: string, password: string): Chainable; + + registerUser( + username: string, + password: string, + isAdmin?: boolean + ): Chainable; + + resetState(): Chainable; + + visitHome(): Chainable; + } + } +} + +export {} diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json new file mode 100644 index 0000000000..6fe7f32cc4 --- /dev/null +++ b/cypress/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "lib": ["dom", "es5"], + "target": "es5", + "types": ["cypress", "node"] + }, + "include": ["./**/*.ts"] +} diff --git a/package.json b/package.json index 41b865456d..8f5ab0b124 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "typescript": "5.3.3" }, "devDependencies": { + "@types/node": "^20.11.28", "@typescript-eslint/eslint-plugin": "7.1.0", "@typescript-eslint/parser": "7.1.0", "cross-env": "7.0.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2906eef4d8..4c1e228a95 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44,6 +44,9 @@ importers: specifier: 4.4.0 version: 4.4.0 devDependencies: + '@types/node': + specifier: ^20.11.28 + version: 20.11.28 '@typescript-eslint/eslint-plugin': specifier: 7.1.0 version: 7.1.0(@typescript-eslint/parser@7.1.0)(eslint@8.57.0)(typescript@5.3.3) @@ -7650,6 +7653,12 @@ packages: dependencies: undici-types: 5.26.5 + /@types/node@20.11.28: + resolution: {integrity: sha512-M/GPWVS2wLkSkNHVeLkrF2fD5Lx5UC4PxA0uZcKc6QqbIQUJyW1jVjueJYi1z8n0I5PxYrtpnPnWglE+y9A0KA==} + dependencies: + undici-types: 5.26.5 + dev: true + /@types/node@20.11.5: resolution: {integrity: sha512-g557vgQjUUfN76MZAN/dt1z3dzcUsimuysco0KeluHgrPdJXkP/XdAURgyO2W9fZWHRtRBiVKzKn8vyOAwlG+w==} dependencies: