|
| 1 | +# TypeScript-Go Server Testing Guide |
| 2 | + |
| 3 | +## Setup |
| 4 | + |
| 5 | +### 1. Prerequisites |
| 6 | +- 1Password CLI (`op`) installed and configured |
| 7 | +- AWS CLI installed |
| 8 | +- Go 1.21+ installed |
| 9 | +- Access to S3 bucket credentials via `.env.op` |
| 10 | + |
| 11 | +### 2. Running the Server Locally |
| 12 | + |
| 13 | +```bash |
| 14 | +# From the server directory |
| 15 | +cd /Users/zcs/Code/zshannon/2025/typescript-go/server |
| 16 | + |
| 17 | +# Start the server with S3 credentials |
| 18 | +op run --env-file="../.env.op" -- go run . |
| 19 | +``` |
| 20 | + |
| 21 | +The server runs on port 8080 with metrics on port 9091. |
| 22 | + |
| 23 | +## Test Cases |
| 24 | + |
| 25 | +### 1. Health Check |
| 26 | +```bash |
| 27 | +curl -s http://localhost:8080/health | jq |
| 28 | +``` |
| 29 | + |
| 30 | +**Expected Output:** |
| 31 | +```json |
| 32 | +{ |
| 33 | + "status": "healthy", |
| 34 | + "version": "1.0.0", |
| 35 | + "uptime": "3s", |
| 36 | + "cache_size": "32 MB", |
| 37 | + "cache_entries": 2663 |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +### 2. Simple React Component |
| 42 | + |
| 43 | +Create test payload: |
| 44 | +```bash |
| 45 | +cat > /tmp/test-simple.json << 'EOF' |
| 46 | +{ |
| 47 | + "code": "import React from 'react';\nexport default () => React.createElement('div', null, 'Hello');", |
| 48 | + "version": "0.0.4" |
| 49 | +} |
| 50 | +EOF |
| 51 | +``` |
| 52 | + |
| 53 | +Test build: |
| 54 | +```bash |
| 55 | +curl -s -X POST http://localhost:8080/build \ |
| 56 | + -H "Content-Type: application/json" \ |
| 57 | + -d @/tmp/test-simple.json | jq |
| 58 | +``` |
| 59 | + |
| 60 | +**Expected:** Returns `{"code": "..."}` with compiled JavaScript. |
| 61 | + |
| 62 | +### 3. @crayonnow/core Import |
| 63 | + |
| 64 | +Create test payload: |
| 65 | +```bash |
| 66 | +cat > /tmp/test-core.json << 'EOF' |
| 67 | +{ |
| 68 | + "code": "import { Text } from '@crayonnow/core';\nexport default () => <Text>Hello</Text>;", |
| 69 | + "version": "0.0.4" |
| 70 | +} |
| 71 | +EOF |
| 72 | +``` |
| 73 | + |
| 74 | +Test build: |
| 75 | +```bash |
| 76 | +curl -s -X POST http://localhost:8080/build \ |
| 77 | + -H "Content-Type: application/json" \ |
| 78 | + -d @/tmp/test-core.json | jq keys |
| 79 | +``` |
| 80 | + |
| 81 | +**Expected:** `["code"]` - Successfully builds with @crayonnow/core dependencies. |
| 82 | + |
| 83 | +### 4. Complex Component (Meditation Timer) |
| 84 | + |
| 85 | +Create test payload: |
| 86 | +```bash |
| 87 | +cat > /tmp/test-meditation.json << 'EOF' |
| 88 | +{ |
| 89 | + "code": "import { Flex, Text, Button, Picker } from '@crayonnow/core';\nimport { useState, useEffect } from 'react';\n\nexport default () => {\n const [duration, setDuration] = useState('5');\n const [seconds, setSeconds] = useState(0);\n const [running, setRunning] = useState(false);\n\n const handleStartPause = () => {\n if (running) {\n setRunning(false);\n } else {\n if (seconds === 0) {\n setSeconds(parseInt(duration, 10) * 60);\n }\n setRunning(true);\n }\n };\n\n const handleReset = () => {\n setRunning(false);\n setSeconds(parseInt(duration, 10) * 60);\n };\n\n useEffect(() => {\n if (running && seconds > 0) {\n const timer = setTimeout(() => setSeconds(seconds - 1), 1000);\n return () => clearTimeout(timer);\n }\n if (running && seconds === 0) {\n setRunning(false);\n }\n }, [running, seconds]);\n\n const minutesDisplay = String(Math.floor(seconds / 60)).padStart(2, '0');\n const secondsDisplay = String(seconds % 60).padStart(2, '0');\n\n return (\n <Flex style={{ alignItems: 'stretch', minHeight: '100vh', background: '#e0f7fa', padding: '20px', rowGap: '16px' }}>\n <Text style={{ fontSize: '24px', fontWeight: '600', textAlign: 'center', color: '#006064' }}>\n Meditation Timer\n </Text>\n <Picker\n value={duration}\n onChange={(val) => {\n setDuration(val);\n setSeconds(parseInt(val, 10) * 60);\n setRunning(false);\n }}\n style={{ background: 'white', borderRadius: '8px', padding: '12px' }}\n >\n <Text value=\"5\">5 Minutes</Text>\n <Text value=\"10\">10 Minutes</Text>\n <Text value=\"15\">15 Minutes</Text>\n <Text value=\"20\">20 Minutes</Text>\n </Picker>\n <Text style={{ fontSize: '48px', fontWeight: 'bold', textAlign: 'center', color: '#004d40' }}>\n {minutesDisplay}:{secondsDisplay}\n </Text>\n <Button onClick={handleStartPause} style={{ background: running ? '#ff9800' : '#34C759', borderRadius: '8px', padding: '12px' }}>\n <Text style={{ color: 'white', textAlign: 'center', fontWeight: '600' }}>{running ? 'Pause' : 'Start'}</Text>\n </Button>\n <Button onClick={handleReset} style={{ background: '#f44336', borderRadius: '8px', padding: '12px' }}>\n <Text style={{ color: 'white', textAlign: 'center', fontWeight: '600' }}>Reset</Text>\n </Button>\n </Flex>\n );\n};", |
| 90 | + "version": "0.0.4" |
| 91 | +} |
| 92 | +EOF |
| 93 | +``` |
| 94 | + |
| 95 | +Test build: |
| 96 | +```bash |
| 97 | +# Check if it builds successfully (should return >100KB) |
| 98 | +curl -s -X POST http://localhost:8080/build \ |
| 99 | + -H "Content-Type: application/json" \ |
| 100 | + -d @/tmp/test-meditation.json | jq -r .code | wc -c |
| 101 | +``` |
| 102 | + |
| 103 | +**Expected:** Returns ~140KB of compiled JavaScript. |
| 104 | + |
| 105 | +### 5. Type Checking |
| 106 | + |
| 107 | +```bash |
| 108 | +# Test with type error |
| 109 | +cat > /tmp/test-type-error.json << 'EOF' |
| 110 | +{ |
| 111 | + "code": "export const hello: string = 123", |
| 112 | + "version": "0.0.4" |
| 113 | +} |
| 114 | +EOF |
| 115 | + |
| 116 | +curl -s -X POST http://localhost:8080/typecheck \ |
| 117 | + -H "Content-Type: application/json" \ |
| 118 | + -d @/tmp/test-type-error.json | jq |
| 119 | +``` |
| 120 | + |
| 121 | +**Expected Output:** |
| 122 | +```json |
| 123 | +{ |
| 124 | + "errors": [ |
| 125 | + { |
| 126 | + "message": "Type 'number' is not assignable to type 'string'.", |
| 127 | + "line": 1, |
| 128 | + "column": 30 |
| 129 | + } |
| 130 | + ] |
| 131 | +} |
| 132 | +``` |
| 133 | + |
| 134 | +### 6. Build with Type Validation |
| 135 | + |
| 136 | +```bash |
| 137 | +curl -s -X POST "http://localhost:8080/build?validate_types=true" \ |
| 138 | + -H "Content-Type: application/json" \ |
| 139 | + -d @/tmp/test-type-error.json | jq |
| 140 | +``` |
| 141 | + |
| 142 | +**Expected:** Returns type errors, not compiled code. |
| 143 | + |
| 144 | +## Production Testing |
| 145 | + |
| 146 | +Test against deployed server: |
| 147 | +```bash |
| 148 | +# Replace localhost:8080 with production URL |
| 149 | +curl -s -X POST https://server-wild-sea-9370.fly.dev/build \ |
| 150 | + -H "Content-Type: application/json" \ |
| 151 | + -d @/tmp/test-meditation.json | jq -r .code | wc -c |
| 152 | +``` |
| 153 | + |
| 154 | +## Cache Management |
| 155 | + |
| 156 | +### Flush Cache |
| 157 | +```bash |
| 158 | +curl -s -X POST http://localhost:8080/flush-cache | jq |
| 159 | +``` |
| 160 | + |
| 161 | +**Expected Output:** |
| 162 | +```json |
| 163 | +{ |
| 164 | + "status": "success", |
| 165 | + "message": "Cache flushed successfully", |
| 166 | + "entries_cleared": 238, |
| 167 | + "timestamp": 1756255182 |
| 168 | +} |
| 169 | +``` |
| 170 | + |
| 171 | +## Troubleshooting |
| 172 | + |
| 173 | +### Common Issues |
| 174 | + |
| 175 | +1. **"file not found" errors for npm packages** |
| 176 | + - Ensure packages are uploaded to S3 bucket |
| 177 | + - Check S3 bucket contents: `op run --env-file="../.env.op" -- aws s3 ls s3://fly-tsgo-node-modules/0.0.4/node_modules/ --endpoint-url="$AWS_ENDPOINT_URL_S3"` |
| 178 | + - Flush cache after uploading new packages |
| 179 | + |
| 180 | +2. **Port already in use** |
| 181 | + ```bash |
| 182 | + # Kill processes on ports |
| 183 | + lsof -ti:8080 | xargs kill -9 2>/dev/null |
| 184 | + lsof -ti:9091 | xargs kill -9 2>/dev/null |
| 185 | + ``` |
| 186 | + |
| 187 | +3. **Module resolution errors** |
| 188 | + - Enable logging by uncommenting log statements in server.go |
| 189 | + - Check logs for resolution paths: `grep "OnResolve" /tmp/server.log` |
| 190 | + |
| 191 | +## Performance Benchmarks |
| 192 | + |
| 193 | +```bash |
| 194 | +# Local testing |
| 195 | +hyperfine --warmup 3 --min-runs 10 \ |
| 196 | + 'curl -s -X POST http://localhost:8080/typecheck -H "Content-Type: application/json" -d @/tmp/test-meditation.json' \ |
| 197 | + 'curl -s -X POST http://localhost:8080/build -H "Content-Type: application/json" -d @/tmp/test-meditation.json' |
| 198 | +``` |
| 199 | + |
| 200 | +**Expected Performance:** |
| 201 | +- Typecheck: ~200ms (including network) |
| 202 | +- Build: ~150ms (including network) |
| 203 | +- Local: ~10-15ms |
0 commit comments