diff --git a/frontend/test-client/src/agent/mock-agent.ts b/frontend/test-client/src/agent/mock-agent.ts index ff70520..23fcd09 100644 --- a/frontend/test-client/src/agent/mock-agent.ts +++ b/frontend/test-client/src/agent/mock-agent.ts @@ -25,23 +25,24 @@ export class MockAgent extends MockClient { } public async init(): Promise { - await super.init(); + await super.init( + // flaky fetch implementation to use during testing + async ( + input: string | URL | globalThis.Request, + init?: RequestInit + ): Promise => { + await sleep(Math.random() * this.jitterScaleInSeconds * 1000); + const response = await fetch(input, init); + await sleep(Math.random() * this.jitterScaleInSeconds * 1000); + return response; + } + ); assert( (await this.client.checkConnection()).isSuccessful, "Connection check failed" ); - this.client.fetchImplementation = async ( - input: string | URL | globalThis.Request, - init?: RequestInit - ): Promise => { - await sleep(Math.random() * this.jitterScaleInSeconds * 1000); - const response = await fetch(input, init); - await sleep(Math.random() * this.jitterScaleInSeconds * 1000); - return response; - }; - this.client.logger.addOnMessageListener((logLine: LogLine) => { const state = this.client.getSettings().isSyncEnabled ? "(online) " diff --git a/frontend/test-client/src/agent/mock-client.ts b/frontend/test-client/src/agent/mock-client.ts index 1adae4b..9d4d457 100644 --- a/frontend/test-client/src/agent/mock-client.ts +++ b/frontend/test-client/src/agent/mock-client.ts @@ -16,11 +16,17 @@ export class MockClient implements FileSystemOperations { protected readonly useSlowFileEvents: boolean ) {} - public async init(): Promise { - this.client = await SyncClient.create(this, { - load: async () => this.data, - save: async (data) => void (this.data = data) - }); + public async init( + fetchImplementation: typeof globalThis.fetch + ): Promise { + this.client = await SyncClient.create( + this, + { + load: async () => this.data, + save: async (data) => void (this.data = data) + }, + fetchImplementation + ); await Promise.all( Object.keys(this.initialSettings).map(async (key) => {