-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathassembly.spec.ts
More file actions
675 lines (576 loc) · 23 KB
/
assembly.spec.ts
File metadata and controls
675 lines (576 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
import type { ClocksState, RelativeTime, TimeStamp } from '@datadog/browser-core'
import {
ErrorSource,
HookNames,
ONE_MINUTE,
display,
relativeToClocks,
startGlobalContext,
} from '@datadog/browser-core'
import type { Clock } from '@datadog/browser-core/test'
import { registerCleanupTask, mockClock } from '@datadog/browser-core/test'
import {
createRumSessionManagerMock,
createRawRumEvent,
mockRumConfiguration,
mockViewHistory,
noopRecorderApi,
} from '../../test'
import type { RumEventDomainContext } from '../domainContext.types'
import type { RawRumEvent } from '../rawRumEvent.types'
import { RumEventType } from '../rawRumEvent.types'
import type { RumErrorEvent, RumEvent, RumResourceEvent } from '../rumEvent.types'
import { startRumAssembly } from './assembly'
import type { RawRumEventCollectedData } from './lifeCycle'
import { LifeCycle, LifeCycleEventType } from './lifeCycle'
import type { RumConfiguration } from './configuration'
import type { ViewHistory } from './contexts/viewHistory'
import type { RumSessionManager } from './rumSessionManager'
import { startSessionContext } from './contexts/sessionContext'
import { createHooks } from './hooks'
describe('rum assembly', () => {
describe('beforeSend', () => {
describe('fields modification', () => {
describe('modifiable fields', () => {
it('should allow modification', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => (event.view.url = 'modified'),
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.LONG_TASK, { view: { url: '/path?foo=bar' } }),
})
expect(serverRumEvents[0].view.url).toBe('modified')
})
it('should allow addition', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => (event.view.name = 'added'),
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.LONG_TASK, { view: { url: '/path?foo=bar' } }),
})
expect(serverRumEvents[0].view.name).toBe('added')
})
it('should allow modification of view.performance.lcp.resource_url', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => (event.view.performance.lcp.resource_url = 'modified_url'),
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW, {
view: { performance: { lcp: { resource_url: 'original_url' } } },
}),
})
expect((serverRumEvents[0].view as any).performance.lcp.resource_url).toBe('modified_url')
})
})
describe('context field', () => {
it('should allow modification on context field for events other than views', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => {
event.context.foo = 'bar'
},
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.LONG_TASK),
})
expect(serverRumEvents[0].context!.foo).toBe('bar')
})
it('should allow replacing the context field for events other than views', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => {
event.context.foo = 'bar'
},
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.LONG_TASK),
})
expect(serverRumEvents[0].context!.foo).toBe('bar')
})
it('should empty the context field if set to null', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => {
event.context = null
},
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.LONG_TASK, { context: { foo: 'bar' } }),
})
expect(serverRumEvents[0].context).toBeUndefined()
})
it('should empty the context field if set to undefined', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => {
event.context = undefined
},
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.LONG_TASK, { context: { foo: 'bar' } }),
})
expect(serverRumEvents[0].context).toBeUndefined()
})
it('should empty the context field if deleted', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => {
delete event.context
},
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.LONG_TASK, { context: { foo: 'bar' } }),
})
expect(serverRumEvents[0].context).toBeUndefined()
})
it('should define the context field even if the global context is empty', () => {
const { lifeCycle } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => {
expect(event.context).toEqual({})
},
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.LONG_TASK),
})
})
it('should accept modification on context field for view events', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => {
event.context.foo = 'bar'
},
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
})
expect(serverRumEvents[0].context).toEqual({ foo: 'bar' })
})
it('should reject replacing the context field to non-object', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => {
event.context = 1
},
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.LONG_TASK, { context: { foo: 'bar' } }),
})
expect(serverRumEvents[0].context!.foo).toBe('bar')
})
})
describe('allowed customer provided field', () => {
it('should allow modification of the error fingerprint', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => (event.error.fingerprint = 'my_fingerprint'),
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.ERROR),
})
expect((serverRumEvents[0] as RumErrorEvent).error.fingerprint).toBe('my_fingerprint')
})
})
describe('field resource.graphql on Resource events', () => {
it('should allow modification of resource.graphql.variables property', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => {
if (event.resource!.graphql) {
event.resource!.graphql.variables = '{"modified":"value"}'
}
},
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.RESOURCE, {
resource: {
graphql: {
operationType: 'query',
variables: '{"original":"value"}',
},
},
}),
})
expect((serverRumEvents[0] as RumResourceEvent).resource.graphql!.variables).toBe('{"modified":"value"}')
})
})
it('should reject modification of field not sensitive, context or customer provided', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event: RumEvent) => ((event.view as any).id = 'modified'),
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.LONG_TASK, {
view: { id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' },
}),
})
expect(serverRumEvents[0].view.id).toBe('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee')
})
it('should not allow to add a sensitive field on the wrong event type', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => {
event.error = { message: 'added' }
},
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
})
expect((serverRumEvents[0] as any).error?.message).toBeUndefined()
})
})
describe('events dismission', () => {
it('should allow dismissing events other than views', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: () => false,
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.ACTION, {
view: { id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' },
}),
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.ERROR, {
view: { id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' },
}),
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.LONG_TASK, {
view: { id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' },
}),
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.RESOURCE, {
view: { id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' },
}),
})
expect(serverRumEvents.length).toBe(0)
})
it('should not allow dismissing view events', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: () => false,
},
})
const displaySpy = spyOn(display, 'warn')
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW, {
view: { id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' },
}),
})
expect(serverRumEvents[0].view.id).toBe('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee')
expect(displaySpy).toHaveBeenCalledWith("Can't dismiss view or view_update events using beforeSend!")
})
})
it('should not dismiss when true is returned', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: () => true,
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.ACTION, {
view: { id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' },
}),
})
expect(serverRumEvents.length).toBe(1)
})
it('should not dismiss when undefined is returned', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: () => undefined,
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.ACTION, {
view: { id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' },
}),
})
expect(serverRumEvents.length).toBe(1)
})
})
describe('service and version', () => {
const extraConfigurationOptions = { service: 'default-service', version: 'default-version' }
Object.values(RumEventType).forEach((eventType) => {
it(`should be modifiable for ${eventType}`, () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
...extraConfigurationOptions,
beforeSend: (event) => {
event.service = 'bar'
event.version = '0.2.0'
return true
},
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(eventType),
})
expect((serverRumEvents[0] as RumResourceEvent).service).toBe('bar')
expect((serverRumEvents[0] as RumResourceEvent).version).toBe('0.2.0')
})
})
it('should be added to the event as ddtags', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: extraConfigurationOptions,
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
})
expect(serverRumEvents[0].ddtags).toEqual('sdk_version:test,service:default-service,version:default-version')
})
})
describe('assemble hook', () => {
it('should add and override common properties', () => {
const { lifeCycle, hooks, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: { service: 'default-service', version: 'default-version' },
})
hooks.register(HookNames.Assemble, ({ eventType }) => ({
type: eventType,
service: 'new service',
version: 'new version',
view: { id: 'new view id', url: '' },
}))
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.ACTION),
})
expect(serverRumEvents[0].service).toEqual('new service')
expect(serverRumEvents[0].version).toEqual('new version')
expect(serverRumEvents[0].view.id).toEqual('new view id')
})
it('should not override customer context', () => {
const { lifeCycle, hooks, serverRumEvents } = setupAssemblyTestWithDefaults()
hooks.register(HookNames.Assemble, ({ eventType }) => ({
type: eventType,
context: { foo: 'bar' },
}))
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.ACTION, { context: { foo: 'customer context' } }),
})
expect(serverRumEvents[0].context).toEqual({ foo: 'customer context' })
})
})
describe('event generation condition', () => {
it('when tracked, it should generate event', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults()
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
})
expect(serverRumEvents.length).toBe(1)
})
it('when not tracked, it should not generate event', () => {
const sessionManager = createRumSessionManagerMock().setNotTracked()
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({ sessionManager })
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
})
expect(serverRumEvents.length).toBe(0)
})
it('should get session state from event start', () => {
const sessionManager = createRumSessionManagerMock()
spyOn(sessionManager, 'findTrackedSession').and.callThrough()
const { lifeCycle } = setupAssemblyTestWithDefaults({ sessionManager })
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.ACTION),
startClocks: relativeToClocks(123 as RelativeTime),
})
expect(sessionManager.findTrackedSession).toHaveBeenCalledWith(123 as RelativeTime)
})
})
;[
{
eventType: RumEventType.ERROR,
message: 'Reached max number of errors by minute: 1',
},
{
eventType: RumEventType.ACTION,
message: 'Reached max number of actions by minute: 1',
},
{
eventType: RumEventType.VITAL,
message: 'Reached max number of vitals by minute: 1',
},
].forEach(({ eventType, message }) => {
describe(`${eventType} events limitation`, () => {
it(`stops sending ${eventType} events when reaching the limit`, () => {
const { lifeCycle, serverRumEvents, reportErrorSpy } = setupAssemblyTestWithDefaults({
eventRateLimit: 1,
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(eventType, { date: 100 as TimeStamp }),
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(eventType, { date: 200 as TimeStamp }),
})
expect(serverRumEvents.length).toBe(1)
expect(serverRumEvents[0].date).toBe(100)
expect(reportErrorSpy).toHaveBeenCalledTimes(1)
expect(reportErrorSpy.calls.argsFor(0)[0]).toEqual(
jasmine.objectContaining({
message,
source: ErrorSource.AGENT,
})
)
})
it(`does not take discarded ${eventType} events into account`, () => {
const { lifeCycle, serverRumEvents, reportErrorSpy } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => {
if (event.type === eventType && event.date === 100) {
return false
}
},
},
eventRateLimit: 1,
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(eventType, { date: 100 as TimeStamp }),
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(eventType, { date: 100 as TimeStamp }),
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(eventType, { date: 100 as TimeStamp }),
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(eventType, { date: 200 as TimeStamp }),
})
expect(serverRumEvents.length).toBe(1)
expect(serverRumEvents[0].date).toBe(200)
expect(reportErrorSpy).not.toHaveBeenCalled()
})
describe('when clock ticks with one minute', () => {
let clock: Clock
beforeEach(() => {
clock = mockClock()
})
it(`allows to send new ${eventType} events after a minute`, () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
eventRateLimit: 1,
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(eventType, { date: 100 as TimeStamp }),
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(eventType, { date: 200 as TimeStamp }),
})
clock.tick(ONE_MINUTE)
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(eventType, { date: 300 as TimeStamp }),
})
expect(serverRumEvents.length).toBe(2)
expect(serverRumEvents[0].date).toBe(100)
expect(serverRumEvents[1].date).toBe(300)
})
})
})
})
describe('view_update events', () => {
it('should not allow dismissing view_update events', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: () => false,
},
})
const displaySpy = spyOn(display, 'warn')
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW_UPDATE, {
view: { id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' },
}),
})
expect(serverRumEvents.length).toBe(1)
expect(displaySpy).toHaveBeenCalledWith("Can't dismiss view or view_update events using beforeSend!")
})
it('should allow modification of view_update events via beforeSend', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: {
beforeSend: (event) => {
event.view.name = 'modified name'
},
},
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW_UPDATE),
})
expect(serverRumEvents[0].view.name).toBe('modified name')
})
it('should not rate-limit view_update events', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
eventRateLimit: 1,
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW_UPDATE, { date: 100 as TimeStamp }),
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW_UPDATE, { date: 200 as TimeStamp }),
})
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW_UPDATE, { date: 300 as TimeStamp }),
})
expect(serverRumEvents.length).toBe(3)
})
})
})
function notifyRawRumEvent<E extends RawRumEvent>(
lifeCycle: LifeCycle,
partialData: Omit<RawRumEventCollectedData<E>, 'startClocks' | 'domainContext'> &
Partial<Pick<RawRumEventCollectedData<E>, 'startClocks' | 'domainContext'>>
) {
const fullData = {
startClocks: relativeToClocks(0 as RelativeTime),
domainContext: {} as RumEventDomainContext,
...partialData,
}
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, fullData)
}
interface AssemblyTestParams {
partialConfiguration?: Partial<RumConfiguration>
sessionManager?: RumSessionManager
ciVisibilityContext?: Record<string, string>
findView?: ViewHistory['findView']
eventRateLimit?: number
}
function setupAssemblyTestWithDefaults({
partialConfiguration,
sessionManager,
findView = () => ({ id: '7890', name: 'view name', startClocks: {} as ClocksState, sessionIsActive: false }),
eventRateLimit,
}: AssemblyTestParams = {}) {
const lifeCycle = new LifeCycle()
const hooks = createHooks()
const reportErrorSpy = jasmine.createSpy('reportError')
const rumSessionManager = sessionManager ?? createRumSessionManagerMock().setId('1234')
const serverRumEvents: RumEvent[] = []
const subscription = lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, (serverRumEvent) => {
serverRumEvents.push(serverRumEvent)
})
const recorderApi = noopRecorderApi
const viewHistory = { ...mockViewHistory(), findView: () => findView() }
startGlobalContext(hooks, mockRumConfiguration(), 'rum', true)
startSessionContext(hooks, rumSessionManager, recorderApi, viewHistory)
startRumAssembly(mockRumConfiguration(partialConfiguration), lifeCycle, hooks, reportErrorSpy, eventRateLimit)
registerCleanupTask(() => {
subscription.unsubscribe()
})
return { lifeCycle, hooks, reportErrorSpy, serverRumEvents, recorderApi }
}