@datadog/mobile-react-native 1.0.0-rc3 → 1.0.0-rc6
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 +47 -16
- package/android/build.gradle +2 -3
- package/android/gradle.properties +4 -4
- 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/lib/commonjs/DdSdkReactNative.js +42 -22
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +17 -2
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/InternalLog.js +51 -0
- package/lib/commonjs/InternalLog.js.map +1 -0
- package/lib/commonjs/ProxyConfiguration.js.map +1 -1
- package/lib/commonjs/SdkVerbosity.js +26 -0
- package/lib/commonjs/SdkVerbosity.js.map +1 -0
- package/lib/commonjs/TimeProvider.js +72 -0
- package/lib/commonjs/TimeProvider.js.map +1 -0
- package/lib/commonjs/Timer.js +10 -23
- package/lib/commonjs/Timer.js.map +1 -1
- package/lib/commonjs/TrackingConsent.js.map +1 -1
- package/lib/commonjs/foundation.js +62 -40
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/index.js +26 -18
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal.js +14 -0
- package/lib/commonjs/internal.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +14 -5
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +51 -20
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +141 -30
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +46 -7
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js +34 -0
- package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/TraceIdentifier.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 +34 -22
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +18 -3
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/InternalLog.js +46 -0
- package/lib/module/InternalLog.js.map +1 -0
- package/lib/module/ProxyConfiguration.js.map +1 -1
- package/lib/module/SdkVerbosity.js +18 -0
- package/lib/module/SdkVerbosity.js.map +1 -0
- package/lib/module/TimeProvider.js +63 -0
- package/lib/module/TimeProvider.js.map +1 -0
- package/lib/module/Timer.js +14 -23
- package/lib/module/Timer.js.map +1 -1
- package/lib/module/TrackingConsent.js.map +1 -1
- package/lib/module/foundation.js +42 -40
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal.js +2 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js +11 -5
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +46 -20
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js +133 -29
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +41 -6
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js +25 -0
- package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
- package/lib/module/rum/instrumentation/TraceIdentifier.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 +7 -6
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +15 -4
- package/lib/typescript/InternalLog.d.ts +6 -0
- package/lib/typescript/SdkVerbosity.d.ts +9 -0
- package/lib/typescript/TimeProvider.d.ts +20 -0
- package/lib/typescript/Timer.d.ts +3 -2
- package/lib/typescript/index.d.ts +3 -2
- package/lib/typescript/internal.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +3 -2
- package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +13 -8
- package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -3
- package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +13 -3
- package/lib/typescript/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
- package/lib/typescript/types.d.ts +12 -11
- package/lib/typescript/version.d.ts +1 -0
- package/package.json +7 -4
- package/src/DdSdkReactNative.tsx +112 -58
- package/src/DdSdkReactNativeConfiguration.tsx +22 -14
- package/src/InternalLog.tsx +45 -0
- package/src/ProxyConfiguration.tsx +5 -5
- package/src/{NativeSdkVerbosity.tsx → SdkVerbosity.tsx} +6 -6
- package/src/TimeProvider.tsx +64 -0
- package/src/Timer.ts +20 -35
- package/src/TrackingConsent.tsx +3 -3
- package/src/__mocks__/InternalLog.tsx +9 -0
- package/src/__tests__/DdRumWrapper.test.tsx +98 -0
- package/src/__tests__/DdSdkReactNative.test.tsx +699 -500
- package/src/__tests__/InternalLog.test.tsx +379 -0
- package/src/__tests__/TimeProvider.test.tsx +75 -0
- package/src/__tests__/Timer.test.ts +148 -57
- package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +151 -92
- package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +243 -76
- package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +723 -403
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +239 -85
- package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +31 -0
- package/src/__tests__/rum/instrumentation/TraceIdentifier.test.tsx +13 -15
- package/src/__tests__/rum/instrumentation/__utils__/XMLHttpRequestMock.ts +97 -0
- package/src/foundation.tsx +55 -42
- package/src/index.tsx +13 -3
- package/src/internal.tsx +1 -0
- package/src/rum/instrumentation/DdEventsInterceptor.tsx +51 -35
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +75 -42
- package/src/rum/instrumentation/DdRumResourceTracking.tsx +312 -166
- package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +72 -25
- package/src/rum/instrumentation/DdRumXhr.tsx +21 -11
- package/src/rum/instrumentation/EventsInterceptor.tsx +3 -3
- package/src/rum/instrumentation/NoOpEventsInterceptor.tsx +2 -2
- package/src/rum/instrumentation/ShallowObjectEqualityChecker.ts +24 -0
- package/src/rum/instrumentation/TraceIdentifier.tsx +19 -19
- package/src/types.tsx +199 -157
- package/src/version.ts +2 -0
- package/lib/commonjs/NativeSdkVerbosity.js +0 -26
- package/lib/commonjs/NativeSdkVerbosity.js.map +0 -1
- package/lib/module/NativeSdkVerbosity.js +0 -18
- package/lib/module/NativeSdkVerbosity.js.map +0 -1
- package/lib/typescript/NativeSdkVerbosity.d.ts +0 -9
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
import { DdRumErrorTracking } from '../../../rum/instrumentation/DdRumErrorTracking'
|
|
6
|
+
|
|
8
7
|
import { DdRum } from '../../../index';
|
|
8
|
+
import { DdRumErrorTracking } from '../../../rum/instrumentation/DdRumErrorTracking';
|
|
9
9
|
|
|
10
|
-
jest.useFakeTimers()
|
|
10
|
+
jest.useFakeTimers();
|
|
11
11
|
|
|
12
12
|
jest.mock('../../../foundation', () => {
|
|
13
13
|
return {
|
|
@@ -16,22 +16,21 @@ jest.mock('../../../foundation', () => {
|
|
|
16
16
|
addError: jest.fn().mockImplementation(() => {
|
|
17
17
|
return Promise.resolve();
|
|
18
18
|
})
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
20
|
};
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
|
|
24
23
|
let baseErrorHandlerCalled = false;
|
|
25
|
-
|
|
26
|
-
baseErrorHandlerCalled = true
|
|
24
|
+
const baseErrorHandler = (error: any, isFatal?: boolean) => {
|
|
25
|
+
baseErrorHandlerCalled = true;
|
|
27
26
|
};
|
|
28
|
-
let originalErrorHandler
|
|
27
|
+
let originalErrorHandler;
|
|
29
28
|
|
|
30
29
|
let baseConsoleErrorCalled = false;
|
|
31
|
-
|
|
32
|
-
baseConsoleErrorCalled = true
|
|
33
|
-
}
|
|
34
|
-
let originalConsoleError
|
|
30
|
+
const baseConsoleError = (...params: unknown) => {
|
|
31
|
+
baseConsoleErrorCalled = true;
|
|
32
|
+
};
|
|
33
|
+
let originalConsoleError;
|
|
35
34
|
|
|
36
35
|
const flushPromises = () => new Promise(setImmediate);
|
|
37
36
|
|
|
@@ -42,21 +41,47 @@ beforeEach(() => {
|
|
|
42
41
|
ErrorUtils.setGlobalHandler(baseErrorHandler);
|
|
43
42
|
originalConsoleError = console.error;
|
|
44
43
|
console.error = baseConsoleError;
|
|
45
|
-
jest.setTimeout(20000)
|
|
46
|
-
})
|
|
44
|
+
jest.setTimeout(20000);
|
|
45
|
+
});
|
|
47
46
|
|
|
48
47
|
afterEach(() => {
|
|
49
|
-
DdRumErrorTracking['isTracking'] = false
|
|
50
|
-
ErrorUtils.setGlobalHandler(originalErrorHandler)
|
|
51
|
-
console.error = originalConsoleError
|
|
52
|
-
})
|
|
48
|
+
DdRumErrorTracking['isTracking'] = false;
|
|
49
|
+
ErrorUtils.setGlobalHandler(originalErrorHandler);
|
|
50
|
+
console.error = originalConsoleError;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('M intercept and send a RUM event W onGlobalError() {no message}', async () => {
|
|
54
|
+
// GIVEN
|
|
55
|
+
DdRumErrorTracking.startTracking();
|
|
56
|
+
const is_fatal = Math.random() < 0.5;
|
|
57
|
+
const error = {
|
|
58
|
+
stack: ['doSomething() at ./path/to/file.js:67:3']
|
|
59
|
+
};
|
|
53
60
|
|
|
61
|
+
// WHEN
|
|
62
|
+
DdRumErrorTracking.onGlobalError(error, is_fatal);
|
|
63
|
+
await flushPromises();
|
|
64
|
+
|
|
65
|
+
// THEN
|
|
66
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
67
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe(String(error));
|
|
68
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe('SOURCE');
|
|
69
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe(
|
|
70
|
+
'doSomething() at ./path/to/file.js:67:3'
|
|
71
|
+
);
|
|
72
|
+
const attributes = DdRum.addError.mock.calls[0][3];
|
|
73
|
+
expect(attributes['_dd.error.raw']).toStrictEqual(error);
|
|
74
|
+
expect(attributes['_dd.error.is_crash']).toStrictEqual(is_fatal);
|
|
75
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
76
|
+
});
|
|
54
77
|
|
|
55
78
|
it('M intercept and send a RUM event W onGlobalError() {empty stack trace}', async () => {
|
|
56
79
|
// GIVEN
|
|
57
80
|
DdRumErrorTracking.startTracking();
|
|
58
81
|
const is_fatal = Math.random() < 0.5;
|
|
59
|
-
const error =
|
|
82
|
+
const error = {
|
|
83
|
+
message: 'Something bad happened'
|
|
84
|
+
};
|
|
60
85
|
|
|
61
86
|
// WHEN
|
|
62
87
|
DdRumErrorTracking.onGlobalError(error, is_fatal);
|
|
@@ -64,25 +89,50 @@ it('M intercept and send a RUM event W onGlobalError() {empty stack trace}', asy
|
|
|
64
89
|
|
|
65
90
|
// THEN
|
|
66
91
|
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
67
|
-
expect(DdRum.addError.mock.calls[0][0]).toBe(
|
|
68
|
-
expect(DdRum.addError.mock.calls[0][1]).toBe(
|
|
69
|
-
expect(DdRum.addError.mock.calls[0][2]).toBe(
|
|
92
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe('Something bad happened');
|
|
93
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe('SOURCE');
|
|
94
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe('');
|
|
70
95
|
const attributes = DdRum.addError.mock.calls[0][3];
|
|
71
|
-
expect(attributes[
|
|
72
|
-
expect(attributes[
|
|
96
|
+
expect(attributes['_dd.error.raw']).toStrictEqual(error);
|
|
97
|
+
expect(attributes['_dd.error.is_crash']).toStrictEqual(is_fatal);
|
|
73
98
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
74
|
-
})
|
|
99
|
+
});
|
|
75
100
|
|
|
101
|
+
it('M intercept and send a RUM event W onGlobalError() {Error object}', async () => {
|
|
102
|
+
// GIVEN
|
|
103
|
+
DdRumErrorTracking.startTracking();
|
|
104
|
+
const is_fatal = Math.random() < 0.5;
|
|
105
|
+
const error = new Error('Something bad happened');
|
|
106
|
+
|
|
107
|
+
// WHEN
|
|
108
|
+
DdRumErrorTracking.onGlobalError(error, is_fatal);
|
|
109
|
+
await flushPromises();
|
|
110
|
+
|
|
111
|
+
// THEN
|
|
112
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
113
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe('Something bad happened');
|
|
114
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe('SOURCE');
|
|
115
|
+
expect(DdRum.addError.mock.calls[0][2]).toContain(
|
|
116
|
+
'Error: Something bad happened'
|
|
117
|
+
);
|
|
118
|
+
expect(DdRum.addError.mock.calls[0][2]).toContain(
|
|
119
|
+
'/packages/core/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx'
|
|
120
|
+
);
|
|
121
|
+
const attributes = DdRum.addError.mock.calls[0][3];
|
|
122
|
+
expect(attributes['_dd.error.raw']).toStrictEqual(error);
|
|
123
|
+
expect(attributes['_dd.error.is_crash']).toStrictEqual(is_fatal);
|
|
124
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
125
|
+
});
|
|
76
126
|
|
|
77
127
|
it('M intercept and send a RUM event W onGlobalError() {with source file info}', async () => {
|
|
78
128
|
// GIVEN
|
|
79
129
|
DdRumErrorTracking.startTracking();
|
|
80
130
|
const is_fatal = Math.random() < 0.5;
|
|
81
131
|
const error = {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
132
|
+
sourceURL: './path/to/file.js',
|
|
133
|
+
line: 1038,
|
|
134
|
+
column: 57,
|
|
135
|
+
message: 'Something bad happened'
|
|
86
136
|
};
|
|
87
137
|
|
|
88
138
|
// WHEN
|
|
@@ -91,23 +141,28 @@ it('M intercept and send a RUM event W onGlobalError() {with source file info}',
|
|
|
91
141
|
|
|
92
142
|
// THEN
|
|
93
143
|
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
94
|
-
expect(DdRum.addError.mock.calls[0][0]).toBe(
|
|
95
|
-
expect(DdRum.addError.mock.calls[0][1]).toBe(
|
|
96
|
-
expect(DdRum.addError.mock.calls[0][2]).toBe(
|
|
144
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe('Something bad happened');
|
|
145
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe('SOURCE');
|
|
146
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe(
|
|
147
|
+
'at ./path/to/file.js:1038:57'
|
|
148
|
+
);
|
|
97
149
|
const attributes = DdRum.addError.mock.calls[0][3];
|
|
98
|
-
expect(attributes[
|
|
99
|
-
expect(attributes[
|
|
150
|
+
expect(attributes['_dd.error.raw']).toStrictEqual(error);
|
|
151
|
+
expect(attributes['_dd.error.is_crash']).toStrictEqual(is_fatal);
|
|
100
152
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
101
|
-
})
|
|
102
|
-
|
|
153
|
+
});
|
|
103
154
|
|
|
104
155
|
it('M intercept and send a RUM event W onGlobalError() {with component stack}', async () => {
|
|
105
156
|
// GIVEN
|
|
106
157
|
DdRumErrorTracking.startTracking();
|
|
107
158
|
const is_fatal = Math.random() < 0.5;
|
|
108
159
|
const error = {
|
|
109
|
-
|
|
110
|
-
|
|
160
|
+
componentStack: [
|
|
161
|
+
'doSomething() at ./path/to/file.js:67:3',
|
|
162
|
+
'nestedCall() at ./path/to/file.js:1064:9',
|
|
163
|
+
'root() at ./path/to/index.js:10:1'
|
|
164
|
+
],
|
|
165
|
+
message: 'Something bad happened'
|
|
111
166
|
};
|
|
112
167
|
|
|
113
168
|
// WHEN
|
|
@@ -116,18 +171,80 @@ it('M intercept and send a RUM event W onGlobalError() {with component stack}',
|
|
|
116
171
|
|
|
117
172
|
// THEN
|
|
118
173
|
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
119
|
-
expect(DdRum.addError.mock.calls[0][0]).toBe(
|
|
120
|
-
expect(DdRum.addError.mock.calls[0][1]).toBe(
|
|
121
|
-
expect(DdRum.addError.mock.calls[0][2]).toBe(
|
|
174
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe('Something bad happened');
|
|
175
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe('SOURCE');
|
|
176
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe(
|
|
177
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1'
|
|
178
|
+
);
|
|
179
|
+
const attributes = DdRum.addError.mock.calls[0][3];
|
|
180
|
+
expect(attributes['_dd.error.raw']).toStrictEqual(error);
|
|
181
|
+
expect(attributes['_dd.error.is_crash']).toStrictEqual(is_fatal);
|
|
182
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('M intercept and send a RUM event W onGlobalError() {with stack}', async () => {
|
|
186
|
+
// GIVEN
|
|
187
|
+
DdRumErrorTracking.startTracking();
|
|
188
|
+
const is_fatal = Math.random() < 0.5;
|
|
189
|
+
const error = {
|
|
190
|
+
stack: [
|
|
191
|
+
'doSomething() at ./path/to/file.js:67:3',
|
|
192
|
+
'nestedCall() at ./path/to/file.js:1064:9',
|
|
193
|
+
'root() at ./path/to/index.js:10:1'
|
|
194
|
+
],
|
|
195
|
+
message: 'Something bad happened'
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// WHEN
|
|
199
|
+
DdRumErrorTracking.onGlobalError(error, is_fatal);
|
|
200
|
+
await flushPromises();
|
|
201
|
+
|
|
202
|
+
// THEN
|
|
203
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
204
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe('Something bad happened');
|
|
205
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe('SOURCE');
|
|
206
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe(
|
|
207
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1'
|
|
208
|
+
);
|
|
209
|
+
const attributes = DdRum.addError.mock.calls[0][3];
|
|
210
|
+
expect(attributes['_dd.error.raw']).toStrictEqual(error);
|
|
211
|
+
expect(attributes['_dd.error.is_crash']).toStrictEqual(is_fatal);
|
|
212
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('M intercept and send a RUM event W onGlobalError() {with stacktrace}', async () => {
|
|
216
|
+
// GIVEN
|
|
217
|
+
DdRumErrorTracking.startTracking();
|
|
218
|
+
const is_fatal = Math.random() < 0.5;
|
|
219
|
+
const error = {
|
|
220
|
+
stacktrace: [
|
|
221
|
+
'doSomething() at ./path/to/file.js:67:3',
|
|
222
|
+
'nestedCall() at ./path/to/file.js:1064:9',
|
|
223
|
+
'root() at ./path/to/index.js:10:1'
|
|
224
|
+
],
|
|
225
|
+
message: 'Something bad happened'
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// WHEN
|
|
229
|
+
DdRumErrorTracking.onGlobalError(error, is_fatal);
|
|
230
|
+
await flushPromises();
|
|
231
|
+
|
|
232
|
+
// THEN
|
|
233
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
234
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe('Something bad happened');
|
|
235
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe('SOURCE');
|
|
236
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe(
|
|
237
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1'
|
|
238
|
+
);
|
|
122
239
|
const attributes = DdRum.addError.mock.calls[0][3];
|
|
123
|
-
expect(attributes[
|
|
124
|
-
expect(attributes[
|
|
240
|
+
expect(attributes['_dd.error.raw']).toStrictEqual(error);
|
|
241
|
+
expect(attributes['_dd.error.is_crash']).toStrictEqual(is_fatal);
|
|
125
242
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
126
|
-
})
|
|
243
|
+
});
|
|
127
244
|
|
|
128
245
|
it('M not report error in console handler W onGlobalError() {with console reporting handler}', async () => {
|
|
129
246
|
// GIVEN
|
|
130
|
-
const consoleReportingErrorHandler = jest.fn((error, isFatal)=> {
|
|
247
|
+
const consoleReportingErrorHandler = jest.fn((error, isFatal) => {
|
|
131
248
|
console.error(error.message);
|
|
132
249
|
baseErrorHandler(error, isFatal);
|
|
133
250
|
});
|
|
@@ -135,8 +252,12 @@ it('M not report error in console handler W onGlobalError() {with console report
|
|
|
135
252
|
DdRumErrorTracking.startTracking();
|
|
136
253
|
const is_fatal = Math.random() < 0.5;
|
|
137
254
|
const error = {
|
|
138
|
-
|
|
139
|
-
|
|
255
|
+
componentStack: [
|
|
256
|
+
'doSomething() at ./path/to/file.js:67:3',
|
|
257
|
+
'nestedCall() at ./path/to/file.js:1064:9',
|
|
258
|
+
'root() at ./path/to/index.js:10:1'
|
|
259
|
+
],
|
|
260
|
+
message: 'Something bad happened'
|
|
140
261
|
};
|
|
141
262
|
|
|
142
263
|
// WHEN
|
|
@@ -145,25 +266,27 @@ it('M not report error in console handler W onGlobalError() {with console report
|
|
|
145
266
|
|
|
146
267
|
// THEN
|
|
147
268
|
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
148
|
-
expect(DdRum.addError.mock.calls[0][0]).toBe(
|
|
149
|
-
expect(DdRum.addError.mock.calls[0][1]).toBe(
|
|
150
|
-
expect(DdRum.addError.mock.calls[0][2]).toBe(
|
|
269
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe('Something bad happened');
|
|
270
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe('SOURCE');
|
|
271
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe(
|
|
272
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1'
|
|
273
|
+
);
|
|
151
274
|
const attributes = DdRum.addError.mock.calls[0][3];
|
|
152
|
-
expect(attributes[
|
|
153
|
-
expect(attributes[
|
|
275
|
+
expect(attributes['_dd.error.raw']).toStrictEqual(error);
|
|
276
|
+
expect(attributes['_dd.error.is_crash']).toStrictEqual(is_fatal);
|
|
154
277
|
expect(consoleReportingErrorHandler).toBeCalledTimes(1);
|
|
155
278
|
expect(baseConsoleErrorCalled).toStrictEqual(false);
|
|
156
|
-
})
|
|
279
|
+
});
|
|
157
280
|
|
|
158
281
|
it('M intercept and send a RUM event W onConsole() {Error with source file info}', async () => {
|
|
159
282
|
// GIVEN
|
|
160
283
|
DdRumErrorTracking.startTracking();
|
|
161
|
-
const message=
|
|
284
|
+
const message = 'Oops I did it again!';
|
|
162
285
|
const error = {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
286
|
+
sourceURL: './path/to/file.js',
|
|
287
|
+
line: 1038,
|
|
288
|
+
column: 57,
|
|
289
|
+
message: 'Something bad happened'
|
|
167
290
|
};
|
|
168
291
|
|
|
169
292
|
// WHEN
|
|
@@ -172,20 +295,28 @@ it('M intercept and send a RUM event W onConsole() {Error with source file info}
|
|
|
172
295
|
|
|
173
296
|
// THEN
|
|
174
297
|
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
175
|
-
expect(DdRum.addError.mock.calls[0][0]).toBe(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
expect(DdRum.addError.mock.calls[0][
|
|
298
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe(
|
|
299
|
+
'Oops I did it again! Something bad happened'
|
|
300
|
+
);
|
|
301
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe('CONSOLE');
|
|
302
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe(
|
|
303
|
+
'at ./path/to/file.js:1038:57'
|
|
304
|
+
);
|
|
305
|
+
expect(DdRum.addError.mock.calls[0][3]).toBeUndefined();
|
|
179
306
|
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
180
|
-
})
|
|
307
|
+
});
|
|
181
308
|
|
|
182
309
|
it('M intercept and send a RUM event W onConsole() {Error with component stack}', async () => {
|
|
183
310
|
// GIVEN
|
|
184
311
|
DdRumErrorTracking.startTracking();
|
|
185
|
-
const message=
|
|
312
|
+
const message = 'Oops I did it again!';
|
|
186
313
|
const error = {
|
|
187
|
-
|
|
188
|
-
|
|
314
|
+
componentStack: [
|
|
315
|
+
'doSomething() at ./path/to/file.js:67:3',
|
|
316
|
+
'nestedCall() at ./path/to/file.js:1064:9',
|
|
317
|
+
'root() at ./path/to/index.js:10:1'
|
|
318
|
+
],
|
|
319
|
+
message: 'Something bad happened'
|
|
189
320
|
};
|
|
190
321
|
|
|
191
322
|
// WHEN
|
|
@@ -194,17 +325,21 @@ it('M intercept and send a RUM event W onConsole() {Error with component stack}'
|
|
|
194
325
|
|
|
195
326
|
// THEN
|
|
196
327
|
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
197
|
-
expect(DdRum.addError.mock.calls[0][0]).toBe(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
expect(DdRum.addError.mock.calls[0][
|
|
328
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe(
|
|
329
|
+
'Oops I did it again! Something bad happened'
|
|
330
|
+
);
|
|
331
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe('CONSOLE');
|
|
332
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe(
|
|
333
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1'
|
|
334
|
+
);
|
|
335
|
+
expect(DdRum.addError.mock.calls[0][3]).toBeUndefined();
|
|
201
336
|
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
202
|
-
})
|
|
337
|
+
});
|
|
203
338
|
|
|
204
339
|
it('M intercept and send a RUM event W onConsole() {message only}', async () => {
|
|
205
340
|
// GIVEN
|
|
206
341
|
DdRumErrorTracking.startTracking();
|
|
207
|
-
const message=
|
|
342
|
+
const message = 'Something bad happened';
|
|
208
343
|
|
|
209
344
|
// WHEN
|
|
210
345
|
DdRumErrorTracking.onConsoleError(message);
|
|
@@ -213,8 +348,40 @@ it('M intercept and send a RUM event W onConsole() {message only}', async () =>
|
|
|
213
348
|
// THEN
|
|
214
349
|
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
215
350
|
expect(DdRum.addError.mock.calls[0][0]).toBe(message);
|
|
216
|
-
expect(DdRum.addError.mock.calls[0][1]).toBe(
|
|
217
|
-
expect(DdRum.addError.mock.calls[0][2]).toBe(
|
|
218
|
-
expect(DdRum.addError.mock.calls[0][3]).toBeUndefined()
|
|
351
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe('CONSOLE');
|
|
352
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe('');
|
|
353
|
+
expect(DdRum.addError.mock.calls[0][3]).toBeUndefined();
|
|
219
354
|
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
220
|
-
})
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
describe.each([
|
|
358
|
+
[undefined],
|
|
359
|
+
[null],
|
|
360
|
+
[true],
|
|
361
|
+
[1],
|
|
362
|
+
['message'],
|
|
363
|
+
[() => {}],
|
|
364
|
+
[{}],
|
|
365
|
+
[['a']]
|
|
366
|
+
])('console calls with different message types', message => {
|
|
367
|
+
it(`M intercept and send a RUM event W onConsole() { message has ${typeof message} type }`, async () => {
|
|
368
|
+
// GIVEN
|
|
369
|
+
DdRumErrorTracking.startTracking();
|
|
370
|
+
|
|
371
|
+
// WHEN
|
|
372
|
+
DdRumErrorTracking.onConsoleError(message);
|
|
373
|
+
await flushPromises();
|
|
374
|
+
|
|
375
|
+
// THEN
|
|
376
|
+
expect(DdRum.addError.mock.calls.length).toBe(1);
|
|
377
|
+
expect(DdRum.addError.mock.calls[0][0]).toBe(
|
|
378
|
+
message === undefined || message === null
|
|
379
|
+
? 'Unknown Error'
|
|
380
|
+
: String(message)
|
|
381
|
+
);
|
|
382
|
+
expect(DdRum.addError.mock.calls[0][1]).toBe('CONSOLE');
|
|
383
|
+
expect(DdRum.addError.mock.calls[0][2]).toBe('');
|
|
384
|
+
expect(DdRum.addError.mock.calls[0][3]).toBeUndefined();
|
|
385
|
+
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
386
|
+
});
|
|
387
|
+
});
|