Gitlab ci node modules not installed properly test failing
I'm setting up ci/cd for a frontend project on dev server, and I have a small issue regrading test failing.
I have four stages
- prepare
- test
- build
- deploy
Prepare stage will install requirements for the system, so Ansible will run ci.yml and install all dependencies for the system
---
- name: Create a {{ application_name }} for dev machine
hosts: all
become: yes
become_user: root
remote_user: root
vars:
- setup_git_repo: yes
- update_apt_cache: yes
vars_files:
- env_vars/base.yml
- env_vars/vagrant.yml
roles:
- base
- nodejs
- angular-ci-cd
After that test will be run, from gitlab-ci.yml
tests:
stage: test
script:
- npm run test
except:
- develop
- master
After success do build then deploy. The problem is that I'm having is that node_modules are not installed properly and this is happening when test npm run test
> ani-theme-ng6-bs4@6.0.0 test /home/gitlab-runner/builds/f188ace3/0/petarp/itoucan-frontend
> ng test
Could not find module "@angular-devkit/build-angular" from "/home/gitlab-runner/builds/f188ace3/0/petarp/itoucan-frontend".
Error: Could not find module "@angular-devkit/build-angular" from "/home/gitlab-runner/builds/f188ace3/0/petarp/itoucan-frontend".
at Object.resolve (/usr/lib/node_modules/@angular/cli/node_modules/@angular-devkit/core/node/resolve.js:141:11)
at Observable.rxjs_1.Observable [as _subscribe] (/usr/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/src/architect.js:132:40)
at Observable._trySubscribe (/usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Observable.js:43:25)
at Observable.subscribe (/usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Observable.js:29:22)
at DoOperator.call (/usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/tap.js:29:23)
at Observable.subscribe (/usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Observable.js:24:22)
at /usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/util/subscribeTo.js:22:31
at Object.subscribeToResult (/usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/util/subscribeToResult.js:7:45)
at MergeMapSubscriber._innerSub (/usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/mergeMap.js:75:38)
at MergeMapSubscriber._tryNext (/usr/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/mergeMap.js:72:14)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ani-theme-ng6-bs4@6.0.0 test: `ng test`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ani-theme-ng6-bs4@6.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
This is the shell trace from Prepare state, as you can see prepare is running nice and it delivers the setup, but my assumptions are that modules are not properly installed, and tests are failing because they don't see that module, if I do this manually and locally it will be fine.
Is there a way to overcome this, what are the best practice to do in this case?