Cypress dependency issues in Docker container

Viewed 221

I am trying to integrate cypress to the bitbucket pipeline. And I am following the official documentation:

- step:
    script:
      # install dependencies
      - npm ci
      # run Cypress tests
      - npm run e2e (env variables here)

I launch the container locally as follows:

docker run -v `pwd`:/mycode -it imagename /bin/sh

cd /mycode
and I run the steps in the script:
/mycode# npm ci; npm run e2e (env variables here)

But I get the following error:

/root/.cache/Cypress/8.2.0/Cypress/Cypress: error while loading shared libraries: libgbm.so.1: cannot open shared object file: No such file or directory

I ran apt-get install xvfb libgtk2.0-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2, as per documentation when I got libgtk2.0-0 missing dependency and it threw the next one. I also have added :nvm install "lts/*" --reinstall-packages-from="$(nvm current)" as a step to update node to the latest version and match cypress requirements, but is there any general practice on how to integrate cypress in an existing project's pipeline and to work around these library issues? Is the fix just to install the library or is there a better integration practice and something I'm missing?

1 Answers

You can actually use an official cypress image only for the step where you want to run the tests. You can choose the version which suits you the best.

      - step:
          name: run tests
          image: cypress/browsers:node12.18.3-chrome87-ff82
          script:
            # install dependencies
            - npm ci
            # run Cypress tests
            - npm run e2e (env variables here)

Related