Skip to content

Commit 73ca3d5

Browse files
committed
test(messaging, ios): avoid remote notification register on iOS17.2 simulators
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
1 parent deac037 commit 73ca3d5

File tree

1 file changed

+60
-31
lines changed

1 file changed

+60
-31
lines changed

packages/messaging/e2e/messaging.e2e.js

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ async function isSimulator() {
2222
async function isAPNSCapableSimulator() {
2323
supportedAbis = await DeviceInfo.supportedAbis(); // looking for an ARM Simulator implying M1 host
2424
iosVersionMajor = DeviceInfo.getSystemVersion().split('.')[0]; // looking for iOS16+
25+
iosVersionMinor = DeviceInfo.getSystemVersion().split('.')[1]; // iOS 17.2 has a problem !?
2526
macOSVersionMajor = require('os').release().split('.')[0]; // host macOS13+ has Darwin kernel 22+
26-
if (macOSVersionMajor >= 22 && supportedAbis.includes('ARM64E') && iosVersionMajor >= 16) {
27+
if (
28+
macOSVersionMajor >= 22 &&
29+
supportedAbis.includes('ARM64E') &&
30+
iosVersionMajor >= 16 &&
31+
`${iosVersionMajor}.${iosVersionMinor}` !== '17.2'
32+
) {
2733
return true;
2834
}
35+
2936
return false;
3037
}
3138

@@ -90,8 +97,13 @@ describe('messaging()', function () {
9097
if (device.getPlatform() === 'ios') {
9198
await firebase.messaging().unregisterDeviceForRemoteMessages();
9299
should.equal(firebase.messaging().isDeviceRegisteredForRemoteMessages, false);
93-
await firebase.messaging().registerDeviceForRemoteMessages();
94-
should.equal(firebase.messaging().isDeviceRegisteredForRemoteMessages, true);
100+
// did this happen in logs?
101+
// 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
102+
tryToRegister = await isAPNSCapableSimulator();
103+
if (tryToRegister) {
104+
await firebase.messaging().registerDeviceForRemoteMessages();
105+
should.equal(firebase.messaging().isDeviceRegisteredForRemoteMessages, true);
106+
}
95107
} else {
96108
this.skip();
97109
}
@@ -133,14 +145,12 @@ describe('messaging()', function () {
133145
});
134146
it('resolves on ios with token on supported simulators', async function () {
135147
// Make sure we are registered for remote notifications, else no token
136-
await firebase.messaging().registerDeviceForRemoteMessages();
137-
138-
if (device.getPlatform() === 'ios') {
148+
aPNSCapableSimulator = await isAPNSCapableSimulator();
149+
simulator = await isSimulator();
150+
if (device.getPlatform() === 'ios' && (!simulator || (simulator && aPNSCapableSimulator))) {
151+
await firebase.messaging().registerDeviceForRemoteMessages();
139152
apnsToken = await firebase.messaging().getAPNSToken();
140153

141-
simulator = await isSimulator();
142-
aPNSCapableSimulator = await isAPNSCapableSimulator();
143-
144154
if (!simulator || (simulator && aPNSCapableSimulator)) {
145155
apnsToken.should.be.a.String();
146156
} else {
@@ -197,7 +207,9 @@ describe('messaging()', function () {
197207
});
198208

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

231243
describe('deleteToken()', function () {
232244
it('generate a new token after deleting', async function () {
233-
const token1 = await firebase.messaging().getToken();
234-
should.exist(token1);
235-
await firebase.messaging().deleteToken();
236-
const token2 = await firebase.messaging().getToken();
237-
should.exist(token2);
238-
token1.should.not.eql(token2);
245+
aPNSCapableSimulator = await isAPNSCapableSimulator();
246+
simulator = await isSimulator();
247+
if (device.getPlatform() === 'ios' && simulator && !aPNSCapableSimulator) {
248+
this.skip();
249+
} else {
250+
const token1 = await firebase.messaging().getToken();
251+
should.exist(token1);
252+
await firebase.messaging().deleteToken();
253+
const token2 = await firebase.messaging().getToken();
254+
should.exist(token2);
255+
token1.should.not.eql(token2);
256+
}
239257
});
240258
});
241259

@@ -546,8 +564,15 @@ describe('messaging()', function () {
546564
if (device.getPlatform() === 'ios') {
547565
await unregisterDeviceForRemoteMessages(getMessaging());
548566
should.equal(isDeviceRegisteredForRemoteMessages(getMessaging()), false);
549-
await registerDeviceForRemoteMessages(getMessaging());
550-
should.equal(isDeviceRegisteredForRemoteMessages(getMessaging()), true);
567+
aPNSCapableSimulator = await isAPNSCapableSimulator();
568+
simulator = await isSimulator();
569+
if (
570+
device.getPlatform() === 'ios' &&
571+
(!simulator || (simulator && aPNSCapableSimulator))
572+
) {
573+
await registerDeviceForRemoteMessages(getMessaging());
574+
should.equal(isDeviceRegisteredForRemoteMessages(getMessaging()), true);
575+
}
551576
} else {
552577
this.skip();
553578
}
@@ -594,14 +619,12 @@ describe('messaging()', function () {
594619
it('resolves on ios with token on supported simulators', async function () {
595620
// Make sure we are registered for remote notifications, else no token
596621
const { getMessaging, getAPNSToken, registerDeviceForRemoteMessages } = messagingModular;
597-
await registerDeviceForRemoteMessages(getMessaging());
598-
599-
if (device.getPlatform() === 'ios') {
622+
aPNSCapableSimulator = await isAPNSCapableSimulator();
623+
simulator = await isSimulator();
624+
if (device.getPlatform() === 'ios' && (!simulator || (simulator && aPNSCapableSimulator))) {
625+
await registerDeviceForRemoteMessages(getMessaging());
600626
apnsToken = await getAPNSToken(getMessaging());
601627

602-
simulator = await isSimulator();
603-
aPNSCapableSimulator = await isAPNSCapableSimulator();
604-
605628
if (!simulator || (simulator && aPNSCapableSimulator)) {
606629
apnsToken.should.be.a.String();
607630
} else {
@@ -662,7 +685,9 @@ describe('messaging()', function () {
662685

663686
it('correctly sets new token on ios', async function () {
664687
const { getMessaging, getAPNSToken, setAPNSToken } = messagingModular;
665-
if (device.getPlatform() === 'ios') {
688+
aPNSCapableSimulator = await isAPNSCapableSimulator();
689+
simulator = await isSimulator();
690+
if (device.getPlatform() === 'ios' && (!simulator || (simulator && aPNSCapableSimulator))) {
666691
originalAPNSToken = await getAPNSToken(getMessaging());
667692
// 74657374696E67746F6B656E6D6F64756C6172 is hex for "testingtokenmodular"
668693
await firebase
@@ -690,12 +715,16 @@ describe('messaging()', function () {
690715
describe('deleteToken()', function () {
691716
it('generate a new token after deleting', async function () {
692717
const { getMessaging, getToken, deleteToken } = messagingModular;
693-
const token1 = await getToken(getMessaging());
694-
should.exist(token1);
695-
await deleteToken(getMessaging());
696-
const token2 = await getToken(getMessaging());
697-
should.exist(token2);
698-
token1.should.not.eql(token2);
718+
aPNSCapableSimulator = await isAPNSCapableSimulator();
719+
simulator = await isSimulator();
720+
if (device.getPlatform() === 'ios' && (!simulator || (simulator && aPNSCapableSimulator))) {
721+
const token1 = await getToken(getMessaging());
722+
should.exist(token1);
723+
await deleteToken(getMessaging());
724+
const token2 = await getToken(getMessaging());
725+
should.exist(token2);
726+
token1.should.not.eql(token2);
727+
}
699728
});
700729

701730
it('should throw Error with wrong parameter types', async function () {

0 commit comments

Comments
 (0)