@openobserve/browser-core 0.3.2 → 0.3.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.
Files changed (83) hide show
  1. package/cjs/boot/init.js +1 -1
  2. package/cjs/domain/configuration/endpointBuilder.js +1 -1
  3. package/cjs/domain/tags.js +1 -1
  4. package/cjs/domain/telemetry/telemetry.js +1 -1
  5. package/cjs/domain/telemetry/telemetryEvent.types.d.ts +1 -1
  6. package/esm/boot/init.js +1 -1
  7. package/esm/domain/configuration/endpointBuilder.js +1 -1
  8. package/esm/domain/tags.js +1 -1
  9. package/esm/domain/telemetry/telemetry.js +1 -1
  10. package/esm/domain/telemetry/telemetryEvent.types.d.ts +1 -1
  11. package/package.json +2 -2
  12. package/src/domain/telemetry/telemetryEvent.types.ts +1 -1
  13. package/src/boot/displayAlreadyInitializedError.spec.ts +0 -18
  14. package/src/boot/init.spec.ts +0 -50
  15. package/src/browser/addEventListener.spec.ts +0 -141
  16. package/src/browser/cookie.spec.ts +0 -53
  17. package/src/browser/fetchObservable.spec.ts +0 -334
  18. package/src/browser/pageMayExitObservable.spec.ts +0 -56
  19. package/src/browser/xhrObservable.spec.ts +0 -405
  20. package/src/domain/allowedTrackingOrigins.spec.ts +0 -210
  21. package/src/domain/bufferedData.spec.ts +0 -34
  22. package/src/domain/configuration/configuration.spec.ts +0 -236
  23. package/src/domain/configuration/endpointBuilder.spec.ts +0 -173
  24. package/src/domain/configuration/transportConfiguration.spec.ts +0 -130
  25. package/src/domain/connectivity/connectivity.spec.ts +0 -50
  26. package/src/domain/console/consoleObservable.spec.ts +0 -151
  27. package/src/domain/context/contextManager.spec.ts +0 -152
  28. package/src/domain/context/contextUtils.spec.ts +0 -26
  29. package/src/domain/context/storeContextManager.spec.ts +0 -103
  30. package/src/domain/contexts/accountContext.spec.ts +0 -99
  31. package/src/domain/contexts/globalContext.spec.ts +0 -88
  32. package/src/domain/contexts/userContext.spec.ts +0 -156
  33. package/src/domain/error/error.spec.ts +0 -294
  34. package/src/domain/error/trackRuntimeError.spec.ts +0 -343
  35. package/src/domain/eventRateLimiter/createEventRateLimiter.spec.ts +0 -119
  36. package/src/domain/extension/extensionUtils.spec.ts +0 -47
  37. package/src/domain/report/reportObservable.spec.ts +0 -71
  38. package/src/domain/session/oldCookiesMigration.spec.ts +0 -76
  39. package/src/domain/session/sessionManager.spec.ts +0 -684
  40. package/src/domain/session/sessionState.spec.ts +0 -88
  41. package/src/domain/session/sessionStore.spec.ts +0 -647
  42. package/src/domain/session/sessionStoreOperations.spec.ts +0 -234
  43. package/src/domain/session/storeStrategies/sessionInCookie.spec.ts +0 -228
  44. package/src/domain/session/storeStrategies/sessionInLocalStorage.spec.ts +0 -75
  45. package/src/domain/synthetics/syntheticsWorkerValues.spec.ts +0 -82
  46. package/src/domain/tags.spec.ts +0 -74
  47. package/src/domain/telemetry/telemetry.spec.ts +0 -494
  48. package/src/domain/trackingConsent.spec.ts +0 -44
  49. package/src/tools/abstractHooks.spec.ts +0 -76
  50. package/src/tools/abstractLifeCycle.spec.ts +0 -46
  51. package/src/tools/boundedBuffer.spec.ts +0 -40
  52. package/src/tools/catchUserErrors.spec.ts +0 -20
  53. package/src/tools/encoder.spec.ts +0 -112
  54. package/src/tools/experimentalFeatures.spec.ts +0 -60
  55. package/src/tools/getZoneJsOriginalValue.spec.ts +0 -36
  56. package/src/tools/instrumentMethod.spec.ts +0 -381
  57. package/src/tools/matchOption.spec.ts +0 -41
  58. package/src/tools/mergeInto.spec.ts +0 -198
  59. package/src/tools/monitor.spec.ts +0 -172
  60. package/src/tools/observable.spec.ts +0 -259
  61. package/src/tools/queueMicrotask.spec.ts +0 -24
  62. package/src/tools/readBytesFromStream.spec.ts +0 -62
  63. package/src/tools/requestIdleCallback.spec.ts +0 -65
  64. package/src/tools/serialisation/jsonStringify.spec.ts +0 -76
  65. package/src/tools/serialisation/sanitize.spec.ts +0 -284
  66. package/src/tools/stackTrace/capturedExceptions.specHelper.ts +0 -316
  67. package/src/tools/stackTrace/computeStackTrace.spec.ts +0 -1007
  68. package/src/tools/stackTrace/handlingStack.spec.ts +0 -20
  69. package/src/tools/taskQueue.spec.ts +0 -60
  70. package/src/tools/timer.spec.ts +0 -76
  71. package/src/tools/utils/browserDetection.spec.ts +0 -120
  72. package/src/tools/utils/byteUtils.spec.ts +0 -29
  73. package/src/tools/utils/functionUtils.spec.ts +0 -229
  74. package/src/tools/utils/numberUtils.spec.ts +0 -27
  75. package/src/tools/utils/stringUtils.spec.ts +0 -74
  76. package/src/tools/utils/typeUtils.spec.ts +0 -25
  77. package/src/tools/utils/urlPolyfill.spec.ts +0 -55
  78. package/src/tools/valueHistory.spec.ts +0 -180
  79. package/src/transport/batch.spec.ts +0 -261
  80. package/src/transport/eventBridge.spec.ts +0 -90
  81. package/src/transport/flushController.spec.ts +0 -267
  82. package/src/transport/httpRequest.spec.ts +0 -400
  83. package/src/transport/sendWithRetryStrategy.spec.ts +0 -393
@@ -1,405 +0,0 @@
1
- import type { Configuration } from '../domain/configuration'
2
- import { withXhr, mockXhr } from '../../test'
3
- import type { Subscription } from '../tools/observable'
4
- import type { XhrCompleteContext, XhrContext } from './xhrObservable'
5
- import { initXhrObservable } from './xhrObservable'
6
-
7
- describe('xhr observable', () => {
8
- let requestsTrackingSubscription: Subscription
9
- let contextEditionSubscription: Subscription | undefined
10
- let requests: XhrCompleteContext[]
11
- let originalMockXhrSend: XMLHttpRequest['send']
12
- let configuration: Configuration
13
-
14
- beforeEach(() => {
15
- mockXhr()
16
- configuration = {} as Configuration
17
- // eslint-disable-next-line @typescript-eslint/unbound-method
18
- originalMockXhrSend = XMLHttpRequest.prototype.send
19
-
20
- requests = []
21
- startTrackingRequests()
22
- })
23
-
24
- afterEach(() => {
25
- requestsTrackingSubscription.unsubscribe()
26
- contextEditionSubscription?.unsubscribe()
27
- })
28
-
29
- function startTrackingRequests() {
30
- requestsTrackingSubscription = initXhrObservable(configuration).subscribe((context) => {
31
- if (context.state === 'complete') {
32
- requests.push(context)
33
- }
34
- })
35
- }
36
-
37
- it('should track successful request', (done) => {
38
- withXhr({
39
- setup(xhr) {
40
- xhr.open('GET', '/ok')
41
- xhr.send()
42
- xhr.complete(200, 'ok')
43
- },
44
- onComplete() {
45
- const request = requests[0]
46
- expect(request.method).toBe('GET')
47
- expect(request.url).toContain('/ok')
48
- expect(request.status).toBe(200)
49
- expect(request.isAborted).toBe(false)
50
- expect(request.duration).toEqual(jasmine.any(Number))
51
- expect(request.handlingStack).toBeDefined()
52
- done()
53
- },
54
- })
55
- })
56
-
57
- it('should sanitize request method', (done) => {
58
- withXhr({
59
- setup(xhr) {
60
- xhr.open('get', '/ok')
61
- xhr.send()
62
- xhr.complete(200, 'ok')
63
- },
64
- onComplete() {
65
- const request = requests[0]
66
- expect(request.method).toBe('GET')
67
- expect(request.handlingStack).toBeDefined()
68
- done()
69
- },
70
- })
71
- })
72
-
73
- it('should track client error', (done) => {
74
- withXhr({
75
- setup(xhr) {
76
- xhr.open('GET', '/expected-404')
77
- xhr.send()
78
- xhr.complete(404, 'NOT FOUND')
79
- },
80
- onComplete() {
81
- const request = requests[0]
82
- expect(request.method).toBe('GET')
83
- expect(request.url).toContain('/expected-404')
84
- expect(request.status).toBe(404)
85
- expect(request.isAborted).toBe(false)
86
- expect(request.duration).toEqual(jasmine.any(Number))
87
- expect(request.handlingStack).toBeDefined()
88
- done()
89
- },
90
- })
91
- })
92
-
93
- it('should track server error', (done) => {
94
- withXhr({
95
- setup(xhr) {
96
- xhr.open('GET', '/throw')
97
- xhr.send()
98
- xhr.complete(500, 'expected server error')
99
- },
100
- onComplete() {
101
- const request = requests[0]
102
- expect(request.method).toBe('GET')
103
- expect(request.url).toContain('/throw')
104
- expect(request.status).toBe(500)
105
- expect(request.isAborted).toBe(false)
106
- expect(request.duration).toEqual(jasmine.any(Number))
107
- expect(request.handlingStack).toBeDefined()
108
- done()
109
- },
110
- })
111
- })
112
-
113
- it('should track network error', (done) => {
114
- withXhr({
115
- setup(xhr) {
116
- xhr.open('GET', 'http://foo.bar/qux')
117
- xhr.send()
118
- xhr.complete(0, '')
119
- },
120
- onComplete() {
121
- const request = requests[0]
122
- expect(request.method).toBe('GET')
123
- expect(request.url).toBe('http://foo.bar/qux')
124
- expect(request.status).toBe(0)
125
- expect(request.isAborted).toBe(false)
126
- expect(request.duration).toEqual(jasmine.any(Number))
127
- expect(request.handlingStack).toBeDefined()
128
- done()
129
- },
130
- })
131
- })
132
-
133
- it('should track successful request aborted', (done) => {
134
- withXhr({
135
- setup(xhr) {
136
- xhr.onreadystatechange = () => {
137
- if (xhr.readyState === XMLHttpRequest.DONE) {
138
- xhr.abort()
139
- }
140
- }
141
- spyOn(xhr, 'onreadystatechange').and.callThrough()
142
- xhr.open('GET', '/ok')
143
- xhr.send()
144
- xhr.complete(200, 'ok')
145
- },
146
- onComplete(xhr) {
147
- const request = requests[0]
148
- expect(requests.length).toBe(1)
149
- expect(request.method).toBe('GET')
150
- expect(request.url).toContain('/ok')
151
- expect(request.status).toBe(200)
152
- expect(request.duration).toEqual(jasmine.any(Number))
153
- expect(request.isAborted).toBe(false)
154
- expect(xhr.status).toBe(0)
155
- expect(xhr.onreadystatechange).toHaveBeenCalledTimes(1)
156
- expect(request.handlingStack).toBeDefined()
157
- done()
158
- },
159
- })
160
- })
161
-
162
- it('should track aborted requests', (done) => {
163
- withXhr({
164
- setup(xhr) {
165
- xhr.open('GET', '/ok')
166
- xhr.send()
167
- xhr.abort()
168
- },
169
- onComplete(xhr) {
170
- const request = requests[0]
171
- expect(request.method).toBe('GET')
172
- expect(request.url).toContain('/ok')
173
- expect(request.status).toBe(0)
174
- expect(request.duration).toEqual(jasmine.any(Number))
175
- expect(request.isAborted).toBe(true)
176
- expect(xhr.status).toBe(0)
177
- expect(request.handlingStack).toBeDefined()
178
- done()
179
- },
180
- })
181
- })
182
-
183
- it('should track request with onreadystatechange overridden before open', (done) => {
184
- withXhr({
185
- setup(xhr) {
186
- xhr.onreadystatechange = jasmine.createSpy()
187
- xhr.open('GET', '/ok')
188
- xhr.send()
189
- xhr.complete(200, 'ok')
190
- },
191
- onComplete(xhr) {
192
- const request = requests[0]
193
- expect(request.method).toBe('GET')
194
- expect(request.url).toContain('/ok')
195
- expect(request.status).toBe(200)
196
- expect(request.isAborted).toBe(false)
197
- expect(request.duration).toEqual(jasmine.any(Number))
198
- expect(xhr.onreadystatechange).toHaveBeenCalled()
199
- expect(request.handlingStack).toBeDefined()
200
- done()
201
- },
202
- })
203
- })
204
-
205
- it('should track request with onreadystatechange overridden after open', (done) => {
206
- withXhr({
207
- setup(xhr) {
208
- xhr.open('GET', '/ok')
209
- xhr.send()
210
- xhr.onreadystatechange = jasmine.createSpy()
211
- xhr.complete(200, 'ok')
212
- },
213
- onComplete(xhr) {
214
- const request = requests[0]
215
- expect(request.method).toBe('GET')
216
- expect(request.url).toContain('/ok')
217
- expect(request.status).toBe(200)
218
- expect(request.isAborted).toBe(false)
219
- expect(request.duration).toEqual(jasmine.any(Number))
220
- expect(xhr.onreadystatechange).toHaveBeenCalled()
221
- expect(request.handlingStack).toBeDefined()
222
- done()
223
- },
224
- })
225
- })
226
-
227
- it('should allow to enhance the context', (done) => {
228
- type CustomContext = XhrContext & { foo: string }
229
- contextEditionSubscription = initXhrObservable(configuration).subscribe((rawContext) => {
230
- const context = rawContext as CustomContext
231
- if (context.state === 'start') {
232
- context.foo = 'bar'
233
- }
234
- })
235
- withXhr({
236
- setup(xhr) {
237
- xhr.open('GET', '/ok')
238
- xhr.send()
239
- xhr.complete(200)
240
- },
241
- onComplete() {
242
- const request = requests[0]
243
- expect((request as CustomContext).foo).toBe('bar')
244
- done()
245
- },
246
- })
247
- })
248
-
249
- it('should not break xhr opened before the instrumentation', (done) => {
250
- requestsTrackingSubscription.unsubscribe()
251
- withXhr({
252
- setup(xhr) {
253
- xhr.open('GET', '/ok')
254
- startTrackingRequests()
255
- xhr.send()
256
- xhr.complete(200)
257
- },
258
- onComplete() {
259
- expect(requests.length).toBe(0)
260
- done()
261
- },
262
- })
263
- })
264
-
265
- it('should track multiple requests with the same xhr instance', (done) => {
266
- let listeners: { [k: string]: Array<(event: Event) => void> }
267
- withXhr({
268
- setup(xhr) {
269
- const secondOnload = () => {
270
- xhr.removeEventListener('load', secondOnload)
271
- }
272
- const onLoad = () => {
273
- xhr.removeEventListener('load', onLoad)
274
- xhr.addEventListener('load', secondOnload)
275
- xhr.open('GET', '/ok?request=2')
276
- xhr.send()
277
- xhr.complete(400, 'ok')
278
- }
279
- xhr.onreadystatechange = jasmine.createSpy()
280
- xhr.addEventListener('load', onLoad)
281
- xhr.open('GET', '/ok?request=1')
282
- xhr.send()
283
- xhr.complete(200, 'ok')
284
- listeners = xhr.listeners
285
- },
286
- onComplete(xhr) {
287
- const firstRequest = requests[0]
288
- expect(firstRequest.method).toBe('GET')
289
- expect(firstRequest.url).toContain('/ok?request=1')
290
- expect(firstRequest.status).toBe(200)
291
- expect(firstRequest.isAborted).toBe(false)
292
- expect(firstRequest.duration).toEqual(jasmine.any(Number))
293
- expect(firstRequest.handlingStack).toBeDefined()
294
-
295
- const secondRequest = requests[1]
296
- expect(secondRequest.method).toBe('GET')
297
- expect(secondRequest.url).toContain('/ok?request=2')
298
- expect(secondRequest.status).toBe(400)
299
- expect(secondRequest.isAborted).toBe(false)
300
- expect(secondRequest.duration).toEqual(jasmine.any(Number))
301
- expect(secondRequest.handlingStack).toBeDefined()
302
-
303
- expect(xhr.onreadystatechange).toHaveBeenCalledTimes(2)
304
- expect(listeners.load.length).toBe(0)
305
- expect(listeners.loadend.length).toBe(0)
306
- done()
307
- },
308
- })
309
- })
310
-
311
- it('should track request to undefined url', (done) => {
312
- withXhr({
313
- setup(xhr) {
314
- xhr.open('GET', undefined)
315
- xhr.send()
316
- xhr.complete(404, 'NOT FOUND')
317
- },
318
- onComplete() {
319
- const request = requests[0]
320
- expect(request.method).toBe('GET')
321
- expect(request.url).toContain('/undefined')
322
- expect(request.status).toBe(404)
323
- done()
324
- },
325
- })
326
- })
327
-
328
- it('should track request to null url', (done) => {
329
- withXhr({
330
- setup(xhr) {
331
- xhr.open('GET', null)
332
- xhr.send()
333
- xhr.complete(404, 'NOT FOUND')
334
- },
335
- onComplete() {
336
- const request = requests[0]
337
- expect(request.method).toBe('GET')
338
- expect(request.url).toContain('/null')
339
- expect(request.status).toBe(404)
340
- done()
341
- },
342
- })
343
- })
344
-
345
- it('should track request to URL object', (done) => {
346
- withXhr({
347
- setup(xhr) {
348
- xhr.open('GET', new URL('http://example.com/path'))
349
- xhr.send()
350
- xhr.complete(200, 'ok')
351
- },
352
- onComplete() {
353
- const request = requests[0]
354
- expect(request.method).toBe('GET')
355
- expect(request.url).toBe('http://example.com/path')
356
- done()
357
- },
358
- })
359
- })
360
-
361
- describe('when unsubscribing', () => {
362
- it('should stop tracking requests', (done) => {
363
- requestsTrackingSubscription.unsubscribe()
364
-
365
- withXhr({
366
- setup(xhr) {
367
- xhr.open('GET', '/ok')
368
- xhr.send()
369
- xhr.complete(200)
370
- },
371
- onComplete() {
372
- expect(requests.length).toBe(0)
373
- done()
374
- },
375
- })
376
- })
377
-
378
- it('should restore original XMLHttpRequest methods', () => {
379
- requestsTrackingSubscription.unsubscribe()
380
-
381
- // eslint-disable-next-line @typescript-eslint/unbound-method
382
- expect(XMLHttpRequest.prototype.send).toBe(originalMockXhrSend)
383
- })
384
- })
385
-
386
- it('should track request with undefined or null methods', (done) => {
387
- withXhr({
388
- setup(xhr) {
389
- xhr.open(null, '/ok')
390
- xhr.send()
391
- xhr.onreadystatechange = jasmine.createSpy()
392
- xhr.complete(200, 'ok')
393
- xhr.open(undefined, '/ok')
394
- xhr.send()
395
- xhr.onreadystatechange = jasmine.createSpy()
396
- xhr.complete(200, 'ok')
397
- },
398
- onComplete() {
399
- expect(requests[0].method).toBe('NULL')
400
- expect(requests[1].method).toBe('UNDEFINED')
401
- done()
402
- },
403
- })
404
- })
405
- })
@@ -1,210 +0,0 @@
1
- import { STACK_WITH_INIT_IN_EXTENSION, STACK_WITH_INIT_IN_PAGE } from '../../test'
2
- import { display } from '../tools/display'
3
- import {
4
- isAllowedTrackingOrigins,
5
- ERROR_NOT_ALLOWED_TRACKING_ORIGIN,
6
- ERROR_DOES_NOT_HAVE_ALLOWED_TRACKING_ORIGIN,
7
- } from './allowedTrackingOrigins'
8
-
9
- const DEFAULT_CONFIG = {
10
- applicationId: 'xxx',
11
- clientToken: 'xxx',
12
- allowedTrackingOrigins: undefined as any,
13
- }
14
-
15
- describe('checkForAllowedTrackingOrigins', () => {
16
- let displayErrorSpy: jasmine.Spy
17
-
18
- beforeEach(() => {
19
- displayErrorSpy = spyOn(display, 'error')
20
- })
21
-
22
- it('should not warn if not in extension environment', () => {
23
- const result = isAllowedTrackingOrigins(DEFAULT_CONFIG, STACK_WITH_INIT_IN_PAGE, 'https://app.example.com')
24
- expect(displayErrorSpy).not.toHaveBeenCalled()
25
- expect(result).toBe(true)
26
- })
27
-
28
- describe('when configuration has allowedTrackingOrigins and origin is allowed', () => {
29
- it('should not warn if origin matches exactly', () => {
30
- const result = isAllowedTrackingOrigins(
31
- {
32
- ...DEFAULT_CONFIG,
33
- allowedTrackingOrigins: ['https://app.example.com'],
34
- },
35
- STACK_WITH_INIT_IN_PAGE,
36
- 'https://app.example.com'
37
- )
38
- expect(displayErrorSpy).not.toHaveBeenCalled()
39
- expect(result).toBe(true)
40
- })
41
-
42
- it('should not warn if origin matches regex pattern', () => {
43
- const result = isAllowedTrackingOrigins(
44
- {
45
- ...DEFAULT_CONFIG,
46
- allowedTrackingOrigins: [/^https:\/\/.*\.example\.com$/],
47
- },
48
- STACK_WITH_INIT_IN_PAGE,
49
- 'https://app.example.com'
50
- )
51
- expect(displayErrorSpy).not.toHaveBeenCalled()
52
- expect(result).toBe(true)
53
- })
54
-
55
- it('should not warn if origin matches predicate function', () => {
56
- const result = isAllowedTrackingOrigins(
57
- {
58
- ...DEFAULT_CONFIG,
59
- allowedTrackingOrigins: [(origin: string) => origin.includes('example.com')],
60
- },
61
- STACK_WITH_INIT_IN_PAGE,
62
- 'https://app.example.com'
63
- )
64
- expect(displayErrorSpy).not.toHaveBeenCalled()
65
- expect(result).toBe(true)
66
- })
67
-
68
- it('should handle multiple patterns', () => {
69
- const result = isAllowedTrackingOrigins(
70
- {
71
- ...DEFAULT_CONFIG,
72
- allowedTrackingOrigins: [
73
- 'https://exact-match.com',
74
- /^https:\/\/.*\.example\.com$/,
75
- (origin: string) => origin.startsWith('https://app.'),
76
- ],
77
- },
78
- STACK_WITH_INIT_IN_PAGE,
79
- 'https://app.example.com'
80
- )
81
- expect(displayErrorSpy).not.toHaveBeenCalled()
82
- expect(result).toBe(true)
83
- })
84
- })
85
-
86
- describe('when configuration has allowedTrackingOrigins but origin is not allowed in extension context', () => {
87
- it('should error when origin does not match any allowed pattern', () => {
88
- const result = isAllowedTrackingOrigins(
89
- {
90
- ...DEFAULT_CONFIG,
91
- allowedTrackingOrigins: ['https://different.com'],
92
- },
93
- STACK_WITH_INIT_IN_EXTENSION,
94
- 'https://example.com'
95
- )
96
- expect(displayErrorSpy).toHaveBeenCalledWith(ERROR_NOT_ALLOWED_TRACKING_ORIGIN)
97
- expect(result).toBe(false)
98
- })
99
-
100
- it('should error when origin does not match regex pattern', () => {
101
- const result = isAllowedTrackingOrigins(
102
- {
103
- ...DEFAULT_CONFIG,
104
- allowedTrackingOrigins: [/^https:\/\/specific-[a-z]+\.com$/],
105
- },
106
- STACK_WITH_INIT_IN_EXTENSION,
107
- 'https://example.com'
108
- )
109
- expect(displayErrorSpy).toHaveBeenCalledWith(ERROR_NOT_ALLOWED_TRACKING_ORIGIN)
110
- expect(result).toBe(false)
111
- })
112
-
113
- it('should error when origin does not match predicate function', () => {
114
- const result = isAllowedTrackingOrigins(
115
- {
116
- ...DEFAULT_CONFIG,
117
- allowedTrackingOrigins: [(origin: string) => origin.includes('specific-id')],
118
- },
119
- STACK_WITH_INIT_IN_EXTENSION,
120
- 'https://example.com'
121
- )
122
- expect(displayErrorSpy).toHaveBeenCalledWith(ERROR_NOT_ALLOWED_TRACKING_ORIGIN)
123
- expect(result).toBe(false)
124
- })
125
-
126
- it('should error when origin does not match any of multiple patterns', () => {
127
- const result = isAllowedTrackingOrigins(
128
- {
129
- ...DEFAULT_CONFIG,
130
- allowedTrackingOrigins: [
131
- 'https://specific.com',
132
- /^https:\/\/.*\.specific\.com$/,
133
- (origin: string) => origin.includes('specific-id'),
134
- ],
135
- },
136
- STACK_WITH_INIT_IN_EXTENSION,
137
- 'https://example.com'
138
- )
139
- expect(displayErrorSpy).toHaveBeenCalledWith(ERROR_NOT_ALLOWED_TRACKING_ORIGIN)
140
- expect(result).toBe(false)
141
- })
142
-
143
- it('should error when origin is a partial match', () => {
144
- const result = isAllowedTrackingOrigins(
145
- {
146
- ...DEFAULT_CONFIG,
147
- allowedTrackingOrigins: ['https://example.com'],
148
- },
149
- STACK_WITH_INIT_IN_EXTENSION,
150
- 'https://example.com.extra.com'
151
- )
152
- expect(displayErrorSpy).toHaveBeenCalledWith(ERROR_NOT_ALLOWED_TRACKING_ORIGIN)
153
- expect(result).toBe(false)
154
- })
155
-
156
- it('should not error when in extension and origin matches', () => {
157
- const result = isAllowedTrackingOrigins(
158
- {
159
- ...DEFAULT_CONFIG,
160
- allowedTrackingOrigins: [/^chrome-extension:\/\//],
161
- },
162
- STACK_WITH_INIT_IN_EXTENSION,
163
- 'chrome-extension://abcdefghijklmno'
164
- )
165
- expect(displayErrorSpy).not.toHaveBeenCalled()
166
- expect(result).toBe(true)
167
- })
168
- })
169
-
170
- describe('when configuration does not have allowedTrackingOrigins', () => {
171
- it('should log an error when in extension environment and allowedTrackingOrigins is undefined', () => {
172
- const result = isAllowedTrackingOrigins(
173
- {
174
- ...DEFAULT_CONFIG,
175
- allowedTrackingOrigins: undefined,
176
- },
177
- STACK_WITH_INIT_IN_EXTENSION,
178
- 'https://example.com'
179
- )
180
- expect(displayErrorSpy).toHaveBeenCalledWith(ERROR_DOES_NOT_HAVE_ALLOWED_TRACKING_ORIGIN)
181
- expect(result).toBe(false)
182
- })
183
-
184
- it('should error when in extension environment and allowedTrackingOrigins is an empty array', () => {
185
- const result = isAllowedTrackingOrigins(
186
- {
187
- ...DEFAULT_CONFIG,
188
- allowedTrackingOrigins: [],
189
- },
190
- STACK_WITH_INIT_IN_EXTENSION,
191
- 'https://example.com'
192
- )
193
- expect(displayErrorSpy).toHaveBeenCalledWith(ERROR_NOT_ALLOWED_TRACKING_ORIGIN)
194
- expect(result).toBe(false)
195
- })
196
-
197
- it('should not warn when not in extension environment and allowedTrackingOrigins is undefined', () => {
198
- const result = isAllowedTrackingOrigins(
199
- {
200
- ...DEFAULT_CONFIG,
201
- allowedTrackingOrigins: undefined,
202
- },
203
- STACK_WITH_INIT_IN_PAGE,
204
- 'https://example.com'
205
- )
206
- expect(displayErrorSpy).not.toHaveBeenCalled()
207
- expect(result).toBe(true)
208
- })
209
- })
210
- })
@@ -1,34 +0,0 @@
1
- import { registerCleanupTask } from '../../test'
2
- import { Observable } from '../tools/observable'
3
- import { clocksNow } from '../tools/utils/timeUtils'
4
- import { BufferedDataType, startBufferingData } from './bufferedData'
5
- import { ErrorHandling, ErrorSource, type RawError } from './error/error.types'
6
-
7
- describe('startBufferingData', () => {
8
- it('collects runtime errors', (done) => {
9
- const runtimeErrorObservable = new Observable<RawError>()
10
- const { observable, stop } = startBufferingData(() => runtimeErrorObservable)
11
- registerCleanupTask(stop)
12
-
13
- const rawError = {
14
- startClocks: clocksNow(),
15
- source: ErrorSource.SOURCE,
16
- type: 'Error',
17
- stack: 'Error: error!',
18
- handling: ErrorHandling.UNHANDLED,
19
- causes: undefined,
20
- fingerprint: undefined,
21
- message: 'error!',
22
- }
23
-
24
- runtimeErrorObservable.notify(rawError)
25
-
26
- observable.subscribe((data) => {
27
- expect(data).toEqual({
28
- type: BufferedDataType.RUNTIME_ERROR,
29
- error: rawError,
30
- })
31
- done()
32
- })
33
- })
34
- })