[META] Feature Request: Add tests

Currently, Trivabble is tested exclusively manually.

So far we've seen few regressions. To my knowledge, #15 (closed) was a regression (from me). There was a bug when using WebSockets that was also a regression (also from me), fixed in commit 930fc129, where a user using Trivabble for the first time needed to refresh the page to play. Another one surfaced when the script was not stripped from const / let, fixed in 1f9e0620 and it was fortunately caught rapidly. We were lucky that it really badly broke Trivabble and we could not miss it but it could have been more subtle.

But having tests for bugs we have fixed since March, and for essential features (and for possibly features we introduce) would be nice. I don't want to ask people contributing to Trivabble to write tests for features they add or bugs they fix, because contributing to Trivabble should be fun, though.

Having an infrastructure to test things would be useful.

Here's what I can think we could have:

  • a document that lists things to tests before making a new release. Easy to set up.
  • unit tests. Unit tests for me are really useful for interface functions. I don't think we have that many functions worth testing in the client. We have to be careful because unit tests can slow us down. In Trivabble, functions we could test would be the ones that are there since the beginning and/or have a good chance to remain. I don't know. In the server, we could test the functions handling WebSockets, and the ones handling commands. This would really be useful.
  • Functional tests:
    • Server side, we could tests that requests lead to the right responses. We could even simulate a game and check that the state of the game is what we expect
    • Client side + server side, we could try to use something like Cypress that simulates a user interacting with a web page and checking that the UI is always in the desired state. I think this would be very useful.

For unit tests, we could use a framework like Mocha. One difficulty is that Trivabble is not written in a way that eases unit testing: it's not written as packages that exports functions that we can just call in tests.

This ticket is here to explore and discuss the needs and how to fulfil them. A ticket should be opened for each method / kind of test we actually add support for.

Edited by Raphaël Jakse