Skip to content

Commit 3476ce2

Browse files
committed
break up sw static class methods
1 parent c655d58 commit 3476ce2

File tree

5 files changed

+937
-994
lines changed

5 files changed

+937
-994
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
},
9090
{
9191
"path": "./build/releases/OneSignalSDK.sw.js",
92-
"limit": "13.58 kB",
92+
"limit": "13.442 kB",
9393
"gzip": true
9494
},
9595
{

src/entries/worker.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/**
22
* New clients will only be including this entry file, which will result in a reduced service worker size.
33
*/
4-
import { OneSignalServiceWorker } from '../sw/serviceWorker/ServiceWorker';
4+
import { run } from '../sw/serviceWorker/ServiceWorker';
55

6-
// Expose this class to the global scope
7-
declare const self: ServiceWorkerGlobalScope;
8-
self.OneSignalWorker = OneSignalServiceWorker;
6+
// The run() is already called in ServiceWorker.ts, but importing it ensures it's not tree-shaken
7+
void run;

src/global.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ declare global {
4141

4242
interface WorkerGlobalScope {
4343
OneSignal: _OneSignal;
44-
OneSignalWorker: typeof import('./sw/serviceWorker/ServiceWorker').OneSignalServiceWorker;
4544
_workerMessenger: import('./sw/serviceWorker/WorkerMessengerSW').WorkerMessengerSW;
4645
shouldLog: boolean;
4746
}

src/sw/serviceWorker/ServiceWorker.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,20 @@ import type {
3131
UpsertOrDeactivateSessionPayload,
3232
} from 'src/shared/session/types';
3333
import { NotificationType } from 'src/shared/subscriptions/constants';
34+
import { getAppId } from './ServiceWorker';
35+
36+
// Mock webhook notification events
37+
vi.mock('../webhooks/notifications/webhookNotificationEvent', () => ({
38+
notificationClick: vi.fn(),
39+
notificationDismissed: vi.fn(),
40+
notificationWillDisplay: vi.fn(),
41+
}));
42+
3443
import {
3544
notificationClick,
3645
notificationDismissed,
3746
notificationWillDisplay,
3847
} from '../webhooks/notifications/webhookNotificationEvent';
39-
import { OneSignalServiceWorker } from './ServiceWorker';
4048

4149
declare const self: ServiceWorkerGlobalScope;
4250

@@ -114,7 +122,7 @@ describe('ServiceWorker', () => {
114122
// @ts-expect-error - search is readonly but we need to set it for testing
115123
self.location.search = '?appId=some-app-id';
116124

117-
const appId = await OneSignalServiceWorker._getAppId();
125+
const appId = await getAppId();
118126
expect(appId).toBe('some-app-id');
119127
});
120128
});

0 commit comments

Comments
 (0)