Testing Overview
HAI Build Code Generator uses a comprehensive testing strategy that includes unit tests, integration tests, and end-to-end tests to ensure code quality and reliability.Running Tests
All Tests
Run all tests (unit and integration):- Compile the extension
- Compile test files
- Run unit tests
- Run integration tests
Unit Tests Only
Run only unit tests:Integration Tests Only
Run only integration tests:Code Coverage
Generate test coverage reports:coverage/ directory.
End-to-End (E2E) Testing
HAI includes comprehensive E2E tests using Playwright that simulate real user interactions with the extension in VS Code.Running E2E Tests
- Full E2E Suite
- Quick E2E Run
- Debug Mode
- UI Mode
Build and run all E2E tests:This will:
- Install Playwright browsers
- Build the extension as a .vsix package
- Run all E2E tests
E2E Test Structure
E2E tests are located insrc/test/e2e/ and follow this structure:
Writing E2E Tests
Follow existing patterns
Reference these files for examples:
auth.test.ts- Authentication flowschat.test.ts- Chat interactionsdiff.test.ts- Diff operationseditor.test.ts- Editor commands
E2E Test Environment
The E2E test environment includes:- Automated VS Code setup with HAI extension loaded
- Mock API server for backend testing
- Temporary workspaces with test fixtures
- Video recording for failed tests
- Screenshot capture on failures
Webview Tests
Test the React-based webview UI:Writing Tests
Unit Tests
Unit tests should:- Test individual functions and components in isolation
- Use mocks for external dependencies
- Be fast and deterministic
- Follow the Arrange-Act-Assert pattern
Integration Tests
Integration tests should:- Test component interactions
- Use the VS Code test environment
- Verify file operations and API calls
- Test against real (or mocked) VS Code APIs
E2E Tests Best Practices
Wait for elements properly
Wait for elements properly
Use Playwright’s auto-waiting instead of fixed timeouts:
Use semantic selectors
Use semantic selectors
Prefer accessible selectors over CSS:
Keep tests independent
Keep tests independent
Each test should be able to run in isolation:
Use descriptive test names
Use descriptive test names
Test names should clearly describe what is being tested:
Test Requirements
Continuous Integration
All tests run automatically in CI when you:- Push commits to your branch
- Create or update a pull request
- Merge to the main branch
- Type checking (
npm run check-types) - Linting (
npm run lint) - Code formatting (
npm run format) - Unit tests
- Integration tests
- E2E tests (on main branch)
Debugging Tests
Debug Unit/Integration Tests
- Set breakpoints in your test files
- Open the Run and Debug panel in VS Code
- Select the appropriate debug configuration
- Press F5 to start debugging
Debug E2E Tests
Use Playwright’s debug mode:- Step through test execution
- Inspect the DOM
- View network requests
- Generate new test code
- Record user interactions
Mock API Server
For E2E tests, a mock API server is available to simulate backend responses without making real API calls. To run the standalone test server:Next Steps
Contributing Guidelines
Review the full contributing guidelines
Code of Conduct
Read our code of conduct