summaryrefslogtreecommitdiff
path: root/packages/vscode-ide-companion/src/extension-multi-folder.test.ts
diff options
context:
space:
mode:
authorShreya Keshive <[email protected]>2025-08-20 14:09:53 -0700
committerGitHub <[email protected]>2025-08-20 21:09:53 +0000
commit80ff3cd25ef7544ff4e6bde29770d711e820119f (patch)
tree94033ba153f6016e35c32d70f6e5a2cc5d3200a2 /packages/vscode-ide-companion/src/extension-multi-folder.test.ts
parent6aff66f501cb6b124bafc4158b1b56640481cf34 (diff)
feat(ide ext): Write workspace path to port file (#6659)
Diffstat (limited to 'packages/vscode-ide-companion/src/extension-multi-folder.test.ts')
-rw-r--r--packages/vscode-ide-companion/src/extension-multi-folder.test.ts211
1 files changed, 0 insertions, 211 deletions
diff --git a/packages/vscode-ide-companion/src/extension-multi-folder.test.ts b/packages/vscode-ide-companion/src/extension-multi-folder.test.ts
deleted file mode 100644
index c8fff810..00000000
--- a/packages/vscode-ide-companion/src/extension-multi-folder.test.ts
+++ /dev/null
@@ -1,211 +0,0 @@
-/**
- * @license
- * Copyright 2025 Google LLC
- * SPDX-License-Identifier: Apache-2.0
- */
-
-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import * as vscode from 'vscode';
-import * as path from 'path';
-import { activate } from './extension.js';
-
-vi.mock('vscode', () => ({
- window: {
- createOutputChannel: vi.fn(() => ({
- appendLine: vi.fn(),
- })),
- showInformationMessage: vi.fn(),
- createTerminal: vi.fn(() => ({
- show: vi.fn(),
- sendText: vi.fn(),
- })),
- onDidChangeActiveTextEditor: vi.fn(),
- activeTextEditor: undefined,
- tabGroups: {
- all: [],
- close: vi.fn(),
- },
- showTextDocument: vi.fn(),
- },
- workspace: {
- workspaceFolders: [],
- onDidCloseTextDocument: vi.fn(),
- registerTextDocumentContentProvider: vi.fn(),
- onDidChangeWorkspaceFolders: vi.fn(),
- },
- commands: {
- registerCommand: vi.fn(),
- executeCommand: vi.fn(),
- },
- Uri: {
- joinPath: vi.fn(),
- file: (path: string) => ({ fsPath: path }),
- },
- ExtensionMode: {
- Development: 1,
- Production: 2,
- },
- EventEmitter: vi.fn(() => ({
- event: vi.fn(),
- fire: vi.fn(),
- dispose: vi.fn(),
- })),
-}));
-
-describe('activate with multiple folders', () => {
- let context: vscode.ExtensionContext;
- let onDidChangeWorkspaceFoldersCallback: (
- e: vscode.WorkspaceFoldersChangeEvent,
- ) => void;
-
- beforeEach(() => {
- context = {
- subscriptions: [],
- environmentVariableCollection: {
- replace: vi.fn(),
- },
- globalState: {
- get: vi.fn().mockReturnValue(true),
- update: vi.fn(),
- },
- extensionUri: {
- fsPath: '/path/to/extension',
- },
- } as unknown as vscode.ExtensionContext;
-
- vi.mocked(vscode.workspace.onDidChangeWorkspaceFolders).mockImplementation(
- (callback) => {
- onDidChangeWorkspaceFoldersCallback = callback;
- return { dispose: vi.fn() };
- },
- );
- });
-
- afterEach(() => {
- vi.restoreAllMocks();
- });
-
- it('should set a single folder path', async () => {
- const workspaceFoldersSpy = vi.spyOn(
- vscode.workspace,
- 'workspaceFolders',
- 'get',
- );
- workspaceFoldersSpy.mockReturnValue([
- { uri: { fsPath: '/foo/bar' } },
- ] as vscode.WorkspaceFolder[]);
-
- await activate(context);
-
- expect(context.environmentVariableCollection.replace).toHaveBeenCalledWith(
- 'GEMINI_CLI_IDE_WORKSPACE_PATH',
- '/foo/bar',
- );
- });
-
- it('should set multiple folder paths, separated by OS-specific path delimiter', async () => {
- const workspaceFoldersSpy = vi.spyOn(
- vscode.workspace,
- 'workspaceFolders',
- 'get',
- );
- workspaceFoldersSpy.mockReturnValue([
- { uri: { fsPath: '/foo/bar' } },
- { uri: { fsPath: '/baz/qux' } },
- ] as vscode.WorkspaceFolder[]);
-
- await activate(context);
-
- expect(context.environmentVariableCollection.replace).toHaveBeenCalledWith(
- 'GEMINI_CLI_IDE_WORKSPACE_PATH',
- ['/foo/bar', '/baz/qux'].join(path.delimiter),
- );
- });
-
- it('should set an empty string if no folders are open', async () => {
- const workspaceFoldersSpy = vi.spyOn(
- vscode.workspace,
- 'workspaceFolders',
- 'get',
- );
- workspaceFoldersSpy.mockReturnValue([]);
-
- await activate(context);
-
- expect(context.environmentVariableCollection.replace).toHaveBeenCalledWith(
- 'GEMINI_CLI_IDE_WORKSPACE_PATH',
- '',
- );
- });
-
- it('should update the path when workspace folders change', async () => {
- const workspaceFoldersSpy = vi.spyOn(
- vscode.workspace,
- 'workspaceFolders',
- 'get',
- );
- workspaceFoldersSpy.mockReturnValue([
- { uri: { fsPath: '/foo/bar' } },
- ] as vscode.WorkspaceFolder[]);
-
- await activate(context);
-
- expect(context.environmentVariableCollection.replace).toHaveBeenCalledWith(
- 'GEMINI_CLI_IDE_WORKSPACE_PATH',
- '/foo/bar',
- );
-
- // Simulate adding a folder
- workspaceFoldersSpy.mockReturnValue([
- { uri: { fsPath: '/foo/bar' } },
- { uri: { fsPath: '/baz/qux' } },
- ] as vscode.WorkspaceFolder[]);
- onDidChangeWorkspaceFoldersCallback({
- added: [{ uri: { fsPath: '/baz/qux' } } as vscode.WorkspaceFolder],
- removed: [],
- });
-
- expect(context.environmentVariableCollection.replace).toHaveBeenCalledWith(
- 'GEMINI_CLI_IDE_WORKSPACE_PATH',
- ['/foo/bar', '/baz/qux'].join(path.delimiter),
- );
-
- // Simulate removing a folder
- workspaceFoldersSpy.mockReturnValue([
- { uri: { fsPath: '/baz/qux' } },
- ] as vscode.WorkspaceFolder[]);
- onDidChangeWorkspaceFoldersCallback({
- added: [],
- removed: [{ uri: { fsPath: '/foo/bar' } } as vscode.WorkspaceFolder],
- });
-
- expect(context.environmentVariableCollection.replace).toHaveBeenCalledWith(
- 'GEMINI_CLI_IDE_WORKSPACE_PATH',
- '/baz/qux',
- );
- });
-
- it.skipIf(process.platform !== 'win32')(
- 'should handle windows paths',
- async () => {
- const workspaceFoldersSpy = vi.spyOn(
- vscode.workspace,
- 'workspaceFolders',
- 'get',
- );
- workspaceFoldersSpy.mockReturnValue([
- { uri: { fsPath: 'c:/foo/bar' } },
- { uri: { fsPath: 'd:/baz/qux' } },
- ] as vscode.WorkspaceFolder[]);
-
- await activate(context);
-
- expect(
- context.environmentVariableCollection.replace,
- ).toHaveBeenCalledWith(
- 'GEMINI_CLI_IDE_WORKSPACE_PATH',
- 'c:/foo/bar;d:/baz/qux',
- );
- },
- );
-});