Skip to content

Commit 4e7ce95

Browse files
author
echoVic
committed
feat(tests): 添加全面的单元测试、集成测试和端到端测试
重构测试目录结构,将mocks移动到support目录下 新增测试类型包括性能测试、快照测试和安全测试 添加测试辅助工具和断言库 完善测试覆盖率报告和CI集成
1 parent eb6a72b commit 4e7ce95

File tree

95 files changed

+4055
-1206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+4055
-1206
lines changed

.github/workflows/ci.yml

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ jobs:
5050
- name: Build shared package
5151
run: pnpm build:shared
5252

53-
- name: Run tests
54-
run: pnpm test
53+
- name: Run unit tests
54+
run: pnpm --filter @blade/cli test:unit
55+
56+
- name: Run integration tests
57+
run: pnpm --filter @blade/cli test:integration
58+
59+
- name: Run CLI tests
60+
run: pnpm --filter @blade/cli test:cli
5561

5662
- name: Run type check
5763
run: pnpm type-check
@@ -62,6 +68,112 @@ jobs:
6268
- name: Test CLI build
6369
run: pnpm --filter @blade/cli start -- --help
6470

71+
coverage:
72+
name: Test Coverage
73+
runs-on: ubuntu-latest
74+
needs: test
75+
76+
steps:
77+
- name: Checkout code
78+
uses: actions/checkout@v4
79+
80+
- name: Setup Bun
81+
uses: oven-sh/setup-bun@v2
82+
with:
83+
bun-version: latest
84+
85+
- name: Setup Node.js
86+
uses: actions/setup-node@v4
87+
with:
88+
node-version: '20.x'
89+
90+
- name: Install pnpm
91+
run: npm install -g pnpm@9
92+
93+
- name: Get pnpm store directory
94+
shell: bash
95+
run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
96+
97+
- name: Setup pnpm cache
98+
uses: actions/cache@v4
99+
with:
100+
path: ${{ env.STORE_PATH }}
101+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
102+
restore-keys: |
103+
${{ runner.os }}-pnpm-store-
104+
105+
- name: Install dependencies
106+
run: pnpm install --frozen-lockfile
107+
108+
- name: Build shared package
109+
run: pnpm build:shared
110+
111+
- name: Run tests with coverage
112+
run: pnpm --filter @blade/cli test:coverage
113+
114+
- name: Upload coverage to Codecov
115+
uses: codecov/codecov-action@v4
116+
with:
117+
files: ./packages/cli/coverage/lcov.info
118+
flags: unittests
119+
name: blade-cli-coverage
120+
fail_ci_if_error: false
121+
verbose: true
122+
env:
123+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
124+
125+
- name: Upload coverage artifacts
126+
uses: actions/upload-artifact@v4
127+
with:
128+
name: coverage-report
129+
path: packages/cli/coverage/
130+
retention-days: 7
131+
132+
security-tests:
133+
name: Security Tests
134+
runs-on: ubuntu-latest
135+
136+
steps:
137+
- name: Checkout code
138+
uses: actions/checkout@v4
139+
140+
- name: Setup Bun
141+
uses: oven-sh/setup-bun@v2
142+
with:
143+
bun-version: latest
144+
145+
- name: Setup Node.js
146+
uses: actions/setup-node@v4
147+
with:
148+
node-version: '20.x'
149+
150+
- name: Install pnpm
151+
run: npm install -g pnpm@9
152+
153+
- name: Get pnpm store directory
154+
shell: bash
155+
run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
156+
157+
- name: Setup pnpm cache
158+
uses: actions/cache@v4
159+
with:
160+
path: ${{ env.STORE_PATH }}
161+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
162+
restore-keys: |
163+
${{ runner.os }}-pnpm-store-
164+
165+
- name: Install dependencies
166+
run: pnpm install --frozen-lockfile
167+
168+
- name: Build shared package
169+
run: pnpm build:shared
170+
171+
- name: Run security tests
172+
run: pnpm --filter @blade/cli test:security
173+
174+
- name: Run npm audit
175+
run: pnpm audit --audit-level=high || true
176+
65177
code-quality:
66178
name: Code Quality
67179
runs-on: ubuntu-latest

TESTING_IMPROVEMENTS.md

Lines changed: 0 additions & 225 deletions
This file was deleted.

0 commit comments

Comments
 (0)