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
4 changes: 4 additions & 0 deletions .github/instructions/generic.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ Provide project context and coding guidelines that AI should follow when generat
## Documentation

- Add clear docstrings to public functions, describing their purpose, parameters, and behavior.

## Learnings

- Avoid using 'any' types in TypeScript; import proper types from VS Code API and use specific interfaces for mocks and test objects (1)
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ export default [{
eqeqeq: "warn",
"no-throw-literal": "warn",
semi: "warn",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-explicit-any": "error",
},
}];
39 changes: 27 additions & 12 deletions src/test/features/terminalEnvVarInjectorBasic.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import * as sinon from 'sinon';
import * as typeMoq from 'typemoq';
import { GlobalEnvironmentVariableCollection, workspace } from 'vscode';
import { Disposable, GlobalEnvironmentVariableCollection, workspace, WorkspaceFolder } from 'vscode';
import { DidChangeEnvironmentVariablesEventArgs } from '../../api';
import { EnvVarManager } from '../../features/execution/envVariableManager';
import { TerminalEnvVarInjector } from '../../features/terminal/terminalEnvVarInjector';

Expand All @@ -18,8 +19,7 @@ suite('TerminalEnvVarInjector Basic Tests', () => {
let envVarManager: typeMoq.IMock<EnvVarManager>;
let injector: TerminalEnvVarInjector;
let mockScopedCollection: MockScopedCollection;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let workspaceFoldersStub: any;
let workspaceFoldersStub: WorkspaceFolder[];

setup(() => {
envVarCollection = typeMoq.Mock.ofType<GlobalEnvironmentVariableCollection>();
Expand All @@ -40,19 +40,25 @@ suite('TerminalEnvVarInjector Basic Tests', () => {
};

// Setup environment variable collection to return scoped collection
envVarCollection.setup((x) => x.getScoped(typeMoq.It.isAny())).returns(() => mockScopedCollection as any);
envVarCollection.setup((x) => x.getScoped(typeMoq.It.isAny())).returns(() => mockScopedCollection as never);
envVarCollection.setup((x) => x.clear()).returns(() => {});

// Setup minimal mocks for event subscriptions
envVarManager
.setup((m) => m.onDidChangeEnvironmentVariables)
.returns(
() =>
.returns(() => {
// Return a mock Event function that returns a Disposable when called
const mockEvent = (_listener: (e: DidChangeEnvironmentVariablesEventArgs) => void) =>
({
dispose: () => {},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any),
);
} as Disposable);
return mockEvent;
});

// Mock workspace.onDidChangeConfiguration to return a Disposable
sinon.stub(workspace, 'onDidChangeConfiguration').returns({
dispose: () => {},
} as Disposable);
});

teardown(() => {
Expand Down Expand Up @@ -85,12 +91,21 @@ suite('TerminalEnvVarInjector Basic Tests', () => {
envVarManager.reset();
envVarManager
.setup((m) => m.onDidChangeEnvironmentVariables)
.returns((_handler) => {
.returns(() => {
eventHandlerRegistered = true;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return { dispose: () => {} } as any;
// Return a mock Event function that returns a Disposable when called
const mockEvent = (_listener: (e: DidChangeEnvironmentVariablesEventArgs) => void) =>
({
dispose: () => {},
} as Disposable);
return mockEvent;
});

// Mock workspace.onDidChangeConfiguration to return a Disposable
sinon.stub(workspace, 'onDidChangeConfiguration').returns({
dispose: () => {},
} as Disposable);

// Act
injector = new TerminalEnvVarInjector(envVarCollection.object, envVarManager.object);

Expand Down
Loading