【发布时间】:2019-09-28 09:38:13
【问题描述】:
我发现我的 Gitlab 作业在运行实际测试之前成功并结束。
首先,我为我的应用程序安装所需的依赖项,然后调用 mocha 命令,但在它们有任何输出之前作业就成功了。
我的 .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/
以及控制台输出的跑步者的最后几行:
...
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 命令的别名,但结果相同。
【问题讨论】:
-
cd server/youre' 在那里安装您的应用程序。你确定你的代码也在那里吗?可能是没有建立任何要运行的测试。本地你可能不运行cd server/全局安装mocha 后你可能需要再次执行cd ../ -
代码肯定有,基本上是自己的npm项目。
标签: node.js gitlab mocha.js gitlab-ci gitlab-ci-runner