Macaca [基于 Node.js 的自动化测试-Macaca] - 部署新版 Reliable 平台

达峰的夏天 · 2019年07月05日 · 最后由 九宫格中迷了路 回复于 2019年08月15日 · 2898 次阅读

Reliable 官网:https://macacajs.github.io/reliable/zh/guide/

Reliable 是 Macaca 的持续交付服务套件,提供测试通过率、覆盖率的趋势分析,排行,报警,主要解决持续集成期的测试结果归档和管理问题。对比老版本 Reliable,新版 Reliable 专注于对执行结果的归档,并与 Jenkins gitlab-ci 这类任务调度系统做集成。

Reliable 在设计上还是分为两个模块,上报客户端,Web 平台 (服务端),通信模式上遵循常规的 C/S 架构,接下来我们先看下如何将服务端部署玩转起来。

老相识,环境

环境问题是大家绕不过的第一步,为了避免过于麻烦,这里演示基于 Docker 的方案,参见 文档

通过 Docker compose 联合部署多项服务:

$ git clone https://github.com/macacajs/reliable.git --depth=1
$ cd reliable
$ docker-compose -p reliable -f docker-compose.yml up -d

有经验的同学可以自己尝试通过源码部署,但是也要自己解决数据库服务依赖等问题。

访问服务

hardcore paradite 为我们提供了种子数据,可以方便开箱即用。

注意:如果以前本机有常驻的 mysql 服务,在运行 reliable 前请关闭,避免冲突。

$ NODE_ENV=production npm run db:seed:all

通过访问 http://127.0.0.1:9900/ 就可以看到界面了。

上报数据

服务端已经 ok 了,再说说上报端。文档提供有 iOS,Android,Web 三种类型的工程示例。

$ git clone https://github.com/app-bootstrap/web-app-bootstrap.git --depth=1
$ cnpm i
$ npm run test
$ NOT_IN_DOCKER=1 BUILD_NUMBER=2 JOB_NAME=test RELIABLE_SERVER_URL=http://127.0.0.1:9900 npm run reliable

其他参考

共收到 3 条回复 时间 点赞

走到楼主访问服务 NODE_ENV=production npm run db:seed:all 这步的时候报错了,如下图所示:

Mzc-Test:reliable Mzc$ NODE_ENV=production npm run db:seed:all

> reliable-web@1.0.0 db:seed:all /usr/local/lib/node_modules/reliable
> sequelize db:seed:all

sh: sequelize: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! reliable-web@1.0.0 db:seed:all: `sequelize db:seed:all`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the reliable-web@1.0.0 db:seed:all script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

经过询问,发现需要在 reliable 这个目录下安装 npm 依赖,命令如下:

$ cd reliable
$ cnpm i 

安装完成后再次运行NODE_ENV=production npm run db:seed:all,就可以了,

Mzc-Test:reliable Mzc$ NODE_ENV=production npm run db:seed:all

> reliable-web@1.0.0 db:seed:all /usr/local/lib/node_modules/reliable
> sequelize db:seed:all


Sequelize CLI [Node: 11.0.0, CLI: 5.5.0, ORM: 4.44.2]

Loaded configuration file "database/config.js".
Using environment "production".
== 20180815163737-add-seed-to-table-jobNames: migrating =======
item
item
item
item
finish up
== 20180815163737-add-seed-to-table-jobNames: migrated (0.017s)

== 20180815172240-add-seed-to-table-builds: migrating =======
== 20180815172240-add-seed-to-table-builds: migrated (0.040s)

== 20180816055801-add-seed-to-table-configs: migrating =======
== 20180816055801-add-seed-to-table-configs: migrated (0.005s)


这个时候去访问http://127.0.0.1:9900/就可以看到界面了

再做个记录哈,看到有人报这个问题,如下:

Mzc-Test:reliable Mzc$ NODE_ENV=production npm run db:seed:all

> reliable-web@1.0.0 db:seed:all /usr/local/lib/node_modules/reliable
> sequelize db:seed:all


Sequelize CLI [Node: 11.0.0, CLI: 5.5.0, ORM: 4.44.2]

Loaded configuration file "database/config.js".
Using environment "production".

ERROR: connect ECONNREFUSED 127.0.0.1:3306

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reliable-web@1.0.0 db:seed:all: `sequelize db:seed:all`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the reliable-web@1.0.0 db:seed:all script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/Mzc/.npm/_logs/2019-07-25T09_51_47_063Z-debug.log

是因为 docker 服务没有起来导致的,需要运行下面命令启动服务才可以
docker-compose -p reliable -f docker-compose.yml up -d

求助:运行完 npm run test 后,报如下错误

>> >> html reporter generated: /home/user/code/web-app-bootstrap/reports/index.html

>> >> json reporter generated: /home/user/code/web-app-bootstrap/reports/json-final.json

>> >> reporter config generated: /home/user/code/web-app-bootstrap/reports/config.json

>> Test completed!
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! web-app-bootstrap@1.0.5 test: `npm run clean:coverage && macaca run -d ./test --verbose`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the web-app-bootstrap@1.0.5 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2019-08-15T08_50_00_397Z-debug.log

运行完测试用例,报上述错误,且服务正常启动

CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS                       PORTS                               NAMES
d0f33e93d401        macacajs/reliable-web:v2   "./entrypoint.sh n..."   About an hour ago   Up About an hour (healthy)   0.0.0.0:9900->9900/tcp              reliable_web_1
172309ca2454        macacajs/reliable-mysql    "docker-entrypoint..."   About an hour ago   Up About an hour             0.0.0.0:3306->3306/tcp, 33060/tcp   reliable_mysql_1
f8a70aad9486        macacajs/reliable-nginx    "nginx -g 'daemon ..."   About an hour ago   Up About an hour             0.0.0.0:9920->80/tcp                reliable_static_1
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册