-
Notifications
You must be signed in to change notification settings - Fork 4
269 lines (233 loc) · 9.55 KB
/
Copy pathjavascript-tests.yml
File metadata and controls
269 lines (233 loc) · 9.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
name: JavaScript Tests
on:
push:
branches: [ main, develop ]
paths:
- 'dist/javascript/**'
- '.github/workflows/javascript-tests.yml'
pull_request:
branches: [ main ]
paths:
- 'dist/javascript/**'
- '.github/workflows/javascript-tests.yml'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: 'dist/javascript/package-lock.json'
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Install wasm-pack
run: cargo install wasm-pack
- name: Build WebAssembly
run: |
# Build the WASM package from core directory
cd core
wasm-pack build --target web --out-dir ../dist/javascript/wasm
# List what was generated
echo "Generated WASM files:"
ls -la ../dist/javascript/wasm/
# Verify the expected file exists
if [ -f "../dist/javascript/wasm/fastgeotoolkit.js" ]; then
echo "✅ fastgeotoolkit.js found"
echo "Content preview:"
head -10 ../dist/javascript/wasm/fastgeotoolkit.js
echo ""
echo "Exports inspection:"
# Look for export patterns
grep -n "export" ../dist/javascript/wasm/fastgeotoolkit.js | head -5
echo ""
echo "File size and permissions:"
ls -lh ../dist/javascript/wasm/fastgeotoolkit.js
else
echo "❌ fastgeotoolkit.js not found"
echo "Available files:"
find ../dist/javascript/wasm/ -name "*.js" -o -name "*.wasm"
# Try to find any JS files and see what they're named
echo "All JS files in wasm directory:"
find ../dist/javascript/wasm/ -name "*.js" -exec basename {} \;
fi
# Check all files generated
echo ""
echo "All generated files with details:"
find ../dist/javascript/wasm/ -type f -exec ls -lh {} \;
# Check if there are any background JS files
if [ -f "../dist/javascript/wasm/fastgeotoolkit_bg.js" ]; then
echo ""
echo "✅ Found background JS file:"
head -5 ../dist/javascript/wasm/fastgeotoolkit_bg.js
fi
# Also check the parent directory structure
echo "JavaScript directory structure:"
ls -la ../dist/javascript/
# Verify WASM files have correct MIME types would be served
echo ""
echo "WASM file verification:"
if [ -f "../dist/javascript/wasm/fastgeotoolkit_bg.wasm" ]; then
echo "✅ WASM binary file exists: $(ls -lh ../dist/javascript/wasm/fastgeotoolkit_bg.wasm)"
file ../dist/javascript/wasm/fastgeotoolkit_bg.wasm
else
echo "❌ WASM binary file missing"
fi
# Test that JavaScript file can be loaded
if [ -f "../dist/javascript/wasm/fastgeotoolkit.js" ]; then
echo "✅ Testing JS file structure:"
echo "Checking for key exports..."
if grep -q "export.*init" ../dist/javascript/wasm/fastgeotoolkit.js; then
echo " ✅ Has init export"
else
echo " ❌ Missing init export"
fi
if grep -q "export.*decode_polyline" ../dist/javascript/wasm/fastgeotoolkit.js; then
echo " ✅ Has decode_polyline export"
else
echo " ❌ Missing decode_polyline export"
fi
fi
- name: Install dependencies
run: |
# Check if package-lock.json is in sync, if not run npm install
if npm ci --dry-run 2>/dev/null; then
echo "Lock file is in sync, using npm ci"
npm ci
else
echo "Lock file out of sync, using npm install"
npm install
fi
working-directory: ./dist/javascript
- name: Build JavaScript package
run: |
# Build the JavaScript package to ensure TypeScript is compiled
echo "Building JavaScript package..."
npm run build
# Verify the build outputs exist
echo "Build verification:"
if [ -f "dist/index.js" ]; then
echo "✅ CommonJS build exists"
else
echo "❌ CommonJS build missing"
fi
if [ -f "dist/index.esm.js" ]; then
echo "✅ ES module build exists"
else
echo "❌ ES module build missing"
fi
if [ -f "dist/index.d.ts" ]; then
echo "✅ TypeScript definitions exist"
else
echo "❌ TypeScript definitions missing"
fi
working-directory: ./dist/javascript
- name: Run tests with coverage
run: |
# Run Node.js tests first (these will mostly skip WASM functionality)
echo "=== Running Node.js Tests ==="
npm run test:node > node_test_output.txt 2>&1 || true
# Run browser tests (these will actually test WASM functionality)
echo "=== Running Browser Tests ==="
npm run test:browser > browser_test_output.txt 2>&1 || true
# Run all tests with JSON reporter and coverage
npx jest --coverage --json --outputFile=test_results.json || true
# Parse test results
echo "Parsing test results..."
# Extract test counts from Jest output
if [ -f test_results.json ]; then
TOTAL_TESTS=$(node -e "
try {
const results = JSON.parse(require('fs').readFileSync('test_results.json', 'utf8'));
console.log(results.numTotalTests || 0);
} catch(e) {
console.log(0);
}
")
PASSED_TESTS=$(node -e "
try {
const results = JSON.parse(require('fs').readFileSync('test_results.json', 'utf8'));
console.log(results.numPassedTests || 0);
} catch(e) {
console.log(0);
}
")
else
# Fallback: parse from text output
NODE_TOTAL=$(grep -o "[0-9]* total" node_test_output.txt | tail -1 | awk '{print $1}' || echo "0")
NODE_PASSED=$(grep -o "[0-9]* passed" node_test_output.txt | tail -1 | awk '{print $1}' || echo "0")
BROWSER_TOTAL=$(grep -o "[0-9]* total" browser_test_output.txt | tail -1 | awk '{print $1}' || echo "0")
BROWSER_PASSED=$(grep -o "[0-9]* passed" browser_test_output.txt | tail -1 | awk '{print $1}' || echo "0")
TOTAL_TESTS=$((NODE_TOTAL + BROWSER_TOTAL))
PASSED_TESTS=$((NODE_PASSED + BROWSER_PASSED))
fi
echo "Total tests: $TOTAL_TESTS"
echo "Passed tests: $PASSED_TESTS"
# Calculate percentage
if [ "$TOTAL_TESTS" != "0" ]; then
PERCENTAGE=$(node -e "console.log(Math.round($PASSED_TESTS * 100 / $TOTAL_TESTS))")
else
PERCENTAGE="0"
fi
echo "Percentage: $PERCENTAGE%"
# Determine badge color
if [ "$PASSED_TESTS" = "$TOTAL_TESTS" ] && [ "$TOTAL_TESTS" != "0" ]; then
COLOR="brightgreen"
elif [ "$PERCENTAGE" -ge "80" ] 2>/dev/null; then
COLOR="yellow"
else
COLOR="red"
fi
echo "Badge color: $COLOR"
# Create badge URL
BADGE_URL="https://img.shields.io/badge/js_tests-${PASSED_TESTS}%2F${TOTAL_TESTS}_passed-${COLOR}"
echo "Badge URL: $BADGE_URL"
# Save results for badge generation
echo "TOTAL_TESTS=$TOTAL_TESTS" >> $GITHUB_ENV
echo "PASSED_TESTS=$PASSED_TESTS" >> $GITHUB_ENV
echo "PERCENTAGE=$PERCENTAGE" >> $GITHUB_ENV
echo "BADGE_COLOR=$COLOR" >> $GITHUB_ENV
echo "BADGE_URL=$BADGE_URL" >> $GITHUB_ENV
# Display test outputs
echo "=== Node.js Test Output ==="
cat node_test_output.txt
echo ""
echo "=== Browser Test Output ==="
cat browser_test_output.txt
# Check if all tests passed
if [ "$PASSED_TESTS" != "$TOTAL_TESTS" ] || [ "$TOTAL_TESTS" = "0" ]; then
echo "Some tests failed or no tests found"
exit 1
else
echo "All tests passed!"
fi
working-directory: ./dist/javascript
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./dist/javascript/coverage/lcov.info
flags: javascript
name: js-coverage
fail_ci_if_error: false
- name: Create test summary
if: always()
run: |
echo "## JavaScript Test Results Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Metric | Value |" >> $GITHUB_STEP_SUMMARY
echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Total Tests | ${{ env.TOTAL_TESTS }} |" >> $GITHUB_STEP_SUMMARY
echo "| Passed | ${{ env.PASSED_TESTS }} |" >> $GITHUB_STEP_SUMMARY
echo "| Success Rate | ${{ env.PERCENTAGE }}% |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ env.PASSED_TESTS }}" = "${{ env.TOTAL_TESTS }}" ] && [ "${{ env.TOTAL_TESTS }}" != "0" ]; then
echo "### ✅ All JavaScript tests passed!" >> $GITHUB_STEP_SUMMARY
else
echo "### ❌ Some JavaScript tests failed" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Badge:** \`\`" >> $GITHUB_STEP_SUMMARY