This directory contains the end-to-end (E2E) test suite for the Thea Code VSCode extension. These tests run in a real VSCode environment using the official @vscode/test-electron framework with Mocha as the test runner.
- Real Environment: Tests run in actual VSCode, not mocked
- Integration Testing: Tests real interactions between components
- User Perspective: Tests features as users would experience them
- VSCode Test Explorer: Full integration with VSCode's built-in test runner
- Clean & Simple: No complex mocking or stubbing required
e2e/
├── src/
│ ├── suite/
│ │ ├── basic.test.ts # Basic extension functionality
│ │ ├── commands.test.ts # Command registration and execution
│ │ ├── configuration.test.ts # Settings and configuration
│ │ ├── extension.test.ts # Extension activation
│ │ ├── mcp.test.ts # Model Context Protocol tests
│ │ ├── modes.test.ts # Mode switching functionality
│ │ ├── providers.test.ts # API provider tests
│ │ ├── webview.test.ts # Webview panel tests
│ │ ├── task.test.ts # Task execution
│ │ ├── subtasks.test.ts # Subtask handling
│ │ └── utilities.test.ts # Utility functions
│ ├── runTest.ts # Test runner configuration
│ └── thea-constants.ts # Extension constants
└── out/ # Compiled JavaScript output
# Run all e2e tests
npm run test:e2e
# From the e2e directory
npm test
# Compile tests only
npm run compile
# Watch mode (compile on change)
npm run watch- Open the Test Explorer (Testing icon in sidebar)
- Navigate to the test you want to run
- Click the play button to run individual tests or suites
- Use the debug button to debug tests with breakpoints
- Press
F5or go to Run and Debug - Select "Extension Tests (watch)" from the dropdown
- Tests will run in a new VSCode window
import * as assert from "assert"
import * as vscode from "vscode"
import { EXTENSION_ID } from "../thea-constants"
suite("Feature Name", () => {
let extension: vscode.Extension<any> | undefined
suiteSetup(async function() {
this.timeout(30000) // Allow time for extension activation
extension = vscode.extensions.getExtension(EXTENSION_ID)
if (!extension) {
assert.fail("Extension not found")
}
if (!extension.isActive) {
await extension.activate()
}
})
test("should do something", async function() {
this.timeout(10000) // Set timeout for async operations
// Your test code here
assert.ok(true, "Test passed")
})
})- Use Descriptive Names: Test names should clearly describe what they test
- Set Appropriate Timeouts: Network operations need longer timeouts
- Clean Up After Tests: Use
teardown()to restore state - Test User Workflows: Focus on real user scenarios
- Avoid External Dependencies: Don't rely on external services when possible
- Use Skip for WIP Tests: Use
test.skip()for tests under development
// Basic assertions
assert.ok(value, "Value should be truthy")
assert.strictEqual(actual, expected, "Values should be equal")
assert.deepStrictEqual(obj1, obj2, "Objects should be deeply equal")
// Pattern matching
assert.match(string, /pattern/, "String should match pattern")
// Error testing
assert.throws(() => dangerousFunction(), "Should throw error")
assert.rejects(async () => asyncFunction(), "Should reject promise")
// Array/Collection testing
assert.ok(array.includes(item), "Array should contain item")
assert.strictEqual(array.length, expected, "Array should have expected length")- basic.test.ts: Extension presence and basic functionality
- extension.test.ts: Extension activation and lifecycle
- commands.test.ts: Command registration and execution
- configuration.test.ts: Settings management
- modes.test.ts: Mode switching (Ask, Edit, Code, etc.)
- webview.test.ts: Webview panel functionality
- providers.test.ts: API provider integration
- mcp.test.ts: Model Context Protocol integration
- task.test.ts: Task execution and management
- subtasks.test.ts: Subtask handling
- utilities.test.ts: Helper functions and utilities
Create a .env.local file in the e2e directory for test configuration:
# API Keys (optional, for integration tests)
OPENROUTER_API_KEY=sk-or-v1-...
ANTHROPIC_API_KEY=sk-ant-...
# Test Configuration
TEST_TIMEOUT=60000
SKIP_SLOW_TESTS=false- Set breakpoints in your test files
- Use VSCode's Test Explorer debug button
- Or use the "Extension Tests (watch)" launch configuration
- Check the Debug Console for output
We're migrating from Jest to this E2E framework. Key differences:
| Jest | Mocha (E2E) |
|---|---|
describe() |
suite() |
it() |
test() |
beforeEach() |
setup() |
afterEach() |
teardown() |
beforeAll() |
suiteSetup() |
afterAll() |
suiteTeardown() |
expect().toBe() |
assert.strictEqual() |
expect().toEqual() |
assert.deepStrictEqual() |
expect().toMatch() |
assert.match() |
The E2E tests can be run in CI environments:
# Example GitHub Actions
- name: Run E2E Tests
run: |
npm run build
xvfb-run -a npm run test:e2e- Ensure the extension compiles:
npm run build - Check for TypeScript errors:
npm run compile - Verify extension ID in
thea-constants.ts
- Increase timeout for slow operations
- Check network connectivity for API tests
- Ensure extension activates properly
- Use
console.log()for quick debugging - Check the Output panel in VSCode
- Look at the Extension Host log
When adding new tests:
- Choose the appropriate test file or create a new one
- Follow the existing patterns and structure
- Add descriptive test names and failure messages
- Update this README if adding new test categories
- Ensure tests pass locally before committing
- Add performance benchmarks
- Implement test coverage reporting
- Add visual regression tests for webview
- Create test data fixtures
- Add automated test generation for commands
- Implement parallel test execution
- Add test result reporting dashboard