error1337 error1337 - 5 months ago 215
AngularJS Question

How to run tests automatically in GitLab CI using gitlab-ci-multi-runner

I'm really sorry if this is a stupid question, but I tried to get it to work for one day now and I could not find a solution...

I started working with the GitLab CI using the gitlab-ci-multi-runner for Windows (64bit). Everything works fine so far, there are connections to my repositories and my configured jobs get started on each push.

What I want to do now is having one job which runs

npm install
to download all dependencies and one job which executes all my tests written with karma/jasmine by running
karma start karma.conf.js
or using grunt and running
grunt test
.

So the first job I tried was:

cd app
npm install
karma start karma.conf.js


The first two commands get executed, but the last one is completely ignored. So I tried to split the jobs. The first to commands get their own job (tab "run in parallel") and the last one was moved to its own job in the tab "run on success". Now all dependencies get installed and the second job starts. So far so good, but the second job starts with removing all previously installed dependencies and then tries to run
karma start karma.conf.js
. This obviously ends up in failing all tests because the npm dependency "angular-mocks" was not downloaded. If I add
npm install
to the second job (which does not make that much sense to me), the karma task will be ignored again.

What is the problem here? How can I fix this? And is there a way to not always download all dependencies on each test execution?

Answer

Since this question was posted, Gitlab CI has switched to using .gitlab-ci.yml for config. I believe the recommended way to install dependencies is with a before_script command such as

before_script:
  - npm install

test:
  script: npm test