首页 > 解决方案 > 如何创建 GitHub Action 以使用 Yarn 运行 Jest 测试?

问题描述

我使用Yarn来运行我的Jest测试。

package.json

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

当我在 GitHub 中合并提交时,我想创建一个GitHub 操作来运行我的测试。Node Starter Workflow使用NPM 运行测试。但我想用 Yarn 运行它们。

如何创建一个操作来运行我的测试?

标签: node.jsgithubjestjsyarnpkggithub-actions

解决方案


使用Node Starter Workflow,但将 NPM 部分替换为 Yarn 命令。例如:

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

推荐阅读