tyler36 / ddev-cypress

Cypress E2E testing for use with DDEV
Apache License 2.0
11 stars 7 forks source link

Support Question - Cypress not picking up test changes from host in ddev container. #33

Closed laetus007 closed 10 months ago

laetus007 commented 10 months ago

Hi! I have a working ddev cypress install on a M1 Mac. My only hiccup is that when I run ddev cypress-open and update a test while the instance is still running, it does not pick up the changes. I thought the issue may be mutagen related so I ran ddev mutagen sync and then will reload the tests. The test will continue to look for the old values without picking up the changes. I was just wondering if you have a fix for this. At the moment, I'm just killing the open test suite and running ddev cypress-open again.

Here is my current config. Thank you in advance for any feedback.

`services: cypress: image: cypress/included:13.4.0 container_name: ddev-${DDEV_SITENAME}-cypress labels: com.ddev.site-name: ${DDEV_SITENAME} com.ddev.approot: ${DDEV_APPROOT} networks: [default,ddev_default]

tty: true

environment:
  - CYPRESS_baseUrl=${DDEV_PRIMARY_URL}
  - DISPLAY=192.168.217.136:0

volumes:
  # Mount the project root to Cypress's project point
  - "${DDEV_APPROOT}:/e2e"
  # Mount DDEV to allow commands
  - ".:/mnt/ddev_config"
  # Allow X11 forwarding
  - /tmp/.X11-unix:/tmp/.X11-unix

external_links:
  # Resolve links via DDEV router
  - "ddev-router:${DDEV_HOSTNAME}"
  - "ddev-router:test.ddev.site"

entrypoint: /bin/bash
working_dir: /e2e`
tyler36 commented 10 months ago

I am unable to replicate the issue using your config; changing a test cause the test to reload on my PC. I tried with Cypress 12.7.0 and 13.4.0 images.

On 13.4.0 image reloaded using Chrome 118, Edge118and Firefox118, Electron114`.

I don't use mutegen but you could try disabling it completely to see if its interferring.

The only difference my config file generally has user: "${DDEV_UID}:${DDEV_GID}" which makes sure your file permissions are correct. But removing it didn't affect my tests.

Perhaps you could provide a repo that I could test against?

rfay commented 10 months ago

FYI @tyler36 it's trivial to turn on mutagen on WSL2, does no harm, and you can see if it's related. Mutagen works fine on linux/wsl2.

laetus007 commented 10 months ago

@tyler36 - thank you greatly for your time on this - I went down a deep rabbit hole this morning and I've concluded that I just don't think the watchForFileChanges will work with the M1 Mac setup at this time; however, I believe there are sufficient work arounds that do not make this a deal breaker.

  1. Using phpStorm, I'm able to run individual tests as headless in the ide and only the test I want not the whole spec with this add-on
  2. I'm still able to use ddev cypress-open if I want to visually inspect an issue with the caveat that I will need to restart it if there are any changes
  3. Any substantial cypress builds, I can just run locally

Here are my findings from this morning

  1. Turning off mutagen did not change the observed behavior.
  2. I commented out user: "${DDEV_UID}:${DDEV_GID}" as this prevents newer versions of cypress running properly on the Mac
  3. Hardcoding "watchForFileChanges": true in my cypress.config.js did nothing (as expected since this is the default behavior)
  4. Mounting the volumes as a bind mount did not change the observed behavior.
  5. --vm-type qemu vs vz in colima did not change the observed behavior.
  6. Changing to vz seems to have some performance benefits for my general ddev usage (so gratitude for the exploration this morning) but identified that "${DDEV_APPROOT}:/e2e" is way to inclusive and ended up with a Error: EMFILE: too many open files. We run a multisite setup where our docroot will include copies of the files/images from the multiple sites among other things.
  7. Modified the above line to the following which has resulted in both a mutagen sync speed up on start and loading of ddev cypress-open
    - "${DDEV_APPROOT}/cypress.config.js:/e2e/cypress.config.js" - "${DDEV_APPROOT}/cypress:/e2e/cypress"
tyler36 commented 10 months ago

Thank you posting about your experience and further research. Its always good to know what works, and doesn't, for other people.

If you find the workaround to troublesome, you can just install cypress locally; Cypress only needs to be able to see the website so just point it to https://myproject.ddev.com.

PRs are welcome if you think we can improve the docs or configuration. Happy testing!