Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-yaml
args: [--allow-multiple-documents]
- id: check-json
- id: trailing-whitespace
66 changes: 33 additions & 33 deletions src/__tests__/env_test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jest.mock('vscode', () => {
tooltip: '',
command: undefined,
};

return {
window: {
createStatusBarItem: () => statusBarItem,
Expand Down Expand Up @@ -63,8 +63,8 @@ jest.mock('vscode', () => {
});

jest.mock('../utils/envDetection', () => ({
findPythonEnvsWithJac: jest.fn(),
validateJacExecutable: jest.fn(),
findPythonEnvsWithJac: jest.fn(),
validateJacExecutable: jest.fn(),
}));

// Mock the LspManager class
Expand All @@ -87,27 +87,27 @@ describe('EnvManager (Jest)', () => {

beforeEach(() => {
jest.clearAllMocks();

// Reset LSP manager mock
mockLspManager.start.mockClear();
mockLspManager.stop.mockClear();
mockLspManager.restart.mockClear();
mockLspManager.getClient.mockClear();

context = {
globalState: {
get: jest.fn().mockReturnValue(undefined),
update: jest.fn().mockResolvedValue(undefined),
update: jest.fn().mockResolvedValue(undefined),
},
subscriptions: [],
subscriptions: [],
};

envManager = new EnvManager(context);
});

/**
* TEST-1: Default behavior when no environment is configured
*
*
* - EnvManager should provide a sensible default when no Jac environment is saved
* - The default should be platform-appropriate ('jac.exe' on Windows, 'jac' on Unix)
*
Expand All @@ -122,7 +122,7 @@ describe('EnvManager (Jest)', () => {

/**
* TEST 2: Status bar updates correctly when environment is set
*
*
* - Status bar text is updated to show current Jac environment
* - Status bar is properly displayed to the user
*
Expand All @@ -137,7 +137,7 @@ describe('EnvManager (Jest)', () => {

/**
* TEST 3: Manual path entry - successful validation
*
*
* What we're testing:
* - User can manually enter a path to a Jac executable
* - Valid paths are accepted and saved
Expand All @@ -158,7 +158,7 @@ describe('EnvManager (Jest)', () => {

/**
* TEST 4: Manual path entry - validation failure and retry
*
*
* - Invalid paths are rejected with error message
* - User is prompted to retry after entering invalid path
* - Error handling works correctly in the retry flow
Expand All @@ -168,7 +168,7 @@ describe('EnvManager (Jest)', () => {
(envDetection.validateJacExecutable as jest.Mock).mockResolvedValue(false);
(vscode.window.showInputBox as jest.Mock)
.mockResolvedValueOnce('/bad/jac')
.mockResolvedValueOnce(undefined);
.mockResolvedValueOnce(undefined);
(vscode.window.showErrorMessage as jest.Mock).mockResolvedValue('Retry');

await (envManager as any).handleManualPathEntry();
Expand All @@ -179,11 +179,11 @@ describe('EnvManager (Jest)', () => {

/**
* TEST 5: Successful environment selection from auto-detected environments
*
*
* - Auto-detection finds available Jac environments
* - User can select from a list of found environments
* - Selected environment is saved and applied
*
*
*/
test('should prompt environment selection when envs found', async () => {

Expand All @@ -203,10 +203,10 @@ describe('EnvManager (Jest)', () => {

/**
* TEST 6: Warning displayed when no environments are found
*
*
* - Appropriate warning is shown when no Jac environments are detected
* - User gets helpful guidance when Jac is not installed
*
*
*/
test('should show warning when no envs are found', async () => {

Expand All @@ -225,11 +225,11 @@ describe('EnvManager (Jest)', () => {

/**
* TEST 7: Initialization with saved environment path
*
*
* - EnvManager correctly loads a previously saved environment path
* - Status bar is updated with the saved environment
* - No prompting occurs when valid saved environment exists
*
*
*/
test('should initialize with saved environment path', async () => {

Expand All @@ -244,11 +244,11 @@ describe('EnvManager (Jest)', () => {

/**
* TEST 8: Initialization handles invalid saved environment
*
*
* - Invalid saved environments are detected and cleared
* - User is warned about the invalid environment
* - New environment selection is prompted
*
*
*/
test('should handle invalid saved environment during init', async () => {

Expand All @@ -267,11 +267,11 @@ describe('EnvManager (Jest)', () => {

/**
* TEST 9: User cancels environment selection
*
*
* - Graceful handling when user cancels the environment selection dialog
* - Status bar still updates appropriately even when user cancels
* - No errors occur when user dismisses dialogs
*
*
*/
test('should handle user cancellation of environment selection', async () => {

Expand All @@ -286,11 +286,11 @@ describe('EnvManager (Jest)', () => {

/**
* TEST 10: Language server restart without VSCode reload on environment change
*
*
* - When LSP manager is available, it should restart the language server
* - VSCode window reload should NOT be called when LSP manager exists
* - Success message should be shown for environment change
*
*
*/
test('should restart language server without VSCode reload when environment changes', async () => {
(getLspManager as jest.Mock).mockReturnValue(mockLspManager);
Expand All @@ -304,7 +304,7 @@ describe('EnvManager (Jest)', () => {
await envManager.promptEnvironmentSelection();

expect(mockLspManager.restart).toHaveBeenCalledTimes(1);

expect(vscode.commands.executeCommand).not.toHaveBeenCalledWith('workbench.action.reloadWindow');
expect(context.globalState.update).toHaveBeenCalledWith('jacEnvPath', '/new/jac/path');
expect(vscode.window.showInformationMessage).toHaveBeenCalledWith(
Expand All @@ -318,11 +318,11 @@ describe('EnvManager (Jest)', () => {

/**
* TEST 11: Fallback to VSCode reload when LSP manager is unavailable
*
*
* - When LSP manager is not available, fall back to VSCode reload
* - Appropriate fallback message should be shown
* - Environment change should still be saved
*
*
*/
test('should fallback to VSCode reload when LSP manager unavailable', async () => {
(getLspManager as jest.Mock).mockReturnValue(undefined);
Expand All @@ -345,11 +345,11 @@ describe('EnvManager (Jest)', () => {

/**
* TEST 12: Handle LSP manager restart failure with graceful fallback
*
*
* - When LSP restart fails, should show error and fall back to reload
* - Should handle restart errors gracefully without crashing
* - Environment should still be saved even if restart fails
*
*
*/
test('should handle LSP restart failure and fallback to reload', async () => {
const mockError = new Error('LSP restart failed');
Expand Down Expand Up @@ -377,11 +377,11 @@ describe('EnvManager (Jest)', () => {

/**
* TEST 13: Manual path entry with successful LSP restart
*
*
* - Manual path entry should trigger LSP restart when LSP manager is available
* - Should not reload VSCode when LSP restart succeeds
* - Should validate path before attempting restart
*
*
*/
test('should restart LSP after successful manual path entry', async () => {
(getLspManager as jest.Mock).mockReturnValue(mockLspManager);
Expand All @@ -401,11 +401,11 @@ describe('EnvManager (Jest)', () => {

/**
* TEST 14: File browser selection with successful LSP restart
*
*
* - File browser selection should trigger LSP restart when available
* - Should not reload VSCode when LSP restart succeeds
* - Should validate selected file before attempting restart
*
*
*/
test('should restart LSP after successful file browser selection', async () => {
(getLspManager as jest.Mock).mockReturnValue(mockLspManager);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function registerAllCommands(context: vscode.ExtensionContext, envManager
vscode.commands.registerCommand(COMMANDS.TOGGLE_DEV_MODE, async () => {
const config = vscode.workspace.getConfiguration('jaclang-extension');
const currentMode = config.get<boolean>('developerMode', false);

// Toggle the mode
await config.update('developerMode', !currentMode, vscode.ConfigurationTarget.Global);
})
Expand Down
Loading