This document provides essential testing information for the Divemap application. For comprehensive testing strategy and detailed procedures, see TESTING_STRATEGY.md.
- Quick Start
- Approved Testing Methods
- DO NOT: Running tests inside divemap_backend
- Running Tests (Host vs Containers)
- Frontend Testing (Host and Docker)
- Docker-Based Testing (Backend CI-like)
- Troubleshooting
- Quick host-based backend tests (fast, local venv, acceptable for quick checks):
cd backend
source divemap_venv/bin/activate
export PYTHONPATH="/home/kargig/src/divemap/backend/divemap_venv/lib/python3.11/site-packages:$PYTHONPATH"
# Required for OAuth tests to avoid 500 errors
export GOOGLE_CLIENT_ID="dummy-client-id-for-testing"
python -m pytest tests/ -v- Thorough containerized backend tests (CI-like, isolated, REQUIRED before committing significant changes):
cd backend
./docker-test-github-actions.sh- Frontend quick tests (host):
cd frontend
npm test-
Host-based (Quick):
- Run pytest from the host in a Python virtual environment.
- Uses SQLite by default unless
DATABASE_URLis explicitly set. - Frontend tests run via Node.js on host.
- Purpose: fast feedback during development.
-
Containerized (Thorough):
- Use
backend/docker-test-github-actions.shfor backend. - For frontend, use the development Dockerfile to build and run tests if needed.
- Mirrors CI environment; REQUIRED before merges or major refactors.
- Use
- Tests MUST NEVER be run inside the
divemap_backendservice/container. - Reason:
divemap_backendusesDATABASE_URL=mysql+pymysql://...@db:3306/divemap. Tests would connect to the live MySQL container and the test session will drop all tables at teardown, wiping dev data. - Forbidden examples (do NOT run):
# ❌ Do not run inside the container
docker exec -it divemap_backend bash
pytest
python -m pytest# Run all backend tests
cd backend
source divemap_venv/bin/activate
export PYTHONPATH="/home/kargig/src/divemap/backend/divemap_venv/lib/python3.11/site-packages:$PYTHONPATH"
# Required for OAuth tests
export GOOGLE_CLIENT_ID="dummy-client-id-for-testing"
python -m pytest tests/ -v
# Run specific file
python -m pytest tests/test_diving_centers.py -v
# With coverage
python -m pytest tests/ --cov=app --cov-report=htmlcd backend
./docker-test-github-actions.sh- What this does:
- Starts an isolated MySQL test container (port 3307, no volumes)
- Builds a test image
- Runs migrations and executes pytest in isolation
- Cleans up test containers/networks/images
# React unit tests (Jest)
cd frontend
npm test
# Validation tests (accessibility, navigation, basic UI flows)
node tests/validate_frontend.js
# Full frontend test suite runner (aggregates)
node tests/run_frontend_tests.js
# Regression/API-focused tests (no browser required)
node tests/test_regressions.js- Notes:
- Prefer host-based frontend tests for iteration speed.
- Ensure dependencies are installed:
npm install. - Some browser-driven tests may require Google Chrome to be installed on the host.
Development container (use when you need an isolated Node environment):
cd frontend
# Build development image with full test tooling
docker build -f Dockerfile.dev -t divemap_frontend_dev .
# Run frontend tests in dev container
docker run --rm divemap_frontend_dev npm run test:frontend
docker run --rm divemap_frontend_dev npm run test:validation
docker run --rm divemap_frontend_dev npm run test:e2e
# Optionally run the development server from the container
docker run --rm -p 3000:3000 divemap_frontend_devProduction image (no test tooling; for runtime checks only):
cd frontend
docker build -t divemap_frontend_prod .
# Run production server
docker run --rm -p 8080:8080 divemap_frontend_prod- Development (frontend) containers are for building/running the app, not for backend tests.
- Use the host venv or the CI-like script for backend tests.
- ModuleNotFoundError:
source backend/divemap_venv/bin/activate
export PYTHONPATH="/home/kargig/src/divemap/backend/divemap_venv/lib/python3.11/site-packages:$PYTHONPATH"- Database Connection Errors:
docker-compose up -d db-
Puppeteer or headless browser issues:
- Ensure Chrome is available on host, or run tests in the
divemap_frontend_devcontainer. - Replace deprecated
waitForTimeoutwithawait new Promise(resolve => setTimeout(resolve, ...))if needed.
- Ensure Chrome is available on host, or run tests in the
-
Dependency issues:
cd frontend
rm -rf node_modules package-lock.json
npm install