Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .copier/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,24 @@ workflows:
exclude:
- "mflix/client/**/.gitignore"
- "mflix/server/python-fastapi/**/.gitignore"

# --------------------------------------------------------------------------
# TanStack Framework
# --------------------------------------------------------------------------
- name: "tanstack-framework"
destination:
repo: "10gen/docs-mongodb-internal"
branch: "main"
transformations:
- move: { from: "frameworks/javascript/tanstack/testedSnippets/src", to: "code-examples/javascript/tanstack" }
commit_strategy:
pr_title: "Update TanStack code examples from docs-sample-apps"
pr_body: |
Automated update of TanStack framework example snippets

**Source:** ${source_repo} (${source_branch})
**PR:** #${pr_number} | **Commit:** ${commit_sha}
**Changes:** ${file_count} files updated
exclude:
- "**/*.test.ts"
- "**/*.test.tsx"
128 changes: 128 additions & 0 deletions .github/scripts/generate-test-summary-vitest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/bin/bash
set -e

# Generate Detailed Test Summary from Multiple Vitest JSON Output Files
# Shows breakdown by test type (unit vs integration)
# Usage: ./generate-test-summary-vitest.sh <unit-json> <integration-json>

# Guard: skip if GITHUB_STEP_SUMMARY is not set
if [ -z "$GITHUB_STEP_SUMMARY" ]; then
echo "Warning: GITHUB_STEP_SUMMARY not set, skipping summary generation"
exit 0
fi

UNIT_JSON="${1:-}"
INTEGRATION_JSON="${2:-}"

echo "## Test Results" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"

# Function to parse Vitest JSON file
parse_json() {
local json_file="$1"
local test_type="$2"

if [ ! -f "$json_file" ]; then
echo "0 0 0 0"
return
fi

if command -v jq &> /dev/null; then
# Use jq if available (preferred)
total_tests=$(jq -r '.numTotalTests // 0' "$json_file")
passed=$(jq -r '.numPassedTests // 0' "$json_file")
failed=$(jq -r '.numFailedTests // 0' "$json_file")
skipped=$(jq -r '.numPendingTests // 0' "$json_file")
else
# Fallback to grep/sed if jq is not available
total_tests=$(grep -oP '"numTotalTests":\s*\K[0-9]+' "$json_file" | head -1)
passed=$(grep -oP '"numPassedTests":\s*\K[0-9]+' "$json_file" | head -1)
failed=$(grep -oP '"numFailedTests":\s*\K[0-9]+' "$json_file" | head -1)
skipped=$(grep -oP '"numPendingTests":\s*\K[0-9]+' "$json_file" | head -1)
fi

# Default to 0 if values are empty
total_tests=${total_tests:-0}
passed=${passed:-0}
failed=${failed:-0}
skipped=${skipped:-0}

echo "$total_tests $passed $failed $skipped"
}

# Parse both files
read -r unit_tests unit_passed unit_failed unit_skipped <<< "$(parse_json "$UNIT_JSON" "Unit")"
read -r int_tests int_passed int_failed int_skipped <<< "$(parse_json "$INTEGRATION_JSON" "Integration")"

# Calculate totals
total_tests=$((unit_tests + int_tests))
total_passed=$((unit_passed + int_passed))
total_failed=$((unit_failed + int_failed))
total_skipped=$((unit_skipped + int_skipped))

# Display detailed breakdown
echo "### Summary by Test Type" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "| Test Type | Passed | Failed | Skipped | Total |" >> "$GITHUB_STEP_SUMMARY"
echo "|-----------|--------|--------|---------|-------|" >> "$GITHUB_STEP_SUMMARY"

if [ -f "$UNIT_JSON" ]; then
echo "| 🔧 Unit Tests | $unit_passed | $unit_failed | $unit_skipped | $unit_tests |" >> "$GITHUB_STEP_SUMMARY"
fi

if [ -f "$INTEGRATION_JSON" ]; then
echo "| 🔗 Integration Tests | $int_passed | $int_failed | $int_skipped | $int_tests |" >> "$GITHUB_STEP_SUMMARY"
fi

echo "| **Total** | **$total_passed** | **$total_failed** | **$total_skipped** | **$total_tests** |" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"

# Overall status
echo "### Overall Status" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "| Status | Count |" >> "$GITHUB_STEP_SUMMARY"
echo "|--------|-------|" >> "$GITHUB_STEP_SUMMARY"
echo "| ✅ Passed | $total_passed |" >> "$GITHUB_STEP_SUMMARY"
echo "| ❌ Failed | $total_failed |" >> "$GITHUB_STEP_SUMMARY"
echo "| ⏭️ Skipped | $total_skipped |" >> "$GITHUB_STEP_SUMMARY"
echo "| **Total** | **$total_tests** |" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"

# List failed tests if any
if [ $total_failed -gt 0 ]; then
echo "### ❌ Failed Tests" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"

failed_tests_file=$(mktemp)

# Extract failed tests from both files
for json_file in "$UNIT_JSON" "$INTEGRATION_JSON"; do
if [ -f "$json_file" ]; then
if command -v jq &> /dev/null; then
jq -r '.testResults[]? | select(.status == "failed") | .assertionResults[]? | select(.status == "failed") | "\(.ancestorTitles | join(" > ")) > \(.title)"' "$json_file" >> "$failed_tests_file" 2>/dev/null || true
else
# Basic fallback without jq
grep -oP '"fullName":\s*"\K[^"]*' "$json_file" | while read -r line; do
if echo "$line" | grep -q "failed"; then
echo "$line" >> "$failed_tests_file"
fi
done 2>/dev/null || true
fi
fi
done

if [ -s "$failed_tests_file" ]; then
while IFS= read -r test; do
echo "- \`$test\`" >> "$GITHUB_STEP_SUMMARY"
done < "$failed_tests_file"
else
echo "_Unable to parse individual test names_" >> "$GITHUB_STEP_SUMMARY"
fi

echo "" >> "$GITHUB_STEP_SUMMARY"
echo "❌ **Tests failed!**" >> "$GITHUB_STEP_SUMMARY"
rm -f "$failed_tests_file"
exit 1
else
echo "✅ **All tests passed!**" >> "$GITHUB_STEP_SUMMARY"
fi
83 changes: 83 additions & 0 deletions .github/workflows/run-tanstack-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Run TanStack Tests

on:
pull_request:
branches:
- development
- frameworks-tanstack
paths:
- 'frameworks/javascript/tanstack/**'
push:
branches:
- development
- frameworks-tanstack
paths:
- 'frameworks/javascript/tanstack/**'

jobs:
test:
name: Run TanStack Tests
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Install Atlas CLI
run: |
curl https://fastdl.mongodb.org/mongocli/mongodb-atlas-cli_1.47.0_linux_x86_64.deb --output atlas-cli.deb
sudo apt install ./atlas-cli.deb

- name: Set up a local deployment using Atlas CLI
run: |
atlas deployments setup myLocalRs1 --type local --port 27017 --force

- name: Install MongoDB Database Tools to load sample data
run: |
curl https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2204-x86_64-100.13.0.deb --output mdb-db-tools.deb
sudo apt install ./mdb-db-tools.deb

- name: Download sample data
run: curl https://atlas-education.s3.amazonaws.com/sampledata.archive -o sampledata.archive

- name: Add sample data to database
run: mongorestore --archive=sampledata.archive --port=27017

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install dependencies
working-directory: frameworks/javascript/tanstack/app
run: npm install

- name: Run unit tests
working-directory: frameworks/javascript/tanstack/app
run: npm run test:unit -- --reporter=json --outputFile=test-results-unit.json
env:
MONGODB_URI: mongodb://localhost:27017/sample_restaurants?directConnection=true

- name: Run integration tests
working-directory: frameworks/javascript/tanstack/app
run: npm run test:integration -- --reporter=json --outputFile=test-results-integration.json
env:
MONGODB_URI: mongodb://localhost:27017/sample_restaurants?directConnection=true

- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: |
frameworks/javascript/tanstack/app/test-results-unit.json
frameworks/javascript/tanstack/app/test-results-integration.json
retention-days: 30

- name: Generate Test Summary
if: always()
run: |
chmod +x .github/scripts/generate-test-summary-vitest.sh
.github/scripts/generate-test-summary-vitest.sh \
frameworks/javascript/tanstack/app/test-results-unit.json \
frameworks/javascript/tanstack/app/test-results-integration.json
Loading
Loading