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: 0 additions & 4 deletions .github/instructions/generic.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,3 @@ 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": "error",
"@typescript-eslint/no-explicit-any": "warn",
},
}];
39 changes: 12 additions & 27 deletions src/test/features/terminalEnvVarInjectorBasic.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

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

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

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

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

Check warning on line 43 in src/test/features/terminalEnvVarInjectorBasic.unit.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

Check warning on line 43 in src/test/features/terminalEnvVarInjectorBasic.unit.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
envVarCollection.setup((x) => x.clear()).returns(() => {});

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

// Mock workspace.onDidChangeConfiguration to return a Disposable
sinon.stub(workspace, 'onDidChangeConfiguration').returns({
dispose: () => {},
} as Disposable);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any),
);
});

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

// 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