Skip to content

Commit cc3b6fa

Browse files
authored
⌨️🥢 ↝ [SSG-268]: Merge pull request #200 from Signal-K/SSG-268
🏸⌨️ ↝ [SSG-268]: Missions/entities as blocks/sections
2 parents 3b87545 + 118cbcb commit cc3b6fa

File tree

435 files changed

+9473
-11716
lines changed

Some content is hidden

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

435 files changed

+9473
-11716
lines changed

.DS_Store

2 KB
Binary file not shown.

.env.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Test Environment Variables
2+
NODE_ENV=test
3+
NEXTAUTH_URL=http://localhost:3000
4+
NEXT_PUBLIC_BASE_URL=http://localhost:3000
5+
6+
# Placeholder Supabase environment variables for testing
7+
NEXT_PUBLIC_SUPABASE_URL=https://placeholder.supabase.co
8+
NEXT_PUBLIC_SUPABASE_ANON_KEY=placeholder_key
9+
10+
# Skip problematic tests
11+
SKIP_USER_CREATION_TESTS=true

.github/workflows/cypress.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Test Suite
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
env:
14+
NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
15+
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
16+
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}
17+
SKIP_USER_CREATION_TESTS: true
18+
NODE_ENV: test
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: '18'
27+
cache: 'npm'
28+
29+
- name: Install dependencies
30+
run: npm ci
31+
32+
- name: Run unit tests
33+
run: npm run test:unit
34+
35+
- name: Install Cypress
36+
run: npm install cypress --save-dev --legacy-peer-deps
37+
38+
- name: Build Next.js app
39+
run: npm run build
40+
41+
- name: Run E2E tests
42+
run: npm run test:e2e

.github/workflows/e2e.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: E2E Tests
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
e2e-tests:
11+
runs-on: ubuntu-latest
12+
13+
services:
14+
postgres:
15+
image: postgres:13
16+
env:
17+
POSTGRES_PASSWORD: postgres
18+
POSTGRES_DB: test_db
19+
options: >-
20+
--health-cmd pg_isready
21+
--health-interval 10s
22+
--health-timeout 5s
23+
--health-retries 5
24+
ports:
25+
- 5432:5432
26+
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
31+
- name: Setup Node.js
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version: '18'
35+
cache: 'npm'
36+
37+
- name: Install dependencies
38+
run: npm ci --legacy-peer-deps
39+
40+
- name: Setup environment
41+
run: |
42+
echo "SKIP_USER_CREATION_TESTS=true" >> $GITHUB_ENV
43+
echo "NODE_ENV=test" >> $GITHUB_ENV
44+
45+
- name: Build application
46+
run: npm run build
47+
48+
- name: Start application
49+
run: |
50+
npm start &
51+
sleep 10
52+
env:
53+
NODE_ENV: production
54+
55+
- name: Run E2E tests
56+
run: npm run test:e2e:headless
57+
env:
58+
SKIP_USER_CREATION_TESTS: true
59+
60+
- name: Upload cypress screenshots
61+
uses: actions/upload-artifact@v4
62+
if: failure()
63+
with:
64+
name: cypress-screenshots
65+
path: cypress/screenshots
66+
67+
- name: Upload cypress videos
68+
uses: actions/upload-artifact@v4
69+
if: always()
70+
with:
71+
name: cypress-videos
72+
path: cypress/videos

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ public/sw.js
5555
public/workbox-7144475a.js
5656
public/workbox-7144475a.js.map
5757
public/workbox-f1770938.js
58-
certificates
58+
certificates
59+
.env.local

DOCKER_TESTING_GUIDE.md

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
# Docker Testing Environment Setup 🐳
2+
3+
## Overview
4+
Complete Docker setup for running unit and E2E tests in containerized environments, supporting both CI/CD and local development workflows.
5+
6+
## Files Created
7+
8+
### Docker Files
9+
- `test.dockerfile` - Specialized Dockerfile for testing with Cypress dependencies
10+
- `docker-compose.test.yml` - Complete testing environment with multiple profiles
11+
- Updated `compose.yml` - Added E2E testing service to development stack
12+
13+
### Updated Configuration
14+
- `cypress.config.ts` - Enhanced with Docker-specific settings and environment variables
15+
- `package.json` - Added Docker testing scripts
16+
17+
## Docker Testing Architecture
18+
19+
### 1. Test Dockerfile (`test.dockerfile`)
20+
```dockerfile
21+
# Key features:
22+
- Node.js 22 with Cypress dependencies
23+
- Pre-installed system packages for headless testing
24+
- Optimized for CI/CD environments
25+
- Built-in Cypress cache handling
26+
```
27+
28+
### 2. Development Integration (`compose.yml`)
29+
```yaml
30+
# New service added:
31+
e2e-tests:
32+
- Runs alongside development server
33+
- Uses profile-based activation
34+
- Configured for headless testing
35+
```
36+
37+
### 3. Dedicated Test Environment (`docker-compose.test.yml`)
38+
```yaml
39+
# Multiple testing profiles:
40+
- unit: Unit tests only
41+
- e2e: Headless E2E tests
42+
- local-test: E2E with user creation
43+
- all: Complete test suite
44+
```
45+
46+
## Usage
47+
48+
### Quick Commands
49+
50+
#### Run specific test types:
51+
```bash
52+
# Unit tests only
53+
npm run docker:test:unit
54+
55+
# E2E tests (headless, no user creation)
56+
npm run docker:test:e2e
57+
58+
# E2E tests with user creation (local development)
59+
npm run docker:test:e2e:local
60+
61+
# All tests (unit + E2E)
62+
npm run docker:test:all
63+
64+
# Clean up test containers and volumes
65+
npm run docker:test:clean
66+
```
67+
68+
#### Direct Docker Compose commands:
69+
```bash
70+
# Run E2E tests
71+
docker-compose -f docker-compose.test.yml --profile e2e up --build
72+
73+
# Run all tests
74+
docker-compose -f docker-compose.test.yml --profile all up --build
75+
76+
# Clean up
77+
docker-compose -f docker-compose.test.yml down --volumes
78+
```
79+
80+
### Development Workflow
81+
82+
#### 1. Add testing to development stack:
83+
```bash
84+
# Start development with testing capability
85+
docker-compose --profile test up
86+
87+
# In another terminal, run tests
88+
docker-compose exec e2e-tests yarn test:e2e:headless
89+
```
90+
91+
#### 2. Standalone testing:
92+
```bash
93+
# Start test environment
94+
docker-compose -f docker-compose.test.yml up nextapp-test
95+
96+
# Run tests when ready
97+
docker-compose -f docker-compose.test.yml --profile e2e up
98+
```
99+
100+
## Environment Configuration
101+
102+
### Environment Variables
103+
```env
104+
# .env.local for Docker testing
105+
NODE_ENV=test
106+
SKIP_USER_CREATION_TESTS=true # Set to false for local testing
107+
CYPRESS_baseUrl=http://nextapp-test:3000 # Auto-configured for Docker
108+
```
109+
110+
### Cypress Configuration
111+
- **Dynamic baseUrl**: Automatically uses Docker service URLs
112+
- **Extended timeouts**: Optimized for container startup times
113+
- **Video recording**: Enabled in CI environments
114+
- **Retry logic**: Built-in test retry for flaky network conditions
115+
116+
## Testing Profiles
117+
118+
### Profile: `unit`
119+
```bash
120+
npm run docker:test:unit
121+
```
122+
- Runs Vitest unit tests only
123+
- Fast execution
124+
- No external dependencies
125+
126+
### Profile: `e2e`
127+
```bash
128+
npm run docker:test:e2e
129+
```
130+
- Headless Cypress tests
131+
- No user creation (CI-friendly)
132+
- Full application testing
133+
134+
### Profile: `local-test`
135+
```bash
136+
npm run docker:test:e2e:local
137+
```
138+
- Includes user creation tests
139+
- Suitable for local development
140+
- Full feature testing
141+
142+
### Profile: `all`
143+
```bash
144+
npm run docker:test:all
145+
```
146+
- Complete test suite
147+
- Unit tests followed by E2E tests
148+
- Comprehensive validation
149+
150+
## CI/CD Integration
151+
152+
### GitHub Actions Integration
153+
```yaml
154+
# Add to your existing workflow:
155+
- name: Run Docker Tests
156+
run: |
157+
npm run docker:test:all
158+
159+
- name: Upload Test Artifacts
160+
uses: actions/upload-artifact@v4
161+
if: failure()
162+
with:
163+
name: test-results
164+
path: |
165+
cypress/screenshots
166+
cypress/videos
167+
```
168+
169+
### Docker Build Optimization
170+
```bash
171+
# Multi-stage builds for production
172+
docker build --target test -f test.dockerfile .
173+
174+
# Cache optimization
175+
docker-compose -f docker-compose.test.yml build --parallel
176+
```
177+
178+
## Troubleshooting
179+
180+
### Common Issues
181+
182+
#### 1. Cypress Cannot Connect
183+
```bash
184+
# Check if app is running
185+
docker-compose -f docker-compose.test.yml logs nextapp-test
186+
187+
# Verify network connectivity
188+
docker-compose -f docker-compose.test.yml exec e2e-tests-headless curl http://nextapp-test:3000
189+
```
190+
191+
#### 2. Permission Issues
192+
```bash
193+
# Fix Cypress cache permissions
194+
docker-compose -f docker-compose.test.yml exec e2e-tests-headless chown -R node:node /app/.cypress
195+
```
196+
197+
#### 3. Out of Memory
198+
```bash
199+
# Increase Docker memory limits
200+
docker-compose -f docker-compose.test.yml up --scale e2e-tests-headless=1
201+
```
202+
203+
### Performance Optimization
204+
205+
#### 1. Build Cache
206+
```bash
207+
# Use Docker buildkit for faster builds
208+
DOCKER_BUILDKIT=1 docker-compose -f docker-compose.test.yml build
209+
```
210+
211+
#### 2. Parallel Testing
212+
```bash
213+
# Run tests in parallel (requires Cypress Dashboard)
214+
docker-compose -f docker-compose.test.yml up --scale e2e-tests-headless=2
215+
```
216+
217+
## Monitoring and Debugging
218+
219+
### View Logs
220+
```bash
221+
# All services
222+
docker-compose -f docker-compose.test.yml logs -f
223+
224+
# Specific service
225+
docker-compose -f docker-compose.test.yml logs -f e2e-tests-headless
226+
```
227+
228+
### Interactive Debugging
229+
```bash
230+
# Enter test container
231+
docker-compose -f docker-compose.test.yml exec e2e-tests-headless bash
232+
233+
# Run tests manually
234+
docker-compose -f docker-compose.test.yml exec e2e-tests-headless yarn test:e2e:open
235+
```
236+
237+
## Best Practices
238+
239+
### 1. Resource Management
240+
- Always clean up containers after testing
241+
- Use profiles to run only necessary services
242+
- Monitor Docker resource usage
243+
244+
### 2. Test Isolation
245+
- Each test profile uses separate containers
246+
- Network isolation between test environments
247+
- Volume mounting for artifact collection
248+
249+
### 3. Environment Consistency
250+
- Same Node.js version across all environments
251+
- Consistent dependency installation
252+
- Environment variable parity
253+
254+
Your Docker testing environment is now fully configured and ready for both local development and CI/CD usage! 🚀

0 commit comments

Comments
 (0)