Running Cypress with Docker inside CI

Oct 25, 2019

I've been looking at Cypress lately as a solution to do better end to end testing, and even in some cases to just dodge TDD altogether, and rely on seeing my code work in a browser like environment and actually see the results.

Locally, Cypress runs with ease, just cypress open or cypress run, and voila. The problem has come from getting it running in CI.

Insert your CI of Choice

Jenkins is the CI of choice at Eventbrite, and we use containers to build and test things in our Jenkins workers. The big issue has been, how do I get our local dev server started, THEN run cypress?

The following instructions are really universal to any CI.

The following is my current solution, but I'm all ears for a better one if such a solution exists...

The Dockerfile above creates a container with all the tools needed to run Cypress.

Then the bash script does a few things.

First it runs adds an entry to the hosts file because we talk over that domain to a QA server for data.

Then yarn dev actually runs the server, now this being a dev server, it can take a second to spin up. Therefore, a while loop curls the server until it's ready.

Finally, we run cypress run and output mocha/junit style xml results so Jenkins can show us nice failure messages.

Again, not sure if this is janky or elegant, but it seems to work, and I'm all for things working.

If you or your team have a similar solution for your CI, particularly if it's Jenkins, reach out and let me know!