Skip to content

Commit b4e028d

Browse files
authored
Merge TanStack Framework into Development (#105)
* Set up TanStack Start sample app with tests, CI/CD, and Bluehawk snippet extraction (#101) * Adding TanStack Start + Unit & Integration Tests * Adding GH Actions * Add Bluehawk snippet extraction and improve test documentation - Set up Bluehawk for snippet extraction from source code - Add generic snip.js script for framework examples - Add processFiles.js for handling unannotated files - Extract 8 code snippets to testedSnippets/ - Add test:all npm script to run both unit and integration tests - Update all READMEs to clarify test commands (test vs test:all) - Document component testing status (not implemented due to TanStack Start beta) - Add Bluehawk annotations to source files (Header, RestaurantList, db, routes) * addressing pr feedback * Adding in copier flow (#104)
1 parent 38e1892 commit b4e028d

57 files changed

Lines changed: 9156 additions & 71 deletions

Some content is hidden

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

.copier/config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,24 @@ workflows:
108108
exclude:
109109
- "mflix/client/**/.gitignore"
110110
- "mflix/server/python-fastapi/**/.gitignore"
111+
112+
# --------------------------------------------------------------------------
113+
# TanStack Framework
114+
# --------------------------------------------------------------------------
115+
- name: "tanstack-framework"
116+
destination:
117+
repo: "10gen/docs-mongodb-internal"
118+
branch: "main"
119+
transformations:
120+
- move: { from: "frameworks/javascript/tanstack/testedSnippets/src", to: "code-examples/javascript/tanstack" }
121+
commit_strategy:
122+
pr_title: "Update TanStack code examples from docs-sample-apps"
123+
pr_body: |
124+
Automated update of TanStack framework example snippets
125+
126+
**Source:** ${source_repo} (${source_branch})
127+
**PR:** #${pr_number} | **Commit:** ${commit_sha}
128+
**Changes:** ${file_count} files updated
129+
exclude:
130+
- "**/*.test.ts"
131+
- "**/*.test.tsx"
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Generate Detailed Test Summary from Multiple Vitest JSON Output Files
5+
# Shows breakdown by test type (unit vs integration)
6+
# Usage: ./generate-test-summary-vitest.sh <unit-json> <integration-json>
7+
8+
# Guard: skip if GITHUB_STEP_SUMMARY is not set
9+
if [ -z "$GITHUB_STEP_SUMMARY" ]; then
10+
echo "Warning: GITHUB_STEP_SUMMARY not set, skipping summary generation"
11+
exit 0
12+
fi
13+
14+
UNIT_JSON="${1:-}"
15+
INTEGRATION_JSON="${2:-}"
16+
17+
echo "## Test Results" >> "$GITHUB_STEP_SUMMARY"
18+
echo "" >> "$GITHUB_STEP_SUMMARY"
19+
20+
# Function to parse Vitest JSON file
21+
parse_json() {
22+
local json_file="$1"
23+
local test_type="$2"
24+
25+
if [ ! -f "$json_file" ]; then
26+
echo "0 0 0 0"
27+
return
28+
fi
29+
30+
if command -v jq &> /dev/null; then
31+
# Use jq if available (preferred)
32+
total_tests=$(jq -r '.numTotalTests // 0' "$json_file")
33+
passed=$(jq -r '.numPassedTests // 0' "$json_file")
34+
failed=$(jq -r '.numFailedTests // 0' "$json_file")
35+
skipped=$(jq -r '.numPendingTests // 0' "$json_file")
36+
else
37+
# Fallback to grep/sed if jq is not available
38+
total_tests=$(grep -oP '"numTotalTests":\s*\K[0-9]+' "$json_file" | head -1)
39+
passed=$(grep -oP '"numPassedTests":\s*\K[0-9]+' "$json_file" | head -1)
40+
failed=$(grep -oP '"numFailedTests":\s*\K[0-9]+' "$json_file" | head -1)
41+
skipped=$(grep -oP '"numPendingTests":\s*\K[0-9]+' "$json_file" | head -1)
42+
fi
43+
44+
# Default to 0 if values are empty
45+
total_tests=${total_tests:-0}
46+
passed=${passed:-0}
47+
failed=${failed:-0}
48+
skipped=${skipped:-0}
49+
50+
echo "$total_tests $passed $failed $skipped"
51+
}
52+
53+
# Parse both files
54+
read -r unit_tests unit_passed unit_failed unit_skipped <<< "$(parse_json "$UNIT_JSON" "Unit")"
55+
read -r int_tests int_passed int_failed int_skipped <<< "$(parse_json "$INTEGRATION_JSON" "Integration")"
56+
57+
# Calculate totals
58+
total_tests=$((unit_tests + int_tests))
59+
total_passed=$((unit_passed + int_passed))
60+
total_failed=$((unit_failed + int_failed))
61+
total_skipped=$((unit_skipped + int_skipped))
62+
63+
# Display detailed breakdown
64+
echo "### Summary by Test Type" >> "$GITHUB_STEP_SUMMARY"
65+
echo "" >> "$GITHUB_STEP_SUMMARY"
66+
echo "| Test Type | Passed | Failed | Skipped | Total |" >> "$GITHUB_STEP_SUMMARY"
67+
echo "|-----------|--------|--------|---------|-------|" >> "$GITHUB_STEP_SUMMARY"
68+
69+
if [ -f "$UNIT_JSON" ]; then
70+
echo "| 🔧 Unit Tests | $unit_passed | $unit_failed | $unit_skipped | $unit_tests |" >> "$GITHUB_STEP_SUMMARY"
71+
fi
72+
73+
if [ -f "$INTEGRATION_JSON" ]; then
74+
echo "| 🔗 Integration Tests | $int_passed | $int_failed | $int_skipped | $int_tests |" >> "$GITHUB_STEP_SUMMARY"
75+
fi
76+
77+
echo "| **Total** | **$total_passed** | **$total_failed** | **$total_skipped** | **$total_tests** |" >> "$GITHUB_STEP_SUMMARY"
78+
echo "" >> "$GITHUB_STEP_SUMMARY"
79+
80+
# Overall status
81+
echo "### Overall Status" >> "$GITHUB_STEP_SUMMARY"
82+
echo "" >> "$GITHUB_STEP_SUMMARY"
83+
echo "| Status | Count |" >> "$GITHUB_STEP_SUMMARY"
84+
echo "|--------|-------|" >> "$GITHUB_STEP_SUMMARY"
85+
echo "| ✅ Passed | $total_passed |" >> "$GITHUB_STEP_SUMMARY"
86+
echo "| ❌ Failed | $total_failed |" >> "$GITHUB_STEP_SUMMARY"
87+
echo "| ⏭️ Skipped | $total_skipped |" >> "$GITHUB_STEP_SUMMARY"
88+
echo "| **Total** | **$total_tests** |" >> "$GITHUB_STEP_SUMMARY"
89+
echo "" >> "$GITHUB_STEP_SUMMARY"
90+
91+
# List failed tests if any
92+
if [ $total_failed -gt 0 ]; then
93+
echo "### ❌ Failed Tests" >> "$GITHUB_STEP_SUMMARY"
94+
echo "" >> "$GITHUB_STEP_SUMMARY"
95+
96+
failed_tests_file=$(mktemp)
97+
98+
# Extract failed tests from both files
99+
for json_file in "$UNIT_JSON" "$INTEGRATION_JSON"; do
100+
if [ -f "$json_file" ]; then
101+
if command -v jq &> /dev/null; then
102+
jq -r '.testResults[]? | select(.status == "failed") | .assertionResults[]? | select(.status == "failed") | "\(.ancestorTitles | join(" > ")) > \(.title)"' "$json_file" >> "$failed_tests_file" 2>/dev/null || true
103+
else
104+
# Basic fallback without jq
105+
grep -oP '"fullName":\s*"\K[^"]*' "$json_file" | while read -r line; do
106+
if echo "$line" | grep -q "failed"; then
107+
echo "$line" >> "$failed_tests_file"
108+
fi
109+
done 2>/dev/null || true
110+
fi
111+
fi
112+
done
113+
114+
if [ -s "$failed_tests_file" ]; then
115+
while IFS= read -r test; do
116+
echo "- \`$test\`" >> "$GITHUB_STEP_SUMMARY"
117+
done < "$failed_tests_file"
118+
else
119+
echo "_Unable to parse individual test names_" >> "$GITHUB_STEP_SUMMARY"
120+
fi
121+
122+
echo "" >> "$GITHUB_STEP_SUMMARY"
123+
echo "❌ **Tests failed!**" >> "$GITHUB_STEP_SUMMARY"
124+
rm -f "$failed_tests_file"
125+
exit 1
126+
else
127+
echo "✅ **All tests passed!**" >> "$GITHUB_STEP_SUMMARY"
128+
fi
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Run TanStack Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- development
7+
- frameworks-tanstack
8+
paths:
9+
- 'frameworks/javascript/tanstack/**'
10+
push:
11+
branches:
12+
- development
13+
- frameworks-tanstack
14+
paths:
15+
- 'frameworks/javascript/tanstack/**'
16+
17+
jobs:
18+
test:
19+
name: Run TanStack Tests
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v5
25+
26+
- name: Install Atlas CLI
27+
run: |
28+
curl https://fastdl.mongodb.org/mongocli/mongodb-atlas-cli_1.47.0_linux_x86_64.deb --output atlas-cli.deb
29+
sudo apt install ./atlas-cli.deb
30+
31+
- name: Set up a local deployment using Atlas CLI
32+
run: |
33+
atlas deployments setup myLocalRs1 --type local --port 27017 --force
34+
35+
- name: Install MongoDB Database Tools to load sample data
36+
run: |
37+
curl https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2204-x86_64-100.13.0.deb --output mdb-db-tools.deb
38+
sudo apt install ./mdb-db-tools.deb
39+
40+
- name: Download sample data
41+
run: curl https://atlas-education.s3.amazonaws.com/sampledata.archive -o sampledata.archive
42+
43+
- name: Add sample data to database
44+
run: mongorestore --archive=sampledata.archive --port=27017
45+
46+
- name: Set up Node.js
47+
uses: actions/setup-node@v4
48+
with:
49+
node-version: '20'
50+
51+
- name: Install dependencies
52+
working-directory: frameworks/javascript/tanstack/app
53+
run: npm install
54+
55+
- name: Run unit tests
56+
working-directory: frameworks/javascript/tanstack/app
57+
run: npm run test:unit -- --reporter=json --outputFile=test-results-unit.json
58+
env:
59+
MONGODB_URI: mongodb://localhost:27017/sample_restaurants?directConnection=true
60+
61+
- name: Run integration tests
62+
working-directory: frameworks/javascript/tanstack/app
63+
run: npm run test:integration -- --reporter=json --outputFile=test-results-integration.json
64+
env:
65+
MONGODB_URI: mongodb://localhost:27017/sample_restaurants?directConnection=true
66+
67+
- name: Upload test results
68+
uses: actions/upload-artifact@v4
69+
if: always()
70+
with:
71+
name: test-results
72+
path: |
73+
frameworks/javascript/tanstack/app/test-results-unit.json
74+
frameworks/javascript/tanstack/app/test-results-integration.json
75+
retention-days: 30
76+
77+
- name: Generate Test Summary
78+
if: always()
79+
run: |
80+
chmod +x .github/scripts/generate-test-summary-vitest.sh
81+
.github/scripts/generate-test-summary-vitest.sh \
82+
frameworks/javascript/tanstack/app/test-results-unit.json \
83+
frameworks/javascript/tanstack/app/test-results-integration.json

0 commit comments

Comments
 (0)