简体   繁体   English

npm ERR:使用 github 动作时缺少脚本“测试”

[英]npm ERR! Missing script: "test" when using github actions

I wrote a test for my javascript application from the Actions part of git.我从 git 的 Actions 部分为我的 javascript 应用程序编写了一个测试。 However, it does not work as expected.但是,它没有按预期工作。 Here it is:这里是:

# 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

However, when I run it, I get the following errors:但是,当我运行它时,我收到以下错误:

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.

I searched the internet for how to fix the problem and added the following line to my test file:我在互联网上搜索了如何解决该问题,并将以下行添加到我的测试文件中:

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

. . but without success.但没有成功。 Here is my package.json file:这是我的 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"
  }
}

That is happening because when Github Actions is trying to run this part of the worflow:这是因为当 Github Actions 试图运行这部分工作流时:

  • name: Run test名称:运行测试

    run: npm test运行:npm 测试

npm does not find a "test" script in your package.json: npm 在您的 package.json 中找不到“测试”脚本:

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

So if you don't have tests in your project you can get rid of "run: npm test" in your workflow or add a "test" script in your package.json:因此,如果您的项目中没有测试,您可以在工作流程中去掉“运行:npm 测试”或在 package.json 中添加“测试”脚本:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM