@planningcenter/chat-react-native 3.37.0-rc.1 → 3.37.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/conversation/message.d.ts.map +1 -1
- package/build/components/conversation/message.js +3 -3
- package/build/components/conversation/message.js.map +1 -1
- package/build/components/index.d.ts +2 -0
- package/build/components/index.d.ts.map +1 -1
- package/build/components/index.js +2 -0
- package/build/components/index.js.map +1 -1
- package/build/components/page/component_error_boundary.d.ts +4 -0
- package/build/components/page/component_error_boundary.d.ts.map +1 -0
- package/build/components/page/component_error_boundary.js +8 -0
- package/build/components/page/component_error_boundary.js.map +1 -0
- package/build/components/page/error_boundary.d.ts +13 -10
- package/build/components/page/error_boundary.d.ts.map +1 -1
- package/build/components/page/error_boundary.js +20 -90
- package/build/components/page/error_boundary.js.map +1 -1
- package/build/components/page/page_error_boundary.d.ts +4 -0
- package/build/components/page/page_error_boundary.d.ts.map +1 -0
- package/build/components/page/page_error_boundary.js +80 -0
- package/build/components/page/page_error_boundary.js.map +1 -0
- package/build/navigation/screenLayout.d.ts.map +1 -1
- package/build/navigation/screenLayout.js +5 -3
- package/build/navigation/screenLayout.js.map +1 -1
- package/build/utils/native_adapters/log.d.ts +11 -0
- package/build/utils/native_adapters/log.d.ts.map +1 -1
- package/build/utils/native_adapters/log.js +9 -0
- package/build/utils/native_adapters/log.js.map +1 -1
- package/package.json +2 -2
- package/src/components/conversation/message.tsx +6 -4
- package/src/components/index.tsx +2 -0
- package/src/components/page/__tests__/component_error_boundary.test.tsx +46 -0
- package/src/components/page/__tests__/error_boundary.test.tsx +93 -0
- package/src/components/page/__tests__/page_error_boundary.test.tsx +77 -0
- package/src/components/page/component_error_boundary.tsx +13 -0
- package/src/components/page/error_boundary.tsx +34 -118
- package/src/components/page/page_error_boundary.tsx +112 -0
- package/src/navigation/screenLayout.tsx +6 -3
- package/src/utils/native_adapters/__tests__/log.test.ts +62 -0
- package/src/utils/native_adapters/log.ts +22 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { LogAdapter } from '../log'
|
|
2
|
+
|
|
3
|
+
describe('LogAdapter', () => {
|
|
4
|
+
describe('reportError', () => {
|
|
5
|
+
it('forwards the error and context to the host callback', () => {
|
|
6
|
+
const reportError = jest.fn()
|
|
7
|
+
const adapter = new LogAdapter({ reportError })
|
|
8
|
+
const error = new Error('boom')
|
|
9
|
+
const context = { scope: 'screen' as const, screenName: 'ConversationScreen' }
|
|
10
|
+
|
|
11
|
+
adapter.reportError(error, context)
|
|
12
|
+
|
|
13
|
+
expect(reportError).toHaveBeenCalledWith(error, context)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('fires even when the adapter is disabled', () => {
|
|
17
|
+
const reportError = jest.fn()
|
|
18
|
+
const adapter = new LogAdapter({ enabled: false, reportError })
|
|
19
|
+
|
|
20
|
+
adapter.reportError(new Error('boom'))
|
|
21
|
+
|
|
22
|
+
expect(reportError).toHaveBeenCalledTimes(1)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('falls back to console.error when no host callback is configured', () => {
|
|
26
|
+
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
|
|
27
|
+
const adapter = new LogAdapter()
|
|
28
|
+
const error = new Error('boom')
|
|
29
|
+
|
|
30
|
+
adapter.reportError(error, { scope: 'http' })
|
|
31
|
+
|
|
32
|
+
expect(spy).toHaveBeenCalledWith(error, { scope: 'http' })
|
|
33
|
+
spy.mockRestore()
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe('info and error', () => {
|
|
38
|
+
it('drops info and error calls when disabled', () => {
|
|
39
|
+
const info = jest.fn()
|
|
40
|
+
const error = jest.fn()
|
|
41
|
+
const adapter = new LogAdapter({ enabled: false, info, error })
|
|
42
|
+
|
|
43
|
+
adapter.info('hi')
|
|
44
|
+
adapter.error('bye')
|
|
45
|
+
|
|
46
|
+
expect(info).not.toHaveBeenCalled()
|
|
47
|
+
expect(error).not.toHaveBeenCalled()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('forwards info and error calls when enabled', () => {
|
|
51
|
+
const info = jest.fn()
|
|
52
|
+
const error = jest.fn()
|
|
53
|
+
const adapter = new LogAdapter({ enabled: true, info, error })
|
|
54
|
+
|
|
55
|
+
adapter.info('hi', { a: 1 })
|
|
56
|
+
adapter.error('bye', { b: 2 })
|
|
57
|
+
|
|
58
|
+
expect(info).toHaveBeenCalledWith('hi', { a: 1 })
|
|
59
|
+
expect(error).toHaveBeenCalledWith('bye', { b: 2 })
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
})
|
|
@@ -1,18 +1,31 @@
|
|
|
1
|
+
export type ReportErrorScope = 'screen' | 'component' | 'http'
|
|
2
|
+
|
|
3
|
+
export type ReportErrorContext = {
|
|
4
|
+
componentStack?: string
|
|
5
|
+
scope?: ReportErrorScope
|
|
6
|
+
screenName?: string
|
|
7
|
+
tags?: Record<string, string>
|
|
8
|
+
extra?: Record<string, unknown>
|
|
9
|
+
}
|
|
10
|
+
|
|
1
11
|
interface LogAdapterConfig {
|
|
2
12
|
enabled: boolean
|
|
3
13
|
error: (message: string, ...args: any[]) => void
|
|
4
14
|
info: (message: string, ...args: any[]) => void
|
|
15
|
+
reportError: (error: Error, context?: ReportErrorContext) => void
|
|
5
16
|
}
|
|
6
17
|
|
|
7
18
|
export class LogAdapter {
|
|
8
19
|
enabled: boolean
|
|
9
20
|
onError?: LogAdapterConfig['error']
|
|
10
21
|
onInfo?: LogAdapterConfig['info']
|
|
22
|
+
onReportError?: LogAdapterConfig['reportError']
|
|
11
23
|
|
|
12
24
|
constructor(config: Partial<LogAdapterConfig> = {}) {
|
|
13
25
|
this.enabled = config.enabled ?? false
|
|
14
26
|
this.onError = config.error
|
|
15
27
|
this.onInfo = config.info
|
|
28
|
+
this.onReportError = config.reportError
|
|
16
29
|
}
|
|
17
30
|
|
|
18
31
|
error(message: string, ...args: any[]) {
|
|
@@ -26,4 +39,13 @@ export class LogAdapter {
|
|
|
26
39
|
|
|
27
40
|
this.onInfo?.(message, ...args)
|
|
28
41
|
}
|
|
42
|
+
|
|
43
|
+
reportError(error: Error, context?: ReportErrorContext) {
|
|
44
|
+
if (this.onReportError) {
|
|
45
|
+
this.onReportError(error, context)
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.error(error, context)
|
|
50
|
+
}
|
|
29
51
|
}
|