Sometimes using a separate cache folder in the $HOME is not possible. Some CI's like Heroku CI only cache node_modules and that's it. So it would be nice to be able to download the binary into the local node_modules folder.
I got this to work in https://github.com/cypress-io/cypress-example-kitchensink/pull/143 but it was non-obvious.
CYPRESS_CACHE_FOLDER=cache/CypressCYPRESS_CACHE_FOLDER=./node_modules/cypress/cache/Cypress npx cypress openI think it would be very nice
node_modules/cypress or right inside the node_modules/cypress/package.jsonCYPRESS_CACHE_FOLDER during install and run. I think CYPRESS_CACHE_FOLDER=node_modules/cypress/cache/Cypress would be greatPS: we need documentation page for caching to cover more cases than https://github.com/cypress-io/cypress-documentation/pull/596/files covers (like GitLab CI example https://github.com/cypress-io/cypress-example-kitchensink/blob/master/.gitlab-ci.yml) and also we need a redirect https://on.cypress.io/caching
@bahmutov I see, so a problem is during install time, CYPRESS_CACHE_FOLDER is relative to ./node_modules/cypress/, but during run-time, CYPRESS_CACHE_FOLDER is relative to project root?
Yup
Sent from my iPhone
On Oct 23, 2018, at 17:16, Ben Kucera notifications@github.com wrote:
@bahmutov I see, so a problem is during install time, CYPRESS_CACHE_FOLDER is relative to ./node_modules/cypress/, but during run-time, CYPRESS_CACHE_FOLDER is relative to project root?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
EDIT: Removing the CYPRESS_CACHE_FOLDER environment variable fixed this for me. So yes, it would be nice to fix the confusion of finding the binary.
Has anything been done on this? Struggling with locating the binary in our CI/CD pipeline and getting this error:
$ yarn run cypress:run
yarn run v1.10.1
$ node_modules/.bin/cypress run
The cypress npm package is installed, but the Cypress binary is missing.We expected the binary to be installed here:
PATH/TO/PROJECT/~/.cache/Cypress/3.1.5/Cypress/CypressReasons it may be missing:
- You're caching 'node_modules' but are not caching this path: /root/.cache/Cypress
- You ran 'npm install' at an earlier build step but did not persist: /root/.cache/Cypress
Properly caching the binary will fix this error and avoid downloading and unzipping Cypress.
Alternatively, you can run 'cypress install' to download the binary again.
I have CYPRESS_CACHE_FOLDER set to ~/.cache/Cypress explicitly in the pipeline's environment variables to ensure that it's there. Lo and behold, when I cd to ~/ in the pipeline and then do an ls -la, there is no .cache folder. This is true whether I have the environment variable set or not.
The image I'm using is cypress/base:10. My .gitlab-ci.yml file looks like this:
functional-test:cypress-e2e:
image: cypress/base:10
stage: functional-test
script:
- yarn config set registry <CORPORATE_ARTIFACTORY_URL>
- yarn install
- yarn run cypress:run
artifacts:
expire_in: 1 week
when: always
paths:
- cypress/screenshots
- cypress/videos
I'm using Cypress version 3.1.5 so I have no idea why the .cache folder isn't showing up. I'm using the gitlab ci cypress example here, but am having trouble adapting it to our needs correctly.
If caching the Cypress binary is made easier so we can get it into our pipeline, we'll have an easier time convincing our test organization to adopt Cypress.
I have the same problem. Using the cypress/base:10 image as base, installed the cypress to it and tagged and pushed to my local repository.
I don't wanna install cypress during every test run, however, I cannot run it. I tried to add an alias to the /node_modules/.bin/cypress but still have the same error.
I tried to set CYPRESS_CACHE_FOLDER to ~/.cache/Cypress, but still the same error using jenkins.
This is a blocker to me :( so I would be very happy if you can help to solve this.
Update:
The problem was that Jenkins run the scripts with jenkins user (whoami gives root :S). I bypassed the problem copying the cache to the jenkins user home:
sh "mkdir /home/jenkins/.cache/"
sh "mv /root/.cache/Cypress/ /home/jenkins/.cache/"
Hacky but I can't find a better solution now.
so a problem is during install time, CYPRESS_CACHE_FOLDER is relative to ./node_modules/cypress/, but during run-time, CYPRESS_CACHE_FOLDER is relative to project root?
Since this bug no longer exists I'm closing this issue
I still see this issue with 3.4.0. It seems to work (on gitlab) with
cache:
paths:
- cache/Cypress
script:
- 'export CYPRESS_CACHE_FOLDER=../../cache/Cypress'
- 'npm ci'
- 'export CYPRESS_CACHE_FOLDER=cache/Cypress'
- 'npm run ci'
@eiswind Interesting, I cant reproduce this is docker, but it may be some issue with Gitlab specifically, thanks for letting us know
Hey there. I updated to [email protected] and since then my travis CI is failing with something similar.
You can consult the pipeline full log here https://travis-ci.org/danielcaldas/react-d3-graph/jobs/580469437.
> export CYPRESS_SANDBOX_URL=http://127.0.0.1:8888 && cypress run
The cypress npm package is installed, but the Cypress binary is missing.
We expected the binary to be installed here: /home/travis/.cache/Cypress/3.4.1/Cypress/Cypress
Reasons it may be missing:
- You're caching 'node_modules' but are not caching this path: /home/travis/.cache/Cypress
- You ran 'npm install' at an earlier build step but did not persist: /home/travis/.cache/Cypress
Properly caching the binary will fix this error and avoid downloading and unzipping Cypress.
Alternatively, you can run 'cypress install' to download the binary again.
https://on.cypress.io/not-installed-ci-error
----------
Platform: linux (Ubuntu Linux - 16.04)
Cypress Version: 3.4.1
EDIT: As it is a caching issue, in my case, deleting the caches on the travis UI fixes the issue.
I still see this issue with 3.4.0. It seems to work (on gitlab) with
cache: paths: - cache/Cypress script: - 'export CYPRESS_CACHE_FOLDER=../../cache/Cypress' - 'npm ci' - 'export CYPRESS_CACHE_FOLDER=cache/Cypress' - 'npm run ci'
Thanks, this worked for us. (we are using yarn then npx cypress run). I don't fully understand why it needs to be done though?
I'll look into this
Just to add, this seems to work between stages, but the caching doesn't work between pipelines for us. I'm not sure why it's not picking up the binary
I created an example project in https://gitlab.com/bahmutov/test-cypress-cache-in-node-modules
I think the best solution that matches the user's intuition would be:
postinstall hook and installing binary detect if we are installing inside node_modules/cypress - this means we are installing Cypress binary as a dependency. In that case IF CYPRESS_CACHE_FOLDER is relative path, then use absolute path as ../.. + CYPRESS_CACHE_FOLDER to match human intutionThe code for this is done in cypress-io/cypress#5407, but has yet to be released.
We'll update this issue and reference the changelog when it's released.
Released in 3.5.0.
Most helpful comment
I have the same problem. Using the
cypress/base:10image as base, installed the cypress to it and tagged and pushed to my local repository.I don't wanna install cypress during every test run, however, I cannot run it. I tried to add an alias to the
/node_modules/.bin/cypressbut still have the same error.I tried to set
CYPRESS_CACHE_FOLDERto~/.cache/Cypress, but still the same error using jenkins.This is a blocker to me :( so I would be very happy if you can help to solve this.
Update:
The problem was that Jenkins run the scripts with jenkins user (
whoamigivesroot:S). I bypassed the problem copying the cache to the jenkins user home:sh "mkdir /home/jenkins/.cache/" sh "mv /root/.cache/Cypress/ /home/jenkins/.cache/"Hacky but I can't find a better solution now.