This project uses a comprehensive testing strategy with different types of tests for different purposes. This README explains the current state of testing and how to extend it.
Integration tests verify that different parts of the application work together correctly, but they use mocks for external dependencies like databases and APIs. These tests are fast, reliable, and don't require external services to be running.
Location: src/__test__/integration/
Run with: bun test:integration
The integration tests use a dummy environment set in vitest.config.ts
which provides all necessary environment variables with test values. This is sufficient for running integration tests without any additional setup.
Environment Validation:
- Integration tests run the
scripts:check-app-env
script before execution to ensure all required application environment variables are set. - This is configured in
package.json
:"test:integration": "bun scripts:check-app-env && vitest run src/__test__/integration/"
Examples:
- Authentication tests in
src/__test__/integration/auth.test.ts
- Middleware tests in
src/__test__/integration/middleware.test.ts
Current Status: E2E tests are not yet implemented. There is a placeholder file at src/__test__/e2e/placeholder.test.ts
.
Location: src/__test__/e2e/
Run with: bun test:e2e
Environment Validation:
- E2E tests run the
scripts:check-all-env
script before execution to ensure all required environment variables are set. - This is configured in
package.json
:"test:e2e": "bun scripts:check-all-env && vitest run src/__test__/e2e/"
To run all tests:
bun test:run
To run only integration tests:
bun test:integration
To run only E2E tests (currently just the placeholder):
bun test:e2e
Currently, only integration tests are configured to run in CI/CD:
(See .github/workflows/test.yml
)
Integration tests use the environment variables defined in .github/workflows/test.yml
or .env
files.
These values are sufficient for running integration tests without any additional setup.
When implementing E2E tests, you will need to:
- Create
.env
files with real credentials for external services & additional variables for e2e tests - Update the
testEnvSchema
insrc/lib/env.ts
to validate the required additional environment variables - Update the GitHub Actions workflow to include E2E tests with the necessary secrets
To start implementing E2E tests:
-
Create a proper environment setup:
- Create a
.env.test.example
file showing required variables - Add validation in
scripts/check-e2e-env.ts
to ensure all required variables are present
- Create a
-
Update GitHub Actions workflow:
- Add a new job for E2E tests in
.github/workflows/test.yml
- Configure it to run after integration tests pass
- Add necessary secrets to GitHub repository settings
- Add a new job for E2E tests in
-
Implement actual E2E tests:
- Replace the placeholder in
src/__test__/e2e/placeholder.test.ts
with real tests - Focus on critical user flows like authentication, team management, etc.
- Add logic to skip tests if required environment variables are missing
- Replace the placeholder in
-
Update this README:
- Document the new E2E tests and how to run them
- Update the environment variables section with the actual requirements
- Write integration tests for most functionality: They're faster and more reliable.
- Use E2E tests for critical paths: Focus on key user journeys like authentication, payment, etc.
- Keep E2E tests minimal: They're slower and more brittle, so use them sparingly.
- Use test data: Create and clean up test data in your E2E tests to avoid polluting your development/production environment.
- Skip E2E tests if environment variables are missing: This allows the tests to be run in environments without the necessary credentials.