@markwharton/pwa-push 1.2.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -221,6 +221,14 @@ function setupEmptyNavigator() {
|
|
|
221
221
|
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
222
222
|
(0, vitest_1.expect)(result.error).toBe('Network error');
|
|
223
223
|
});
|
|
224
|
+
(0, vitest_1.it)('handles non-Error throw', async () => {
|
|
225
|
+
global.Notification.requestPermission.mockResolvedValue('granted');
|
|
226
|
+
mockPushManager.subscribe.mockRejectedValueOnce('string error');
|
|
227
|
+
const { subscribeToPush } = await Promise.resolve().then(() => __importStar(require('../../client/subscribe')));
|
|
228
|
+
const result = await subscribeToPush('vapid-key');
|
|
229
|
+
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
230
|
+
(0, vitest_1.expect)(result.error).toBe('Subscription failed');
|
|
231
|
+
});
|
|
224
232
|
});
|
|
225
233
|
(0, vitest_1.describe)('unsubscribeFromPush', () => {
|
|
226
234
|
(0, vitest_1.it)('unsubscribes successfully', async () => {
|
|
@@ -242,6 +250,13 @@ function setupEmptyNavigator() {
|
|
|
242
250
|
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
243
251
|
(0, vitest_1.expect)(result.error).toBe('Failed');
|
|
244
252
|
});
|
|
253
|
+
(0, vitest_1.it)('handles non-Error throw', async () => {
|
|
254
|
+
mockPushManager.getSubscription.mockRejectedValueOnce('string error');
|
|
255
|
+
const { unsubscribeFromPush } = await Promise.resolve().then(() => __importStar(require('../../client/subscribe')));
|
|
256
|
+
const result = await unsubscribeFromPush();
|
|
257
|
+
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
258
|
+
(0, vitest_1.expect)(result.error).toBe('Unsubscribe failed');
|
|
259
|
+
});
|
|
245
260
|
});
|
|
246
261
|
(0, vitest_1.describe)('getCurrentSubscription', () => {
|
|
247
262
|
(0, vitest_1.it)('returns current subscription', async () => {
|
|
@@ -264,5 +279,12 @@ function setupEmptyNavigator() {
|
|
|
264
279
|
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
265
280
|
(0, vitest_1.expect)(result.error).toBe('Service worker error');
|
|
266
281
|
});
|
|
282
|
+
(0, vitest_1.it)('handles non-Error throw', async () => {
|
|
283
|
+
mockPushManager.getSubscription.mockRejectedValueOnce('string error');
|
|
284
|
+
const { getCurrentSubscription } = await Promise.resolve().then(() => __importStar(require('../../client/subscribe')));
|
|
285
|
+
const result = await getCurrentSubscription();
|
|
286
|
+
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
287
|
+
(0, vitest_1.expect)(result.error).toBe('Failed to get subscription');
|
|
288
|
+
});
|
|
267
289
|
});
|
|
268
290
|
});
|
|
@@ -136,6 +136,15 @@ const web_push_1 = __importDefault(require("web-push"));
|
|
|
136
136
|
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
137
137
|
(0, vitest_1.expect)(result.error).toBe('Push not initialized');
|
|
138
138
|
});
|
|
139
|
+
(0, vitest_1.it)('returns unknown error when error has no message', async () => {
|
|
140
|
+
vitest_1.vi.mocked(web_push_1.default.sendNotification).mockRejectedValue({ statusCode: 500 });
|
|
141
|
+
const { initPush, sendPushNotification } = await Promise.resolve().then(() => __importStar(require('../../server/send')));
|
|
142
|
+
initPush(validConfig);
|
|
143
|
+
const result = await sendPushNotification(subscription, payload);
|
|
144
|
+
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
145
|
+
(0, vitest_1.expect)(result.error).toBe('Unknown error');
|
|
146
|
+
(0, vitest_1.expect)(result.statusCode).toBe(500);
|
|
147
|
+
});
|
|
139
148
|
});
|
|
140
149
|
(0, vitest_1.describe)('sendPushToAll', () => {
|
|
141
150
|
const subscriptions = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markwharton/pwa-push",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Web push notifications for Azure PWA projects",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,8 +8,22 @@
|
|
|
8
8
|
".": "./dist/index.js",
|
|
9
9
|
"./server": "./dist/server/index.js",
|
|
10
10
|
"./client": "./dist/client/index.js",
|
|
11
|
+
"./types": "./dist/types.js",
|
|
11
12
|
"./sw": "./dist/pwa-push-sw.js"
|
|
12
13
|
},
|
|
14
|
+
"typesVersions": {
|
|
15
|
+
"*": {
|
|
16
|
+
"server": [
|
|
17
|
+
"dist/server/index.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"client": [
|
|
20
|
+
"dist/client/index.d.ts"
|
|
21
|
+
],
|
|
22
|
+
"types": [
|
|
23
|
+
"dist/types.d.ts"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
13
27
|
"scripts": {
|
|
14
28
|
"build": "tsc && npm run build:sw",
|
|
15
29
|
"build:sw": "esbuild src/sw.ts --bundle --outfile=dist/pwa-push-sw.js --format=iife --global-name=PwaPush",
|