Search code examples
github-actionsvitevitest

GitHub Action Vitest CI pipeline


I would like to create a CI pipeline with GitHub Action but I have problems. The front end of the project is developed in Vue 3 and uses vitest to run the tests. It's in a folder called "WEB" in the root directory. So I would like to run my tests at each commit in the master branch but it returns this error:

Error: .github#L1
each step must define a `uses` or `run` key

I used the preexisting "Node.js" template and just added the "working-directory" property to specify the "WEB" folder.

Here is my ".yml" file

name: Runs frontend tests

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [16.x]

    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node-version }}
        working-directory: ./WEB
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'
      - name: Execute Unit tests
      - run: npm ci
      - run: npm run test

Solution

  • When you add a - it add an element at the steps array:

    You should do it like this:

    - name: Execute Unit tests
      run: |
        npm ci
        npm run test