test(service-worker): improve adding clients in SwTestHarness
(#23625)
This commits changes how clients are added in `SwTestHarness`, so that the behavior in tests closer mimics what would happen in an actual ServiceWorker. It also removes auto-adding clients when calling `clients.get()`, which could hide bugs related to non-existing clients. PR Close #23625
This commit is contained in:

committed by
Igor Minar

parent
2e466f4bea
commit
1a655836cb
@ -62,10 +62,7 @@ export class MockClients implements Clients {
|
||||
|
||||
remove(clientId: string): void { this.clients.delete(clientId); }
|
||||
|
||||
async get(id: string): Promise<Client> {
|
||||
this.add(id);
|
||||
return this.clients.get(id) !as any as Client;
|
||||
}
|
||||
async get(id: string): Promise<Client> { return this.clients.get(id) !as any as Client; }
|
||||
|
||||
getMock(id: string): MockClient|undefined { return this.clients.get(id); }
|
||||
|
||||
@ -197,6 +194,10 @@ export class SwTestHarness implements ServiceWorkerGlobalScope, Adapter, Context
|
||||
const event = new MockFetchEvent(req, clientId || null);
|
||||
this.eventHandlers.get('fetch') !.call(this, event);
|
||||
|
||||
if (clientId) {
|
||||
this.clients.add(clientId);
|
||||
}
|
||||
|
||||
return [event.response, event.ready];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user