如何使用cypress github动作修复缺失的构建脚本?



我尝试添加一个github动作,它应该使用cypress测试我的应用程序。

我的workflowfile是这样的:

name: Cypress Tests
on: [push]
jobs:
cypress-run:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./client
steps:
- name: Checkout
uses: actions/checkout@v2
# Install NPM dependencies, cache them correctly
# and run all Cypress tests
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: 14
- name: Test
run: |
ls
cat package.json
- name: Cypress run
uses: cypress-io/github-action@v2.11.7
with:
build: npm run build
start: npm start
- name: Test
run: ls

Test步骤包含cat package.json,它显示了包。Json文件,看起来像这样:

{
"name": "client",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
},
"dependencies": {
"@reduxjs/toolkit": "^1.6.1",
"axios": "^0.21.4",
"framer-motion": "^4.1.17",
"next": "11.1.2",
"phosphor-react": "^1.3.1",
"qs": "^6.10.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-leaflet": "^3.2.1",
"react-redux": "^7.2.5",
"uuid": "^8.3.2",
"cypress": "^8.6.0"
},
"devDependencies": {
"autoprefixer": "^10.3.4",
"cypress": "^8.6.0",
"eslint": "7.32.0",
"eslint-config-next": "11.1.2",
"postcss": "^8.3.6",
"tailwindcss": "^2.2.15"
}
}

您可以看到有一个构建脚本,但是当工作流运行时,它会抛出这个错误:

build app command "npm run build"
current working directory "/home/runner/work/mlc/mlc"
/opt/hostedtoolcache/node/14.18.0/x64/bin/npm run build
npm ERR! missing script: build
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-10-17T11_04_01_715Z-debug.log
Error: The process '/opt/hostedtoolcache/node/14.18.0/x64/bin/npm' failed with exit code 1

我不知道为什么会发生这种情况,因为包。Json证明,有一个构建脚本。

您必须添加:working-directory: clientwith:内Cypress运行如下:

name: Cypress Tests

on: [push]

jobs:   cypress-run:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# Install NPM dependencies, cache them correctly
# and run all Cypress tests
- name: Cypress run
uses: cypress-io/github-action@v2
with:
working-directory: client
build: npm run build
start: npm start