我有一个包含笑话测试的 React 应用程序。要执行测试,需要输入命令 yarn web:test:ui。此命令至少要执行 20 个测试。
在本地计算机中运行时,测试正确完成,并且笑话本身会生成摘要报告。
当在 github actions runner 中运行相同的代码时,会进行测试,但不会生成摘要报告。
github/workflow 的 yml 文件如下:
name: Run UI Tests with Enhanced Reporting
on:
push:
branches: ["main"] # Adjust branch(es) as needed
jobs:
test:
runs-on: ubuntu-latest # Adjust runner OS as needed
steps:
- uses: actions/checkout@v3 # Checkout the repository code
- name: Use Node.js with yarn
uses: actions/setup-node@v3
with:
node-version: 19.9.0 # Adjust Node.js version as needed
- name: get yarn cache dir path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v3
id: yarn-cache
# use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install project dependencies
# if: steps.yarn-cache.outputs.cache-hit != 'false'
run: yarn --prefer-offline #yarn install
- name: Run UI tests
continue-on-error: true
run: |
cd ./packages
yarn web:test:ui > test-results.txt # Capture test output
- name: Upload test results
uses: actions/upload-artifact@v3
with:
name: test-results.txt
path: test-results.txt
- name: Store exit code
id: store-exit-code
continue-on-error: true
run: echo "::set-output name=exit-code::$(yarn web:test:ui)"
- name: Check test results
if: steps.store-exit-code.outputs.exit-code != 0
run: echo "Test suite failed with exit code ${{ steps.store-exit-code.outputs.exit-code }}"
tldr:在本地机器中运行时会生成摘要报告,但在 github actions 的运行程序中不会生成。
我尝试过使用 --coverage --verbose 等标志,但没有效果。
我有一个包含笑话测试的 React 应用程序。要执行测试,需要输入命令 yarn web:test:ui。此命令至少要执行 20 个测试。
在本地计算机中运行时,测试正确完成,并且笑话本身会生成摘要报告。
当在 github actions runner 中运行相同的代码时,会进行测试,但不会生成摘要报告。
github/workflow 的 yml 文件如下:
name: Run UI Tests with Enhanced Reporting
on:
push:
branches: ["main"] # Adjust branch(es) as needed
jobs:
test:
runs-on: ubuntu-latest # Adjust runner OS as needed
steps:
- uses: actions/checkout@v3 # Checkout the repository code
- name: Use Node.js with yarn
uses: actions/setup-node@v3
with:
node-version: 19.9.0 # Adjust Node.js version as needed
- name: get yarn cache dir path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v3
id: yarn-cache
# use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install project dependencies
# if: steps.yarn-cache.outputs.cache-hit != 'false'
run: yarn --prefer-offline #yarn install
- name: Run UI tests
continue-on-error: true
run: |
cd ./packages
yarn web:test:ui > test-results.txt # Capture test output
- name: Upload test results
uses: actions/upload-artifact@v3
with:
name: test-results.txt
path: test-results.txt
- name: Store exit code
id: store-exit-code
continue-on-error: true
run: echo "::set-output name=exit-code::$(yarn web:test:ui)"
- name: Check test results
if: steps.store-exit-code.outputs.exit-code != 0
run: echo "Test suite failed with exit code ${{ steps.store-exit-code.outputs.exit-code }}"
tldr:在本地机器中运行时会生成摘要报告,但在 github actions 的运行程序中不会生成。
我尝试过使用 --coverage --verbose 等标志,但没有效果。
您可以为此使用 github 操作 链接 - https://github.com/MishaKav/jest-coverage-comment
- name: Jest Coverage Comment
uses: MishaKav/jest-coverage-comment@main
with:
coverage-summary-path: ./coverage/coverage-summary.json
title: My Jest Coverage Comment
summary-title: My Summary Title
badge-title: Coverage
hide-comment: false
create-new-comment: false
hide-summary: false
junitxml-title: My JUnit Title
junitxml-path: ./coverage/junit.xml
coverage-title: My Coverage Title
coverage-path: ./coverage.txt