Jest, command not found on GitLab

2.9k Views Asked by At

I'd like to execute my unit tests using JEST on GITLAB, but it seeem's not working.

It works on my local machine but not on GitLab.

The entire code of .gitlab-ci.yml :

image: node:16

cache:
  paths:
    - node_modules

install:
  stage: build
  script: npm ci

jest:
  stage: test
  script: npm run test:ci
  artifacts:
    when: always
    reports:
      junit:
        - junit.xml

Package.json

"test": "jest",
"test:ci": "jest --config ./jest.config.js --ci --reporters=default --reporters=jest-junit"

Error :

npm ERR! code E401
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR!     https://www.npmjs.com/forgot
npm ERR! 
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR!     npm login
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-05-12T08_05_01_634Z-debug-0.log
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

I found the issue by replacing the Node version (same version in my local machine) : image: node:14.

1

There are 1 best solutions below

6
Tony Yip On BEST ANSWER

You need to have a step to install, better to check with GitLab CI document

image: node:16

cache:
  paths:
    - node_modules

install:
  stage: build
  script: npm ci

jest:
  stage: test
  script: npm run test:ci
  artifacts:
    when: always
    reports:
      junit:
        - junit.xml