This document provides essential testing information for the Divemap application. For comprehensive testing strategy and detailed procedures, see TESTING_STRATEGY.md.
- Quick Start
- The ONLY Approved Backend Testing Method
- Why SQLite is Not Supported
- DO NOT: Running pytest directly
- Frontend Testing (Host and Docker)
- Troubleshooting
- Backend tests (MANDATORY, safe, isolated):
cd backend
./docker-test-github-actions.sh- Frontend quick tests (host):
cd frontend
npm testYou MUST use backend/docker-test-github-actions.sh for all backend testing.
This script:
- Starts an isolated MySQL 8.0 test container.
- Builds a dedicated test image.
- Runs all Alembic migrations and executes pytest in complete isolation.
- Safely cleans up the environment without touching your development database.
Unlike many Python projects, Divemap is not compatible with SQLite. The application relies heavily on native MySQL features that SQLite cannot replicate, including:
- Spatial Data Types: Uses
POINTcolumns andST_Distance_Spherefor geographic searches. - MySQL-Specific Types: Uses
LONGTEXTfor large content fields (e.g., newsletters). - Strict Constraints: Uses specific MySQL Enum behaviors.
Because the test suite initializes the entire schema at the start of every session (Base.metadata.create_all), attempting to run pytest against an SQLite database will result in a fatal CompileError. Do not attempt to use SQLite for backend testing.
- ❌ DO NOT run tests inside the
divemap_backendcontainer. - ❌ DO NOT run tests using the local
divemap_venvon your host machine.
Forbidden examples that will cause errors or fatal data loss:
# ❌ FATAL: Wipes live database
docker-compose exec backend pytest
# ❌ FORBIDDEN: SQLite incompatibility (will crash)
cd backend && source divemap_venv/bin/activate && pytest# 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- 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