From 8c5b55575c5c961cbf8b6788d63f77c907f67f1a Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Mon, 12 May 2025 21:20:15 -0400 Subject: [PATCH 1/6] Update cy.press signature to be Chainable Since it's added via `Commands.add`, I believe `cy.press` should have a return type of `Chainable` rather than `void` --- cli/types/cypress.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index 0104b365cc3d..65f51f96722e 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -1755,7 +1755,7 @@ declare namespace Cypress { * cy.press(Cypress.Keyboard.Keys.TAB) // dispatches a keydown and press event to the browser, followed by a keyup event. * @see https://on.cypress.io/press */ - press(key: typeof Cypress.Keyboard.Keys[keyof typeof Cypress.Keyboard.Keys], options?: Partial): void + press(key: typeof Cypress.Keyboard.Keys[keyof typeof Cypress.Keyboard.Keys], options?: Partial): Chainable /** * Get the immediately preceding sibling of each element in a set of the elements. From 16a1ce6c98878d2c8dd2ad0f9c8880d3cbcc7602 Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Mon, 12 May 2025 21:25:12 -0400 Subject: [PATCH 2/6] Update first_spec.cy.js Updated test for chainable --- .../cy-press-second-spec-error/cypress/e2e/first_spec.cy.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/system-tests/projects/cy-press-second-spec-error/cypress/e2e/first_spec.cy.js b/system-tests/projects/cy-press-second-spec-error/cypress/e2e/first_spec.cy.js index 6c63f4b14538..0c8f111882ea 100644 --- a/system-tests/projects/cy-press-second-spec-error/cypress/e2e/first_spec.cy.js +++ b/system-tests/projects/cy-press-second-spec-error/cypress/e2e/first_spec.cy.js @@ -1,5 +1,7 @@ describe('this one should pass', () => { it('dispatches a key press', () => { - cy.press(Cypress.Keyboard.Keys.TAB) + cy.press(Cypress.Keyboard.Keys.TAB).then((val) => { + expect(val).to.be.null + }) }) }) From 3c5cd67e85c4a909e28b40f50c12cf310b9669f8 Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Tue, 13 May 2025 10:06:51 -0400 Subject: [PATCH 3/6] use addAll rather than add to avoid type check --- packages/driver/src/cy/commands/actions/press.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/driver/src/cy/commands/actions/press.ts b/packages/driver/src/cy/commands/actions/press.ts index 5e96fa503264..7c4110f35de8 100644 --- a/packages/driver/src/cy/commands/actions/press.ts +++ b/packages/driver/src/cy/commands/actions/press.ts @@ -36,7 +36,7 @@ export default function (Commands: Cypress.Commands, Cypress: Cypress.Cypress, c // throwErrByPath always throws, but there's no way to indicate that // code beyond this point is unreachable to typescript / linters - return + return null } if (Cypress.browser.family === 'webkit') { @@ -47,7 +47,7 @@ export default function (Commands: Cypress.Commands, Cypress: Cypress.Cypress, c }, }) - return + return null } if (Cypress.browser.name === 'firefox' && Number(Cypress.browser.majorVersion) < 135) { @@ -71,7 +71,11 @@ export default function (Commands: Cypress.Commands, Cypress: Cypress.Cypress, c } catch (err) { $errUtils.throwErr(err, { onFail: log }) } + + return null } - return Commands.add('press', pressCommand) + return Commands.addAll({ + press: pressCommand, + }) } From ac961aca96fbdbfbcdcdacff1914f77dbc19082e Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Tue, 13 May 2025 11:30:44 -0400 Subject: [PATCH 4/6] fix unit test --- .../test/unit/cy/commands/actions/press.spec.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/driver/test/unit/cy/commands/actions/press.spec.ts b/packages/driver/test/unit/cy/commands/actions/press.spec.ts index 2e77adae79f2..228afe24d7f9 100644 --- a/packages/driver/test/unit/cy/commands/actions/press.spec.ts +++ b/packages/driver/test/unit/cy/commands/actions/press.spec.ts @@ -51,9 +51,9 @@ describe('cy/commands/actions/press', () => { }, } - // @ts-expect-error - this is a generic mock impl Commands = { - add: vi.fn(), + // @ts-expect-error - this is a generic mock impl + addAll: vi.fn(), } // @ts-expect-error @@ -84,14 +84,14 @@ describe('cy/commands/actions/press', () => { addCommand(Commands, Cypress, cy, state, config) - expect(Commands.add).toHaveBeenCalledOnce() + expect(Commands.addAll).toHaveBeenCalledOnce() // @ts-expect-error - const [[cmdName, cmd]]: [[string, PressCommand]] = Commands.add.mock.calls + const [[obj]]: [[{press: PressCommand}]] = Commands.addAll.mock.calls - expect(cmdName).toEqual('press') + expect(typeof obj.press).toBe('function') - press = cmd as PressCommand + press = obj.press as PressCommand }) describe('with a valid key', () => { From 84c061cdb9f1b43455e6312b4755dc0e3ee60158 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Tue, 13 May 2025 13:18:24 -0400 Subject: [PATCH 5/6] Add cli entry --- cli/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 7f6c2f2336fa..8c83a25b8222 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -10,6 +10,7 @@ _Released 5/20/2025 (PENDING)_ **Misc:** - Cursor is now available as an IDE option for opening files in Cypress, if it is installed on your system. Addressed in [#31691](https://github.com/cypress-io/cypress/pull/31691). +- `cy.press()` types now have a return type of `Chainable` instead of `void`. Addressed in [#31698](https://github.com/cypress-io/cypress/pull/31698). **Dependency Updates:** From 4424d512beef4e57bc70c285d39fa8d48b100e92 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Wed, 14 May 2025 09:51:09 -0400 Subject: [PATCH 6/6] update changelog --- cli/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 1cefa6715604..366c2b4aa169 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -9,13 +9,13 @@ _Released 5/20/2025 (PENDING)_ **Bugfixes:** -- Fixed an issue with the experimental usage of WebKit where Cypress incorrectly displayed `0` as the WebKit version. Addresses [#31684](https://github.com/cypress-io/cypress/issues/31684). - Fixed an issue where framebusting was occurring when `top.window.location` was being set explicitly. This fix does not require the `experimentalModifyObstructiveThirdPartyCode` configuration option. Addresses [#31687](https://github.com/cypress-io/cypress/issues/31687). +- `cy.press()` now has a return type of `Chainable` instead of `void` to match the convention of other commands that yield `null`. Addressed in [#31698](https://github.com/cypress-io/cypress/pull/31698). +- Fixed an issue with the experimental usage of WebKit where Cypress incorrectly displayed `0` as the WebKit version. Addresses [#31684](https://github.com/cypress-io/cypress/issues/31684). **Misc:** - Cursor is now available as an IDE option for opening files in Cypress, if it is installed on your system. Addressed in [#31691](https://github.com/cypress-io/cypress/pull/31691). -- `cy.press()` types now have a return type of `Chainable` instead of `void`. Addressed in [#31698](https://github.com/cypress-io/cypress/pull/31698). - The error shown when the `--record` flag is missing has been updated to be shorter. Addressed in [#31676](https://github.com/cypress-io/cypress/pull/31676). **Dependency Updates:**