【问题标题】:How do I create a GitHub Action to run Jest tests with Yarn?如何创建 GitHub Action 以使用 Yarn 运行 Jest 测试?
【发布时间】:2023-12-22 16:14:01
【问题描述】:

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

package.json

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

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

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

【问题讨论】:

标签: node.js github jestjs yarnpkg github-actions


【解决方案1】:

使用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

【讨论】:

  • 请注意,yarn 在所有环境中都是 installed
  • 此工作流无法使用Run yarn test:unit:coverage yarn test:unit:coverage shell: /bin/bash -e {0} yarn run v1.22.5 error Command "test:unit:coverage" not found. My pacakge .json "test:unit:coverage": "jest --coverage", 进行测试
  • @smac89 是的,你是对的。此操作假定。该操作的目的是安装 Yarn 依赖项(在本例中为 Jest)并运行 Yarn 命令。
最近更新 更多