Skip to content

Commit c79e0fd

Browse files
committed
feat(FR-1329): add a github action for regression test
1 parent 2357539 commit c79e0fd

File tree

4 files changed

+170
-8
lines changed

4 files changed

+170
-8
lines changed

.github/workflows/e2e-test.yml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# .github/workflows/playwright.yml
2+
name: Playwright Tests
3+
4+
on:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
runs-on: [self-hosted, linux, x64]
10+
permissions:
11+
checks: write
12+
pull-requests: write
13+
contents: read
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
lts:
18+
- name: "v25.6"
19+
apiEndpoint: "http://10.122.10.224:8090"
20+
- name: "v24.09"
21+
apiEndpoint: "http://10.122.10.224:8090"
22+
23+
name: E2E Playwright Tests for LTS ${{ matrix.lts.name }}
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
- uses: pnpm/action-setup@v4
29+
name: Install pnpm
30+
with:
31+
version: latest
32+
run_install: false
33+
34+
- uses: actions/setup-node@v4
35+
name: Install Node.js
36+
with:
37+
node-version-file: ".nvmrc"
38+
cache: "pnpm"
39+
40+
- name: Get pnpm store directory
41+
shell: bash
42+
run: |
43+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
44+
45+
- uses: actions/cache@v4
46+
name: Setup pnpm cache
47+
with:
48+
path: ${{ env.STORE_PATH }}
49+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
50+
restore-keys: |
51+
${{ runner.os }}-pnpm-store-
52+
53+
- name: Install dependencies
54+
run: pnpm install
55+
56+
- name: Install Playwright Browsers
57+
run: pnpm exec playwright install --with-deps
58+
59+
- name: Copy config.toml.sample to config.toml
60+
run: |
61+
awk '
62+
/^[[:space:]]*$/ { next }
63+
/^\[.*\]$/ { if (n++) print ""; print; next }
64+
/^[[:space:]]*#[^=]/ { print; next }
65+
{
66+
line = $0
67+
sub(/#.*/, "", line)
68+
sub(/[[:space:]]+$/, "", line)
69+
if (line != "") print line
70+
}
71+
' config.toml.sample > config-cleaned.toml
72+
73+
- name: Inject apiEndpoint and allowChangeSigninMode into config.toml
74+
run: |
75+
EP="${{ matrix.lts.apiEndpoint }}"
76+
awk -v ep="$EP" '
77+
{
78+
if ($0 ~ /^apiEndpoint[[:space:]]*=/) {
79+
print "apiEndpoint = \"" ep "\""
80+
} else if ($0 ~ /^allowChangeSigninMode[[:space:]]*=/) {
81+
print "allowChangeSigninMode = true"
82+
} else {
83+
print
84+
}
85+
}
86+
' config-cleaned.toml > config.toml
87+
88+
- name: Upload config.toml artifact
89+
uses: actions/upload-artifact@v4
90+
with:
91+
name: config-toml-${{ matrix.lts.name }}
92+
path: config.toml
93+
94+
# - name: Run Relay
95+
# run: pnpm run relay
96+
97+
# - name: Build project
98+
# run: pnpm run build
99+
100+
# - name: Serve build at port 9081 (background)
101+
# run: |
102+
# npx serve -s -l 9081 > /dev/null 2>&1 &
103+
# echo "Waiting for server to start..."
104+
# for i in {1..30}; do
105+
# if curl -s http://127.0.0.1:9081 > /dev/null; then
106+
# echo "Server is up!"
107+
# break
108+
# fi
109+
# sleep 1
110+
# done
111+
112+
# - name: Prepare .env.playwright with local server URL
113+
# run: |
114+
# cp e2e/envs/.env.playwright.sample e2e/envs/.env.playwright
115+
# if grep -q '^BASE_URL=' e2e/envs/.env.playwright; then
116+
# sed -i 's|^BASE_URL=.*|BASE_URL=http://127.0.0.1:9081|' e2e/envs/.env.playwright
117+
# else
118+
# echo 'BASE_URL=http://127.0.0.1:9081' >> e2e/envs/.env.playwright
119+
# fi
120+
121+
- name: Run Relay
122+
run: pnpm run relay
123+
124+
- name: Build project
125+
run: pnpm run build
126+
127+
- name: Serve build at port 9081 (background)
128+
run: |
129+
pnpm server:p -s -l 9081 > /dev/null 2>&1 &
130+
echo "Waiting for server to start..."
131+
for i in {1..30}; do
132+
if curl -s http://127.0.0.1:9081 > /dev/null; then
133+
echo "Server is up!"
134+
break
135+
fi
136+
sleep 1
137+
done
138+
139+
- name: Run Playwright Tests
140+
run: pnpm playwright test e2e/agent.test.ts
141+
142+
- name: Upload HTML report (on failure)
143+
if: failure()
144+
uses: actions/upload-artifact@v4
145+
with:
146+
name: playwright-report-${{ matrix.lts.name }}
147+
path: playwright-report/

e2e/utils/test-util.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ export async function login(
1414
await page.goto(webuiEndpoint);
1515
await page.getByLabel('Email or Username').fill(username);
1616
await page.getByRole('textbox', { name: 'Password' }).fill(password);
17-
await page.getByRole('textbox', { name: 'Endpoint' }).fill(endpoint);
17+
18+
const endpointInput = page.locator('#id_api_endpoint label');
19+
try {
20+
await endpointInput.waitFor({ state: 'visible', timeout: 1000 });
21+
await page.getByRole('textbox', { name: 'Endpoint' }).fill(endpoint);
22+
} catch (_e) {
23+
// Endpoint input not visible, skip filling it
24+
}
1825
await page.getByLabel('Login', { exact: true }).click();
1926
await page.waitForSelector('[data-testid="user-dropdown-button"]');
2027
}

playwright.config.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default defineConfig({
2323
/* Opt out of parallel tests on CI. */
2424
workers: process.env.CI ? 1 : undefined,
2525
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
26-
reporter: "html",
26+
reporter: process.env.CI ? [["html", { open: "never" }], ["list"]] : "html",
2727
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2828
use: {
2929
/* Base URL to use in actions like `await page.goto('/')`. */
@@ -72,9 +72,11 @@ export default defineConfig({
7272
// },
7373
],
7474
/* Run your local dev server before starting the tests */
75-
// webServer: {
76-
// command: 'npm run start',
77-
// url: 'http://127.0.0.1:3000',
78-
// reuseExistingServer: !process.env.CI,
79-
// },
75+
// webServer: process.env.CI
76+
// ? {
77+
// command: 'concurrently "npm run build:d" "npm run server:d"',
78+
// url: "http://127.0.0.1:9081",
79+
// timeout: 1000 * 60 * 5,
80+
// }
81+
// : undefined,
8082
});

tsconfig.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,11 @@
2525
"lib": ["es6", "dom", "es2016", "es2017", "es2020"],
2626
"preserveWatchOutput": true
2727
},
28-
"include": ["src/components/*", "src/plugins/*", "src/reducers/*", "src/*"]
28+
"include": [
29+
"src/components/*",
30+
"src/plugins/*",
31+
"src/reducers/*",
32+
"src/*",
33+
"playwright.config.ts"
34+
]
2935
}

0 commit comments

Comments
 (0)