Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a GitHub Action to run Jest tests with Yarn?

I use Yarn to run my Jest tests.

package.json

{
  "scripts": {
    "test": "jest"
  }
}
yarn test

I want to create a GitHub action to run my tests when I merge commits in GitHub. The Node Starter Workflow runs tests with NPM. But I want to run them with Yarn.

How do I create an action to run my tests?

like image 511
Ryan Payne Avatar asked Dec 18 '19 19:12

Ryan Payne


People also ask

Can I use yarn in GitHub actions?

GitHub Actions for YarnThis Action for yarn enables arbitrary actions with the yarn command-line client, including testing packages and publishing to a registry. Please keep in mind that this Action was originally written for GitHub Actions beta (when Docker was the only way of doing things).

How do you run all tests of yarn?

Press `a` to run all tests, or run Jest with `--watchAll`. Watch Usage › Press a to run all tests. › Press f to run only failed tests. › Press p to filter by a filename regex pattern. › Press t to filter by a test name regex pattern. › Press q to quit watch mode. › Press Enter to trigger a test run.

What is the command to install Jest using yarn?

You can run Jest directly from the CLI (if it's globally available in your PATH , e.g. by yarn global add jest or npm install jest --global ) with a variety of useful options.


1 Answers

Use the Node Starter Workflow but replace the NPM portion with Yarn commands. For example:

name: Node CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x, 12.x]

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: yarn install
    - run: yarn test
like image 170
Ryan Payne Avatar answered Sep 23 '22 23:09

Ryan Payne