Testing Environment Setup Guides
This document provides detailed instructions for setting up various testing environments for the Gradiant platform. Following these guides will ensure consistent testing across development, CI/CD, and production environments.Local Development Environment Setup
Prerequisites
- Node.js v18.17.0 or higher
- pnpm v8.6.0 or higher
- Docker and Docker Compose (for integration tests)
- Git
Basic Setup
- Clone the repository:
- Install dependencies:
- Set up environment variables:
- Edit
.env.test.localto configure test-specific variables:
- Run the test suite:
Setting Up Vitest
Gradiant uses Vitest for unit and integration testing. Here’s how to configure it:- The Vitest configuration is in
vitest.config.ts:
- Create a
vitest.setup.tsfile for global test setup:
CI/CD Testing Environment
GitHub Actions Setup
- Create a
.github/workflows/test.ymlfile:
Docker Testing Environment
For consistent testing across environments, use Docker:- Create a
docker-compose.test.ymlfile:
- Create a
Dockerfile.test:
- Run tests with Docker:
Testing with Mocks
Setting Up Mock Services
- Create a
mocksdirectory for mock services:
- Create a mock service for external APIs:
- Use the mock in tests:
Database Testing
Setting Up Test Databases
- Create a separate database for testing:
- Use Prisma for database testing:
- Use in tests:
Performance Testing
Setting Up Performance Tests
- Create a performance test directory:
- Create a performance test file:
- Run performance tests:
Troubleshooting Common Issues
Database Connection Issues
If you encounter database connection issues:- Verify the database is running:
- Check the connection URL:
- Ensure the database exists:
Test Timeouts
If tests are timing out:- Increase the timeout in Vitest config:
- Check for long-running operations or infinite loops.
- Use proper mocking for external services.
Memory Issues
If you encounter memory issues during testing:- Run tests with increased memory:
- Split large test suites into smaller files.
-
Use
beforeAllandafterAllfor expensive setup/teardown operations.