-
Notifications
You must be signed in to change notification settings - Fork 32
Refactor storage.ts into testable modules and add unit tests #589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,142 @@ | |||
import { vi } from "vitest"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly we have to duplicate this "vscode" definition manually for tests because we cannot just import VS Code types
private readonly logger: Logger, | ||
private readonly pathResolver: PathResolver, | ||
private readonly mementoManager: MementoManager, | ||
private readonly secretsManager: SecretsManager, | ||
private readonly binaryManager: BinaryManager, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially I can introduce something like a ServiceContainer
that contains all our services/data objects
/** | ||
* Migrate the session token file from "session_token" to "session", if needed. | ||
*/ | ||
private async migrateSessionToken(label: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This util will be cleaned up as part of the effort for refactoring the remote.ts
* Code API to get the contents of an output panel. We use this to get the | ||
* active port so we can display network information. | ||
*/ | ||
private async getRemoteSSHLogPath(): Promise<string | undefined> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
878914a
to
4ae208b
Compare
Closes #588
This PR refactors
storage.ts
into small, isolated modules that are straightforward to unit test (with mocks). It also upgradesvitest
to a version that plays nicely with VS Code extensions, so we can view coverage, run and debug tests directly in VS Code.VS Code Test Explorer:
Screencast.from.2025-09-22.16-54-03.webm
Why mock
vscode
?With the current VS Code Extension API, we essentially have two testing layers:
vscode
) : Validate our module's behavior independently of the VS Code API and external calls (e.g., Axios). These are fast, reliable, and cover most logic.By mocking
vscode
for unit tests, we keep feedback tight and deterministic, while reserving integration tests for end-to-end scenarios that require the actual runtime.