Separating development and testing servers

Good job. Using a test database is certainly a step forward, but our testing workflow is still disjointed. At the moment, to run our tests, we need to stop our development API server, set the environment variables, and then restart it. Similarly, once the tests are finished, we need to stop and restart it again with the development environment.

Ideally, we should run two separate instances of the API server—one for development, one for testing—each binding to its own port. This way, there's no need to stop and restart our server just to run tests.

To achieve this, simply override the SERVER_PORT environment variable for our test environment by adding the following line to envs/test.env and envs/test.env.example:

SERVER_PORT=8888

Now, we can run yarn run watch to run our development API server, and at the same time, run npx dotenv -e envs/test.env yarn run watch to run our testing API server. We no longer need to stop and restart!

Although this is a minor change, let's still commit it to our repository:

$ git add -A && git commit -m "Run test API server on different port"