11import { withOAuth , withLogging , applyMiddlewares , createMiddleware } from './middleware.js' ;
22import { OAuthClientProvider } from './auth.js' ;
33import { FetchLike } from '../shared/transport.js' ;
4+ import { MockInstance , Mocked , MockedFunction } from 'vitest' ;
45
5- jest . mock ( '../client/auth.js' , ( ) => {
6- const actual = jest . requireActual ( '../client/auth.js' ) ;
6+ vi . mock ( '../client/auth.js' , async ( ) => {
7+ const actual = await vi . importActual < typeof import ( '../client/auth.js' ) > ( '../client/auth.js' ) ;
78 return {
89 ...actual ,
9- auth : jest . fn ( ) ,
10- extractWWWAuthenticateParams : jest . fn ( )
10+ auth : vi . fn ( ) ,
11+ extractWWWAuthenticateParams : vi . fn ( )
1112 } ;
1213} ) ;
1314
1415import { auth , extractWWWAuthenticateParams } from './auth.js' ;
1516
16- const mockAuth = auth as jest . MockedFunction < typeof auth > ;
17- const mockExtractWWWAuthenticateParams = extractWWWAuthenticateParams as jest . MockedFunction < typeof extractWWWAuthenticateParams > ;
17+ const mockAuth = auth as MockedFunction < typeof auth > ;
18+ const mockExtractWWWAuthenticateParams = extractWWWAuthenticateParams as MockedFunction < typeof extractWWWAuthenticateParams > ;
1819
1920describe ( 'withOAuth' , ( ) => {
20- let mockProvider : jest . Mocked < OAuthClientProvider > ;
21- let mockFetch : jest . MockedFunction < FetchLike > ;
21+ let mockProvider : Mocked < OAuthClientProvider > ;
22+ let mockFetch : MockedFunction < FetchLike > ;
2223
2324 beforeEach ( ( ) => {
24- jest . clearAllMocks ( ) ;
25+ vi . clearAllMocks ( ) ;
2526
2627 mockProvider = {
2728 get redirectUrl ( ) {
@@ -30,16 +31,16 @@ describe('withOAuth', () => {
3031 get clientMetadata ( ) {
3132 return { redirect_uris : [ 'http://localhost/callback' ] } ;
3233 } ,
33- tokens : jest . fn ( ) ,
34- saveTokens : jest . fn ( ) ,
35- clientInformation : jest . fn ( ) ,
36- redirectToAuthorization : jest . fn ( ) ,
37- saveCodeVerifier : jest . fn ( ) ,
38- codeVerifier : jest . fn ( ) ,
39- invalidateCredentials : jest . fn ( )
34+ tokens : vi . fn ( ) ,
35+ saveTokens : vi . fn ( ) ,
36+ clientInformation : vi . fn ( ) ,
37+ redirectToAuthorization : vi . fn ( ) ,
38+ saveCodeVerifier : vi . fn ( ) ,
39+ codeVerifier : vi . fn ( ) ,
40+ invalidateCredentials : vi . fn ( )
4041 } ;
4142
42- mockFetch = jest . fn ( ) ;
43+ mockFetch = vi . fn ( ) ;
4344 } ) ;
4445
4546 it ( 'should add Authorization header when tokens are available (with explicit baseUrl)' , async ( ) => {
@@ -371,8 +372,8 @@ describe('withOAuth', () => {
371372} ) ;
372373
373374describe ( 'withLogging' , ( ) => {
374- let mockFetch : jest . MockedFunction < FetchLike > ;
375- let mockLogger : jest . MockedFunction <
375+ let mockFetch : MockedFunction < FetchLike > ;
376+ let mockLogger : MockedFunction <
376377 ( input : {
377378 method : string ;
378379 url : string | URL ;
@@ -384,17 +385,17 @@ describe('withLogging', () => {
384385 error ?: Error ;
385386 } ) => void
386387 > ;
387- let consoleErrorSpy : jest . SpyInstance ;
388- let consoleLogSpy : jest . SpyInstance ;
388+ let consoleErrorSpy : MockInstance ;
389+ let consoleLogSpy : MockInstance ;
389390
390391 beforeEach ( ( ) => {
391- jest . clearAllMocks ( ) ;
392+ vi . clearAllMocks ( ) ;
392393
393- consoleErrorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
394- consoleLogSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
394+ consoleErrorSpy = vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
395+ consoleLogSpy = vi . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
395396
396- mockFetch = jest . fn ( ) ;
397- mockLogger = jest . fn ( ) ;
397+ mockFetch = vi . fn ( ) ;
398+ mockLogger = vi . fn ( ) ;
398399 } ) ;
399400
400401 afterEach ( ( ) => {
@@ -614,11 +615,11 @@ describe('withLogging', () => {
614615} ) ;
615616
616617describe ( 'applyMiddleware' , ( ) => {
617- let mockFetch : jest . MockedFunction < FetchLike > ;
618+ let mockFetch : MockedFunction < FetchLike > ;
618619
619620 beforeEach ( ( ) => {
620- jest . clearAllMocks ( ) ;
621- mockFetch = jest . fn ( ) ;
621+ vi . clearAllMocks ( ) ;
622+ mockFetch = vi . fn ( ) ;
622623 } ) ;
623624
624625 it ( 'should compose no middleware correctly' , ( ) => {
@@ -703,7 +704,7 @@ describe('applyMiddleware', () => {
703704 } ;
704705
705706 // Use custom logger to avoid console output
706- const mockLogger = jest . fn ( ) ;
707+ const mockLogger = vi . fn ( ) ;
707708 const composedFetch = applyMiddlewares ( oauthMiddleware , withLogging ( { logger : mockLogger , statusLevel : 0 } ) ) ( mockFetch ) ;
708709
709710 await composedFetch ( 'https://api.example.com/data' ) ;
@@ -743,11 +744,11 @@ describe('applyMiddleware', () => {
743744} ) ;
744745
745746describe ( 'Integration Tests' , ( ) => {
746- let mockProvider : jest . Mocked < OAuthClientProvider > ;
747- let mockFetch : jest . MockedFunction < FetchLike > ;
747+ let mockProvider : Mocked < OAuthClientProvider > ;
748+ let mockFetch : MockedFunction < FetchLike > ;
748749
749750 beforeEach ( ( ) => {
750- jest . clearAllMocks ( ) ;
751+ vi . clearAllMocks ( ) ;
751752
752753 mockProvider = {
753754 get redirectUrl ( ) {
@@ -756,16 +757,16 @@ describe('Integration Tests', () => {
756757 get clientMetadata ( ) {
757758 return { redirect_uris : [ 'http://localhost/callback' ] } ;
758759 } ,
759- tokens : jest . fn ( ) ,
760- saveTokens : jest . fn ( ) ,
761- clientInformation : jest . fn ( ) ,
762- redirectToAuthorization : jest . fn ( ) ,
763- saveCodeVerifier : jest . fn ( ) ,
764- codeVerifier : jest . fn ( ) ,
765- invalidateCredentials : jest . fn ( )
760+ tokens : vi . fn ( ) ,
761+ saveTokens : vi . fn ( ) ,
762+ clientInformation : vi . fn ( ) ,
763+ redirectToAuthorization : vi . fn ( ) ,
764+ saveCodeVerifier : vi . fn ( ) ,
765+ codeVerifier : vi . fn ( ) ,
766+ invalidateCredentials : vi . fn ( )
766767 } ;
767768
768- mockFetch = jest . fn ( ) ;
769+ mockFetch = vi . fn ( ) ;
769770 } ) ;
770771
771772 it ( 'should work with SSE transport pattern' , async ( ) => {
@@ -783,7 +784,7 @@ describe('Integration Tests', () => {
783784 mockFetch . mockResolvedValue ( response ) ;
784785
785786 // Use custom logger to avoid console output
786- const mockLogger = jest . fn ( ) ;
787+ const mockLogger = vi . fn ( ) ;
787788 const enhancedFetch = applyMiddlewares (
788789 withOAuth ( mockProvider as OAuthClientProvider , 'https://mcp-server.example.com' ) ,
789790 withLogging ( { logger : mockLogger , statusLevel : 400 } ) // Only log errors
@@ -830,7 +831,7 @@ describe('Integration Tests', () => {
830831 mockFetch . mockResolvedValue ( response ) ;
831832
832833 // Use custom logger to avoid console output
833- const mockLogger = jest . fn ( ) ;
834+ const mockLogger = vi . fn ( ) ;
834835 const enhancedFetch = applyMiddlewares (
835836 withOAuth ( mockProvider as OAuthClientProvider , 'https://streamable-server.example.com' ) ,
836837 withLogging ( {
@@ -891,7 +892,7 @@ describe('Integration Tests', () => {
891892 mockAuth . mockResolvedValue ( 'AUTHORIZED' ) ;
892893
893894 // Use custom logger to avoid console output
894- const mockLogger = jest . fn ( ) ;
895+ const mockLogger = vi . fn ( ) ;
895896 const enhancedFetch = applyMiddlewares (
896897 withOAuth ( mockProvider as OAuthClientProvider , 'https://mcp-server.example.com' ) ,
897898 withLogging ( { logger : mockLogger , statusLevel : 0 } )
@@ -914,11 +915,11 @@ describe('Integration Tests', () => {
914915} ) ;
915916
916917describe ( 'createMiddleware' , ( ) => {
917- let mockFetch : jest . MockedFunction < FetchLike > ;
918+ let mockFetch : MockedFunction < FetchLike > ;
918919
919920 beforeEach ( ( ) => {
920- jest . clearAllMocks ( ) ;
921- mockFetch = jest . fn ( ) ;
921+ vi . clearAllMocks ( ) ;
922+ mockFetch = vi . fn ( ) ;
922923 } ) ;
923924
924925 it ( 'should create middleware with cleaner syntax' , async ( ) => {
0 commit comments