@@ -6,16 +6,20 @@ import path from "path";
6
6
import fs from "fs/promises" ;
7
7
import defaultState from "../../src/state.js" ;
8
8
9
- export async function setupIntegrationTest ( ) : Promise < {
9
+ export async function setupIntegrationTest ( { mockStateStore = true } : { mockStateStore : boolean } ) : Promise < {
10
10
client : Client ;
11
11
server : Server ;
12
12
teardown : ( ) => Promise < void > ;
13
13
} > {
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
+ }
19
23
20
24
const clientTransport = new InMemoryTransport ( ) ;
21
25
const serverTransport = new InMemoryTransport ( ) ;
@@ -47,8 +51,8 @@ export async function setupIntegrationTest(): Promise<{
47
51
await client . close ( ) ;
48
52
await server . close ( ) ;
49
53
50
- loadCredentialsMock . mockRestore ( ) ;
51
- saveCredentialsMock . mockRestore ( ) ;
54
+ loadCredentialsMock ? .mockRestore ( ) ;
55
+ saveCredentialsMock ? .mockRestore ( ) ;
52
56
} ,
53
57
} ;
54
58
}
0 commit comments