Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expo v36 support #670

Merged
merged 13 commits into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/delivery-expo/network-status.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { NetInfo } = require('react-native')
const NetInfo = require('@react-native-community/netinfo')

/*
* This class provides the following:
Expand All @@ -24,11 +24,11 @@ module.exports = class NetworkStatus {

_watch () {
// get the initial status
NetInfo.isConnected.fetch().then(isConnected => {
this._update(isConnected)
NetInfo.fetch().then(state => {
this._update(state.isConnected)
// then listen for subsequent changes
NetInfo.isConnected.addEventListener('connectionChange', isConnected => {
this._update(isConnected)
NetInfo.addEventListener(state => {
this._update(state.isConnected)
})
})
}
Expand Down
27 changes: 9 additions & 18 deletions packages/delivery-expo/test/network-status.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ describe('delivery: expo -> NetworkStatus', () => {
it('should update the value of isConnected when it changes', done => {
const listeners = []
const NetworkStatus = proxyquire('../network-status', {
'react-native': {
NetInfo: {
isConnected: {
addEventListener: (event, fn) => { listeners.push({ event, fn }) },
fetch: () => new Promise(resolve => setTimeout(() => resolve(true), 1))
}
}
'@react-native-community/netinfo': {
addEventListener: (fn) => { listeners.push(fn) },
fetch: () => new Promise(resolve => setTimeout(() => resolve({ isConnected: true }), 1))
}
})
const ns = new NetworkStatus()
Expand All @@ -24,8 +20,7 @@ describe('delivery: expo -> NetworkStatus', () => {
expect(ns.isConnected).toBe(true)
// then it should start listening
expect(listeners.length).toBe(1)
expect(listeners[0].event).toBe('connectionChange')
listeners[0].fn(false)
listeners[0]({ isConnected: false })
// check that the change we sent updated the value
expect(ns.isConnected).toBe(false)
done()
Expand All @@ -35,13 +30,9 @@ describe('delivery: expo -> NetworkStatus', () => {
it('should alert any _watchers when the value of isConnected changes', done => {
const listeners = []
const NetworkStatus = proxyquire('../network-status', {
'react-native': {
NetInfo: {
isConnected: {
addEventListener: (event, fn) => { listeners.push({ event, fn }) },
fetch: () => new Promise(resolve => setTimeout(() => resolve(true), 1))
}
}
'@react-native-community/netinfo': {
addEventListener: (fn) => { listeners.push(fn) },
fetch: () => new Promise(resolve => setTimeout(() => resolve({ isConnected: true }), 1))
}
})
const ns = new NetworkStatus()
Expand All @@ -60,9 +51,9 @@ describe('delivery: expo -> NetworkStatus', () => {
})

setTimeout(() => {
listeners[0].fn(false)
listeners[0]({ isConnected: false })
setTimeout(() => {
listeners[0].fn(true)
listeners[0]({ isConnected: true })
}, 1)
}, 2)
})
Expand Down
21 changes: 17 additions & 4 deletions packages/expo-cli/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,27 @@ const selectVersion = async (dir) => {
try {
const pkg = JSON.parse(await promisify(readFile)(join(dir, 'package.json'), 'utf8'))
const expoVersion = pkg.dependencies.expo

let message = 'If you want the latest version of @bugsnag/expo hit enter, otherwise type the version you want'
let defaultVersion = 'latest'

// help select compatible versions of @bugsnag/expo for older expo releases
const isPre33 = (expoVersion && !semver.gte(semver.minVersion(expoVersion), '33.0.0'))
const isPre36 = (expoVersion && !semver.gte(semver.minVersion(expoVersion), '36.0.0'))

if (isPre33) {
message = 'It looks like you’re using a version of Expo SDK <33. The last version of Bugsnag that supported your version of Expo is v6.3.0'
defaultVersion = '6.3.0'
} else if (isPre36) {
message = 'It looks like you’re using a version of Expo SDK <36. The last version of Bugsnag that supported your version of Expo is v6.4.1'
defaultVersion = '6.4.1'
}

const { version } = await prompts({
type: 'text',
name: 'version',
message: isPre33
? 'It looks like you’re using a version of Expo SDK <33. The latest version of Bugsnag works with SDK >= 33 so it’s recommended that you install the last version of Bugsnag that supported your Expo version: v6.3.0'
: 'If you want the latest version of @bugsnag/expo hit enter, otherwise type the version you want',
initial: isPre33 ? '6.3.0' : 'latest',
message: message,
initial: defaultVersion,
validate: str => {
if (str === 'latest') return true
if (semver.valid(str)) return true
Expand Down
1 change: 1 addition & 0 deletions packages/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@bugsnag/plugin-react-native-global-error-handler": "^6.4.0",
"@bugsnag/plugin-react-native-orientation-breadcrumbs": "^6.4.1",
"@bugsnag/plugin-react-native-unhandled-rejection": "^6.4.0",
"@react-native-community/netinfo": "^5.0.0",
"bugsnag-build-reporter": "^1.0.1",
"bugsnag-sourcemaps": "^1.1.0",
"expo-constants": "^6.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
const { NetInfo } = require('react-native')
const NetInfo = require('@react-native-community/netinfo')

module.exports = {
init: client => {
const explicitlyDisabled = client.config.connectivityBreadcrumbsEnabled === false
const implicitlyDisabled = client.config.autoBreadcrumbs === false && client.config.connectivityBreadcrumbsEnabled !== true
if (explicitlyDisabled || implicitlyDisabled) return

NetInfo.addEventListener('connectionChange', ({ type, effectiveType }) => {
NetInfo.addEventListener(({ isConnected, isInternetReachable, type }) => {
client.leaveBreadcrumb(
`Connectivity changed`,
{
type,
effectiveType
},
'state'
`Connectivity changed`, { isConnected, isInternetReachable, type }, 'state'
)
})
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ const Client = require('@bugsnag/core/client')
const VALID_NOTIFIER = { name: 't', version: '0', url: 'http://' }

describe('plugin: react native connectivity breadcrumbs', () => {
it('should create a breadcrumb when the NetInfo#connectionChange event happens', () => {
it('should create a breadcrumb when NetInfo events happen', () => {
let _cb
const NetInfo = {
addEventListener: (type, fn) => {
addEventListener: (fn) => {
_cb = fn
}
}
const plugin = proxyquire('../', {
'react-native': { NetInfo }
'@react-native-community/netinfo': NetInfo
})

const client = new Client(VALID_NOTIFIER)
Expand All @@ -25,17 +25,17 @@ describe('plugin: react native connectivity breadcrumbs', () => {
expect(typeof _cb).toBe('function')
expect(client.breadcrumbs.length).toBe(0)

_cb({ type: 'wifi', effectiveType: '3g' })
_cb({ type: 'wifi', isConnected: true, isInternetReachable: true })
expect(client.breadcrumbs.length).toBe(1)
expect(client.breadcrumbs[0].type).toBe('state')
expect(client.breadcrumbs[0].name).toBe('Connectivity changed')
expect(client.breadcrumbs[0].metaData).toEqual({ type: 'wifi', effectiveType: '3g' })
expect(client.breadcrumbs[0].metaData).toEqual({ type: 'wifi', isConnected: true, isInternetReachable: true })

_cb({ type: 'none', effectiveType: 'unknown' })
_cb({ type: 'none', isConnected: false, isInternetReachable: false })
expect(client.breadcrumbs.length).toBe(2)
expect(client.breadcrumbs[1].type).toBe('state')
expect(client.breadcrumbs[1].name).toBe('Connectivity changed')
expect(client.breadcrumbs[1].metaData).toEqual({ type: 'none', effectiveType: 'unknown' })
expect(client.breadcrumbs[1].metaData).toEqual({ type: 'none', isConnected: false, isInternetReachable: false })
})

it('should not be enabled when autoBreadcrumbs=false', () => {
Expand All @@ -46,7 +46,7 @@ describe('plugin: react native connectivity breadcrumbs', () => {
}
}
const plugin = proxyquire('../', {
'react-native': { NetInfo }
'@react-native-community/netinfo': NetInfo
})

const client = new Client(VALID_NOTIFIER)
Expand All @@ -60,12 +60,12 @@ describe('plugin: react native connectivity breadcrumbs', () => {
it('should not be enabled when connectivityBreadcrumbsEnabled=false', () => {
let _cb
const NetInfo = {
addEventListener: (type, fn) => {
addEventListener: (fn) => {
_cb = fn
}
}
const plugin = proxyquire('../', {
'react-native': { NetInfo }
'@react-native-community/netinfo': NetInfo
})

const client = new Client(VALID_NOTIFIER)
Expand All @@ -79,12 +79,12 @@ describe('plugin: react native connectivity breadcrumbs', () => {
it('should be enabled when autoBreadcrumbs=false and connectivityBreadcrumbsEnabled=true', () => {
let _cb
const NetInfo = {
addEventListener: (type, fn) => {
addEventListener: (fn) => {
_cb = fn
}
}
const plugin = proxyquire('../', {
'react-native': { NetInfo }
'@react-native-community/netinfo': NetInfo
})

const client = new Client(VALID_NOTIFIER)
Expand Down
2 changes: 1 addition & 1 deletion test/expo/features/fixtures/test-app/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Test Fixture",
"slug": "test-fixture",
"privacy": "unlisted",
"sdkVersion": "34.0.0",
"sdkVersion": "36.0.0",
"platforms": [
"ios",
"android"
Expand Down
Loading