Gitlab CI job succeeds before mocha tests are run

2019-07-29 23:20发布

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条回答
男人必须洒脱
2楼-- · 2019-07-29 23:31

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.

查看更多
登录 后发表回答