Skip to content

Commit 4389d59

Browse files
authored
test: add end-to-end tests for mobile adaptation (#113)
* fix: update mobile responsive styles based on test feedback * test: add end-to-end tests for mobile adaptation * chore: update pnpm-lock.yaml * chore: update lockfile with @playwright/test * fix(e2e-test): fix test failures * fix(e2e-test): resolve backend connection errors by setting DATABASE_HOST and REDIS_HOST in docker-compose.yml
1 parent b806e4e commit 4389d59

17 files changed

Lines changed: 331 additions & 98 deletions

File tree

.github/workflows/e2e-test.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Playwright E2E Tests
2+
3+
on:
4+
- pull_request
5+
- workflow_dispatch
6+
7+
jobs:
8+
e2e-test:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
checks: write
12+
pull-requests: write
13+
contents: write
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
- uses: pnpm/action-setup@v4
18+
name: Install pnpm
19+
with:
20+
version: 10
21+
run_install: false
22+
- name: Install Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 20
26+
cache: 'pnpm'
27+
- name: Install dependencies
28+
run: pnpm install --frozen-lockfile
29+
- name: Install Playwright browsers
30+
run: pnpm exec playwright install --with-deps
31+
- name: Start Backend Services
32+
run: |
33+
cd template/nestJs
34+
cp .env.example .env
35+
docker compose up -d
36+
- name: Wait for Backend Services
37+
run: |
38+
echo "Waiting for Backend Services to start..."
39+
timeout 120s bash -c 'until nc -z localhost 3000; do
40+
echo "Backend Services are starting..."
41+
sleep 3
42+
done'
43+
echo "Backend Services are ready!"
44+
cd template/nestJs && docker compose ps
45+
- name: Run E2E tests
46+
run: pnpm test:e2e

.github/workflows/unit-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jobs:
2727
- name: Install depend
2828
run: pnpm i
2929
- name: Run Unit Test without coverage
30-
run: pnpm test
30+
run: pnpm test:unit

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@
3838
"fix": "run-s fix:*",
3939
"fix:prettier": "prettier \"src/**/*.ts\" --write",
4040
"fix:tslint": "tslint --fix --project .",
41-
"test": "run-s build test:**",
41+
"test:unit": "run-s build test:lint test:unit:backend test:cov:backend",
42+
"test:all": "run-s build test:**",
4243
"test:lint": "tslint --project . && prettier \"src/**/*.ts\" --list-different",
4344
"test:unit:backend": "pnpm -F tiny-pro-nestjs test",
4445
"test:cov:backend": "pnpm -F tiny-pro-nestjs test:cov",
46+
"test:e2e": "playwright test",
4547
"watch": "run-s clean build:main && run-p \"build:main -- -w\" ",
4648
"cov": "run-s build test:unit cov:html && open-cli coverage/index.html",
4749
"cov:html": "nyc report --reporter=html",
@@ -84,6 +86,7 @@
8486
"devDependencies": {
8587
"@bitjson/npm-scripts-info": "^1.0.0",
8688
"@istanbuljs/nyc-config-typescript": "^1.0.2",
89+
"@playwright/test": "^1.55.0",
8790
"@types/fs-extra": "^11.0.4",
8891
"@types/inquirer": "^9.0.3",
8992
"@types/node": "^14.18.63",

playwright.config.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
export default defineConfig({
4+
workers: 1,
5+
timeout: 60_000,
6+
expect: { timeout: 10_000 },
7+
fullyParallel: false,
8+
forbidOnly: !!process.env.CI,
9+
retries: process.env.CI ? 2 : 1,
10+
reporter: [
11+
['list'],
12+
['html', { outputFolder: 'playwright-report', open: 'never' }]
13+
],
14+
use: {
15+
baseURL: 'http://localhost:3031/vue-pro',
16+
trace: 'on-first-retry',
17+
},
18+
projects: [
19+
// 手机
20+
{
21+
name: 'iPhone 12 Safari', // 390 * 664
22+
use: { ...devices['iPhone 12'] },
23+
testDir: './tests/e2e/mobile',
24+
},
25+
{
26+
name: 'Pixel 5', // 393 * 727
27+
use: { ...devices['Pixel 5'] },
28+
testDir: './tests/e2e/mobile',
29+
},
30+
// 平板
31+
{
32+
name: 'iPad (gen 5)', // 768 * 1024
33+
use: { ...devices['iPad (gen 5)'] },
34+
testDir: './tests/e2e/mobile',
35+
}
36+
],
37+
webServer: {
38+
command: 'pnpm start',
39+
cwd: 'template/tinyvue',
40+
url: 'http://localhost:3031/vue-pro',
41+
reuseExistingServer: true,
42+
timeout: 120_000
43+
}
44+
});

0 commit comments

Comments
 (0)