Thank you for your reply! At the moment, I have a build that is passing as I am now not connecting to my local DB but creating a DB directly in the docker and migrating/seeding it.
- image: circleci/node:12
- image: circleci/postgres:alpine
- run: npm --prefix ./server run migrateDb # migration
- run: npm --prefix ./server run seedDb # seeding
- run: npm --prefix ./server run coverage # run tests
As you can see I have removed pretty much everything from the Node image environment setup (I think that’s the section where the connection to the DB must be set up if I am not mistaken).
Then, to answer your first question, below I paste the full error message from one of the past failing builds:
> firstname.lastname@example.org coverage /home/circleci/repo/server
> jest --collectCoverageFrom=./**/*.js --coverage --detectOpenHandles --no-cache
Executing (default): SELECT "id", "name", "password" FROM "Users" AS "User";
Executing (default): CREATE TABLE IF NOT EXISTS "Users" ("id" SERIAL , "name" VARCHAR(255), "password" VARCHAR(255), PRIMARY KEY ("id"));
Unhandled rejection SequelizeDatabaseError: relation "Users" does not exist
at Query.formatError (/home/circleci/repo/server/node_modules/sequelize/lib/dialects/postgres/query.js:366:16)
at tryCatcher (/home/circleci/repo/server/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/circleci/repo/server/node_modules/bluebird/js/release/promise.js:517:31)
at Promise._settlePromise (/home/circleci/repo/server/node_modules/bluebird/js/release/promise.js:574:18)
at Promise._settlePromise0 (/home/circleci/repo/server/node_modules/bluebird/js/release/promise.js:619:10)
at Promise._settlePromises (/home/circleci/repo/server/node_modules/bluebird/js/release/promise.js:695:18)
at _drainQueueStep (/home/circleci/repo/server/node_modules/bluebird/js/release/async.js:138:12)
at _drainQueue (/home/circleci/repo/server/node_modules/bluebird/js/release/async.js:131:9)
at Async.Object.<anonymous>.Async._drainQueues (/home/circleci/repo/server/node_modules/bluebird/js/release/async.js:147:5)
at Immediate.Async.drainQueues [as _onImmediate] (/home/circleci/repo/server/node_modules/bluebird/js/release/async.js:17:14)
at processImmediate (internal/timers.js:439:21)
This error ends up in socket hang up after showing the failing tests below the error details.
My first thought was the same you had: that it was indeed connecting to the database that I had created in my local machine, but then, why then wouldn’t it query it right?
I decided to move on and do the other (I believe right) approach to do the integration tests. This way, I think I gained a deeper understanding. I believe what was happening originally is that the Docker postgres image was creating the database because of the environment set up I had under the image! But then, of course it could not find the relation ‘Users’ as it was never defined within the Docker.
My conclusion is I think I am not doing something well when trying to connect to my local database.
The issue is solved with the correct approach, but still, I would really like to understand what is really going on here and not based everything on assumptions.
To your second question, and related to my previous comments:
Do we really need to create a schema as part of the test if we were pointing to a local database with a set schema and the connection was right? If this is needed for something that I do not know, then this issue is solved now with the latest approach I took.
Thanks a lot!