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

Cypress was unable to save these commands to your spec file: ENOENT: no such file or directory, open .... #16255

Closed
yuchristina opened this issue Apr 28, 2021 · 6 comments · Fixed by #16533
Labels
experiment: studio Issues when using experimentalStudio pkg/driver This is due to an issue in the packages/driver directory type: bug

Comments

@yuchristina
Copy link

yuchristina commented Apr 28, 2021

Current behavior

When I "Save Commands" using Cypress Studio, I get the following error:

ENOENT: no such file or directory, open '[ABSOLUTE PATH TO THE FOLDER I AM RUNNING THE TEST]/[PACKAGE NAME from PACKAGE.JSON]/[RELATIVE PATH TO TEST FILE]

Cypress was unable to save these commands to your spec file. Cypress Studio is still in beta and the team is working hard to resolve issues like this. To help us fix this issue more quickly, you can provide us with more information by clicking 'Learn more' below.Learn more

Desired behavior

I expect the tests to be saved to the file for which I have ran Cypress Studio on to generate the commands.
The path should not have the package name from the package.json file. Instead, it should be:

'[ABSOLUTE PATH TO THE FOLDER I AM RUNNING THE TEST]/[RELATIVE PATH TO TEST FILE]'

For RELATIVE PATH TO TEST FILE, I had expected it to be derived from the cypress.json file from testFiles or integration Folder:

  "testFiles": "../apps/**/*.cypress.ts",
  "ignoreTestFiles": "**/node_modules/**",
  "integrationFolder": "../apps/",

Curiously, when I click the "open in IDE" button on hover over the file path on the top left, it does open to the correct file path (not the '[ABSOLUTE PATH TO THE FOLDER I AM RUNNING THE TEST]/[PACKAGE NAME from PACKAGE.JSON]/[RELATIVE PATH TO TEST FILE]' version) in the Finder.

Versions

7.2.0 (Latest Version)

@jennifer-shehane jennifer-shehane added the experiment: studio Issues when using experimentalStudio label Apr 28, 2021
@jennifer-shehane
Copy link
Member

I don't think that we read the package name in from the package.json. We will interpret the name of the directory that the cypress.json is within as the 'root' of the project, so that may be what you're seeing there.

Can you show the folder structure like below? I'm having some difficulty recreating and that would be helpful.

📁 root
	- 📁 apps
		- 📄 spec.js
📄 cypress.json
📄 package.json

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Apr 28, 2021
@yuchristina
Copy link
Author

"We will interpret the name of the directory that the cypress.json is within as the 'root' of the project" --> that is consistent with what I am seeing. I am using a monorepo.

root

  • src
    • .cypress
      • cypress.json
      • package.json
    • apps
      • appA
        • package.json
        • appA.cypress.ts
      • appB
        • package.json
        • appB.cypress.ts
    • package.json

@yuchristina
Copy link
Author

yuchristina commented Apr 30, 2021

Hi @jennifer-shehane ,

I have figured out a temporary get around, but seeing that projectRoot is supposedly read-only this is a hack at best.

In plugins/index.ts, add:
module.exports = (on, config) => { config.projectRoot = path.resolve("./../"); return config; };

Looking at how save command locates the file to save to, it seems that the project root is by default resolved to where cypress.json resides.

@panzarino
Copy link
Contributor

This actually turned out to be a pretty weird issue - our source map utils were not generating the correct path to the file. This issue was caused by the way source-map returns a relative file path, it would truncate the ... This issue was actually not caused by the use of workspaces/reading the package.json, but rather due to having a path that was outside of the projectRoot. I've created #16533 with a fix.

(This issue doesn't just affect Studio, it also prevents the "open in IDE" button from working for specific hooks like before each and test body, and possibly also opening your IDE from an error stack trace)

@panzarino panzarino added pkg/driver This is due to an issue in the packages/driver directory type: bug labels May 15, 2021
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: work in progress labels May 15, 2021
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels May 17, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 17, 2021

The code for this is done in cypress-io/cypress#16533, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 24, 2021

Released in 7.4.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v7.4.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators May 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
experiment: studio Issues when using experimentalStudio pkg/driver This is due to an issue in the packages/driver directory type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants