如何使用 cypress github 操作修复缺少的构建脚本?
Posted
技术标签:
【中文标题】如何使用 cypress github 操作修复缺少的构建脚本?【英文标题】:How to fix missing build script using cypress github actions? 【发布时间】:2021-12-04 18:47:05 【问题描述】:我尝试添加一个 github 操作,它应该使用 cypress 测试我的应用程序。
这是我的工作流文件的样子:
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
,其中显示了 package.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
我不知道为什么会发生这种情况,因为 package.json 有点证明存在构建脚本。
【问题讨论】:
【参考方案1】:您必须在 Cypress 中的 with:
之后添加:working-directory: client
,如下所示:
-
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
【讨论】:
以上是关于如何使用 cypress github 操作修复缺少的构建脚本?的主要内容,如果未能解决你的问题,请参考以下文章