Add missing service-worker-mock trigger signatures (#38267)

These are undocumented, but they are needed to make some triggers useful.
This commit is contained in:
Remco Haszing
2019-09-10 22:30:25 -07:00
committed by Mine Starks
parent 8850cc80da
commit 448d6d2922
2 changed files with 16 additions and 0 deletions
+4
View File
@@ -42,6 +42,10 @@ declare global {
* Used to trigger active listeners.
*/
function trigger(type: keyof ServiceWorkerGlobalScopeEventMap): Promise<void>;
function trigger(name: 'fetch', request: string | Request): Promise<void>;
function trigger(name: 'notificationclick' | 'notificationclose', args: Notification): Promise<void>;
function trigger(name: 'push', args: Partial<PushEvent>): Promise<void>;
function trigger(name: 'message', args: Partial<MessageEvent>): Promise<void>;
/**
* Used to generate a snapshot of the service worker internals.
@@ -8,6 +8,18 @@ trigger('install');
mock.trigger('install');
trigger('fetch');
mock.trigger('fetch');
trigger('fetch', 'https://example.com');
mock.trigger('fetch', 'https://example.com');
trigger('fetch', new Request('https://example.com'));
mock.trigger('fetch', new Request('https://example.com'));
trigger('notificationclick', new Notification('Hello!'));
mock.trigger('notificationclick', new Notification('Hello!'));
trigger('notificationclose', new Notification('Hello!'));
mock.trigger('notificationclose', new Notification('Hello!'));
trigger('push', { data: null });
mock.trigger('push', { data: null });
trigger('message', { source: null });
mock.trigger('message', { source: null });
const emitFetch = listeners.get('fetch') as EventListener;
emitFetch(new Event('fetch'));