Tests should be (more) self-contained #245
Description
Our current tests are not self-contained. Meaning, some of the tests use "global" state, which means the test results can vary depending on how many times they've been run, the order they've been run, etc.
More specifically, the global state is the local blockchain instance. It gets started when the server is started, and then just stays running. This is especially unpredictable for the browser tests, because the blockchain gets started with npm start
. You can run the browser tests over and over from there (which is convenient during development). Each time you run the tests, new contracts get created. These contracts can affect following tests.
The specific issue I ran into is that the notifications tests take longer and longer after each test run. After just 4 or 5 they start exceeding the 10ms timeout, and fail.
Anyone should be able to reproduce this:
- run the browser tests on localhost:8081
- wait for them to finish
- reload the page
- repeat
- watch as the length of the notifications tests increases after every test run. Soon they will exceed 10ms.
We have a couple of options:
- reset the entire blockchain before each test run
- provide a test helper for re-deploying our persistent contracts (e.g. listings registry), which is effectively the same as a reset.