运行Mocha测试之前,Gitlab CI作业成功 [英] Gitlab CI job succeeds before mocha tests are run
问题描述
我发现我的Gitlab作业成功且在实际测试运行之前结束.
I found that my Gitlab jobs are succeeding and ending before the actual test is run.
首先,我为我的应用程序安装了必需的依赖项,然后调用了mocha
命令,但是在这些命令没有任何输出之前,该作业成功完成了.
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.
我的.gitlab-ci.yml:
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
我的文件夹结构:
- root
- client/
- server/
public/
src/
tests/
unit/
someUnitTest.js
integration/
someIntegrationTest.js
package.json
...
为什么不等待命令启动/完成?在本地,他们当然会工作.我还尝试使用npm run test
作为2个mocha命令的别名,但结果相同.
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.
推荐答案
我发现了问题:
mocha
命令不返回任何内容,因为它们在启动之前会失败.他们在顶部有一个require('app.js')
来启动服务器,依此类推,并且由于缺少.env文件,因此该代码和mocha测试均以静默方式失败.
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.
因此正确包含.env文件可以解决此问题.
So properly including a .env file solved the problem.
这篇关于运行Mocha测试之前,Gitlab CI作业成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!