Unit Test Failures

Course: Jenkins Pipelines

The unit tests for this project are failing. In order for the pipeline to continue executing, I am using the || true instruction at the end of the test command, preventing it from being interrupted.

Is there any recommendation or instruction to fix the unit tests that are failing?

A couple of suggestions:

  1. First, get it working w/o jenkins, running directly on your system. You’ll need to export all of the MONGO_* fields before you run npm test, but it should definitely work.
  2. Make sure you’re using the actual remote mongo database, since these should work on that. I recall you cloned the db, and the error indicates that an expected field of the schema is missing.

My tests were:


sudo docker run --rm -it -v “${PWD}:/app” -w/app node:16.20.2 bash


npm install --no-audit


export MONGO_URI=“mongodb+srv://supercluster.d83jj.mongodb.net/SuperData” &&
export MONGO_USERNAME=“superuser” &&
export MONGO_PASSWORD=“************”


npm test

Output:

Is there some reason you can’t run npm test directly on your laptop? Running it under docker is likely an additional level of complexity. There dragons lie :slight_smile:

I turned off the junit reporter to get the clearest feedback using the standard reporter (it’s specified in package.json). I did the following:

$ export MONGO_USERNAME=superuser
$ export MONGO_URI="mongodb+srv://supercluster.d83jj.mongodb.net/superData"
$ export MONGO_PASSWORD=****
$ npm test

> Solar [email protected] test
> mocha app-test.js --timeout 10000  --exit

Server successfully running on port - 3000


  Planets API Suite
    Fetching Planet Details
(node:7201) [DEP0170] DeprecationWarning: The URL mongodb://supercluster-shard-00-02.d83jj.mongodb.net:27017,supercluster-shard-00-00.d83jj.mongodb.net:27017,supercluster-shard-00-01.d83jj.mongodb.net:27017/superData?authSource=admin&replicaSet=atlas-11b0vt-shard-0&ssl=true is invalid. Future versions of Node.js will throw an error.
(Use `node --trace-deprecation ...` to show where the warning was created)
      ✔ it should fetch a planet named Mercury (1057ms)
      ✔ it should fetch a planet named Venus (88ms)
      ✔ it should fetch a planet named Earth (87ms)
      ✔ it should fetch a planet named Mars (86ms)
      ✔ it should fetch a planet named Jupiter (86ms)
      ✔ it should fetch a planet named Satrun (85ms)
      ✔ it should fetch a planet named Uranus (125ms)
      ✔ it should fetch a planet named Neptune (104ms)

  Testing Other Endpoints
    it should fetch OS Details
      ✔ it should fetch OS details
    it should fetch Live Status
      ✔ it checks Liveness endpoint
    it should fetch Ready Status
      ✔ it checks Readiness endpoint


  11 passing (2s)

Try this in a virtual, or try this on your system using a bash shell. Should work, as it does for me.

Now it’s working as expected. The problem was at the end of the MONGO_URI variable, where I had written “superData” with a lowercase “d” (“superdata”), causing the error.