CT1*_*100 6 continuous-integration jestjs cypress github-actions
我想使用 Github Actions 进行 CI 并在合并分支之前运行测试。
我有一个存储库,其中包含我的服务器和前端(Nest 和 Angular)。
我正在使用 Cypress/Jest 进行测试。
我需要运行后端服务器才能通过前端 cypress 测试。
目前 GH Actions 不会进入下一步,因为后端进程正在运行 - 但这就是我需要发生的事情......
我应该如何设置才能将 GH Actions 用于 CI?
name: test
on: [push]
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OTHER_SECRETS: ${{ secrets.otherSecrets }}
jobs:
cypress-run:
runs-on: macos-11
steps:
# start cypress w/github action: https://github.com/cypress-io/github-action
- name: Setup Node.js environment
uses: actions/setup-node@v2.5.0
with:
node-version: '16.13.0'
- name: Checkout
uses: 'actions/checkout@v2'
- name: "Start Backend"
run: |
cd server &&
npm install &&
npm run build &&
npm run start:prod
- name: "Start Frontend"
run: |
npm install &&
npm run build &&
npm run start
- name: Cypress run
uses: cypress-io/github-action@v2
with:
record: true
browser: chrome
- name: "Run Jest Tests"
run: |
cd server &&
npm run test
Run Code Online (Sandbox Code Playgroud)
#note:我尝试将“&& sleep 10 && curl http://localhost:port -i”选项附加到 npm 命令中 - 但它对我不起作用。
#note2:这是我第一次使用 GH Actions,所以也许我错过了一些明显的东西!
#note:我尝试将“&& sleep 10 && curl http://localhost:port -i”选项附加到 npm 命令中 - 但它对我不起作用。
这里有一个轻微的错误,&&将等待上一个命令完成,只有在成功时才运行下一个命令&,将在后台运行上一个命令,然后继续运行下一个命令。因此,由于没有任何东西可以阻止您的服务器,因此&&无法工作。
我不确定这是最干净的方法,但以下方法应该可行,我在我的一个项目中使用了等效的方法来运行 UI。
- name: "Start Backend"
run: |
cd server &&
npm install &&
npm run build &&
npm run start:prod &
sleep 5 &&
curl http://localhost:port -I
- name: "Start Frontend"
run: |
npm install &&
npm run build &&
npm run start &
sleep 5 &&
curl http://localhost:port -I
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4263 次 |
| 最近记录: |