0

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.

tonymx227
  • 5,293
  • 16
  • 48
  • 91
  • Do you have a step of performing npm install and cache the node_modules from before stage? – Tony Yip May 12 '22 at 06:31
  • You can see an edit in my post, the code refer to the entire code of my `.gitlab-ci.yml`. I have a lot of node modules in my project and I don't want to push the `node_modules` folder in my repository. – tonymx227 May 12 '22 at 07:39
  • Do you use any private package? – Tony Yip May 12 '22 at 08:54

1 Answers1

2

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

Tony Yip
  • 705
  • 5
  • 14