@@ -6,16 +6,20 @@ import path from "path";
66import fs from "fs/promises" ;
77import defaultState from "../../src/state.js" ;
88
9- export async function setupIntegrationTest ( ) : Promise < {
9+ export async function setupIntegrationTest ( { mockStateStore = true } : { mockStateStore : boolean } ) : Promise < {
1010 client : Client ;
1111 server : Server ;
1212 teardown : ( ) => Promise < void > ;
1313} > {
14- // Mock the load/persist credentials method to avoid state loading/restore messing up with the tests
15- const loadCredentialsMock = jest . spyOn ( defaultState , "loadCredentials" ) . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
16- const saveCredentialsMock = jest
17- . spyOn ( defaultState , "persistCredentials" )
18- . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
14+ let loadCredentialsMock : jest . SpyInstance | undefined ;
15+ let saveCredentialsMock : jest . SpyInstance | undefined ;
16+ if ( mockStateStore ) {
17+ // Mock the load/persist credentials method to avoid state loading/restore messing up with the tests
18+ loadCredentialsMock = jest . spyOn ( defaultState , "loadCredentials" ) . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
19+ saveCredentialsMock = jest
20+ . spyOn ( defaultState , "persistCredentials" )
21+ . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
22+ }
1923
2024 const clientTransport = new InMemoryTransport ( ) ;
2125 const serverTransport = new InMemoryTransport ( ) ;
@@ -47,8 +51,8 @@ export async function setupIntegrationTest(): Promise<{
4751 await client . close ( ) ;
4852 await server . close ( ) ;
4953
50- loadCredentialsMock . mockRestore ( ) ;
51- saveCredentialsMock . mockRestore ( ) ;
54+ loadCredentialsMock ? .mockRestore ( ) ;
55+ saveCredentialsMock ? .mockRestore ( ) ;
5256 } ,
5357 } ;
5458}
0 commit comments