Skip to content

Commit

Permalink
test(messaging, ios): avoid remote notification register on iOS17.2 s…
Browse files Browse the repository at this point in the history
…imulators

This used to work fine with iOS16 through 17.1, but now with 17.2 registerForRemoteNotifications hangs

Since we can't call that, we can't touch any of the getToken type methods, so add 17.2 to list of unsupported
emulators, and skip token-related items for it
  • Loading branch information
mikehardy committed Feb 7, 2024
1 parent ac1a963 commit 65a9763
Showing 1 changed file with 47 additions and 24 deletions.
71 changes: 47 additions & 24 deletions packages/messaging/e2e/messaging.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ async function isSimulator() {
async function isAPNSCapableSimulator() {
supportedAbis = await DeviceInfo.supportedAbis(); // looking for an ARM Simulator implying M1 host
iosVersionMajor = DeviceInfo.getSystemVersion().split('.')[0]; // looking for iOS16+
iosVersionMinor = DeviceInfo.getSystemVersion().split('.')[1]; // iOS 17.2 has a problem !?
macOSVersionMajor = require('os').release().split('.')[0]; // host macOS13+ has Darwin kernel 22+
if (macOSVersionMajor >= 22 && supportedAbis.includes('ARM64E') && iosVersionMajor >= 16) {
if (
macOSVersionMajor >= 22 &&
supportedAbis.includes('ARM64E') &&
iosVersionMajor >= 16 &&
`${iosVersionMajor}.${iosVersionMinor}` !== '17.2'
) {
return true;
}

return false;
}

Expand Down Expand Up @@ -90,8 +97,13 @@ describe('messaging()', function () {
if (device.getPlatform() === 'ios') {
await firebase.messaging().unregisterDeviceForRemoteMessages();
should.equal(firebase.messaging().isDeviceRegisteredForRemoteMessages, false);
await firebase.messaging().registerDeviceForRemoteMessages();
should.equal(firebase.messaging().isDeviceRegisteredForRemoteMessages, true);
// did this happen in logs?
// 2024-02-02 18:35:26.277 Df testing[26266:18d3f] (Detox) 10.20.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified
tryToRegister = await isAPNSCapableSimulator();
if (tryToRegister) {
await firebase.messaging().registerDeviceForRemoteMessages();
should.equal(firebase.messaging().isDeviceRegisteredForRemoteMessages, true);
}
} else {
this.skip();
}
Expand Down Expand Up @@ -133,14 +145,12 @@ describe('messaging()', function () {
});
it('resolves on ios with token on supported simulators', async function () {
// Make sure we are registered for remote notifications, else no token
await firebase.messaging().registerDeviceForRemoteMessages();

if (device.getPlatform() === 'ios') {
aPNSCapableSimulator = await isAPNSCapableSimulator();
simulator = await isSimulator();
if (device.getPlatform() === 'ios' && (!simulator || (simulator && aPNSCapableSimulator))) {
await firebase.messaging().registerDeviceForRemoteMessages();
apnsToken = await firebase.messaging().getAPNSToken();

simulator = await isSimulator();
aPNSCapableSimulator = await isAPNSCapableSimulator();

if (!simulator || (simulator && aPNSCapableSimulator)) {
apnsToken.should.be.a.String();
} else {
Expand Down Expand Up @@ -197,7 +207,9 @@ describe('messaging()', function () {
});

it('correctly sets new token on ios', async function () {
if (device.getPlatform() === 'ios') {
aPNSCapableSimulator = await isAPNSCapableSimulator();
simulator = await isSimulator();
if (device.getPlatform() === 'ios' && (!simulator || (simulator && aPNSCapableSimulator))) {
originalAPNSToken = await firebase.messaging().getAPNSToken();
// 74657374696E67746F6B656E is hex for "testingtoken"
await firebase.messaging().setAPNSToken('74657374696E67746F6B656E', 'unknown');
Expand Down Expand Up @@ -230,12 +242,18 @@ describe('messaging()', function () {

describe('deleteToken()', function () {
it('generate a new token after deleting', async function () {
const token1 = await firebase.messaging().getToken();
should.exist(token1);
await firebase.messaging().deleteToken();
const token2 = await firebase.messaging().getToken();
should.exist(token2);
token1.should.not.eql(token2);
aPNSCapableSimulator = await isAPNSCapableSimulator();
simulator = await isSimulator();
if (device.getPlatform() === 'ios' && simulator && !aPNSCapableSimulator) {
this.skip();
} else {
const token1 = await firebase.messaging().getToken();
should.exist(token1);
await firebase.messaging().deleteToken();
const token2 = await firebase.messaging().getToken();
should.exist(token2);
token1.should.not.eql(token2);
}
});
});

Expand Down Expand Up @@ -546,8 +564,15 @@ describe('messaging()', function () {
if (device.getPlatform() === 'ios') {
await unregisterDeviceForRemoteMessages(getMessaging());
should.equal(isDeviceRegisteredForRemoteMessages(getMessaging()), false);
await registerDeviceForRemoteMessages(getMessaging());
should.equal(isDeviceRegisteredForRemoteMessages(getMessaging()), true);
aPNSCapableSimulator = await isAPNSCapableSimulator();
simulator = await isSimulator();
if (
device.getPlatform() === 'ios' &&
(!simulator || (simulator && aPNSCapableSimulator))
) {
await registerDeviceForRemoteMessages(getMessaging());
should.equal(isDeviceRegisteredForRemoteMessages(getMessaging()), true);
}
} else {
this.skip();
}
Expand Down Expand Up @@ -594,14 +619,12 @@ describe('messaging()', function () {
it('resolves on ios with token on supported simulators', async function () {
// Make sure we are registered for remote notifications, else no token
const { getMessaging, getAPNSToken, registerDeviceForRemoteMessages } = messagingModular;
await registerDeviceForRemoteMessages(getMessaging());

if (device.getPlatform() === 'ios') {
aPNSCapableSimulator = await isAPNSCapableSimulator();
simulator = await isSimulator();
if (device.getPlatform() === 'ios' && (!simulator || (simulator && aPNSCapableSimulator))) {
await registerDeviceForRemoteMessages(getMessaging());
apnsToken = await getAPNSToken(getMessaging());

simulator = await isSimulator();
aPNSCapableSimulator = await isAPNSCapableSimulator();

if (!simulator || (simulator && aPNSCapableSimulator)) {
apnsToken.should.be.a.String();
} else {
Expand Down

0 comments on commit 65a9763

Please sign in to comment.