【发布时间】:2017-06-30 00:42:40
【问题描述】:
我正在尝试对 travis 进行单元测试,这需要位于单独目录中的节点服务器才能运行。所以我需要在运行 chai-mocha 测试之前让服务器在后台运行。但是我在让它全部工作时遇到了很多麻烦......这是我的 .yml 文件
language: node_js
node_js:
- "6.10.0"
services: mongodb
env:
- TEST_DIR=UserService/server
- TEST_DIR=ApplicantService
- TEST_DIR=ta-corrd-service
before_script:
- sleep 15
script:
- cd UserService/server && npm install nodemon && npm install && npm start& cd $TEST_DIR && npm install && npm test
我需要进入 userservice/server 目录,然后执行 npm start,然后在每个 test_dir 中执行 npm 测试。
我在 travis 上遇到的错误
> proj-awol@0.0.0 test /home/travis/build/csc302-2017-spring/proj-Awol/ta-corrd-service
> mocha --recursive
course
(node:1780) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
1) "before all" hook
2) "after all" hook
0 passing (68ms)
2 failing
1) course "before all" hook:
Uncaught Error: connect ECONNREFUSED 127.0.0.1:3002
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)
2) course "after all" hook:
Uncaught Error: socket hang up
at createHangUpError (_http_client.js:254:15)
at Socket.socketCloseListener (_http_client.js:286:23)
at TCP._handle.close [as _onclose] (net.js:498:12)
npm ERR! Test failed. See above for more details.
The command "cd UserService/server && npm install nodemon && npm install && npm start& cd $TEST_DIR && npm install && npm test" exited with 1.
Done. Your build exited with 1.
我真的不知道我做错了什么。当我在我的机器上执行命令时,它可以工作......
编辑:只是更多信息,如果节点服务器未运行,我的本地计算机上也会出现错误消息“错误:连接 ECONNREFUSED”。所以我的猜测是 travis 没有正确启动节点服务器。但我不确定我的脚本有什么问题。
【问题讨论】:
标签: node.js bash mocha.js travis-ci chai