在 CI 上使用 Cypress 启动 rails 测试服务器
Starting a rails test server with Cypress on CI
如果我使用 RAILS_ENV=test rails server
启动 rails 服务器,然后 运行 连接 cypress run
,我可以在本地 运行 cypress 但我迷路了如何在 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)
用于后作业命令(一旦 rspec/cypress 完成 运行)
一种可能性是使用 start-server-and-test 库来启动并等待您的网络服务器然后 运行s cypress 的命令。
将以下行添加到您的 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
如果我使用 RAILS_ENV=test rails server
启动 rails 服务器,然后 运行 连接 cypress run
,我可以在本地 运行 cypress 但我迷路了如何在 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)
用于后作业命令(一旦 rspec/cypress 完成 运行)
一种可能性是使用 start-server-and-test 库来启动并等待您的网络服务器然后 运行s cypress 的命令。
将以下行添加到您的 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