Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intelligent Code Completion to show Custom Commands #2293

Closed
kapalkat opened this issue Aug 7, 2018 · 9 comments
Closed

Intelligent Code Completion to show Custom Commands #2293

kapalkat opened this issue Aug 7, 2018 · 9 comments

Comments

@kapalkat
Copy link

kapalkat commented Aug 7, 2018

Current behavior:

Intelligent Code Completion feature doesn't show results for Custom Commands.
When you create a lot of them it is really hard to find the name in the file. When you work in cooperation with many team members and few of them are adding custom commands you don't even know what has been added.

The one more really annoying thing is that you can't jump to custom command declaration from your test file like for any other imported function or class.
This one together with the above problem makes Custom Commands almost impossible to maintain!

Desired behavior:

Intelligent Code Completion should work with custom commands.

Versions

Cypress 3.0.3

@jennifer-shehane
Copy link
Member

Our intelligent code completion works by using our typescript definitions. I'm not sure how familiar you are with TypeScript, but you can extend those definitions within your custom commands to define the expectations you need like is done in @d3lm project: https://github.com/d3lm/ngx-drag-to-select/blob/master/cypress/support/commands.ts#L105-L114

@kapalkat
Copy link
Author

kapalkat commented Aug 8, 2018 via email

@d3lm
Copy link

d3lm commented Aug 10, 2018

Yep, you would then write your tests with TS instead of JavaScript. An easy solution is to use https://github.com/bahmutov/add-typescript-to-cypress. All you have to do is to install this via npm or yarn and create a tsconfig.json inside your cypress folder. For reference check out this config https://github.com/d3lm/ngx-drag-to-select/blob/master/cypress/tsconfig.json. You also need to install typescript via npm or yarn.

Also make sure to check the documentation https://docs.cypress.io/guides/tooling/typescript-support.html

@kapalkat
Copy link
Author

kapalkat commented Aug 11, 2018 via email

@jennifer-shehane
Copy link
Member

I created a new issue in our docs to document adding custom command support to intelligent code completion here: cypress-io/cypress-documentation#1354. Our documentation is open source and contributions are welcome. 😄

@dwilches
Copy link

dwilches commented Aug 31, 2019

There is no need to transform your specs to TypeScript, nor installing any 3rd party library. All you need to do is:

  1. Create a file index.d.ts in your cypress/support/ folder
  2. Use the triple-slash to import this file in your specs, like the second line here:
/// <reference types="Cypress" />
/// <reference types="../support" />
  1. In the index.d.ts file, add the types definition of your custom commands, for example:
/// <reference types="Cypress" />

declare namespace Cypress {
    interface Chainable {
        myCustomCommandA(selector: string, option: string): Cypress.Chainable<JQuery>;
        myCustomCommandB(param: string, value: any): Cypress.Chainable<JQuery>;
    }
}

This process is documented in this page of the documentation.

@lsdkjflasjflkdasj
Copy link

The typescript definition file seems completely unuseable and unscalable. This file will get massive and it's just a forward declarations/headers file. The last time I had to forward declare my function definitions was in C++.

@lsdkjflasjflkdasj
Copy link

I think this ticket should be reopened because the current solution is infeasible.

@jennifer-shehane
Copy link
Member

@lsdkjflasjflkdasj Please follow this issue for fully integrated TypeScript support. #1859 This is the solution we have for today.

@cypress-io cypress-io locked and limited conversation to collaborators Jan 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants