11import { beforeEach , describe , expect , it , vi } from 'vitest' ;
22import * as vscode from 'vscode' ;
33import { PipServerController } from './PipServerController' ;
4- import type { PythonEnvironment } from '../util' ;
4+ import type { PythonEnvironment , PythonEnvironmentApi } from '../util' ;
55import type { IServerManager , IToastService } from '../types' ;
66
77// See __mocks__/vscode.ts for the mock implementation
@@ -20,7 +20,9 @@ vi.mock('../services', async () => {
2020 await vi . importActual < typeof import ( '../services' ) > ( '../services' ) ;
2121 return {
2222 ...actual ,
23- pollUntilTrue : vi . fn ( ) . mockReturnValue ( { promise : Promise . resolve ( ) , cancel : vi . fn ( ) } ) ,
23+ pollUntilTrue : vi
24+ . fn ( )
25+ . mockReturnValue ( { promise : Promise . resolve ( ) , cancel : vi . fn ( ) } ) ,
2426 } ;
2527} ) ;
2628
@@ -57,7 +59,7 @@ function createMockExtension(
5759 isActive : boolean ,
5860 envResult : PythonEnvironment | undefined ,
5961 packagesResult : typeof mockPackages | undefined
60- ) {
62+ ) : vscode . Extension < PythonEnvironmentApi > {
6163 const api = {
6264 getEnvironment : vi . fn ( ) . mockResolvedValue ( envResult ) ,
6365 getPackages : vi . fn ( ) . mockResolvedValue ( packagesResult ) ,
@@ -67,7 +69,7 @@ function createMockExtension(
6769 isActive,
6870 activate : vi . fn ( ) . mockResolvedValue ( undefined ) ,
6971 exports : api ,
70- } ;
72+ } as unknown as vscode . Extension < PythonEnvironmentApi > ;
7173}
7274
7375function createController ( ) : PipServerController {
@@ -182,7 +184,10 @@ describe('checkPipInstall', () => {
182184 it ( 'returns isAvailable false on unsupported platform' , async ( ) => {
183185 vi . stubEnv ( 'PLATFORM' , 'win32' ) ;
184186 const originalPlatform = process . platform ;
185- Object . defineProperty ( process , 'platform' , { value : 'win32' , configurable : true } ) ;
187+ Object . defineProperty ( process , 'platform' , {
188+ value : 'win32' ,
189+ configurable : true ,
190+ } ) ;
186191
187192 const controller = createController ( ) ;
188193 const result = await controller . checkPipInstall ( ) ;
@@ -220,12 +225,18 @@ describe('checkPipInstall', () => {
220225 } ) ;
221226
222227 it ( 'returns isAvailable false when getEnvironment returns null during package check' , async ( ) => {
223- const mockExtWithEnv = createMockExtension ( true , mockEnvironment , undefined ) ;
228+ const mockExtWithEnv = createMockExtension (
229+ true ,
230+ mockEnvironment ,
231+ undefined
232+ ) ;
224233 const mockExtNoEnv = createMockExtension ( true , undefined , undefined ) ;
225234
226235 vi . mocked ( getPythonEnvsExtensionApi )
227236 . mockReturnValueOnce (
228- mockExtWithEnv as unknown as ReturnType < typeof getPythonEnvsExtensionApi >
237+ mockExtWithEnv as unknown as ReturnType <
238+ typeof getPythonEnvsExtensionApi
239+ >
229240 )
230241 . mockReturnValueOnce (
231242 mockExtNoEnv as unknown as ReturnType < typeof getPythonEnvsExtensionApi >
@@ -246,7 +257,11 @@ describe('checkPipInstall', () => {
246257 version : '1.26.0' ,
247258 } ,
248259 ] ;
249- const mockExt = createMockExtension ( true , mockEnvironment , packagesWithoutDh ) ;
260+ const mockExt = createMockExtension (
261+ true ,
262+ mockEnvironment ,
263+ packagesWithoutDh
264+ ) ;
250265 vi . mocked ( getPythonEnvsExtensionApi ) . mockReturnValue (
251266 mockExt as unknown as ReturnType < typeof getPythonEnvsExtensionApi >
252267 ) ;
0 commit comments