Skip to content

Commit 71044c7

Browse files
Copilotintel352
andcommitted
Add GitHub workflows for Go and Playwright tests
Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
1 parent 02b0db2 commit 71044c7

File tree

4 files changed

+237
-0
lines changed

4 files changed

+237
-0
lines changed

.github/workflows/go-tests.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Go Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
name: Run Go tests
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version: '1.20'
21+
cache: true
22+
23+
- name: Build
24+
run: go build -v ./config/... ./handlers/... ./module/...
25+
26+
- name: Test
27+
run: |
28+
go test -v ./config/...
29+
go test -v ./handlers/...
30+
go test -v ./module/...
31+
go test -v ui_server_test.go
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Playwright API Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
name: Run Playwright API tests
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version: '1.20'
21+
cache: true
22+
23+
- name: Set up Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: '20'
27+
cache: 'npm'
28+
29+
- name: Install dependencies
30+
run: npm ci
31+
32+
- name: Create test configuration
33+
run: |
34+
cat > test_api_config.js << EOL
35+
// @ts-check
36+
const { defineConfig } = require('@playwright/test');
37+
38+
module.exports = defineConfig({
39+
testDir: './tests',
40+
timeout: 30 * 1000,
41+
expect: {
42+
timeout: 5000
43+
},
44+
reporter: [['line']],
45+
use: {
46+
baseURL: 'http://localhost:8080',
47+
},
48+
// Skip browser downloads
49+
skipInstallBrowsers: true,
50+
webServer: {
51+
command: 'go run test_api_server.go',
52+
port: 8080,
53+
reuseExistingServer: false,
54+
},
55+
});
56+
EOL
57+
58+
- name: Build Go code
59+
run: go build -v ./config/... ./handlers/... ./module/...
60+
61+
- name: Run Playwright API tests
62+
env:
63+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
64+
run: npx playwright test tests/ui/workflow-ui-server.test.js --config test_api_config.js
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Playwright E2E Tests
2+
3+
on:
4+
workflow_dispatch: # Manual trigger only, as it requires browser downloads
5+
push:
6+
branches: [ main ]
7+
paths:
8+
- 'ui/**'
9+
- 'tests/**'
10+
pull_request:
11+
branches: [ main ]
12+
paths:
13+
- 'ui/**'
14+
- 'tests/**'
15+
16+
jobs:
17+
test:
18+
name: Run Playwright E2E tests
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Set up Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version: '1.20'
28+
cache: true
29+
30+
- name: Set up Node.js
31+
uses: actions/setup-node@v4
32+
with:
33+
node-version: '20'
34+
cache: 'npm'
35+
36+
- name: Install dependencies
37+
run: npm ci
38+
39+
- name: Install Playwright browsers
40+
run: npx playwright install --with-deps chromium
41+
42+
- name: Create test configuration
43+
run: |
44+
cat > test_e2e_config.js << EOL
45+
// @ts-check
46+
const { defineConfig } = require('@playwright/test');
47+
48+
module.exports = defineConfig({
49+
testDir: './tests',
50+
timeout: 30 * 1000,
51+
expect: {
52+
timeout: 5000
53+
},
54+
fullyParallel: true,
55+
forbidOnly: true,
56+
retries: 2,
57+
workers: 1,
58+
reporter: [['html'], ['line']],
59+
use: {
60+
actionTimeout: 0,
61+
baseURL: 'http://localhost:8080',
62+
trace: 'on-first-retry',
63+
},
64+
projects: [
65+
{
66+
name: 'chromium',
67+
use: {
68+
browserName: 'chromium',
69+
},
70+
}
71+
],
72+
webServer: {
73+
command: 'go run test_api_server.go',
74+
port: 8080,
75+
reuseExistingServer: false,
76+
},
77+
});
78+
EOL
79+
80+
- name: Build Go code
81+
run: go build -v ./config/... ./handlers/... ./module/...
82+
83+
- name: Run Playwright E2E tests
84+
run: npx playwright test tests/ui/workflow-ui.spec.js --config test_e2e_config.js
85+
86+
- name: Upload test results
87+
if: always()
88+
uses: actions/upload-artifact@v4
89+
with:
90+
name: playwright-report
91+
path: playwright-report/
92+
retention-days: 30

test_api_server.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"log"
6+
"net/http"
7+
"os"
8+
"os/signal"
9+
"syscall"
10+
"time"
11+
12+
"github.com/GoCodeAlone/workflow/module"
13+
)
14+
15+
// Simple standalone test server for API tests
16+
func main() {
17+
// Create a UI server
18+
uiServer := module.NewUIServer("test-ui", ":8080", nil)
19+
20+
// Start HTTP server
21+
server := &http.Server{
22+
Addr: ":8080",
23+
Handler: uiServer,
24+
}
25+
26+
// Handle server shutdown
27+
stop := make(chan os.Signal, 1)
28+
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
29+
30+
// Start server in a goroutine
31+
go func() {
32+
log.Printf("Starting test API server on :8080")
33+
if err := server.ListenAndServe(); err != http.ErrServerClosed {
34+
log.Fatalf("Failed to start API server: %v", err)
35+
}
36+
}()
37+
38+
// Wait for shutdown signal
39+
<-stop
40+
log.Println("Shutting down server...")
41+
42+
// Allow up to 5 seconds for graceful shutdown
43+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
44+
defer cancel()
45+
46+
if err := server.Shutdown(ctx); err != nil {
47+
log.Fatalf("Server shutdown failed: %v", err)
48+
}
49+
log.Println("Server gracefully stopped")
50+
}

0 commit comments

Comments
 (0)