Skip to content

Commit 42115c8

Browse files
authored
Merge pull request g1879#684 from jumodada/feat/tests-support
feat: 增加测试覆盖
2 parents 6957a28 + b3f5c19 commit 42115c8

67 files changed

Lines changed: 6323 additions & 1 deletion

File tree

Some content is hidden

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

.coveragerc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[run]
2+
branch = True
3+
source =
4+
DrissionPage
5+
parallel = True
6+
omit =
7+
tests/*
8+
checks/*
9+
10+
[report]
11+
show_missing = True
12+
skip_covered = False
13+
14+
[xml]
15+
output = coverage.xml
16+
17+
[json]
18+
output = coverage.json
19+
20+
[html]
21+
directory = htmlcov
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
name: DrissionPage tests verification
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '17 3 * * *'
7+
pull_request:
8+
paths:
9+
- 'DrissionPage/**'
10+
- 'tests/**'
11+
- '.github/workflows/drissionpage-tests.yml'
12+
- 'requirements.txt'
13+
push:
14+
branches:
15+
- master
16+
- main
17+
- 'fix/**'
18+
- 'feat/**'
19+
paths:
20+
- 'DrissionPage/**'
21+
- 'tests/**'
22+
- '.github/workflows/drissionpage-tests.yml'
23+
- 'requirements.txt'
24+
25+
permissions:
26+
contents: read
27+
28+
concurrency:
29+
group: drissionpage-tests-${{ github.ref }}
30+
cancel-in-progress: false
31+
32+
jobs:
33+
tests:
34+
runs-on: ubuntu-latest
35+
timeout-minutes: 60
36+
env:
37+
DP_TESTS_REPORT_DIR: ${{ github.workspace }}/tests-artifacts/reports
38+
DP_TESTS_ARTIFACT_DIR: /tmp/dp-tests-artifacts
39+
DP_TESTS_PRE_VENV: /tmp/dp-tests-pre-venv
40+
DP_TESTS_TIMEOUT: '10'
41+
DP_TESTS_REQUIRE_BROWSER: '1'
42+
DP_TESTS_RUN_LOCAL_SSR: '1'
43+
DP_TEST_SITE_URL: http://127.0.0.1:4321
44+
DP_LOCAL_FIXTURE_URL: http://127.0.0.1:4321
45+
HAS_PRIVATE_FIXTURE: ${{ secrets.DP_PRIVATE_FIXTURE_URL != '' }}
46+
RUN_PRIVATE_FIXTURE: ${{ github.event_name != 'pull_request' && secrets.DP_PRIVATE_FIXTURE_URL != '' }}
47+
HAS_CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN != '' }}
48+
steps:
49+
- name: Checkout
50+
uses: actions/checkout@v7
51+
52+
- name: Checkout shared DrissionPage test site
53+
uses: actions/checkout@v7
54+
with:
55+
repository: jumodada/DrissionPage-test-site
56+
path: DrissionPage-test-site
57+
58+
- name: Set up Python
59+
uses: actions/setup-python@v6
60+
with:
61+
python-version: '3.11'
62+
cache: pip
63+
cache-dependency-path: requirements.txt
64+
65+
- name: Install Chrome
66+
id: setup-chrome
67+
uses: browser-actions/setup-chrome@v2
68+
with:
69+
install-dependencies: true
70+
71+
- name: Set up Node
72+
uses: actions/setup-node@v6
73+
with:
74+
node-version: '22'
75+
cache: npm
76+
cache-dependency-path: DrissionPage-test-site/package-lock.json
77+
78+
- name: Audit workflow quality
79+
run: python tests/check_workflow_quality.py
80+
81+
- name: Install Python dependencies
82+
run: |
83+
python -m pip install --upgrade pip
84+
python -m pip install -r requirements.txt
85+
python -m pip install coverage[toml]
86+
87+
- name: Build SSR test site
88+
working-directory: DrissionPage-test-site
89+
run: |
90+
npm ci
91+
npm run build
92+
93+
- name: Start local SSR test site
94+
working-directory: DrissionPage-test-site
95+
run: |
96+
nohup npm run dev -- --host 127.0.0.1 --port 4321 > "$RUNNER_TEMP/drissionpage-ssr-site.log" 2>&1 &
97+
echo $! > "$RUNNER_TEMP/drissionpage-ssr-site.pid"
98+
for _ in $(seq 1 60); do
99+
if curl -fsS "$DP_TEST_SITE_URL/api/health.json" >/dev/null; then
100+
exit 0
101+
fi
102+
sleep 1
103+
done
104+
cat "$RUNNER_TEMP/drissionpage-ssr-site.log"
105+
exit 1
106+
107+
- name: Run tests verification
108+
env:
109+
DP_BROWSER_PATH: ${{ steps.setup-chrome.outputs.chrome-path }}
110+
run: ./tests/ci.sh
111+
112+
- name: Upload coverage to Codecov
113+
if: ${{ always() && env.HAS_CODECOV_TOKEN == 'true' && hashFiles('tests-artifacts/reports/coverage/coverage.xml') != '' }}
114+
uses: codecov/codecov-action@v7
115+
with:
116+
token: ${{ secrets.CODECOV_TOKEN }}
117+
files: tests-artifacts/reports/coverage/coverage.xml
118+
flags: drissionpage
119+
name: drissionpage-tests
120+
disable_search: true
121+
fail_ci_if_error: false
122+
123+
- name: Record SSR fixture smoke eligibility
124+
if: always()
125+
run: |
126+
mkdir -p "$DP_TESTS_REPORT_DIR"
127+
{
128+
echo "event_name=$GITHUB_EVENT_NAME"
129+
echo "has_private_fixture=$HAS_PRIVATE_FIXTURE"
130+
echo "run_private_fixture=$RUN_PRIVATE_FIXTURE"
131+
echo "policy=run when event is not pull_request and DP_PRIVATE_FIXTURE_URL is configured"
132+
} > "$DP_TESTS_REPORT_DIR/ssr-smoke-eligibility.txt"
133+
134+
- name: Report remote SSR business flows (report-only)
135+
if: ${{ env.RUN_PRIVATE_FIXTURE == 'true' }}
136+
env:
137+
DP_BROWSER_PATH: ${{ steps.setup-chrome.outputs.chrome-path }}
138+
DP_TEST_SITE_URL: ${{ secrets.DP_PRIVATE_FIXTURE_URL }}
139+
DP_PRIVATE_FIXTURE_URL: ${{ secrets.DP_PRIVATE_FIXTURE_URL }}
140+
run: |
141+
python - <<'PY'
142+
import os
143+
from urllib.parse import urlparse
144+
145+
url = (os.environ.get("DP_PRIVATE_FIXTURE_URL") or "").strip()
146+
parsed = urlparse(url)
147+
tokens = {url, parsed.netloc}
148+
if parsed.scheme and parsed.netloc:
149+
tokens.add(f"{parsed.scheme}://{parsed.netloc}")
150+
for token in sorted(token for token in tokens if token):
151+
print(f"::add-mask::{token}")
152+
PY
153+
./tests/run.sh current \
154+
--browser-path "$DP_BROWSER_PATH" \
155+
--include-online \
156+
--case ssr_marketplace_flow \
157+
--case ssr_social_notes_mobile \
158+
--report-json "$DP_TESTS_REPORT_DIR/ssr-business-flows.json" \
159+
--report-md "$DP_TESTS_REPORT_DIR/ssr-business-flows.md"
160+
161+
- name: Report remote SSR full smoke known issue (report-only)
162+
if: ${{ env.RUN_PRIVATE_FIXTURE == 'true' }}
163+
env:
164+
DP_BROWSER_PATH: ${{ steps.setup-chrome.outputs.chrome-path }}
165+
DP_TEST_SITE_URL: ${{ secrets.DP_PRIVATE_FIXTURE_URL }}
166+
DP_PRIVATE_FIXTURE_URL: ${{ secrets.DP_PRIVATE_FIXTURE_URL }}
167+
run: |
168+
./tests/run.sh current \
169+
--browser-path "$DP_BROWSER_PATH" \
170+
--include-online \
171+
--case ssr_site_smoke \
172+
--report-json "$DP_TESTS_REPORT_DIR/ssr-full-smoke-known.json" \
173+
--report-md "$DP_TESTS_REPORT_DIR/ssr-full-smoke-known.md"
174+
175+
- name: Upload tests reports
176+
if: always()
177+
uses: actions/upload-artifact@v7
178+
with:
179+
name: drissionpage-tests-reports
180+
path: |
181+
tests-artifacts/reports
182+
/tmp/dp-tests-artifacts
183+
if-no-files-found: warn
184+
retention-days: 14

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,12 @@ dmypy.json
114114
# Pyre type checker
115115
.pyre/
116116
test*
117+
!tests/
118+
!tests/**
119+
/tests/**/__pycache__/
120+
/tests/**/*.py[cod]
117121
.idea
118-
tmp
122+
tmp
123+
# DrissionPage tests generated reports
124+
/reports/
125+
/tests/reports/

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# ✨️ 概述
22

3+
[![DrissionPage tests verification](https://github.com/jumodada/DrissionPage/actions/workflows/drissionpage-tests.yml/badge.svg)](https://github.com/jumodada/DrissionPage/actions/workflows/drissionpage-tests.yml)
4+
[![codecov](https://codecov.io/gh/jumodada/DrissionPage/branch/master/graph/badge.svg)](https://codecov.io/gh/jumodada/DrissionPage)
5+
36
DrissionPage 是一个基于 Python 的网页自动化工具。
47

58
简洁优雅,功能强大。

0 commit comments

Comments
 (0)