mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-10 03:28:03 +00:00
Some checks are pending
Code QA Roo Code / check-translations (push) Waiting to run
Code QA Roo Code / knip (push) Waiting to run
Code QA Roo Code / compile (push) Waiting to run
Code QA Roo Code / platform-unit-test (ubuntu-latest) (push) Waiting to run
Code QA Roo Code / platform-unit-test (windows-latest) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Nightly Publish / publish-nightly (push) Waiting to run
Deploy roocode.com / check-secrets (push) Waiting to run
Deploy roocode.com / deploy (push) Blocked by required conditions
* Remove Roo Code Cloud and evals * Remove unused onboarding and web helper files * Update ChatView welcome tests after cloud removal
210 lines
5 KiB
TypeScript
210 lines
5 KiB
TypeScript
// npx vitest run __tests__/extension.spec.ts
|
|
|
|
import type * as vscode from "vscode"
|
|
|
|
vi.mock("vscode", () => ({
|
|
window: {
|
|
createOutputChannel: vi.fn().mockReturnValue({
|
|
appendLine: vi.fn(),
|
|
}),
|
|
registerWebviewViewProvider: vi.fn(),
|
|
registerUriHandler: vi.fn(),
|
|
tabGroups: {
|
|
onDidChangeTabs: vi.fn(),
|
|
},
|
|
onDidChangeActiveTextEditor: vi.fn(),
|
|
},
|
|
workspace: {
|
|
registerTextDocumentContentProvider: vi.fn(),
|
|
getConfiguration: vi.fn().mockReturnValue({
|
|
get: vi.fn().mockReturnValue([]),
|
|
}),
|
|
createFileSystemWatcher: vi.fn().mockReturnValue({
|
|
onDidCreate: vi.fn(),
|
|
onDidChange: vi.fn(),
|
|
onDidDelete: vi.fn(),
|
|
dispose: vi.fn(),
|
|
}),
|
|
onDidChangeWorkspaceFolders: vi.fn(),
|
|
},
|
|
languages: {
|
|
registerCodeActionsProvider: vi.fn(),
|
|
},
|
|
commands: {
|
|
executeCommand: vi.fn(),
|
|
},
|
|
env: {
|
|
language: "en",
|
|
},
|
|
ExtensionMode: {
|
|
Production: 1,
|
|
},
|
|
}))
|
|
|
|
vi.mock("@dotenvx/dotenvx", () => ({
|
|
config: vi.fn(),
|
|
}))
|
|
|
|
// Mock fs so the extension module can safely check for optional .env.
|
|
vi.mock("fs", () => ({
|
|
existsSync: vi.fn().mockReturnValue(false),
|
|
}))
|
|
|
|
vi.mock("../utils/outputChannelLogger", () => ({
|
|
createOutputChannelLogger: vi.fn().mockReturnValue(vi.fn()),
|
|
createDualLogger: vi.fn().mockReturnValue(vi.fn()),
|
|
}))
|
|
|
|
vi.mock("../shared/package", () => ({
|
|
Package: {
|
|
name: "test-extension",
|
|
outputChannel: "Test Output",
|
|
version: "1.0.0",
|
|
},
|
|
}))
|
|
|
|
vi.mock("../shared/language", () => ({
|
|
formatLanguage: vi.fn().mockReturnValue("en"),
|
|
}))
|
|
|
|
vi.mock("../core/config/ContextProxy", () => ({
|
|
ContextProxy: {
|
|
getInstance: vi.fn().mockResolvedValue({
|
|
getValue: vi.fn(),
|
|
setValue: vi.fn(),
|
|
getValues: vi.fn().mockReturnValue({}),
|
|
getProviderSettings: vi.fn().mockReturnValue({}),
|
|
}),
|
|
},
|
|
}))
|
|
|
|
vi.mock("../integrations/editor/DiffViewProvider", () => ({
|
|
DIFF_VIEW_URI_SCHEME: "test-diff-scheme",
|
|
}))
|
|
|
|
vi.mock("../integrations/terminal/TerminalRegistry", () => ({
|
|
TerminalRegistry: {
|
|
initialize: vi.fn(),
|
|
cleanup: vi.fn(),
|
|
},
|
|
}))
|
|
|
|
vi.mock("../services/mcp/McpServerManager", () => ({
|
|
McpServerManager: {
|
|
cleanup: vi.fn().mockResolvedValue(undefined),
|
|
getInstance: vi.fn().mockResolvedValue(null),
|
|
unregisterProvider: vi.fn(),
|
|
},
|
|
}))
|
|
|
|
vi.mock("../services/code-index/manager", () => ({
|
|
CodeIndexManager: {
|
|
getInstance: vi.fn().mockReturnValue(null),
|
|
},
|
|
}))
|
|
|
|
vi.mock("../utils/migrateSettings", () => ({
|
|
migrateSettings: vi.fn().mockResolvedValue(undefined),
|
|
}))
|
|
|
|
vi.mock("../utils/autoImportSettings", () => ({
|
|
autoImportSettings: vi.fn().mockResolvedValue(undefined),
|
|
}))
|
|
|
|
vi.mock("../extension/api", () => ({
|
|
API: vi.fn().mockImplementation(() => ({})),
|
|
}))
|
|
|
|
vi.mock("../activate", () => ({
|
|
handleUri: vi.fn(),
|
|
registerCommands: vi.fn(),
|
|
registerCodeActions: vi.fn(),
|
|
registerTerminalActions: vi.fn(),
|
|
CodeActionProvider: vi.fn().mockImplementation(() => ({
|
|
providedCodeActionKinds: [],
|
|
})),
|
|
}))
|
|
|
|
vi.mock("../i18n", () => ({
|
|
initializeI18n: vi.fn(),
|
|
t: vi.fn((key) => key),
|
|
}))
|
|
|
|
// Mock ClineProvider
|
|
vi.mock("../core/webview/ClineProvider", async () => {
|
|
const mockInstance = {
|
|
resolveWebviewView: vi.fn(),
|
|
postMessageToWebview: vi.fn(),
|
|
postStateToWebview: vi.fn(),
|
|
postStateToWebviewWithoutClineMessages: vi.fn(),
|
|
getState: vi.fn().mockResolvedValue({}),
|
|
initializeCloudProfileSyncWhenReady: vi.fn().mockResolvedValue(undefined),
|
|
providerSettingsManager: {},
|
|
contextProxy: { getGlobalState: vi.fn() },
|
|
customModesManager: {},
|
|
upsertProviderProfile: vi.fn().mockResolvedValue(undefined),
|
|
}
|
|
return {
|
|
ClineProvider: Object.assign(
|
|
vi.fn().mockImplementation(() => mockInstance),
|
|
{
|
|
// Static method used by extension.ts
|
|
getVisibleInstance: vi.fn().mockReturnValue(mockInstance),
|
|
sideBarId: "roo-cline-sidebar",
|
|
},
|
|
),
|
|
}
|
|
})
|
|
|
|
// Mock modelCache to prevent network requests during module loading
|
|
vi.mock("../api/providers/fetchers/modelCache", () => ({
|
|
getModels: vi.fn().mockResolvedValue([]),
|
|
initializeModelCacheRefresh: vi.fn(),
|
|
}))
|
|
|
|
describe("extension.ts", () => {
|
|
let mockContext: vscode.ExtensionContext
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
|
|
mockContext = {
|
|
extensionPath: "/test/path",
|
|
globalState: {
|
|
get: vi.fn().mockReturnValue(undefined),
|
|
update: vi.fn(),
|
|
},
|
|
subscriptions: [],
|
|
} as unknown as vscode.ExtensionContext
|
|
})
|
|
|
|
test("does not call dotenvx.config when optional .env does not exist", async () => {
|
|
vi.resetModules()
|
|
vi.clearAllMocks()
|
|
|
|
const fs = await import("fs")
|
|
vi.mocked(fs.existsSync).mockReturnValue(false)
|
|
|
|
const dotenvx = await import("@dotenvx/dotenvx")
|
|
|
|
const { activate } = await import("../extension")
|
|
await activate(mockContext)
|
|
|
|
expect(dotenvx.config).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test("calls dotenvx.config when optional .env exists", async () => {
|
|
vi.resetModules()
|
|
vi.clearAllMocks()
|
|
|
|
const fs = await import("fs")
|
|
vi.mocked(fs.existsSync).mockReturnValue(true)
|
|
|
|
const dotenvx = await import("@dotenvx/dotenvx")
|
|
|
|
const { activate } = await import("../extension")
|
|
await activate(mockContext)
|
|
|
|
expect(dotenvx.config).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|