cy.readFile("path-to-file") failed because the file does not exist, even though it does
See original GitHub issueHello! 😃 cy.readFile
doesn’t seem to find files at a given, correct path anymore. I noticed this behavior using cypress-dark
plugin and my own theme for the test runner, details as following.
Current behavior:
When using dark theme from cypress-dark
plugin and my own theme I get the following error message right at the beginning of every test:
CypressError: Timed out retrying: cy.readFile("/node_modules/cypress-dark/src/dark.css") failed because the file does not exist at the following path:
/node_modules/cypress-dark/src/dark.css
Because this error occurred during a 'before all' hook we are skipping all of the remaining tests.
Actual file and path itself are correct and work as soon as I rollback to 3.3.0. I can reproduce that behavior as I use cy.readFile
in my tests as well.
Desired behavior:
I would love to use cy.readFile
as before to use dark- and my custom theme for Cypress’ test runner.
Steps to reproduce: (app code and test code)
- Install version 3.3.1
- Easiest way: Use dark theme from
cypress-dark
plugin, set"useDarkTheme": true,
in cypress.json and run any test - Alternative: Use the following command anywhere in your test:
cy.readFile('./a/valid/path-to-file.spec.js');
Versions
- Cypress 3.3.1, older versions are not affected
- Browser: Chrome 74
- Operating system: Manjaro linux (local development), Cypress on docker image
cypress/browsers:node8.15.1-chrome73
Thank you very much in advance! ❤️
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (6 by maintainers)
Top Results From Across the Web
readFile - Cypress Documentation
By default, cy.readFile() asserts that the file exists and will fail if it does not exist. It will retry reading the file if...
Read more >What is the difference between cy.readFile and cy.fixture in ...
There are two major differences. First, the two functions handle filepaths differently. cy.readFile() starts at your cypress project folder, ...
Read more >reading files in a directory -- how to get a list of ... - Ask TOM
Original Answer: We cannot do this with PLSQL directly however, using Java (or a C extproc) we can do this pretty easily. The...
Read more >Python Tutorial - File and Text Processing
We can use a with -statement to open a file, which will be closed automatically ... does not exist".format(fileIn)) sys.exit(1) # Verify destination...
Read more >VS Code API | Visual Studio Code Extension API
However, when invoking an editor command not all argument types are supported. This is a sample that registers a command handler and adds...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Cypress cannot find this with the trailing
/
in front ofnode_modules
, so usingcy.readFile("node_modules/cypress-dark/src/dark.css")
should work as a workaround today until a new Cypress fix goes out.This is a bug and has nothing to do with node_modules, so can be replicated with any directory relative to the projectRoot.
With my file being present at
projectRoot/cypress/fixtures/example.json
, there are the following differences in the versions.3.3.0
3.3.1
Looking through the commits between 3.3.0 and 3.3.1, I picked out this little commit https://github.com/cypress-io/cypress/pull/4241/commits/c75a643d42c1ae36c80111bf8e2d9556f06c60e3
Instead of setting the filePath to read/write by calling
path.join(projectRoot, file)
we now callpath.resolve(projectRoot, file)
.I’m sure this was expected to cause no changes, but it has.
cy.readFile('cypress/fixtures/example.json')
:/Users/jennifer/Dev/cypress-example-kitchensink/cypress/fixtures/example.json
cy.readFile('/cypress/fixtures/example.json')
:/Users/jennifer/Dev/cypress-example-kitchensink/cypress/fixtures/example.json
cy.readFile('cypress/fixtures/example.json')
:/Users/jennifer/Dev/cypress-example-kitchensink/cypress/fixtures/example.json
cy.readFile('/cypress/fixtures/example.json')
:/cypress/fixtures/example.json
https://github.com/bahmutov/cypress-dark plugin