如何创建 GitHub 操作以使用 Yarn 运行 Jest 测试?

Rya*_*yne 3 github node.js jestjs yarnpkg github-actions

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

package.json

{
  "scripts": {
    "test": "jest"
  }
}
Run Code Online (Sandbox Code Playgroud)
{
  "scripts": {
    "test": "jest"
  }
}
Run Code Online (Sandbox Code Playgroud)

当我在 GitHub 中合并提交时,我想创建一个GitHub 操作来运行我的测试。该节点启动工作流运行测试与NPM。但我想用 Yarn 运行它们。

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

Rya*_*yne 7

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

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
Run Code Online (Sandbox Code Playgroud)

  • 如您所知,“yarn”已[安装](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/software-installed-on-github-hosted-runners )在所有环境中 (4认同)
  • @smac89新链接:https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages#publishing-packages-using-yarn (2认同)