Environment Configuration
Environment Configuration
The testing-api uses environment variables to manage configurations across different stages of the testing lifecycle. By isolating these variables, you can seamlessly switch between development, staging, and production environments without modifying the source code.
Configuration File Setup
To configure your local environment, create a .env file in the root directory of the project. This file stores sensitive credentials and environment-specific endpoints.
# Example .env file
APP_ENV=development
API_BASE_URL=https://dev-api.supervised.ai
AUTH_TOKEN=your_test_token_here
DB_CONNECTION_STRING=mongodb://localhost:27017/test_db
DEBUG=true
Note: The
.envfile should never be committed to version control. Ensure it is included in your.gitignorefile.
Required Environment Variables
The following variables are required for the testing-api to interface correctly with the Supervised AI platform:
| Variable | Type | Description |
| :--- | :--- | :--- |
| APP_ENV | string | Defines the current environment (development, staging, production). |
| API_BASE_URL | url | The base URL for the Supervised AI API being tested. |
| AUTH_TOKEN | string | A valid Bearer token or API key used for authenticating requests. |
| TIMEOUT_MS | number | The global request timeout duration in milliseconds. Defaults to 5000. |
Switching Environments
The system determines which configuration to load based on the NODE_ENV or APP_ENV variable. You can specify the environment when executing your test suite via the CLI.
Development
Used for local feature development and unit testing.
export APP_ENV=development && npm test
Staging
Used for integration tests and pre-deployment verification on the staging cluster.
export APP_ENV=staging && npm test
Production
Used for smoke tests and health checks against the live environment. Use with caution as these tests interact with real infrastructure.
export APP_ENV=production && npm test
Accessing Variables in Tests
Within your test scripts, you can access these configurations through the internal config loader. This ensures that your tests remain environment-agnostic.
import { config } from './src/config';
describe('API Integration Test', () => {
it('should connect to the correct environment', async () => {
const response = await request(config.API_BASE_URL)
.get('/v1/health')
.set('Authorization', `Bearer ${config.AUTH_TOKEN}`);
expect(response.status).toBe(200);
});
});
Validation
The testing-api includes a validation step on startup. If critical variables (like API_BASE_URL or AUTH_TOKEN) are missing or improperly formatted, the process will exit with a non-zero status code to prevent invalid test runs.