From fd7b6bf40a9c274f92dbfc576f4157217b0101f8 Mon Sep 17 00:00:00 2001 From: Christian Gunderman Date: Mon, 5 Jan 2026 13:41:35 -0800 Subject: [PATCH] Fix failing unit tests (#15940) --- packages/core/src/code_assist/oauth2.test.ts | 38 ++++++++------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/packages/core/src/code_assist/oauth2.test.ts b/packages/core/src/code_assist/oauth2.test.ts index 8e37537763..63e63c897c 100644 --- a/packages/core/src/code_assist/oauth2.test.ts +++ b/packages/core/src/code_assist/oauth2.test.ts @@ -1129,21 +1129,7 @@ describe('oauth2', () => { ); // Spy on process.on to capture the SIGINT handler - let sigIntHandler: (() => void) | undefined; - const originalOn = process.on; - const processOnSpy = vi - .spyOn(process, 'on') - .mockImplementation( - ( - event: string | symbol, - listener: (...args: unknown[]) => void, - ) => { - if (event === 'SIGINT') { - sigIntHandler = listener as () => void; - } - return originalOn.call(process, event, listener); - }, - ); + const processOnSpy = vi.spyOn(process, 'on'); const processRemoveListenerSpy = vi.spyOn(process, 'removeListener'); const clientPromise = getOauthClient( @@ -1154,6 +1140,11 @@ describe('oauth2', () => { // Wait a tick to ensure the SIGINT handler is registered await new Promise((resolve) => setTimeout(resolve, 0)); + const sigintCall = processOnSpy.mock.calls.find( + (call) => call[0] === 'SIGINT', + ); + const sigIntHandler = sigintCall?.[1] as (() => void) | undefined; + expect(sigIntHandler).toBeDefined(); // Trigger SIGINT @@ -1196,15 +1187,7 @@ describe('oauth2', () => { ); // Spy on process.stdin.on - let dataHandler: ((data: Buffer) => void) | undefined; - const stdinOnSpy = vi - .spyOn(process.stdin, 'on') - .mockImplementation((event: string | symbol, listener) => { - if (event === 'data') { - dataHandler = listener as (data: Buffer) => void; - } - return process.stdin; - }); + const stdinOnSpy = vi.spyOn(process.stdin, 'on'); const stdinRemoveListenerSpy = vi.spyOn( process.stdin, 'removeListener', @@ -1217,6 +1200,13 @@ describe('oauth2', () => { await new Promise((resolve) => setTimeout(resolve, 0)); + const dataCall = stdinOnSpy.mock.calls.find( + (call: [string, ...unknown[]]) => call[0] === 'data', + ); + const dataHandler = dataCall?.[1] as + | ((data: Buffer) => void) + | undefined; + expect(dataHandler).toBeDefined(); // Trigger Ctrl+C