|
1 | 1 | import { apiMethods, asyncApiMethods } from '../../src/loaders/api/api-methods'
|
2 | 2 | import { checkAjaxEvents, checkJsErrors, checkMetrics, checkGenericEvents, checkPVT, checkRumBody, checkRumQuery, checkSessionTrace, checkSpa } from '../util/basic-checks'
|
3 |
| -import { testAjaxEventsRequest, testAjaxTimeSlicesRequest, testBlobTraceRequest, testCustomMetricsRequest, testErrorsRequest, testEventsRequest, testInsRequest, testInteractionEventsRequest, testMetricsRequest, testRumRequest, testTimingEventsRequest } from '../../tools/testing-server/utils/expect-tests' |
| 3 | +import { testAjaxEventsRequest, testAjaxTimeSlicesRequest, testBlobTraceRequest, testCustomMetricsRequest, testErrorsRequest, testEventsRequest, testInsRequest, testInteractionEventsRequest, testLogsRequest, testMetricsRequest, testRumRequest, testTimingEventsRequest } from '../../tools/testing-server/utils/expect-tests' |
| 4 | +import { rumFlags } from '../../tools/testing-server/constants' |
| 5 | +import { LOGGING_MODE } from '../../src/features/logging/constants' |
4 | 6 |
|
5 | 7 | describe('newrelic api', () => {
|
6 | 8 | afterEach(async () => {
|
@@ -49,6 +51,71 @@ describe('newrelic api', () => {
|
49 | 51 | expect(result).toEqual(true)
|
50 | 52 | })
|
51 | 53 |
|
| 54 | + it('should fire `newrelic` event after RUM call', async () => { |
| 55 | + const rumCapture = await browser.testHandle.createNetworkCaptures('bamServer', { test: testRumRequest }) |
| 56 | + |
| 57 | + await browser.testHandle.scheduleReply('bamServer', { |
| 58 | + test: testRumRequest, |
| 59 | + body: JSON.stringify(rumFlags({ log: LOGGING_MODE.INFO })) |
| 60 | + }) |
| 61 | + |
| 62 | + const [rumHarvests] = |
| 63 | + await Promise.all([ |
| 64 | + rumCapture.waitForResult({ timeout: 10000 }), |
| 65 | + browser.url(await browser.testHandle.assetURL('event-listener-newrelic.html')) |
| 66 | + .then(() => browser.waitForAgentLoad()) |
| 67 | + .then(() => browser.waitUntil( |
| 68 | + () => browser.execute(function () { |
| 69 | + return window?.newrelicEventTime |
| 70 | + }), |
| 71 | + { |
| 72 | + timeout: 10000, |
| 73 | + timeoutMsg: 'Timeout while waiting on `newrelic` event' |
| 74 | + } |
| 75 | + )) |
| 76 | + ]) |
| 77 | + |
| 78 | + expect(rumHarvests.length).toEqual(1) |
| 79 | + const rumResult = JSON.parse(rumHarvests[0].reply.body) |
| 80 | + |
| 81 | + const newrelicEventTime = await browser.execute(function () { |
| 82 | + return window.newrelicEventTime |
| 83 | + }) |
| 84 | + |
| 85 | + expect(newrelicEventTime > rumResult.app.nrServerTime).toBe(true) |
| 86 | + }) |
| 87 | + |
| 88 | + it('should work as expected within `newrelic` event listeners', async () => { |
| 89 | + const [logsCapture, errorsCapture] = await browser.testHandle.createNetworkCaptures('bamServer', [ |
| 90 | + { test: testLogsRequest }, |
| 91 | + { test: testErrorsRequest } |
| 92 | + ]) |
| 93 | + await browser.testHandle.scheduleReply('bamServer', { |
| 94 | + test: testRumRequest, |
| 95 | + body: JSON.stringify(rumFlags({ log: LOGGING_MODE.INFO })) |
| 96 | + }) |
| 97 | + |
| 98 | + const [logsHarvests, errorsHarvests] = |
| 99 | + await Promise.all([ |
| 100 | + logsCapture.waitForResult({ totalCount: 1, timeout: 10000 }), |
| 101 | + errorsCapture.waitForResult({ totalCount: 1, timeout: 10000 }), |
| 102 | + browser.url(await browser.testHandle.assetURL('event-listener-newrelic.html')) |
| 103 | + .then(() => browser.waitForAgentLoad()) |
| 104 | + ]) |
| 105 | + |
| 106 | + expect(errorsHarvests.length).toEqual(1) |
| 107 | + expect(errorsHarvests[0].request.query.ct).toEqual('http://custom.transaction/some-page') |
| 108 | + const actualErrors = errorsHarvests[0].request.body.err |
| 109 | + expect(actualErrors.length).toEqual(1) |
| 110 | + expect(actualErrors[0].params.message).toEqual('error 1') |
| 111 | + |
| 112 | + expect(logsHarvests.length).toEqual(1) |
| 113 | + const logsPayload = JSON.parse(logsHarvests[0].request.body) |
| 114 | + expect(logsPayload[0].common.attributes['application.version']).toEqual('1.0.0') |
| 115 | + expect(logsPayload[0].common.attributes.foo).toEqual('bar') |
| 116 | + expect(logsPayload[0].logs[0].message).toEqual('test message') |
| 117 | + }) |
| 118 | + |
52 | 119 | describe('setPageViewName()', () => {
|
53 | 120 | it('includes the 1st argument (page name) in rum, resources, events, and ajax calls', async () => {
|
54 | 121 | const [rumCapture, eventsCapture, ajaxCapture] =
|
|
0 commit comments