1

I wrote a test for my javascript application from the Actions part of git. 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:

{
  "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"
  }
}
1
  • Did you try to replace your run: npm test into run: npm run test in your yml file?. Oh nevermind, you don't have test script in your package.json to begin with Commented Jul 26, 2022 at 6:59

1 Answer 1

3

That is happening because when Github Actions is trying to run this part of the worflow:

  • name: Run test

    run: npm test

npm does not find a "test" script in your 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:

 "scripts": {
        "start": "vite",
        "dev": "vite",
        "build": "vite build",
        "serve": "vite preview",
        "test": "echo \"Error: no test specified\" && exit 1"
      },
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply, but I was expecting git to create tests for the whole project and later on updates. Does this mean that I have to explicitly add tests in my application in order for git to perform only these tests.
You will have to create your own unit tests or similar using a JS testing framework such as JEST which is pretty much the most popular framework for React apps. It's probably best to follow a tutorial such as this one here: testim.io/blog/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.