<commit_before>---
layout: post
title: "Boost your Cypress end-to-end Tests"
description: "4 simple tips to improve the speed and the maintainability of your cypress tests."
date: 2020-03-27 22:00:00
tags: [devops, javascript]
comments: true
share: true
---

I have been working with cypress recently, and every day I learn new stuff about it.

In the previous post I have shared [how to configure continuous integration with Github actions and cypress](https://andreybleme.com/2020-02-29/continuous-Integration-with-github-actions-and-cypress-end-to-end-tests/](https://andreybleme.com/2020-02-29/continuous-Integration-with-github-actions-and-cypress-end-to-end-tests/)

Now I will share some tips and tricks that may help you to boost the performance and the maintainability of your cypress tests.
  

Parallelize the execution of your tests
-------------

First things first: we all know that these e2e tests take a really long time to run take here as an example of my 169 spec tests:

![Cypress test taking too much time](https://raw.githubusercontent.com/andreybleme/andreybleme.github.io/master/assets/img/tests-taking-long-time.png "Cypress test taking too much time")


Wait 57 minutes for your tests to run at the CI is simply unacceptable.

Fortunately, cypress provides great integration with the most popular CI tools to parallelize the execution of our tests. Here is how to do this with Github Actions: make sure you are using the [official cypress GitHub action workflow](https://github.com/cypress-io/github-action), and add the `matrix` strategy in your job configuration specifying the number of containers you want the CI to spin up to run all your tests:

<script src="https://gist.github.com/andreybleme/84c92626835e3245d8b6b4a8604e17f0.js"></script>

Here on my workflow file I'm running 10 containers so my tests can run really fast. See the results after adding this simple configuration:

![Cypress test running fast](https://raw.githubusercontent.com/andreybleme/andreybleme.github.io/master/assets/img/cypress-tests-fast.png "Cypress test running fast")

From 57 minutes to less than 7 minutes. Awesome!


Wait for complete server startup
-------------
It's important to guarantee that the application being tested is up and running before you cypress test starts to run. Otherwise you may face annoying and nondeterministic timeout errors:

![Cypress test timeout error](https://raw.githubusercontent.com/andreybleme/andreybleme.github.io/master/assets/img/cypress-test-timeout.png "Cypress test timeout error")
<commit_msg>Fix link<commit_after>---
layout: post
title: "Boost your Cypress end-to-end Tests"
description: "4 simple tips to improve the speed and the maintainability of your cypress tests."
date: 2020-03-27 22:00:00
tags: [devops, javascript]
comments: true
share: true
---

I have been working with cypress recently, and every day I learn new stuff about it.

In the previous post I have shared [how to configure continuous integration with Github actions and cypress](https://andreybleme.com/2020-02-29/continuous-Integration-with-github-actions-and-cypress-end-to-end-tests/)

Now I will share some tips and tricks that may help you to boost the performance and the maintainability of your cypress tests.
  

Parallelize the execution of your tests
-------------

First things first: we all know that these e2e tests take a really long time to run take here as an example of my 169 spec tests:

![Cypress test taking too much time](https://raw.githubusercontent.com/andreybleme/andreybleme.github.io/master/assets/img/tests-taking-long-time.png "Cypress test taking too much time")


Wait 57 minutes for your tests to run at the CI is simply unacceptable.

Fortunately, cypress provides great integration with the most popular CI tools to parallelize the execution of our tests. Here is how to do this with Github Actions: make sure you are using the [official cypress GitHub action workflow](https://github.com/cypress-io/github-action), and add the `matrix` strategy in your job configuration specifying the number of containers you want the CI to spin up to run all your tests:

<script src="https://gist.github.com/andreybleme/84c92626835e3245d8b6b4a8604e17f0.js"></script>

Here on my workflow file I'm running 10 containers so my tests can run really fast. See the results after adding this simple configuration:

![Cypress test running fast](https://raw.githubusercontent.com/andreybleme/andreybleme.github.io/master/assets/img/cypress-tests-fast.png "Cypress test running fast")

From 57 minutes to less than 7 minutes. Awesome!


Wait for complete server startup
-------------
It's important to guarantee that the application being tested is up and running before you cypress test starts to run. Otherwise you may face annoying and nondeterministic timeout errors:

![Cypress test timeout error](https://raw.githubusercontent.com/andreybleme/andreybleme.github.io/master/assets/img/cypress-test-timeout.png "Cypress test timeout error")

{'fraction_non_alphanumeric': 0.08350020024028834, 'fraction_numerical': 0.024829795754905886, 'mean_word_length': 4.513245033112582, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 13, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1686249', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1358, 'n_words': 597}