Skip to content

Refactor storage.ts into testable modules and add unit tests#589

Merged
EhabY merged 12 commits intocoder:mainfrom
EhabY:untangle-storage-ts
Sep 25, 2025
Merged

Refactor storage.ts into testable modules and add unit tests#589
EhabY merged 12 commits intocoder:mainfrom
EhabY:untangle-storage-ts

Conversation

@EhabY
Copy link
Copy Markdown
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.

@EhabY EhabY force-pushed the untangle-storage-ts branch from 878914a to 4ae208b Compare September 22, 2025 13:52
Copy link
Copy Markdown
Member

@code-asher code-asher left a comment

Choose a reason for hiding this comment

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

Excellent! The only thing I think maybe needs a double-check before merging is the useCustom with the proposed API. If you want to merge and address the rest later, I think that is chill, or you could do it here, up to you!

@EhabY EhabY force-pushed the untangle-storage-ts branch from 4ae208b to ac418d1 Compare September 24, 2025 09:59
@EhabY EhabY merged commit 52df12c into coder:main Sep 25, 2025
2 checks passed
@EhabY EhabY self-assigned this Jan 15, 2026
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

2 participants