Skip to content

Commit

Permalink
Merge pull request #1665 from bugsnag/avoid-deprecated-constants
Browse files Browse the repository at this point in the history
Expo: avoid using deprecated constants
  • Loading branch information
imjoehaines authored Jan 21, 2022
2 parents c7d8446 + 5476463 commit 84cf0f4
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 42 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## TBD

### Changed

- (expo): Avoid using deprecated constants [#1665](https://github.com/bugsnag/bugsnag-js/pull/1665)

## 7.15.1 (2022-01-18)

### Changed
Expand Down
1 change: 1 addition & 0 deletions packages/expo/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ When a new version of the Expo SDK is released, the dependencies we use must be
The following modules are currently used:

- `@react-native-community/netinfo` (`@bugsnag/delivery-expo`, `@bugsnsag/plugin-react-native-connectivity-breadcrumbs`)
- `expo-application` (`@bugsnag/plugin-expo-app`)
- `expo-constants` (`@bugsnag/expo`, `@bugsnag/plugin-expo-app`, `@bugsnag/plugin-expo-device`)
- `expo-crypto` (`@bugsnag/expo`, `@bugsnag/delivery-expo`)
- `expo-device` (`@bugsnag/plugin-expo-device`)
Expand Down
2 changes: 2 additions & 0 deletions packages/expo/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jest.mock('../../plugin-expo-device/node_modules/expo-constants', () => ({
}
}))

jest.mock('../../plugin-expo-app/node_modules/expo-application', () => ({}))

jest.mock('../../plugin-expo-app/node_modules/expo-constants', () => ({
default: {
platform: {},
Expand Down
11 changes: 7 additions & 4 deletions packages/plugin-expo-app/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const Application = require('expo-application')
const Constants = require('expo-constants').default
const { AppState } = require('react-native')

Expand All @@ -16,12 +17,14 @@ module.exports = {
})

let nativeBundleVersion, nativeVersionCode

if (Constants.appOwnership === 'standalone') {
if (Constants.platform.ios && Constants.platform.ios.buildNumber) {
nativeBundleVersion = Constants.platform.ios.buildNumber
if (Constants.platform.ios) {
nativeBundleVersion = Application.nativeBuildVersion
}
if (Constants.platform.android && Constants.platform.android.versionCode) {
nativeVersionCode = Constants.platform.android.versionCode

if (Constants.platform.android) {
nativeVersionCode = Application.nativeBuildVersion
}
}

Expand Down
16 changes: 15 additions & 1 deletion packages/plugin-expo-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/plugin-expo-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@bugsnag/core": "^7.15.1"
},
"dependencies": {
"expo-application": "~4.0.1",
"expo-constants": "~13.0.0"
},
"peerDependencies": {
Expand Down
14 changes: 10 additions & 4 deletions packages/plugin-expo-app/test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ describe('plugin: expo app', () => {
it('should should use revisionId if defined (all platforms)', done => {
const VERSION = '1.0.0'
const REVISION_ID = '1.0.0-r132432'

jest.doMock('expo-application', () => ({}))
jest.doMock('expo-constants', () => ({
default: {
platform: {},
Expand All @@ -39,13 +41,14 @@ describe('plugin: expo app', () => {
c.notify(new Error('flip'))
})

it('should should use versionCode if defined (android)', done => {
it('should record nativeVersionCode on android', done => {
const VERSION_CODE = '1.0'

jest.doMock('expo-application', () => ({ nativeBuildVersion: VERSION_CODE }))
jest.doMock('expo-constants', () => ({
default: {
platform: {
android: { versionCode: VERSION_CODE }
android: {}
},
manifest: { version: '1.0.0' },
appOwnership: 'standalone'
Expand All @@ -68,13 +71,14 @@ describe('plugin: expo app', () => {
c.notify(new Error('flip'))
})

it('should should use bundleVersion if defined (ios)', done => {
it('should record nativeBundleVersion on ios', done => {
const BUNDLE_VERSION = '1.0'

jest.doMock('expo-application', () => ({ nativeBuildVersion: BUNDLE_VERSION }))
jest.doMock('expo-constants', () => ({
default: {
platform: {
ios: { buildNumber: BUNDLE_VERSION }
ios: {}
},
manifest: { version: '1.0.0' },
appOwnership: 'standalone'
Expand Down Expand Up @@ -103,6 +107,7 @@ describe('plugin: expo app', () => {
currentState: 'active'
}

jest.doMock('expo-application', () => ({}))
jest.doMock('expo-constants', () => ({
default: {
platform: {},
Expand Down Expand Up @@ -152,6 +157,7 @@ describe('plugin: expo app', () => {
it('includes duration in event.app', done => {
const start = Date.now()

jest.doMock('expo-application', () => ({}))
jest.doMock('expo-constants', () => ({
default: {
platform: {},
Expand Down
13 changes: 4 additions & 9 deletions packages/plugin-expo-device/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,10 @@ module.exports = {
const device = {
id: Constants.installationId,
manufacturer: Device.manufacturer,
// On a real device these two seem equivalent, however on a simulator
// 'Constants' is a bit more useful as it returns 'Simulator' whereas
// 'Device' just returns 'iPhone'
model: Constants.platform.ios
? Constants.platform.ios.model
: Device.modelName,
modelNumber: Constants.platform.ios ? Constants.platform.ios.platform : undefined,
model: Device.modelName,
modelNumber: Device.modelId || undefined,
osName: Platform.OS,
osVersion: Constants.platform.ios ? Constants.platform.ios.systemVersion : Constants.systemVersion,
osVersion: Device.osVersion,
runtimeVersions: {
reactNative: rnVersion,
expoApp: Constants.expoVersion,
Expand All @@ -51,7 +46,7 @@ module.exports = {
client.addOnError(event => {
event.device = { ...event.device, time: new Date(), orientation, ...device }
event.addMetadata('device', {
isDevice: Constants.isDevice,
isDevice: Device.isDevice,
appOwnership: Constants.appOwnership
})
addDefaultAppType(event)
Expand Down
42 changes: 18 additions & 24 deletions packages/plugin-expo-device/test/device.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ describe('plugin: expo device', () => {
platform: { android: {} },
manifest: { sdkVersion: SDK_VERSION },
expoVersion: EXPO_VERSION,
systemVersion: ANDROID_VERSION,
isDevice: true,
appOwnership: 'standalone'
}
}))
jest.doMock('expo-device', () => ({
manufacturer: 'Google',
modelName: 'Pixel 4'
modelName: 'Pixel 4',
isDevice: true,
osVersion: ANDROID_VERSION
}))
jest.doMock('react-native', () => ({
Dimensions: {
Expand Down Expand Up @@ -84,15 +84,18 @@ describe('plugin: expo device', () => {

jest.doMock('expo-constants', () => ({
default: {
platform: { ios: { model: IOS_MODEL, platform: IOS_PLATFORM, systemVersion: IOS_VERSION } },
platform: { ios: {} },
manifest: { sdkVersion: SDK_VERSION },
expoVersion: EXPO_VERSION,
isDevice: false,
appOwnership: 'expo'
}
}))
jest.doMock('expo-device', () => ({
manufacturer: 'Apple'
manufacturer: 'Apple',
isDevice: false,
modelName: IOS_MODEL,
modelId: IOS_PLATFORM,
osVersion: IOS_VERSION
}))
jest.doMock('react-native', () => ({
Dimensions: {
Expand Down Expand Up @@ -142,21 +145,18 @@ describe('plugin: expo device', () => {
const REACT_NATIVE_VERSION = '0.57.1'
const SDK_VERSION = '32.3.0'
const EXPO_VERSION = '2.10.4'
const IOS_MODEL = 'iPhone 7 Plus'
const IOS_PLATFORM = 'iPhone1,1'
const IOS_VERSION = '11.2'

jest.doMock('expo-constants', () => ({
default: {
platform: { ios: { model: IOS_MODEL, platform: IOS_PLATFORM, systemVersion: IOS_VERSION } },
platform: { ios: {} },
manifest: { sdkVersion: SDK_VERSION },
expoVersion: EXPO_VERSION,
isDevice: false,
appOwnership: 'expo'
}
}))
jest.doMock('expo-device', () => ({
manufacturer: 'Apple'
manufacturer: 'Apple',
isDevice: true
}))
jest.doMock('react-native', () => ({
Dimensions: {
Expand Down Expand Up @@ -191,22 +191,19 @@ describe('plugin: expo device', () => {
const REACT_NATIVE_VERSION = '0.57.1'
const SDK_VERSION = '32.3.0'
const EXPO_VERSION = '2.10.4'
const IOS_MODEL = 'iPhone 7 Plus'
const IOS_PLATFORM = 'iPhone1,1'
const IOS_VERSION = '11.2'

jest.doMock('expo-constants', () => ({
default: {
installationId: '123',
platform: { ios: { model: IOS_MODEL, platform: IOS_PLATFORM, systemVersion: IOS_VERSION } },
platform: { ios: {} },
manifest: { sdkVersion: SDK_VERSION },
expoVersion: EXPO_VERSION,
isDevice: false,
appOwnership: 'expo'
}
}))
jest.doMock('expo-device', () => ({
manufacturer: 'Apple'
manufacturer: 'Apple',
isDevice: true
}))
jest.doMock('react-native', () => ({
Dimensions: {
Expand Down Expand Up @@ -242,9 +239,7 @@ describe('plugin: expo device', () => {
const REACT_NATIVE_VERSION = '0.57.1'
const SDK_VERSION = '32.3.0'
const EXPO_VERSION = '2.10.4'
const IOS_MODEL = 'iPhone 7 Plus'
const IOS_PLATFORM = 'iPhone1,1'
const IOS_VERSION = '11.2'

class Dimensions {
_listeners: { change: Array<(payload: { screen: { width: number, height: number}, window: {} }) => void> } = { change: [] }
_width!: number;
Expand Down Expand Up @@ -277,14 +272,13 @@ describe('plugin: expo device', () => {

jest.doMock('expo-constants', () => ({
default: {
platform: { ios: { model: IOS_MODEL, platform: IOS_PLATFORM, system: IOS_VERSION } },
platform: { ios: {} },
manifest: { sdkVersion: SDK_VERSION },
expoVersion: EXPO_VERSION,
isDevice: true,
appOwnership: 'guest'
}
}))
jest.doMock('expo-device', () => ({}))
jest.doMock('expo-device', () => ({ isDevice: true }))

jest.doMock('react-native', () => ({
Dimensions: d,
Expand Down

0 comments on commit 84cf0f4

Please sign in to comment.