一尘不染

npm 错误!缺少脚本:使用 github 操作时的“test”

javascript

我从 git 的 Actions 部分为我的 javascript 应用程序编写了一个测试。但是,它没有按预期工作。这里是:

# This is a basic workflow to help you get started with Actions
name: Node.js CI Testing

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js
      uses: actions/setup-node@v2
      with:
        node-version: "16.x"

    - name: Install dependencies
      run: npm install --legacy-peer-deps

    - name: Run test

      run: npm test

但是,当我运行它时,我收到以下错误:

Run npm test
npm ERR! Missing script: "test"
npm ERR! 
npm ERR! To see a list of scripts, run:
npm ERR!   npm run

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2022-07-25T23_14_24_295Z-debug-0.log
Error: Process completed with exit code 1.

我在互联网上搜索了如何解决该问题,并将以下行添加到我的测试文件中:

 - name: Run test
          working-directory: ./src
          run: npm test

. 但没有成功。这是我的 package.json 文件:

{
  "name": "hydrogen",
  "version": "1.0",
  "scripts": {
    "start": "vite",
    "dev": "vite",
    "build": "vite build",
    "serve": "vite preview"
  },
  "devDependencies": {
    "autoprefixer": "^10.4.2",
    "postcss": "^8.4.5",
    "tailwindcss": "^3.0.18",
    "vite": "^2.7.13",
    "vite-plugin-solid": "^2.2.5"
  },
  "dependencies": {
    "@tailwindcss/forms": "^0.4.0",
       ...
    "solid-js": "^1.3.3"
  }
}

阅读 80

收藏
2022-07-27

共1个答案

一尘不染

这是因为当 Github Actions 试图运行这部分工作流时:

  • 名称:运行测试

运行:npm 测试

npm 在您的 package.json 中找不到“测试”脚本:

"scripts": {
    "start": "vite",
    "dev": "vite",
    "build": "vite build",
    "serve": "vite preview"
  },

因此,如果您的项目中没有测试,您可以在工作流程中去掉“run: npm test”,或者在 package.json 中添加“test”脚本:

 "scripts": {
        "start": "vite",
        "dev": "vite",
        "build": "vite build",
        "serve": "vite preview",
        "test": "echo \"Error: no test specified\" && exit 1"
      },
2022-07-27