Closed bahmutov closed 5 years ago
for now I work around this by installing cypress-plugin-snapshots
in examples/blogs__testing-redux-store
folder, but I really would prefer only the root folder install.
Yeah paths are hard in Cypress. Because if you want to use cy.readFile
you need to access it's path relative to Cypress directory.
I like your suggestion to do it via the plugin in a task. Will investigate it.
Thanks for the feedback by the way. Much appreciated.
@bahmutov I am now loading the files via a task. This should solve the issues where paths are not 100% reliable.
I am not 100% convinced by this solution, it seems a bit slow. Perhaps I could cache the results in memory somehow so it doesn't have to execute the task every time. But I am not sure how this would behave since the tests run in isolation.
Can you verify if it also works in your setup?
edge case:
In our Cypress example recipes repo https://github.com/cypress-io/cypress-example-recipes each separate application is in a subfolder and all dependencies are installed at the root level. Thus we only need to clone the repo, run
npm install
from the root and then inside eachexamples/...
folder we can start the app and run Cypress tests. Example package json from branch that uses this plugin istesting-redux-store
and pull request https://github.com/cypress-io/cypress-example-recipes/pull/211The application is in
examples/blogs__testing-redux-store
and itspackage.json
is just(or at least it should be this)
"cypress-plugin-snapshots": "1.0.6"
is installed in the root folder.But if I run tests I get an exception
I have not looked at the dependency loading code, but I know it can be in an unexpected place, see how I load CSS for
cypress-dark
here https://github.com/bahmutov/cypress-dark/blob/0460aa71a23080780605936257896ed3f0777cb9/src/utils.js#L7 which is ugly.I was thinking a better way would be to somehow to ask the plugin where it is installed - because it has access to the true
__dirname
without browserify wrap. Then the front end code can correctly do its part, or even ask the plugin viacy.task
for the path to load.