Gitlab CI job succeeds before mocha tests are run

天大地大妈咪最大 提交于 2019-12-24 08:18:15

问题


I found that my Gitlab jobs are succeeding and ending before the actual test is run.

First, I installing the required dependencies for my app, then I call the mocha commands, but the job succeeds before there is any output from them.

My .gitlab-ci.yml:

image: node:lts-alpine

stages:
  - test

test:
  stage: test
  services:
    - mongo:latest
  script:
    - cd server/
    - apk add --update git
    - apk --no-cache add g++ gcc libgcc libstdc++ linux-headers make python
    - npm install --quiet node-gyp -g
    - npm install
    - npm rebuild bcrypt --build-from-source
    - npm i mocha -g
    - mocha ./src/tests/unit/. --timeout 10000 --exit
    - mocha ./src/tests/integration/. --timeout 10000 --exit
  cache:
    key: "$CI_PROJECT_ID"
    paths:
      - server/node_modules/

And the last couple of lines from the runners output from the console:

...
make: Leaving directory '/builds/myapp/myapp/server/node_modules/bcrypt/build'
bcrypt@3.0.2 /builds/myapp/myapp/server/node_modules/bcrypt
$ npm i mocha -g
/usr/local/bin/mocha -> /usr/local/lib/node_modules/mocha/bin/mocha
/usr/local/bin/_mocha -> /usr/local/lib/node_modules/mocha/bin/_mocha
+ mocha@6.1.4
added 115 packages from 509 contributors in 5.54s
$ mocha ./src/tests/unit/. --timeout 10000 --exit
$ mocha ./src/tests/integration/. --timeout 10000 --exit
Creating cache 8738844...
server/node_modules/: found 19633 matching files   
Uploading cache.zip to https://storage.googleapis.com/gitlab-com-runners-cache/project/XXXX/XXXX 
Created cache
Job succeeded

my folder structure:

- root
    - client/
    - server/
        public/
        src/
            tests/
                unit/
                    someUnitTest.js
                integration/
                    someIntegrationTest.js
        package.json
        ...

Why is it not waiting for the commands to start/finish? Locally, they work of course. I also tried using npm run test as an alias for the 2 mocha commands, but it results in the same.


回答1:


I have found the problem:

The mocha commands are not returning anything because they fail before they start. They have a require('app.js') at the top which starts the server and so on, and due to a missing .env file, this and the mocha tests failed silently.

So properly including a .env file solved the problem.



来源:https://stackoverflow.com/questions/56078252/gitlab-ci-job-succeeds-before-mocha-tests-are-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!