go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/testing_tools/fakes/fake_service_worker_registration.ts (about) 1 // Copyright 2022 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 /* eslint-disable @typescript-eslint/no-explicit-any */ 16 17 /** 18 * A fake service worker registration with none of its method implemented. 19 * The method should be stubbed according to the test requirement. 20 * We cannot stub `ServiceWorkerRegistration` because it doesn't have a legal 21 * constructor. 22 */ 23 export class FakeServiceWorkerRegistration 24 implements ServiceWorkerRegistration 25 { 26 active: ServiceWorker | null = null; 27 installing: ServiceWorker | null = null; 28 waiting: ServiceWorker | null = null; 29 updateViaCache: ServiceWorkerUpdateViaCache = 'none'; 30 onupdatefound: ((this: ServiceWorkerRegistration, ev: Event) => any) | null = 31 null; 32 33 get navigationPreload(): NavigationPreloadManager { 34 throw new Error('Method not implemented.'); 35 } 36 get pushManager(): PushManager { 37 throw new Error('Method not implemented.'); 38 } 39 40 constructor(public scope: string) {} 41 42 getNotifications( 43 filter?: GetNotificationOptions | undefined, 44 ): Promise<Notification[]>; 45 getNotifications(_filter?: unknown): Promise<Notification[]> { 46 throw new Error('Method not implemented.'); 47 } 48 49 showNotification( 50 title: string, 51 options?: NotificationOptions | undefined, 52 ): Promise<void>; 53 showNotification(_title: unknown, _options?: unknown): Promise<void> { 54 throw new Error('Method not implemented.'); 55 } 56 57 unregister(): Promise<boolean>; 58 unregister(): Promise<boolean> { 59 throw new Error('Method not implemented.'); 60 } 61 62 update(): Promise<void>; 63 update(): Promise<void> { 64 throw new Error('Method not implemented.'); 65 } 66 67 addEventListener<K extends 'updatefound'>( 68 type: K, 69 listener: ( 70 this: ServiceWorkerRegistration, 71 ev: ServiceWorkerRegistrationEventMap[K], 72 ) => any, 73 options?: boolean | AddEventListenerOptions | undefined, 74 ): void; 75 addEventListener( 76 type: string, 77 listener: EventListenerOrEventListenerObject, 78 options?: boolean | AddEventListenerOptions | undefined, 79 ): void; 80 addEventListener( 81 _type: unknown, 82 _listener: unknown, 83 _options?: unknown, 84 ): void { 85 throw new Error('Method not implemented.'); 86 } 87 88 removeEventListener<K extends 'updatefound'>( 89 type: K, 90 listener: ( 91 this: ServiceWorkerRegistration, 92 ev: ServiceWorkerRegistrationEventMap[K], 93 ) => any, 94 options?: boolean | EventListenerOptions | undefined, 95 ): void; 96 removeEventListener( 97 type: string, 98 listener: EventListenerOrEventListenerObject, 99 options?: boolean | EventListenerOptions | undefined, 100 ): void; 101 removeEventListener( 102 _type: unknown, 103 _listener: unknown, 104 _options?: unknown, 105 ): void { 106 throw new Error('Method not implemented.'); 107 } 108 109 dispatchEvent(event: Event): boolean; 110 dispatchEvent(_event: unknown): boolean { 111 throw new Error('Method not implemented.'); 112 } 113 }