I am running the basic example for the Node.js expo-server-sdk’s push notifications and the code that runs
let ticketChunk = await expo.sendPushNotificationsAsync(chunk);
never returns.
I think traced it down into the expo-server-sdk source code and this is the line that runs but never returns:
console.log("testing start")
let response = yield this._limitConcurrentRequests(() => node_fetch_1.default(url, {
method: options.httpMethod,
body: requestBody,
headers: requestHeaders,
agent: this._httpAgent,
}));
console.log("testing end")
I see the “testing start” in my console but never see the “testing end”
Here is the full code that calls it (comments removed for brevity):
const { Expo } = require('expo-server-sdk')
function sendNotification() {
let expo = new Expo();
let tokens = ['ExponentPushToken[____REDACTED_TOKEN____]']
let messages = [];
for (let pushToken of tokens) {
if (!Expo.isExpoPushToken(pushToken)) {
console.error(`Push token ${pushToken} is not a valid Expo push token`);
continue;
}
messages.push({
to: pushToken,
sound: 'default',
body: 'This is a test notification',
data: { withSome: 'data' },
})
}
let chunks = expo.chunkPushNotifications(messages);
let tickets = [];
(async () => {
for (let chunk of chunks) {
try {
console.log('about to send')
let ticketChunk = await expo.sendPushNotificationsAsync(chunk);
console.log('back from send')
console.log(ticketChunk)
tickets.push(...ticketChunk);
console.log('ticket chunk pushed')
} catch (error) {
console.log('sendPushNotificationsAsync Error')
console.error(error);
}
}
})();
}
module.exports.sendNotification = sendNotification
And my test harness that I am using to test it:
var chai = require('chai')
var PushNotification = require('../utility_modules/pushnotification')
describe('pushNotification Tests', function () {
it('should send a notification', (done) => {
PushNotification.sendNotification()
done()
})
})
Test Results:
pushNotification Tests
about to send
testing start
✓ should send a notification
1 passing (24ms)
Hopefully I’m just missing something stupid, but I can’t seem to figure it out because my test harness returns a positive test result, no errors are generated, and the notification is never sent. Any help would be greatly appreciated.