This document describes the integration test setup for the Roo Code VSCode extension.
The integration tests use the @vscode/test-electron package to run tests in a real VSCode environment. These tests verify that the extension works correctly within VSCode, including features like mode switching, webview interactions, and API communication.
e2e/src/
├── runTest.ts # Main test runner
├── suite/
│ ├── index.ts # Test suite configuration
│ ├── modes.test.ts # Mode switching tests
│ ├── tasks.test.ts # Task execution tests
│ └── extension.test.ts # Extension activation tests
The test runner (runTest.ts) is responsible for:
@vscode/test-electronCreate a .env.local file in the root directory with required environment variables:
OPENROUTER_API_KEY=sk-or-v1-...
The test suite (suite/index.ts) configures:
Tests are organized using Mocha's TDD interface (suite and test functions). The main test files are:
modes.test.ts: Tests mode switching functionalitytasks.test.ts: Tests task executionextension.test.ts: Tests extension activationThe following global objects are available in tests:
declare global {
var api: RooCodeAPI
var provider: ClineProvider
var extension: vscode.Extension<RooCodeAPI>
var panel: vscode.WebviewPanel
}
Ensure you have the required environment variables set in .env.local
Run the integration tests:
npm run test:integration
If you want to run a specific test, you can use the test.only function in the test file. This will run only the test you specify and ignore the others. Be sure to remove the test.only function before committing your changes.
The tests will:
When writing new integration tests:
Create a new test file in src/test/suite/ with the .test.ts extension
Structure your tests using the TDD interface:
import * as assert from "assert"
import * as vscode from "vscode"
suite("Your Test Suite Name", () => {
test("Should do something specific", async function () {
// Your test code here
})
})
Use the global objects (api, provider, extension, panel) to interact with the extension
Timeouts: Use appropriate timeouts for async operations:
const timeout = 30000
const interval = 1000
State Management: Reset extension state before/after tests:
await globalThis.api.setConfiguration({
mode: "Ask",
alwaysAllowModeSwitch: true,
})
Assertions: Use clear assertions with meaningful messages:
assert.ok(condition, "Descriptive message about what failed")
Error Handling: Wrap test code in try/catch blocks and clean up resources:
try {
// Test code
} finally {
// Cleanup code
}
Wait for Operations: Use polling when waiting for async operations:
let startTime = Date.now()
while (Date.now() - startTime < timeout) {
if (condition) {
break
}
await new Promise((resolve) => setTimeout(resolve, interval))
}
Grading: When grading tests, use the Grade: format to ensure the test is graded correctly (See modes.test.ts for an example).
await globalThis.api.startNewTask({
text: `Given this prompt: ${testPrompt} grade the response from 1 to 10 in the format of "Grade: (1-10)": ${output} \n Be sure to say 'I AM DONE GRADING' after the task is complete`,
})