Skip to content

Conversation

EhabY
Copy link
Collaborator

@EhabY EhabY commented Sep 22, 2025

Closes #588

This PR refactors storage.ts into small, isolated modules that are straightforward to unit test (with mocks). It also upgrades vitest 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:

  • Unit tests (mocked 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.
  • Integration/E2E tests (real VS Code): Exercise "real" user flows by launching VS Code and, eventually, a server. These are valuable but more limited, since UI interaction is hard to automate and not all code paths are easily reachable.

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.

@@ -0,0 +1,142 @@
import { vi } from "vitest";
Copy link
Collaborator Author

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

Comment on lines +43 to +47
private readonly logger: Logger,
private readonly pathResolver: PathResolver,
private readonly mementoManager: MementoManager,
private readonly secretsManager: SecretsManager,
private readonly binaryManager: BinaryManager,
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@EhabY EhabY force-pushed the untangle-storage-ts branch from 878914a to 4ae208b Compare September 22, 2025 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor storage.ts into testable modules and add unit tests
1 participant