Dalius's blog

Thursday, March 21, 2024

Frontend testing: end-to-end testing

Lastly I would like to cover end-to-end (e2e) testing. What you want to do here is to test how your front-end code works in the whole system overall. You can use Cypress, Playwright, Puppeteer, Selenium and maybe there is more tools to test your system. The main benefit of e2e tests is that they give the most assurance that everything is still working. E.g. that allows setting up automated upgrades of used packages as you are confident that upgrade is not breaking your product.

One of the problems is how to run e2e tests against your system. There are several ways how it is handled:

  1. Full system is run and tests are run against it. This is feasible only for small and simple systems, but this is the best option IMHO. I do this in one side-project and I am quite happy with it (but again it is very simple system).

  2. Full test environment is run somewhere with some seed data and you run tests against it.

  3. Tests are run against production.

  4. Tests are run against only front-end code with mocked back-end system. I have not seen this personally but I guess this might have performance benefits.

First 3 options have extra benefit that you are partially testing back-end code as well.

There are other problems that might arise when doing e2e:

  • how to test authenticated users?

  • e.g. if test is run by multiple PRs and uses the same test environment how do you make sure that there are no race conditions?

  • when to run tests? E.g. you might want to run some e2e tests with each PR, but others only after some major deployments or once a day.

This is last part about front-end testing. I may return to this in the future if I have more insight about it.