Gitlab CI 工作在 mocha 测试 运行 之前成功
Gitlab CI job succeeds before mocha tests are run
我发现我的 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/
控制台 运行ners 输出的最后几行:
...
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
...
为什么不等待 start/finish 的命令?在本地,它们当然有效。我还尝试使用 npm run test
作为 2 个 mocha 命令的别名,但结果相同。
我发现了问题:
mocha
命令没有返回任何内容,因为它们在开始之前就失败了。他们在顶部有一个 require('app.js')
启动服务器等等,并且由于缺少 .env 文件,这个和 mocha 测试静默失败。
因此正确包含 .env 文件解决了问题。
我发现我的 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/
控制台 运行ners 输出的最后几行:
...
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
...
为什么不等待 start/finish 的命令?在本地,它们当然有效。我还尝试使用 npm run test
作为 2 个 mocha 命令的别名,但结果相同。
我发现了问题:
mocha
命令没有返回任何内容,因为它们在开始之前就失败了。他们在顶部有一个 require('app.js')
启动服务器等等,并且由于缺少 .env 文件,这个和 mocha 测试静默失败。
因此正确包含 .env 文件解决了问题。