在对分支进行合并之前,我希望对CI使用Github操作并运行测试。
我有一个单独的存储库,其中有我的服务器和前端(Nest &角)。
我用Cypress/Jest做测试。
我需要我的后端服务器运行我的前端柏树测试通过。
目前GH操作并没有进入下一步,因为后端进程正在运行--但这正是我需要实现的.
我应该如何设置它,以便我可以使用GH动作的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#注意:我尝试过在npm命令中附加"&& leep10 && curl http://localhost:port -i“选项,但它对我来说并不管用。
注2:这是我第一次采取行动,所以也许我错过了一些显而易见的事情!!
发布于 2022-06-24 10:26:43
#注意:我尝试过在npm命令中添加"&& lew10 && curl http://localhost:port -i“选项,但它对我来说并不管用。
这里有一个小错误,&&将等待前面的命令完成,只有在成功的情况下才运行下一个命令,&将在后台运行前面的命令,然后继续运行下一个命令。因此,由于没有任何东西停止您的服务器,&&将无法工作。
我不确定这是最干净的方式,但以下应该是有效的,我已经使用了一个等价的运行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发布于 2022-11-07 23:24:12
我也遇到了同样的问题,服务器正在运行,但从未移动到运行Cypress测试的下一步。谢谢您的支持,只使用一个&已启动服务器,然后运行Cypress测试脚本工作了:
jobs:
build:
env:
CI: true
strategy:
matrix:
node-version: [14.x, 16.x]
runs-on: [ ubuntu-latest ]
steps:
- uses: actions/checkout@v2
- name: Use Node.js version ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install --prefix client
- run: npm install --prefix server
- run: npm install
- run: npm run build --prefix client
- run: npm run start --prefix server & npm run test客户端package.json中的脚本:
"build": "BUILD_PATH=../server/public react-scripts build"服务器package.json中的脚本:
"start": "node src/server.js" 根package.json中的脚本:
"test": "npx cypress run"https://stackoverflow.com/questions/70231685
复制相似问题