-
Notifications
You must be signed in to change notification settings - Fork 1
Lessons Learned
Context:
Express API, Vite/React frontend, Postgres DB. They each run in their own containers and are coordinated locally with docker-compose. This containerization is both for local development purposes and to prepare for OpenShift deployment.
Problem:
After initiating Jest with basic configuration and creating a basic test, the error SCRAM-SERVER-FIRST-MESSAGE: client password must be a string
showed up when running the test with npx jest
.
Troubleshooting:
From the above screenshot, we can see the error seems to be related to the pg module not connecting due to a password issue. This was confusing because the API was connected and successfully querying the DB from this point in development, so I knew for a fact it was getting the correct credentials in the container.
Looking for solutions on the pg package documentation was not useful, since my understanding of the reason for the error was misguided to it. I didn't pay attention to the fact I was running Jest from my host system's shell and the API was running in a docker container. The project is set up so docker-compose sets the environment vars when we run the project with docker compose up --watch
. But since Jest was being launched from the host system, it would use the host environment variables.
Solution:
Once @LocalNewsTV pointed me in this direction, I set Jest to run with dotenv so it would properly load the environment variables in ./.env
. The package.json
test script was set to run with "test": "jest --setupFiles dotenv/config",
to ensure it sets up the environment variables in ./.env
.
Lessons learned:
- Pay attention to the error context, not just the message itself.
- Think of what was changed since the error started showing up.