@@ -32,7 +32,7 @@ Your goal is to help me arrive at the most elegant and effective solution by com
32
32
33
33
##Test Coverage Guidelines
34
34
35
- Current status:** 74.35 % overall unit test coverage** with359 unit tests and 69 integration tests passing.
35
+ Current status:** 78.49 % overall unit test coverage** with405 unit tests and 69 integration tests passing.
36
36
37
37
###TDD Approach for New Features
38
38
@@ -52,9 +52,10 @@ Current status: **74.35% overall unit test coverage** with 359 unit tests and 69
52
52
53
53
###Testing Patterns to Follow
54
54
55
- - ** Create factory functions** for common test setups (see test-helpers.ts)
55
+ - ** Use mock factories from test-helpers.ts** - 30+ factory functions available for all common types
56
+ - ** No inline mock definitions** - always use factory functions for consistency
57
+ - ** Minimal` as any ` usage** - reduced from 95 to 4 instances (96% reduction)
56
58
- ** Use createMockOutputChannelWithLogger()** for consistent Logger testing
57
- - ** Avoid` as any ` ** - create proper mock types or use` as never ` for VS Code mocks
58
59
- ** Mock external dependencies** properly using vi.mock() with TypeScript types
59
60
- ** Test core functionality first** - constructor, main methods, error paths
60
61
- ** Ensure backward compatibility** by adding compatibility methods during refactoring
@@ -63,34 +64,60 @@ Current status: **74.35% overall unit test coverage** with 359 unit tests and 69
63
64
###Test Helper Patterns
64
65
65
66
``` typescript
66
- // Example factory function from test-helpers.ts
67
- export function createMockOutputChannelWithLogger(options ? : {
68
- verbose? : boolean ;
69
- }): {
70
- mockOutputChannel: { appendLine: ReturnType <typeof vi .fn > };
71
- logger: Logger ;
72
- }
67
+ // Example factory functions from test-helpers.ts
68
+
69
+ // Storage variants
70
+ export function createMockStorageWithAuth(): Storage
71
+ export function createMockStorageMinimal(): Storage
72
+
73
+ // Workspace variants
74
+ export function createMockWorkspaceRunning(): Workspace
75
+ export function createMockWorkspaceStopped(): Workspace
76
+ export function createMockWorkspaceFailed(): Workspace
77
+
78
+ // VSCode components
79
+ export function createMockExtensionContext(): vscode .ExtensionContext
80
+ export function createMockRemoteSSHExtension(): vscode .Extension <unknown >
81
+ export function createMockTreeView<T >(): vscode .TreeView <T >
82
+ export function createMockStatusBarItem(): vscode .StatusBarItem
83
+ export function createMockQuickPick<T >(): vscode .QuickPick <T >
84
+ export function createMockTerminal(): vscode .Terminal
85
+ export function createMockOutputChannel(): vscode .OutputChannel
86
+
87
+ // Other utilities
88
+ export function createMockWorkspaceProvider(): WorkspaceProvider
89
+ export function createMockRemote(): Remote
90
+ export function createMockCommands(): Commands
91
+ export function createMockEventEmitter<T >(): vscode .EventEmitter <T >
92
+ export function createMockAxiosInstance(): AxiosInstance
93
+ export function createMockProxyAgent(): ProxyAgent
94
+ export function createMockUri(path : string ,scheme ? : string ): vscode .Uri
73
95
```
74
96
75
97
###Files with Excellent Coverage (> 90 % )- Use as Examples :
76
98
77
99
- featureSet .ts :100 %
78
100
- proxy .ts :100 %
79
101
- logger .ts :98.44 % (good TDD example )
102
+ - sshSupport .ts :98.13 %
80
103
- util .ts :97.31 %
81
104
- headers .ts :96.49 %
82
105
- api - helper .ts :96.36 %
83
106
- sshConfig .ts :96.21 %
84
107
- api .ts :95.52 %
108
+ - extension .ts :93.07 % (refactored from 39.71 % using TDD )
109
+ - workspaceMonitor .ts :92.37 %
85
110
- error .ts :90.44 %
111
+ - cliManager .ts :90.05 %
86
112
87
113
###Current Development Approach
88
114
89
115
- ** TDD for new features ** - test first ,implement second
90
116
- ** Incremental refactoring ** - small ,measurable improvements
91
117
- ** Backward compatibility ** - add compatibility methods when changing interfaces
92
- - ** Factory functions in test-helpers.ts** - reusable test setup patterns
93
- - ** Systematic cleanup** - remove` as any ` casts, add proper types
118
+ - ** Comprehensive mock factories ** - 30 + factory functions in test - helpers .ts
119
+ - ** No inline mocks ** - all test mocks use factory functions
120
+ - ** Type - safe testing ** - minimal ` as any ` usage (only 4 instances remain )
94
121
- ** Measure progress constantly ** - run ` yarn test:ci --coverage ` after every change
95
122
96
123
###Refactoring Strategy
@@ -102,32 +129,34 @@ When replacing legacy patterns (e.g., writeToCoderOutputChannel):
102
129
3. Incrementally replace usage starting with highest - impact files
103
130
4. Maintain full test suite passing throughout
104
131
105
- ###Example:Logger Integration Pattern
132
+ ###Example :TDD Refactoring Pattern ( extension . ts success story )
106
133
107
134
` ` ` typescript
108
- // 1. Add backward compatibility to new class
109
- class Logger {
110
- // ... new methods ...
111
-
112
- // Backward compatibility for legacy code
113
- writeToCoderOutputChannel(message : string ): void {
114
- this .info (message );
135
+ // 1. Write test for extracted function FIRST
136
+ describe("setupRemoteSSHExtension", () => {
137
+ it("should configure remote SSH when available", () => {
138
+ const mockExtension = createMockRemoteSSHExtension();
139
+ const mockRemote = createMockRemote();
140
+
141
+ const result = setupRemoteSSHExtension(mockExtension);
142
+
143
+ expect(result).toBe(mockRemote);
144
+ });
145
+ });
146
+
147
+ // 2. Extract function to make test pass
148
+ export function setupRemoteSSHExtension(
149
+ remoteSSHExtension: vscode.Extension<unknown> | undefined,
150
+ ): Remote | undefined {
151
+ if (!remoteSSHExtension) {
152
+ return undefined;
115
153
}
154
+ // Implementation here
116
155
}
117
156
118
- // 2. Create factory in test-helpers.ts
119
- export function createMockOutputChannelWithLogger() {
120
- const mockOutputChannel= { appendLine:vi .fn () };
121
- const logger= new Logger (mockOutputChannel );
122
- return {mockOutputChannel ,logger };
123
- }
157
+ // 3. Replace in original code
158
+ const remoteSSHExtension = vscode.extensions.getExtension("ms-vscode-remote.remote-ssh");
159
+ const remote = setupRemoteSSHExtension(remoteSSHExtension);
124
160
125
- // 3. Test compatibility before refactoring
126
- it (" should be backward compatible" , ()=> {
127
- const { mockOutputChannel, logger }= createMockOutputChannelWithLogger ();
128
- logger .writeToCoderOutputChannel (" Test" );
129
- expect (mockOutputChannel .appendLine ).toHaveBeenCalledWith (
130
- expect .stringMatching (/ \[ . * \] \[ INFO\] Test/ )
131
- );
132
- });
161
+ // Result: extension.ts coverage improved from 39.71% to 93.07%
133
162
` ` `