question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New nx workspace doesn't support custom cypress commands

See original GitHub issue

Please make sure you have read the submission guidelines before posting an issue

Expected Behavior

Adding a custom Cypress command with the generated schematics should not cause an error when the tests run.

Current Behavior

The custom commands aren’t registered to due supportFile: false in the cypress.json file.

Failure Information (for bugs)

Adding the minimal steps to reproduce here: https://github.com/ca136/cypress-nx-commands/commit/d9991391140e6aa826b9242ab70ad04bfaf6bb40

Context

Please provide any relevant information about your setup:

Used nx 8.2.0

A minimal reproduce scenario using allows us to quickly confirm a bug (or point out coding problem) as well as confirm that we are fixing the right problem. see github repo above

Failure Logs

Either:

[tsl] ERROR in /Users/caleb.amsden/myapp/apps/myapp-e2e/src/integration/app.spec.ts(6,6)
      TS2339: Property 'login' does not exist on type 'Chainable<undefined>'.

Or:

The support file is missing or invalid.

Your `supportFile` is set to `/Users/caleb.amsden/myapp/apps/myapp-e2e/src/support/index`, but either the file is missing or it's invalid. The `supportFile` must be a `.js` or `.coffee` file or, if you're using a preprocessor plugin, it must be supported by that plugin.

Correct your `cypress.json`, create the appropriate file, or set `supportFile` to `false` if a support file is not necessary for your project.

Learn more at https://on.cypress.io/support-file-missing-or-invalid

Other

Any other relevant information that will help us help you.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
prudhvidandamudicommented, Oct 21, 2019

I had this issue, too, after upgrading to nx 8. You can specifically set the path to your support/index.ts in cypress.json. to me it looks like

"supportFile": "./src/support/index.ts",

And it works for me. @FrozenPandaz

I am facing the same issue, I have manually entered my support file path which is like this "supportFile": "cypress/support/index.ts" When I am running my cypress tests using test runner (ng e2e --watch) the tests are running fine. but when I am trying to run my tests using command line (ng e2e) it’s opening the browser for 4 minutes and not running any tests. I am just seeing the window in the below screenshot for 4 mins without any test execution.

image

My folder structure contains .d.ts files for interfaces and .ts files for custom commands image

Can some help me with this issue, I am actually stuck over here.

1reaction
Foxandxsscommented, Oct 5, 2019

As @juristr mentions in another place, He found a solution:

If inside commands.ts you do something like:

declare namespace Cypress {
  interface Chainable {
    /**
     * Custom command to select DOM element by data-cy attribute.
     * @example cy.dataCy('greeting')
    */
    dataCy(value: string): Chainable<Element>
  }
}


Cypress.Commands.add('dataCy', (value) => {
  return cy.get(`[data-cy=${value}]`)
});

VScode will say, hey, there is a new command, I won’t give you a red wiggle anymore when you use it. Now, running ng e2e will say… what is that dataCy I don’t know about? But if inside the spec file where you use it, you do a import ../support (or your correct path to the support folder), it will actually find it and work.

So you need to do two extra steps for a command. Create the type and import the file with the type where you use it. In a good world you only need to do the former and even better if it is in its own d.ts file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Share Cypress Commands in an Nx Workspace
In your Cypress setup, open the support/commands.ts file to see an example declaration of such a custom command: // eslint-disable-next-line @ ...
Read more >
Share Cypress Commands in an Nx Workspace - YouTube
Nx has had strong Cypress support from the very beginning, by providing generators to automatically set Cypress up for new projects and even ......
Read more >
Shared Cypress Assets in an Nx Workspace | by Preston Lamb
Many times Nx workspaces have multiple applications, and being able to share custom Cypress commands between the end to end test projects.
Read more >
Cypress Component Testing does not use the ...
I am trying to set up cypress component testing in my NX workspace with an angular application. It does work so far, the...
Read more >
@nrwl/cypress | Nx
If the @nrwl/cypress package is not installed, install the version that matches your nx package version. yarn add --dev @nrwl/cypress.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found