Skip to content

Commit ba19c61

Browse files
committed
fix: use stub for console methods if they don't exist
- Check if console.log/error/warn exist before deciding spy vs stub - Use stub if property doesn't exist, spy if it does - This should fix the remaining 2 test failures 9/11 tests are now passing, just need to fix these console spy issues.
1 parent d31d5ec commit ba19c61

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

vscode-extension/src/test/helpers/testUtils.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,15 @@ export function spyOnConsole(sandbox: sinon.SinonSandbox): {
183183
error: sinon.SinonSpy;
184184
warn: sinon.SinonSpy;
185185
} {
186-
// Ensure console methods exist before spying
187-
if (!console.log) {
188-
console.log = () => { /* noop */ };
189-
}
190-
if (!console.error) {
191-
console.error = () => { /* noop */ };
192-
}
193-
if (!console.warn) {
194-
console.warn = () => { /* noop */ };
195-
}
186+
// In VS Code test environment, console methods might not exist
187+
// Use stub if property doesn't exist, spy if it does
188+
const logSpy = console.log ? sandbox.spy(console, 'log') : sandbox.stub(console, 'log');
189+
const errorSpy = console.error ? sandbox.spy(console, 'error') : sandbox.stub(console, 'error');
190+
const warnSpy = console.warn ? sandbox.spy(console, 'warn') : sandbox.stub(console, 'warn');
196191

197192
return {
198-
log: sandbox.spy(console, 'log'),
199-
error: sandbox.spy(console, 'error'),
200-
warn: sandbox.spy(console, 'warn')
193+
log: logSpy,
194+
error: errorSpy,
195+
warn: warnSpy
201196
};
202197
}

0 commit comments

Comments
 (0)