Using Cypress parallelization with Harness CI

We at Harness are using cypress for running our integration tests. Initially everything was working fine, but as the code size grew, so did the number of test cases. This, in turn, led the run times to shoot closer to an hour and was affecting developer productivity negatively and developers waiting for hours to get their pull requests merged.

At this point, we started to explore the parallelization feature of cypress and Since cypress did not have first class support for Harness CI (at least at the time of writing this post), we had to figure it out ourselves. After a little bit of tinkering we were able to figure it out and have documented the findings below:

  1. You must use the official cypress docker images.
  2. You’ll need to run xvfb using Xvfb -screen 0 1024x768x24 :8099 & and set an environment variable DISPLAY=:8099 before running cypress. This is required for xvfb as documented here.
  3. You’ll need to fill in the appropriate git information in order to populate the dashboard correctly. You can do so by setting the following environment variables:
  4. COMMIT_INFO_BRANCH : For setting the branch name. You can use the git rev-parse — abbrev-ref HEAD command to get this information.
  5. COMMIT_INFO_SHA : For setting the commit hash. You can use the git show -s — pretty=%H command to get this information.
  6. COMMIT_INFO_REMOTE : For setting the repository url.You can use the git config — get remote.origin.url command to get this information.
  7. COMMIT_INFO_MESSAGE : For setting the commit message.You can use the git show -s — pretty=%B command to get this information.
  8. COMMIT_INFO_AUTHOR : For setting the name of the author of the commit.You can use the git show -s — pretty=%an command to get this information.
  9. COMMIT_INFO_EMAIL : For setting the email of the author of the commit.You can use the git show -s — pretty=%ae command to get this information.

How do we run cypress at Harness?

We run the cypress pipeline in 2 stages.

Here is an example of the YAML used for the stage 1, specifically the execution part:

As you see in the yaml, we build our code base and then create a docker image and tag it using run-<+pipeline.sequenceId> This is the most important part. This will help us in uniquely identifying the image.

We create the docker image using the following Dockerfile , you might need to customize based on your use case.

Here is the :

Now for stage 2, we added the image created in stage 1 as service dependency:

And use the same image as the base image for our steps. Here is the execution YAML used for stage 2:

For the purposes of this blog, I have put the yaml for just one step, the remaining steps will have the same settings except for the name and identifier.

For now, you’ll need to copy the yaml n times to have n parallel steps. You can also save this as a template and reuse it that way. We are working on something that will make running the same steps in parallel very easy.

Using this strategy, we were able to bring down the run times down to around 20mins using 4 parallel nodes.

I hope that you find this useful in setting up your own cypress on Harness CI

Note: All the entities used in the YAMLs like connectors, repo names and image names are placeholder, you will need to update them accordingly.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store