Skip to content

Commit

Permalink
Adding integration tests to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ColemanRoo committed Jan 27, 2025
1 parent 73532e4 commit d33be68
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 30 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/extension-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
on:
push:
branches: []
pull_request:
types: [opened, reopened, ready_for_review, synchronize]
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'

- name: Install dependencies
run: npm run install:all

- name: Compile TypeScript
run: npm run compile

- name: Run test
run: xvfb-run -a npm run test:extension
49 changes: 19 additions & 30 deletions src/test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const path = require("path")
const fs = require("fs")
const dotenv = require("dotenv")

// Load test environment variables
const testEnvPath = path.join(__dirname, ".test_env")
// Load test environment variables from root directory
const testEnvPath = path.join(__dirname, "..", "..", ".test_env")
dotenv.config({ path: testEnvPath })

suite("Roo Code Extension Test Suite", () => {
Expand Down Expand Up @@ -114,18 +114,20 @@ suite("Roo Code Extension Test Suite", () => {

test("Commands should be registered", async () => {
const commands = await vscode.commands.getCommands(true)
console.log(
"Available commands:",
commands.filter((cmd: string) => cmd.startsWith("roo-")),
)

// Test core commands are registered
const expectedCommands = [
"roo-cline.plusButtonClicked",
"roo-cline.mcpButtonClicked",
"roo-cline.promptsButtonClicked",
"roo-cline.historyButtonClicked",
"roo-cline.popoutButtonClicked",
"roo-cline.settingsButtonClicked",
"roo-cline.openInNewTab",
"roo-cline.explainCode",
"roo-cline.fixCode",
"roo-cline.improveCode",
]

for (const cmd of expectedCommands) {
Expand Down Expand Up @@ -206,14 +208,16 @@ suite("Roo Code Extension Test Suite", () => {
let webviewReady = false
let messagesReceived = false
const originalPostMessage = provider.postMessageToWebview.bind(provider)
// @ts-ignore
provider.postMessageToWebview = async (message) => {
provider.postMessageToWebview = async function (message: {
type: string
state: { codeMessages: string | any[] }
}) {
if (message.type === "state") {
webviewReady = true
console.log("Webview state received:", message)
if (message.state?.clineMessages?.length > 0) {
if (message.state?.codeMessages?.length > 0) {
messagesReceived = true
console.log("Messages in state:", message.state.clineMessages)
console.log("Messages in state:", message.state.codeMessages)
}
}
await originalPostMessage(message)
Expand Down Expand Up @@ -268,18 +272,6 @@ suite("Roo Code Extension Test Suite", () => {
throw error
}

// Wait for task to appear in history with tokens
startTime = Date.now()
while (Date.now() - startTime < timeout) {
const state = await provider.getState()
const task = state.taskHistory?.[0]
if (task && task.tokensOut > 0) {
console.log("Task completed with tokens:", task)
break
}
await new Promise((resolve) => setTimeout(resolve, interval))
}

// Wait for messages to be processed
startTime = Date.now()
let responseReceived = false
Expand All @@ -288,29 +280,27 @@ suite("Roo Code Extension Test Suite", () => {
const messages = provider.clineMessages
if (messages && messages.length > 0) {
console.log("Provider messages:", JSON.stringify(messages, null, 2))
// @ts-ignore
const hasResponse = messages.some(
(m: { type: string; text: string }) =>
m.type === "say" && m.text && m.text.toLowerCase().includes("cline"),
m.type === "say" && m.text && m.text.toLowerCase().includes("roo"),
)
if (hasResponse) {
console.log('Found response containing "Cline" in provider messages')
console.log('Found response containing "Roo" in provider messages')
responseReceived = true
break
}
}

// Check provider.cline.clineMessages
//Check provider.cline.clineMessages
const clineMessages = provider.cline?.clineMessages
if (clineMessages && clineMessages.length > 0) {
console.log("Cline messages:", JSON.stringify(clineMessages, null, 2))
// @ts-ignore
const hasResponse = clineMessages.some(
(m: { type: string; text: string }) =>
m.type === "say" && m.text && m.text.toLowerCase().includes("cline"),
m.type === "say" && m.text && m.text.toLowerCase().includes("roo"),
)
if (hasResponse) {
console.log('Found response containing "Cline" in cline messages')
console.log('Found response containing "Roo" in cline messages')
responseReceived = true
break
}
Expand All @@ -321,8 +311,7 @@ suite("Roo Code Extension Test Suite", () => {

if (!responseReceived) {
console.log("Final provider state:", await provider.getState())
console.log("Final cline messages:", provider.cline?.clineMessages)
throw new Error('Did not receive expected response containing "Cline"')
throw new Error("Did not receive any response")
}
} finally {
panel.dispose()
Expand Down

0 comments on commit d33be68

Please sign in to comment.