@datadog/mobile-react-native 1.0.0-beta4 → 1.0.0-rc4
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/DatadogSDKReactNative.podspec +1 -1
- package/README.md +73 -1
- package/android/build.gradle +2 -3
- package/android/src/main/java/com/datadog/reactnative/DdRum.kt +25 -24
- package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +6 -6
- package/ios/Sources/DdRum.m +10 -9
- package/ios/Sources/DdRum.swift +24 -24
- package/ios/Sources/DdTrace.m +2 -2
- package/ios/Sources/DdTrace.swift +6 -6
- package/ios/Sources/QueueHolder.swift +1 -1
- package/lib/commonjs/DdSdkReactNative.js +57 -0
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +8 -0
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/NativeSdkVerbosity.js +26 -0
- package/lib/commonjs/NativeSdkVerbosity.js.map +1 -0
- package/lib/commonjs/ProxyConfiguration.js +53 -0
- package/lib/commonjs/ProxyConfiguration.js.map +1 -0
- package/lib/commonjs/Timer.js +99 -0
- package/lib/commonjs/Timer.js.map +1 -0
- package/lib/commonjs/TrackingConsent.js +6 -0
- package/lib/commonjs/TrackingConsent.js.map +1 -1
- package/lib/commonjs/foundation.js +88 -8
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/index.js +14 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +51 -11
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +38 -6
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +103 -18
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/version.js +10 -0
- package/lib/commonjs/version.js.map +1 -0
- package/lib/module/DdSdkReactNative.js +56 -1
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +9 -1
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/NativeSdkVerbosity.js +18 -0
- package/lib/module/NativeSdkVerbosity.js.map +1 -0
- package/lib/module/ProxyConfiguration.js +46 -0
- package/lib/module/ProxyConfiguration.js.map +1 -0
- package/lib/module/Timer.js +90 -0
- package/lib/module/Timer.js.map +1 -0
- package/lib/module/TrackingConsent.js +6 -0
- package/lib/module/TrackingConsent.js.map +1 -1
- package/lib/module/foundation.js +89 -3
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js +51 -11
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +37 -6
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js +96 -18
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +3 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/DdSdkReactNative.d.ts +11 -0
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +6 -0
- package/lib/typescript/NativeSdkVerbosity.d.ts +9 -0
- package/lib/typescript/ProxyConfiguration.d.ts +56 -0
- package/lib/typescript/Timer.d.ts +20 -0
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +2 -0
- package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +2 -0
- package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +4 -0
- package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +2 -2
- package/lib/typescript/types.d.ts +25 -24
- package/lib/typescript/version.d.ts +1 -0
- package/package.json +12 -13
- package/src/DdSdkReactNative.tsx +47 -0
- package/src/DdSdkReactNativeConfiguration.tsx +7 -1
- package/src/NativeSdkVerbosity.tsx +15 -0
- package/src/ProxyConfiguration.tsx +37 -0
- package/src/Timer.ts +96 -0
- package/src/TrackingConsent.tsx +6 -0
- package/src/__tests__/DdRumWrapper.test.tsx +91 -0
- package/src/__tests__/DdSdkReactNative.test.tsx +541 -0
- package/src/__tests__/Timer.test.ts +145 -0
- package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +222 -0
- package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +314 -0
- package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +677 -0
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +188 -0
- package/src/__tests__/rum/instrumentation/TraceIdentifier.test.tsx +33 -0
- package/src/foundation.tsx +83 -3
- package/src/index.tsx +3 -2
- package/src/rum/instrumentation/DdEventsInterceptor.tsx +40 -10
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +56 -25
- package/src/rum/instrumentation/DdRumResourceTracking.tsx +92 -22
- package/src/rum/instrumentation/DdRumXhr.tsx +6 -5
- package/src/types.tsx +25 -24
- package/src/version.ts +2 -0
- package/android/.project +0 -17
- package/android/.settings/org.eclipse.buildship.core.prefs +0 -13
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -6
- package/android/gradlew +0 -185
- package/android/gradlew.bat +0 -104
- package/ios/DdSdkReactNative.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/Tests/ModulesTest.swift +0 -43
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { DdEventsInterceptor, RumActionType, UNKNOWN_TARGET_NAME } from '../../../rum/instrumentation/DdEventsInterceptor'
|
|
8
|
+
import { DdRum } from '../../../index';
|
|
9
|
+
|
|
10
|
+
jest.mock('../../../foundation', () => {
|
|
11
|
+
return {
|
|
12
|
+
DdRum: {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
14
|
+
addAction: jest.fn().mockImplementation(() => { })
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Silence the warning https://github.com/facebook/react-native/issues/11094#issuecomment-263240420
|
|
20
|
+
jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper')
|
|
21
|
+
jest.useFakeTimers()
|
|
22
|
+
|
|
23
|
+
let testedEventsInterceptor: DdEventsInterceptor
|
|
24
|
+
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
testedEventsInterceptor = new DdEventsInterceptor()
|
|
27
|
+
jest.setTimeout(20000)
|
|
28
|
+
DdRum.addAction.mockReset()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('M send a RUM Action event W interceptOnPress { arguments with dd-action-name } ', async () => {
|
|
32
|
+
// GIVEN
|
|
33
|
+
const fakeAccessibilityLabel = "target_name"
|
|
34
|
+
const fakeDdActionLabel = "DdActionLabel"
|
|
35
|
+
const fakeArguments = {
|
|
36
|
+
_targetInst: {
|
|
37
|
+
memoizedProps: {
|
|
38
|
+
accessibilityLabel: fakeAccessibilityLabel,
|
|
39
|
+
"dd-action-name": fakeDdActionLabel
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// WHEN
|
|
45
|
+
testedEventsInterceptor.interceptOnPress(fakeArguments)
|
|
46
|
+
|
|
47
|
+
// THEN
|
|
48
|
+
expect(DdRum.addAction.mock.calls.length).toBe(1)
|
|
49
|
+
expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP.valueOf())
|
|
50
|
+
expect(DdRum.addAction.mock.calls[0][1]).toBe(fakeDdActionLabel)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('M send a RUM Action event W interceptOnPress { arguments with dd-action-name on a parent node} ', async () => {
|
|
54
|
+
// GIVEN
|
|
55
|
+
const fakeAccessibilityLabel = "target_name"
|
|
56
|
+
const fakeDdActionLabel = "DdActionLabel"
|
|
57
|
+
const fakeArguments = {
|
|
58
|
+
_targetInst: {
|
|
59
|
+
memoizedProps: {
|
|
60
|
+
accessibilityLabel: fakeAccessibilityLabel
|
|
61
|
+
},
|
|
62
|
+
return: {
|
|
63
|
+
memoizedProps: {
|
|
64
|
+
accessibilityLabel: fakeAccessibilityLabel,
|
|
65
|
+
"dd-action-name": fakeDdActionLabel
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// WHEN
|
|
72
|
+
testedEventsInterceptor.interceptOnPress(fakeArguments)
|
|
73
|
+
|
|
74
|
+
// THEN
|
|
75
|
+
expect(DdRum.addAction.mock.calls.length).toBe(1)
|
|
76
|
+
expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP.valueOf())
|
|
77
|
+
expect(DdRum.addAction.mock.calls[0][1]).toBe(fakeDdActionLabel)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('M send a RUM Action event W interceptOnPress { arguments with accessibilityLabel } ', async () => {
|
|
81
|
+
// GIVEN
|
|
82
|
+
const fakeAccessibilityLabel = "target_name"
|
|
83
|
+
const fakeArguments = { _targetInst: { memoizedProps: { accessibilityLabel: fakeAccessibilityLabel } } }
|
|
84
|
+
|
|
85
|
+
// WHEN
|
|
86
|
+
testedEventsInterceptor.interceptOnPress(fakeArguments)
|
|
87
|
+
|
|
88
|
+
// THEN
|
|
89
|
+
expect(DdRum.addAction.mock.calls.length).toBe(1)
|
|
90
|
+
expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP.valueOf())
|
|
91
|
+
expect(DdRum.addAction.mock.calls[0][1]).toBe(fakeAccessibilityLabel)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('M send only one RUM Action event W interceptOnPress { called multiple times for same target } ', async () => {
|
|
95
|
+
// GIVEN
|
|
96
|
+
const fakeAccessibilityLabel = "target_name"
|
|
97
|
+
const fakeArguments = { _targetInst: { memoizedProps: { accessibilityLabel: fakeAccessibilityLabel } } }
|
|
98
|
+
|
|
99
|
+
// WHEN
|
|
100
|
+
testedEventsInterceptor.interceptOnPress(fakeArguments)
|
|
101
|
+
testedEventsInterceptor.interceptOnPress(fakeArguments)
|
|
102
|
+
testedEventsInterceptor.interceptOnPress(fakeArguments)
|
|
103
|
+
testedEventsInterceptor.interceptOnPress(fakeArguments)
|
|
104
|
+
|
|
105
|
+
// THEN
|
|
106
|
+
expect(DdRum.addAction.mock.calls.length).toBe(1)
|
|
107
|
+
expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP.valueOf())
|
|
108
|
+
expect(DdRum.addAction.mock.calls[0][1]).toBe(fakeAccessibilityLabel)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
it('M send a RUM Action event W interceptOnPress { no accessibilityLabel arguments, elementType is string } ', async () => {
|
|
113
|
+
// GIVEN
|
|
114
|
+
const fakeElementType = "element_type"
|
|
115
|
+
const fakeArguments = { _targetInst: { elementType: fakeElementType } }
|
|
116
|
+
|
|
117
|
+
// WHEN
|
|
118
|
+
testedEventsInterceptor.interceptOnPress(fakeArguments)
|
|
119
|
+
|
|
120
|
+
// THEN
|
|
121
|
+
expect(DdRum.addAction.mock.calls.length).toBe(1)
|
|
122
|
+
expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP.valueOf())
|
|
123
|
+
expect(DdRum.addAction.mock.calls[0][1]).toBe(fakeElementType)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('M send a RUM Action event W interceptOnPress { no accessibilityLabel arguments, elementType is object with name property } ', async () => {
|
|
127
|
+
// GIVEN
|
|
128
|
+
const fakeElementType = "element_type"
|
|
129
|
+
const fakeArguments = { _targetInst: { elementType: { name: fakeElementType } } }
|
|
130
|
+
|
|
131
|
+
// WHEN
|
|
132
|
+
testedEventsInterceptor.interceptOnPress(fakeArguments)
|
|
133
|
+
|
|
134
|
+
// THEN
|
|
135
|
+
expect(DdRum.addAction.mock.calls.length).toBe(1)
|
|
136
|
+
expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP.valueOf())
|
|
137
|
+
expect(DdRum.addAction.mock.calls[0][1]).toBe(fakeElementType)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('M send a RUM Action event W interceptOnPress { no accessibilityLabel, no elementType } ', async () => {
|
|
141
|
+
// GIVEN
|
|
142
|
+
const fakeArguments = { _targetInst: {} }
|
|
143
|
+
|
|
144
|
+
// WHEN
|
|
145
|
+
testedEventsInterceptor.interceptOnPress(fakeArguments)
|
|
146
|
+
|
|
147
|
+
// THEN
|
|
148
|
+
expect(DdRum.addAction.mock.calls.length).toBe(1)
|
|
149
|
+
expect(DdRum.addAction.mock.calls[0][0]).toBe(RumActionType.TAP.valueOf())
|
|
150
|
+
expect(DdRum.addAction.mock.calls[0][1]).toBe(UNKNOWN_TARGET_NAME)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('M do nothing W interceptOnPress { invalid arguments - empty object } ', async () => {
|
|
154
|
+
// GIVEN
|
|
155
|
+
const fakeArguments = {}
|
|
156
|
+
|
|
157
|
+
// WHEN
|
|
158
|
+
testedEventsInterceptor.interceptOnPress(fakeArguments)
|
|
159
|
+
|
|
160
|
+
// THEN
|
|
161
|
+
expect(DdRum.addAction.mock.calls.length).toBe(0)
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
it('M do nothing W interceptOnPress { invalid arguments - array } ', async () => {
|
|
165
|
+
// GIVEN
|
|
166
|
+
const fakeArguments = []
|
|
167
|
+
|
|
168
|
+
// WHEN
|
|
169
|
+
testedEventsInterceptor.interceptOnPress(fakeArguments)
|
|
170
|
+
|
|
171
|
+
// THEN
|
|
172
|
+
expect(DdRum.addAction.mock.calls.length).toBe(0)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it('M do nothing W interceptOnPress { invalid arguments - nested array } ', async () => {
|
|
176
|
+
// GIVEN
|
|
177
|
+
const fakeArguments = [[]]
|
|
178
|
+
|
|
179
|
+
// WHEN
|
|
180
|
+
testedEventsInterceptor.interceptOnPress(fakeArguments)
|
|
181
|
+
|
|
182
|
+
// THEN
|
|
183
|
+
expect(DdRum.addAction.mock.calls.length).toBe(0)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
it('M do nothing W interceptOnPress { invalid arguments - undefined } ', async () => {
|
|
187
|
+
// GIVEN
|
|
188
|
+
const fakeArguments = undefined
|
|
189
|
+
|
|
190
|
+
// WHEN
|
|
191
|
+
testedEventsInterceptor.interceptOnPress(fakeArguments)
|
|
192
|
+
|
|
193
|
+
// THEN
|
|
194
|
+
expect(DdRum.addAction.mock.calls.length).toBe(0)
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
it('M do nothing W interceptOnPress { invalid arguments - null } ', async () => {
|
|
198
|
+
// GIVEN
|
|
199
|
+
const fakeArguments = null
|
|
200
|
+
|
|
201
|
+
// WHEN
|
|
202
|
+
testedEventsInterceptor.interceptOnPress(fakeArguments)
|
|
203
|
+
|
|
204
|
+
// THEN
|
|
205
|
+
expect(DdRum.addAction.mock.calls.length).toBe(0)
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
it('M do nothing W interceptOnPress { invalid arguments - wrong object } ', async () => {
|
|
209
|
+
// WHEN
|
|
210
|
+
testedEventsInterceptor.interceptOnPress({ 'a': 'b' })
|
|
211
|
+
|
|
212
|
+
// THEN
|
|
213
|
+
expect(DdRum.addAction.mock.calls.length).toBe(0)
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
it('M do nothing W interceptOnPress { no arguments call } ', async () => {
|
|
217
|
+
// WHEN
|
|
218
|
+
testedEventsInterceptor.interceptOnPress()
|
|
219
|
+
|
|
220
|
+
// THEN
|
|
221
|
+
expect(DdRum.addAction.mock.calls.length).toBe(0)
|
|
222
|
+
})
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { DdRumErrorTracking } from '../../../rum/instrumentation/DdRumErrorTracking'
|
|
8
|
+
import { DdRum } from '../../../index';
|
|
9
|
+
|
|
10
|
+
jest.useFakeTimers()
|
|
11
|
+
|
|
12
|
+
jest.mock('../../../foundation', () => {
|
|
13
|
+
return {
|
|
14
|
+
DdRum: {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
16
|
+
addError: jest.fn().mockImplementation(() => {
|
|
17
|
+
return Promise.resolve();
|
|
18
|
+
})
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
let baseErrorHandlerCalled = false;
|
|
25
|
+
let baseErrorHandler = (error: any, isFatal?: boolean) => {
|
|
26
|
+
baseErrorHandlerCalled = true
|
|
27
|
+
};
|
|
28
|
+
let originalErrorHandler = undefined;
|
|
29
|
+
|
|
30
|
+
let baseConsoleErrorCalled = false;
|
|
31
|
+
let baseConsoleError = (...params: unknown) => {
|
|
32
|
+
baseConsoleErrorCalled = true
|
|
33
|
+
}
|
|
34
|
+
let originalConsoleError = undefined
|
|
35
|
+
|
|
36
|
+
const flushPromises = () => new Promise(setImmediate);
|
|
37
|
+
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
DdRum.addError.mockClear();
|
|
40
|
+
baseErrorHandlerCalled = false;
|
|
41
|
+
originalErrorHandler = ErrorUtils.getGlobalHandler();
|
|
42
|
+
ErrorUtils.setGlobalHandler(baseErrorHandler);
|
|
43
|
+
originalConsoleError = console.error;
|
|
44
|
+
console.error = baseConsoleError;
|
|
45
|
+
jest.setTimeout(20000)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
afterEach(() => {
|
|
49
|
+
DdRumErrorTracking['isTracking'] = false
|
|
50
|
+
ErrorUtils.setGlobalHandler(originalErrorHandler)
|
|
51
|
+
console.error = originalConsoleError
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('M intercept and send a RUM event W onGlobalError() {no message}', async () => {
|
|
55
|
+
// GIVEN
|
|
56
|
+
DdRumErrorTracking.startTracking();
|
|
57
|
+
const is_fatal = Math.random() < 0.5;
|
|
58
|
+
const error = {
|
|
59
|
+
stack: ["doSomething() at ./path/to/file.js:67:3"]
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// WHEN
|
|
63
|
+
DdRumErrorTracking.onGlobalError(error, is_fatal);
|
|
64
|
+
await flushPromises();
|
|
65
|
+
|
|
66
|
+
// THEN
|
|
67
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
68
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe(String(error));
|
|
69
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe("SOURCE");
|
|
70
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe("doSomething() at ./path/to/file.js:67:3");
|
|
71
|
+
const attributes = DdRum.addError.mock.calls[0][3];
|
|
72
|
+
expect(attributes["_dd.error.raw"]).toStrictEqual(error);
|
|
73
|
+
expect(attributes["_dd.error.is_crash"]).toStrictEqual(is_fatal);
|
|
74
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('M intercept and send a RUM event W onGlobalError() {empty stack trace}', async () => {
|
|
78
|
+
// GIVEN
|
|
79
|
+
DdRumErrorTracking.startTracking();
|
|
80
|
+
const is_fatal = Math.random() < 0.5;
|
|
81
|
+
const error = {
|
|
82
|
+
message: "Something bad happened"
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// WHEN
|
|
86
|
+
DdRumErrorTracking.onGlobalError(error, is_fatal);
|
|
87
|
+
await flushPromises();
|
|
88
|
+
|
|
89
|
+
// THEN
|
|
90
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
91
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe("Something bad happened");
|
|
92
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe("SOURCE");
|
|
93
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe("");
|
|
94
|
+
const attributes = DdRum.addError.mock.calls[0][3];
|
|
95
|
+
expect(attributes["_dd.error.raw"]).toStrictEqual(error);
|
|
96
|
+
expect(attributes["_dd.error.is_crash"]).toStrictEqual(is_fatal);
|
|
97
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('M intercept and send a RUM event W onGlobalError() {Error object}', async () => {
|
|
101
|
+
// GIVEN
|
|
102
|
+
DdRumErrorTracking.startTracking();
|
|
103
|
+
const is_fatal = Math.random() < 0.5;
|
|
104
|
+
const error = new Error('Something bad happened');
|
|
105
|
+
|
|
106
|
+
// WHEN
|
|
107
|
+
DdRumErrorTracking.onGlobalError(error, is_fatal);
|
|
108
|
+
await flushPromises();
|
|
109
|
+
|
|
110
|
+
// THEN
|
|
111
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
112
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe("Something bad happened");
|
|
113
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe("SOURCE");
|
|
114
|
+
expect(DdRum.addError.mock.calls[0][2]).toContain("Error: Something bad happened");
|
|
115
|
+
expect(DdRum.addError.mock.calls[0][2]).toContain("/packages/core/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx");
|
|
116
|
+
const attributes = DdRum.addError.mock.calls[0][3];
|
|
117
|
+
expect(attributes["_dd.error.raw"]).toStrictEqual(error);
|
|
118
|
+
expect(attributes["_dd.error.is_crash"]).toStrictEqual(is_fatal);
|
|
119
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
it('M intercept and send a RUM event W onGlobalError() {with source file info}', async () => {
|
|
124
|
+
// GIVEN
|
|
125
|
+
DdRumErrorTracking.startTracking();
|
|
126
|
+
const is_fatal = Math.random() < 0.5;
|
|
127
|
+
const error = {
|
|
128
|
+
sourceURL: "./path/to/file.js",
|
|
129
|
+
line: 1038,
|
|
130
|
+
column: 57,
|
|
131
|
+
message: "Something bad happened"
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// WHEN
|
|
135
|
+
DdRumErrorTracking.onGlobalError(error, is_fatal);
|
|
136
|
+
await flushPromises();
|
|
137
|
+
|
|
138
|
+
// THEN
|
|
139
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
140
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe("Something bad happened");
|
|
141
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe("SOURCE");
|
|
142
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe("at ./path/to/file.js:1038:57");
|
|
143
|
+
const attributes = DdRum.addError.mock.calls[0][3];
|
|
144
|
+
expect(attributes["_dd.error.raw"]).toStrictEqual(error);
|
|
145
|
+
expect(attributes["_dd.error.is_crash"]).toStrictEqual(is_fatal);
|
|
146
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
it('M intercept and send a RUM event W onGlobalError() {with component stack}', async () => {
|
|
151
|
+
// GIVEN
|
|
152
|
+
DdRumErrorTracking.startTracking();
|
|
153
|
+
const is_fatal = Math.random() < 0.5;
|
|
154
|
+
const error = {
|
|
155
|
+
componentStack: ["doSomething() at ./path/to/file.js:67:3", "nestedCall() at ./path/to/file.js:1064:9", "root() at ./path/to/index.js:10:1"],
|
|
156
|
+
message: "Something bad happened"
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// WHEN
|
|
160
|
+
DdRumErrorTracking.onGlobalError(error, is_fatal);
|
|
161
|
+
await flushPromises();
|
|
162
|
+
|
|
163
|
+
// THEN
|
|
164
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
165
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe("Something bad happened");
|
|
166
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe("SOURCE");
|
|
167
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe("doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1");
|
|
168
|
+
const attributes = DdRum.addError.mock.calls[0][3];
|
|
169
|
+
expect(attributes["_dd.error.raw"]).toStrictEqual(error);
|
|
170
|
+
expect(attributes["_dd.error.is_crash"]).toStrictEqual(is_fatal);
|
|
171
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
it('M intercept and send a RUM event W onGlobalError() {with stack}', async () => {
|
|
175
|
+
// GIVEN
|
|
176
|
+
DdRumErrorTracking.startTracking();
|
|
177
|
+
const is_fatal = Math.random() < 0.5;
|
|
178
|
+
const error = {
|
|
179
|
+
stack: ["doSomething() at ./path/to/file.js:67:3", "nestedCall() at ./path/to/file.js:1064:9", "root() at ./path/to/index.js:10:1"],
|
|
180
|
+
message: "Something bad happened"
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// WHEN
|
|
184
|
+
DdRumErrorTracking.onGlobalError(error, is_fatal);
|
|
185
|
+
await flushPromises();
|
|
186
|
+
|
|
187
|
+
// THEN
|
|
188
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
189
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe("Something bad happened");
|
|
190
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe("SOURCE");
|
|
191
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe("doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1");
|
|
192
|
+
const attributes = DdRum.addError.mock.calls[0][3];
|
|
193
|
+
expect(attributes["_dd.error.raw"]).toStrictEqual(error);
|
|
194
|
+
expect(attributes["_dd.error.is_crash"]).toStrictEqual(is_fatal);
|
|
195
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
it('M intercept and send a RUM event W onGlobalError() {with stacktrace}', async () => {
|
|
199
|
+
// GIVEN
|
|
200
|
+
DdRumErrorTracking.startTracking();
|
|
201
|
+
const is_fatal = Math.random() < 0.5;
|
|
202
|
+
const error = {
|
|
203
|
+
stacktrace: ["doSomething() at ./path/to/file.js:67:3", "nestedCall() at ./path/to/file.js:1064:9", "root() at ./path/to/index.js:10:1"],
|
|
204
|
+
message: "Something bad happened"
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// WHEN
|
|
208
|
+
DdRumErrorTracking.onGlobalError(error, is_fatal);
|
|
209
|
+
await flushPromises();
|
|
210
|
+
|
|
211
|
+
// THEN
|
|
212
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
213
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe("Something bad happened");
|
|
214
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe("SOURCE");
|
|
215
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe("doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1");
|
|
216
|
+
const attributes = DdRum.addError.mock.calls[0][3];
|
|
217
|
+
expect(attributes["_dd.error.raw"]).toStrictEqual(error);
|
|
218
|
+
expect(attributes["_dd.error.is_crash"]).toStrictEqual(is_fatal);
|
|
219
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
it('M not report error in console handler W onGlobalError() {with console reporting handler}', async () => {
|
|
223
|
+
// GIVEN
|
|
224
|
+
const consoleReportingErrorHandler = jest.fn((error, isFatal)=> {
|
|
225
|
+
console.error(error.message);
|
|
226
|
+
baseErrorHandler(error, isFatal);
|
|
227
|
+
});
|
|
228
|
+
ErrorUtils.setGlobalHandler(consoleReportingErrorHandler);
|
|
229
|
+
DdRumErrorTracking.startTracking();
|
|
230
|
+
const is_fatal = Math.random() < 0.5;
|
|
231
|
+
const error = {
|
|
232
|
+
componentStack: ["doSomething() at ./path/to/file.js:67:3", "nestedCall() at ./path/to/file.js:1064:9", "root() at ./path/to/index.js:10:1"],
|
|
233
|
+
message: "Something bad happened"
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// WHEN
|
|
237
|
+
DdRumErrorTracking.onGlobalError(error, is_fatal);
|
|
238
|
+
await flushPromises();
|
|
239
|
+
|
|
240
|
+
// THEN
|
|
241
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
242
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe("Something bad happened");
|
|
243
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe("SOURCE");
|
|
244
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe("doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1");
|
|
245
|
+
const attributes = DdRum.addError.mock.calls[0][3];
|
|
246
|
+
expect(attributes["_dd.error.raw"]).toStrictEqual(error);
|
|
247
|
+
expect(attributes["_dd.error.is_crash"]).toStrictEqual(is_fatal);
|
|
248
|
+
expect(consoleReportingErrorHandler).toBeCalledTimes(1);
|
|
249
|
+
expect(baseConsoleErrorCalled).toStrictEqual(false);
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
it('M intercept and send a RUM event W onConsole() {Error with source file info}', async () => {
|
|
253
|
+
// GIVEN
|
|
254
|
+
DdRumErrorTracking.startTracking();
|
|
255
|
+
const message= "Oops I did it again!";
|
|
256
|
+
const error = {
|
|
257
|
+
sourceURL: "./path/to/file.js",
|
|
258
|
+
line: 1038,
|
|
259
|
+
column: 57,
|
|
260
|
+
message: "Something bad happened"
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// WHEN
|
|
264
|
+
DdRumErrorTracking.onConsoleError(message, error);
|
|
265
|
+
await flushPromises();
|
|
266
|
+
|
|
267
|
+
// THEN
|
|
268
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
269
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe("Oops I did it again! Something bad happened");
|
|
270
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe("CONSOLE");
|
|
271
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe("at ./path/to/file.js:1038:57");
|
|
272
|
+
expect(DdRum.addError.mock.calls[0][3]).toBeUndefined()
|
|
273
|
+
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
it('M intercept and send a RUM event W onConsole() {Error with component stack}', async () => {
|
|
277
|
+
// GIVEN
|
|
278
|
+
DdRumErrorTracking.startTracking();
|
|
279
|
+
const message= "Oops I did it again!";
|
|
280
|
+
const error = {
|
|
281
|
+
componentStack: ["doSomething() at ./path/to/file.js:67:3", "nestedCall() at ./path/to/file.js:1064:9", "root() at ./path/to/index.js:10:1"],
|
|
282
|
+
message: "Something bad happened"
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// WHEN
|
|
286
|
+
DdRumErrorTracking.onConsoleError(message, error);
|
|
287
|
+
await flushPromises();
|
|
288
|
+
|
|
289
|
+
// THEN
|
|
290
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
291
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe("Oops I did it again! Something bad happened");
|
|
292
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe("CONSOLE");
|
|
293
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe("doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1");
|
|
294
|
+
expect(DdRum.addError.mock.calls[0][3]).toBeUndefined()
|
|
295
|
+
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
it('M intercept and send a RUM event W onConsole() {message only}', async () => {
|
|
299
|
+
// GIVEN
|
|
300
|
+
DdRumErrorTracking.startTracking();
|
|
301
|
+
const message= "Something bad happened";
|
|
302
|
+
|
|
303
|
+
// WHEN
|
|
304
|
+
DdRumErrorTracking.onConsoleError(message);
|
|
305
|
+
await flushPromises();
|
|
306
|
+
|
|
307
|
+
// THEN
|
|
308
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
309
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe(message);
|
|
310
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe("CONSOLE");
|
|
311
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe("");
|
|
312
|
+
expect(DdRum.addError.mock.calls[0][3]).toBeUndefined()
|
|
313
|
+
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
314
|
+
})
|