Skip to content

Commit

Permalink
Merge pull request #141 from bugsnag/replace-constants-manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
yousif-bugsnag committed Jul 13, 2023
2 parents 3ada917 + b701631 commit f61bb5c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
2 changes: 1 addition & 1 deletion features/fixtures/test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"expo-screen-orientation": "~6.0.2",
"expo-status-bar": "~1.6.0",
"react": "18.2.0",
"react-native": "0.72.1"
"react-native": "0.72.3"
},
"devDependencies": {
"@babel/core": "^7.20.0"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"jest-expo": "^48.0.1",
"lerna": "^6.0.1",
"react": "18.2.0",
"react-native": "0.72.1",
"react-native": "0.72.3",
"verdaccio": "^5.10.2"
},
"scripts": {
Expand Down
10 changes: 2 additions & 8 deletions packages/expo/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ const { schema } = require('@bugsnag/core/config')
const Constants = require('expo-constants').default
const stringWithLength = require('@bugsnag/core/lib/validators/string-with-length')

// If the developer property is not present in the manifest, it means the app is
// If the developer property is not present it means the app is
// not connected to a development tool and is either a published app running in
// the Expo client, or a standalone app
let IS_PRODUCTION = true

if (Constants.manifest) {
IS_PRODUCTION = !Constants.manifest.developer
} else if (Constants.manifest2) {
IS_PRODUCTION = !Constants.manifest2?.extra?.expoGo?.developer
}
const IS_PRODUCTION = !Constants.expoConfig.developer && !Constants.expoGoConfig.developer

// The app can still run in production "mode" in development environments, in which
// cases the global boolean __DEV__ will be set to true
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/src/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const internalPlugins = [
require('@bugsnag/plugin-expo-device'),
require('@bugsnag/plugin-expo-app'),
require('@bugsnag/plugin-console-breadcrumbs'),
require('@bugsnag/plugin-network-breadcrumbs')([NET_INFO_REACHABILITY_URL, Constants.manifest?.logUrl || Constants.manifest2?.extra?.expoGo?.logUrl]),
require('@bugsnag/plugin-network-breadcrumbs')([NET_INFO_REACHABILITY_URL, Constants.expoConfig.logUrl || Constants.expoGoConfig?.logUrl]),
require('@bugsnag/plugin-expo-app-state-breadcrumbs'),
require('@bugsnag/plugin-expo-connectivity-breadcrumbs'),
require('@bugsnag/plugin-react-native-orientation-breadcrumbs'),
Expand Down
64 changes: 61 additions & 3 deletions packages/expo/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ const delivery = require('@bugsnag/delivery-expo')
jest.mock('expo-constants', () => ({
default: {
platform: {},
expoConfig: {}
expoConfig: {},
expoGoConfig: {}
}
}))

jest.mock('../../plugin-expo-device/node_modules/expo-constants', () => ({
default: {
platform: {},
expoConfig: {}
expoConfig: {},
expoGoConfig: {}
}
}))

Expand All @@ -19,7 +21,8 @@ jest.mock('../../plugin-expo-app/node_modules/expo-application', () => ({}))
jest.mock('../../plugin-expo-app/node_modules/expo-constants', () => ({
default: {
platform: {},
expoConfig: {}
expoConfig: {},
expoGoConfig: {}
}
}))

Expand Down Expand Up @@ -230,4 +233,59 @@ describe('expo notifier', () => {
done()
})
})

describe('configuration', () => {
beforeEach(() => {
jest.resetModules()
})

it('sets a default value for releaseStage correctly (production)', () => {
jest.mock('expo-constants', () => ({
default: {
platform: {},
expoConfig: {},
expoGoConfig: {}
}
}))

const config = require('../src/config')
expect(config.releaseStage.defaultValue()).toBe('production')
})

it('sets a default value for releaseStage correctly (local-dev)', () => {
jest.mock('expo-constants', () => ({
default: {
platform: {},
expoConfig: {},
expoGoConfig: {
developer: {
tool: 'expo-cli'
}
}
}
}))

global.__DEV__ = true
const config = require('../src/config')
expect(config.releaseStage.defaultValue()).toBe('local-dev')
})

it('sets a default value for releaseStage correctly (local-prod)', () => {
jest.mock('expo-constants', () => ({
default: {
platform: {},
expoConfig: {
developer: {
tool: 'expo-cli'
}
},
expoGoConfig: {}
}
}))

global.__DEV__ = false
const config = require('../src/config')
expect(config.releaseStage.defaultValue()).toBe('local-prod')
})
})
})

0 comments on commit f61bb5c

Please sign in to comment.