Issue with Gitlab CI while deploying application solar

Hi,

I’m currently doing GitLab Course. And while deploying facing issue related “mocha app-test.js --timeout 10000 --reporter mocha-junit-reporter --exit”. MongoDB database connected but job getting fail because of report.

Please find below CI logs:

Executing “step_script” stage of the job script00:14

Using effective pull policy of [always] for container node:17-alpine3.14

Using docker image sha256:b20b24e39dda538a41dfa3e9fcd7d70479cad96e3aa7324a0fc7fd1eacd8de45 for node:17-alpine3.14 with digest node@sha256:0d8276c8e82fa717a9a88b8734bbad60ac29a0f15f9d04acbe8dd16a850f783c …

$ npm install

added 364 packages, and audited 365 packages in 8s

44 packages are looking for funding

run npm fund for details

19 vulnerabilities (5 low, 5 moderate, 6 high, 3 critical)

To address issues that do not require attention, run:

npm audit fix

To address all issues (including breaking changes), run:

npm audit fix --force

Run npm audit for details.

$ npm test

Solar [email protected] test

mocha app-test.js --timeout 10000 --reporter mocha-junit-reporter --exit

Server successfully running on port - 3000

Cleaning up project directory and file based variables00:01

ERROR: Job failed: exit code 8

===========================

CI Pipeline:

workflow:
name: Solar System NodeJS Pipeline
rules:
- if: ‘$CI_COMMIT_BRANCH == “main” || $CI_COMMIT_BRANCH =~ /^feature/’
when: always

- if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^feature/ && $CI_PIPELINE_SOURCE == "merge_request_event"'
  when: always

stages:

  • test

variables:
MONGO_URI: mongodb+srv://superadmin:[email protected]/solar-db

MONGO_USER: superadmin

MONGO_PASSWORD: SuperUser

unit_testing:
stage: test
image: node:17-alpine3.14
before_script:
- npm install
script:
- npm test

Please help to find the issue.

The “exit code 8” suggests that you’re not connecting with the target mongodb, and that the tests that depend on that are failing.

It’s a little hard to tell what’s going on with your code, because you’ve pasted it directly into the editing widget, which corrupts your code. To see your code properly, we need it in a “code block”, as described here. Try doing that, and I’ll look at your code and see if I see anything.

CI code:

  name: Solar System NodeJS Pipeline
  rules:
    - if: '$CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH =~ /^feature/'
      when: always

    - if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^feature/ && $CI_PIPELINE_SOURCE == "merge_request_event"'
      when: always

stages:
  - test

variables:
  MONGO_URI: mongodb+srv://superadmin:[email protected]/solar-db
  # MONGO_USER: superadmin
  # MONGO_PASSWORD: SuperUser

unit_testing:
  stage: test
  image: node:17-alpine3.14
  before_script:
    - npm install
  script:
    - npm test
  artifacts:
    when: always
    expire_in: 3days
    name: Moca-Test-Result
    paths:
      - test-results.xml
    reports:
      junit: test-result.xml```


Errors:

* Running with gitlab-runner 18.7.0~pre.433.g3a5f2314 (3a5f2314)
  on green-6.saas-linux-small-amd64.runners-manager.gitlab.com/default YKxHNyexq, system ID: s_a201ab37b78a
Preparing the "docker+machine" executor
00:09
Using Docker executor with image node:17-alpine3.14 ...
Using effective pull policy of [always] for container node:17-alpine3.14
Pulling docker image node:17-alpine3.14 ...
Using docker image sha256:b20b24e39dda538a41dfa3e9fcd7d70479cad96e3aa7324a0fc7fd1eacd8de45 for node:17-alpine3.14 with digest node@sha256:0d8276c8e82fa717a9a88b8734bbad60ac29a0f15f9d04acbe8dd16a850f783c ...
Preparing environment
00:02
Using effective pull policy of [always] for container sha256:64e5b6ee31de30899aed189fd114e8328654db8133c424b8462fbc48489fdf34
Running on runner-ykxhnyexq-project-77368449-concurrent-0 via runner-ykxhnyexq-s-l-s-amd64-1766971826-38d6a74a...
Getting source from Git repository
00:01
Gitaly correlation ID: ad7006612f464aba8530acc29c63fee9
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/jasonroys210/solar-system/.git/
Created fresh repository.
Checking out 98174d39 as detached HEAD (ref is main)...
Skipping Git submodules setup
$ git remote set-url origin "${CI_REPOSITORY_URL}" || echo 'Not a git repository; skipping'
Executing "step_script" stage of the job script
00:14
Using effective pull policy of [always] for container node:17-alpine3.14
Using docker image sha256:b20b24e39dda538a41dfa3e9fcd7d70479cad96e3aa7324a0fc7fd1eacd8de45 for node:17-alpine3.14 with digest node@sha256:0d8276c8e82fa717a9a88b8734bbad60ac29a0f15f9d04acbe8dd16a850f783c ...
$ npm install
added 364 packages, and audited 365 packages in 8s
44 packages are looking for funding
  run `npm fund` for details
19 vulnerabilities (5 low, 5 moderate, 6 high, 3 critical)
To address issues that do not require attention, run:
  npm audit fix
To address all issues (including breaking changes), run:
  npm audit fix --force
Run `npm audit` for details.
$ npm test
> Solar [email protected] test
> mocha app-test.js --timeout 10000 --reporter mocha-junit-reporter --exit
Server successfully running on port - 3000
Uploading artifacts for failed job
00:02
Uploading artifacts...
test-results.xml: found 1 matching artifact files and directories 
Uploading artifacts as "archive" to coordinator... 201 Created  correlation_id=f47cbc4ca93c4c3f855cd7e9c80c4c66 id=12556040772 responseStatus=201 Created token=6b_C8-3JL
Uploading artifacts...
test-result.xml: found 1 matching artifact files and directories 
Uploading artifacts as "junit" to coordinator... 201 Created  correlation_id=265f75247c0f4719b37933565868bd5d id=12556040772 responseStatus=201 Created token=6b_C8-3JL
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 8 *

I don't think issue with DB because it shows server successfully running. But the problem line shows:

* mocha app-test.js --timeout 10000 --reporter mocha-junit-reporter --exit *

After removing exit tag it works but taking too much time. I don't understand what is the issue. May I know on which image node this project should run? Because I have used the same which shows in course.