Change fetch implementation passing
This commit is contained in:
parent
03d0b7e025
commit
198ac93c8c
2 changed files with 23 additions and 16 deletions
|
|
@ -25,14 +25,9 @@ export class MockAgent extends MockClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async init(): Promise<void> {
|
public async init(): Promise<void> {
|
||||||
await super.init();
|
await super.init(
|
||||||
|
// flaky fetch implementation to use during testing
|
||||||
assert(
|
async (
|
||||||
(await this.client.checkConnection()).isSuccessful,
|
|
||||||
"Connection check failed"
|
|
||||||
);
|
|
||||||
|
|
||||||
this.client.fetchImplementation = async (
|
|
||||||
input: string | URL | globalThis.Request,
|
input: string | URL | globalThis.Request,
|
||||||
init?: RequestInit
|
init?: RequestInit
|
||||||
): Promise<Response> => {
|
): Promise<Response> => {
|
||||||
|
|
@ -40,7 +35,13 @@ export class MockAgent extends MockClient {
|
||||||
const response = await fetch(input, init);
|
const response = await fetch(input, init);
|
||||||
await sleep(Math.random() * this.jitterScaleInSeconds * 1000);
|
await sleep(Math.random() * this.jitterScaleInSeconds * 1000);
|
||||||
return response;
|
return response;
|
||||||
};
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
assert(
|
||||||
|
(await this.client.checkConnection()).isSuccessful,
|
||||||
|
"Connection check failed"
|
||||||
|
);
|
||||||
|
|
||||||
this.client.logger.addOnMessageListener((logLine: LogLine) => {
|
this.client.logger.addOnMessageListener((logLine: LogLine) => {
|
||||||
const state = this.client.getSettings().isSyncEnabled
|
const state = this.client.getSettings().isSyncEnabled
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,17 @@ export class MockClient implements FileSystemOperations {
|
||||||
protected readonly useSlowFileEvents: boolean
|
protected readonly useSlowFileEvents: boolean
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public async init(): Promise<void> {
|
public async init(
|
||||||
this.client = await SyncClient.create(this, {
|
fetchImplementation: typeof globalThis.fetch
|
||||||
|
): Promise<void> {
|
||||||
|
this.client = await SyncClient.create(
|
||||||
|
this,
|
||||||
|
{
|
||||||
load: async () => this.data,
|
load: async () => this.data,
|
||||||
save: async (data) => void (this.data = data)
|
save: async (data) => void (this.data = data)
|
||||||
});
|
},
|
||||||
|
fetchImplementation
|
||||||
|
);
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
Object.keys(this.initialSettings).map(async (key) => {
|
Object.keys(this.initialSettings).map(async (key) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue