Skip to content

Commit 2405600

Browse files
committed
ci: add e2e setup script
1 parent b53f490 commit 2405600

File tree

5 files changed

+446
-31
lines changed

5 files changed

+446
-31
lines changed

.github/workflows/end-to-end-tests.yml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: End-to-end tests CI
2-
on: [pull_request]
2+
on: [pull_request, workflow_dispatch]
33
jobs:
44
test:
55
runs-on: ubuntu-latest
@@ -8,20 +8,13 @@ jobs:
88
- name: Test using Node.js
99
uses: actions/setup-node@v1
1010
with:
11-
node-version: "v20.11.0"
11+
node-version: "v22"
1212
- name: Install dependencies
1313
run: npm install
14-
- name: Install http-server
15-
run: npm install -g http-server pm2
16-
- name: Build e2e outputs
17-
run: npm run dev:e2e
18-
- name: Build production outputs
19-
run: npm run build
20-
21-
- name: Start up mock server
22-
run: |
23-
pm2 start 'http-server ./test-e2e/example -p 12345'
24-
pm2 start 'http-server ./test-e2e/example -p 12346'
14+
- name: Setup e2e environment
15+
run: bash script/setup-e2e.sh --all
16+
- name: Start test servers
17+
run: bash script/setup-e2e.sh --start-servers
2518

2619
- name: Run tests
2720
env:

CONTRIBUTING.md

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ npm run build:firefox
8585
npm run build:safari
8686
```
8787

88-
### 5. Testing Your Extension
88+
### 5. Debugging
8989

9090
#### Chrome/Edge
9191

@@ -126,23 +126,24 @@ This will generate coverage reports in the `coverage/` directory.
126126
127127
#### Setup E2E Testing
128128

129-
1. Build the test environment:
129+
Use the provided setup script to initialize the e2e testing environment:
130130

131131
```shell
132-
npm run dev:e2e
133-
npm run build
132+
# Initialize e2e environment (install dependencies and build outputs)
133+
bash script/setup-e2e.sh --init --build
134+
135+
# Start test servers
136+
bash script/setup-e2e.sh --start-servers
134137
```
135138

136-
2. Start test servers:
139+
The setup script will:
137140

138-
```shell
139-
npm install -g http-server pm2
140-
141-
pm2 start 'http-server ./test-e2e/example -p 12345'
142-
pm2 start 'http-server ./test-e2e/example -p 12346'
143-
```
141+
- Install/upgrade global dependencies (`http-server`, `pm2`)
142+
- Download browser for Puppeteer (if needed)
143+
- Build e2e test output (`dist_e2e/`)
144+
- Start test servers on ports 12345 and 12346
144145

145-
3. Run E2E tests:
146+
#### Run E2E Tests
146147

147148
```shell
148149
npm run test-e2e
@@ -157,6 +158,35 @@ export USE_HEADLESS_PUPPETEER=true
157158
npm run test-e2e
158159
```
159160

161+
#### Stop Test Servers
162+
163+
After testing, stop the servers:
164+
165+
```shell
166+
pm2 stop all && pm2 delete all
167+
```
168+
169+
#### Setup Script Options
170+
171+
The `setup-e2e.sh` script supports multiple options:
172+
173+
```shell
174+
# Show help
175+
bash script/setup-e2e.sh --help
176+
177+
# Initialize only (install dependencies)
178+
bash script/setup-e2e.sh --init
179+
180+
# Build e2e output only
181+
bash script/setup-e2e.sh --build
182+
183+
# Initialize and build
184+
bash script/setup-e2e.sh --init --build
185+
186+
# Run all steps (init + build + build production)
187+
bash script/setup-e2e.sh --all
188+
```
189+
160190
## Code Quality
161191

162192
### Code Formatting
@@ -234,7 +264,8 @@ time-tracker-4-browser/
234264
├── types/ # TypeScript declarations
235265
├── rspack/ # Build configuration
236266
├── script/ # Build and utility scripts
237-
│ └── android-firefox.sh # Android development helper
267+
│ ├── android-firefox.sh # Android development helper
268+
│ └── setup-e2e.sh # E2E test environment setup
238269
├── public/ # Static assets
239270
├── doc/ # Documentation
240271
├── dist_dev/ # Chrome/Edge dev build

jest.config.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
import { type Config } from "@jest/types"
2-
import { compilerOptions } from './tsconfig.json'
1+
import { readFileSync } from 'fs'
2+
import type { Config } from "jest"
3+
import { dirname, join } from 'path'
4+
import { fileURLToPath } from 'url'
5+
6+
const __filename = fileURLToPath(import.meta.url)
7+
const __dirname = dirname(__filename)
8+
const tsconfig = JSON.parse(readFileSync(join(__dirname, 'tsconfig.json'), 'utf-8'))
9+
const { compilerOptions } = tsconfig
310

411
const { paths } = compilerOptions
512

@@ -13,7 +20,7 @@ Object.entries(paths).forEach(([alias, sourceArr]) => {
1320
if (!aliasMatch) {
1421
return
1522
}
16-
if (sourceArr.length !== 1) {
23+
if (!Array.isArray(sourceArr) || sourceArr.length !== 1) {
1724
return
1825
}
1926
const sourceMath = sourceArr[0]?.match(sourcePattern)
@@ -30,7 +37,7 @@ Object.entries(paths).forEach(([alias, sourceArr]) => {
3037
console.log("The moduleNameMapper parsed from tsconfig.json: ")
3138
console.log(moduleNameMapper)
3239

33-
const config: Config.InitialOptions = {
40+
const config: Config = {
3441
moduleNameMapper,
3542
roots: [
3643
"<rootDir>/test",

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"@swc/jest": "^0.2.39",
3939
"@types/chrome": "0.1.29",
4040
"@types/decompress": "^4.2.7",
41-
"@types/jest": "^30.0.0",
4241
"@types/node": "^24.10.1",
4342
"@types/punycode": "^2.1.4",
4443
"@vue/babel-plugin-jsx": "^2.0.1",

0 commit comments

Comments
 (0)