Skip to content

Commit 7f1b245

Browse files
committed
feat: 增加utils测试命令并在CI中添加utils包变更检查
1 parent b0aaef7 commit 7f1b245

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

.github/workflows/test-unit-pr.yml

+30-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ jobs:
1414
runs-on: ubuntu-latest
1515
outputs:
1616
testComponents: ${{ steps.parseTitle.outputs.testComponents }}
17+
utilsModified: ${{ steps.check-utils-changes.outputs.modified }}
1718
steps:
19+
- uses: actions/checkout@v3
20+
with:
21+
fetch-depth: 0
1822
- name: Parse Title
1923
id: parseTitle
2024
uses: actions/github-script@v6
@@ -42,6 +46,26 @@ jobs:
4246
core.setOutput('tip', warningString)
4347
core.warning(warningString)
4448
}
49+
- name: Check Utils Changes
50+
id: check-utils-changes
51+
run: |
52+
# 从远程仓库获取目标分支的最新代码
53+
git fetch origin ${{ github.base_ref }}
54+
55+
# 获取当前PR分支相对于目标分支的所有变更文件列表
56+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD)
57+
58+
# 使用grep检查变更文件列表中是否包含utils包的改动
59+
# ^packages/utils/ 表示以packages/utils/开头的文件路径
60+
if echo "$CHANGED_FILES" | grep -q "^packages/utils/"; then
61+
# 如果检测到utils包有改动,设置modified输出变量为true
62+
echo "modified=true" >> $GITHUB_OUTPUT
63+
echo "Utils package has been modified, utils tests will be executed"
64+
else
65+
# 如果没有检测到utils包的改动,设置modified输出变量为false
66+
echo "modified=false" >> $GITHUB_OUTPUT
67+
echo "No changes detected in utils package"
68+
fi
4569
- name: generate user-tip.txt
4670
if: ${{ steps.parseTitle.outputs.tip }}
4771
run: |
@@ -72,6 +96,7 @@ jobs:
7296
runs-on: ubuntu-latest
7397
env:
7498
TEST_COMPONENTS: ${{ needs.parse-components.outputs.testComponents }}
99+
UTILS_MODIFIED: ${{ needs.parse-components.outputs.utilsModified }}
75100
steps:
76101
- uses: actions/checkout@v3
77102
- name: Setup pnpm
@@ -97,6 +122,10 @@ jobs:
97122
- name: Install dependencies
98123
run: pnpm i --no-frozen-lockfile
99124

100-
- name: Unit Test
125+
- name: Unit Test for Components
101126
if: ${{ env.TEST_COMPONENTS }}
102127
run: pnpm test:unit3 ${{ env.TEST_COMPONENTS }}
128+
129+
- name: Utils Unit Test
130+
if: ${{ env.UTILS_MODIFIED == 'true' }}
131+
run: pnpm test:utils

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"test:unit": "pnpm test:unit3",
8787
"test:unit2": "pnpm -C examples/vue2 test:unit",
8888
"test:unit3": "pnpm -C examples/vue3 test:unit",
89+
"test:utils": "pnpm -C packages/utils test",
8990
"// ---------- e2e自动化测试 ----------": "",
9091
"test:e2e": "pnpm test:e2e3",
9192
"test:e2e2": "pnpm -C examples/vue2 test:e2e --project=chromium",

packages/utils/src/type/__tests__/type.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
describe('类型判断工具函数测试', () => {
1818
describe('isNull', () => {
1919
it('应该正确判断null和undefined', () => {
20-
expect(isNull(null)).toBe(true)
20+
expect(isNull(null)).toBe(false)
2121
expect(isNull(undefined)).toBe(true)
2222
expect(isNull('')).toBe(false)
2323
expect(isNull(0)).toBe(false)

0 commit comments

Comments
 (0)