[英]Starting a rails test server with Cypress on CI
如果我使用RAILS_ENV=test rails server
启动RAILS_ENV=test rails server
,然后运行cypress run
,我可以在本地运行cypress run
但我不知道如何在 CI 上执行此操作。
我正在使用 SemaphoreCI,它允许我在运行 rspec 之前拥有设置命令:
$ bundle install
$ npm install
$ bundle exec rake db:create db:migrate db:test:prepare --trace
其次是实际工作:
$ bundle exec rspec
根据cypress ,我不能使用cy.exec()
来启动 rails 服务器,我也不能运行rails server
作为我的最后一个设置命令,因为它不会退出。 我还能如何在 CI 上启动测试服务器以便我可以运行cypress run
?
我最终添加了RAILS_ENV=test bundle exec rails server -p 3000 -d
所以它在后台运行,然后kill -9 $(cat tmp/pids/server.pid)
用于 after job 命令(一旦 rspec/cypress 完成跑步)
一种可能性是使用start-server-and-test库来启动并等待您的 Web 服务器然后运行 cypress 的命令。
package.json
下行添加到您的package.json
:
{
"scripts": {
"test:e2e:ci": "start-server-and-test develop http://localhost:8000 cy:run"
}
}
然后让你的 CI 运行yarn test:e2e:ci
命令。
在 CircleCi 上,我将此步骤添加到配置中。
.cicleci\\config.yml
- run:
name: Rails Server
command: bundle exec rails server -e test -b 0.0.0.0 -p 5002
background: true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.