Skip to content

Commit

Permalink
More test fix with UAs... turned off in testing server
Browse files Browse the repository at this point in the history
  • Loading branch information
cwli24 committed Sep 18, 2024
1 parent 55a2347 commit db404b8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 30 deletions.
6 changes: 3 additions & 3 deletions tests/specs/api.e2e.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { apiMethods, asyncApiMethods } from '../../src/loaders/api/api-methods'
import { checkAjaxEvents, checkJsErrors, checkMetrics, checkPageAction, checkPVT, checkRumBody, checkRumQuery, checkSessionTrace, checkSpa } from '../util/basic-checks'
import { checkAjaxEvents, checkJsErrors, checkMetrics, checkGenericEvents, checkPVT, checkRumBody, checkRumQuery, checkSessionTrace, checkSpa } from '../util/basic-checks'
import { testAjaxEventsRequest, testAjaxTimeSlicesRequest, testBlobTraceRequest, testCustomMetricsRequest, testErrorsRequest, testEventsRequest, testInsRequest, testInteractionEventsRequest, testMetricsRequest, testRumRequest, testTimingEventsRequest } from '../../tools/testing-server/utils/expect-tests'

describe('newrelic api', () => {
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('newrelic api', () => {
.then(() => browser.waitForAgentLoad())
])

const pageActions = insResult[0].request.body.ins
const pageActions = insResult[0].request.body.ins.filter(evt => evt.eventType === 'PageAction')
expect(pageActions).toBeDefined()
expect(pageActions.length).toEqual(1) // exactly 1 PageAction was submitted
expect(pageActions[0].actionName).toEqual('finished') // PageAction has actionName = finished
Expand Down Expand Up @@ -382,7 +382,7 @@ describe('newrelic api', () => {
checkAjaxEvents(results[2][0].request)
checkJsErrors(results[3][0].request, { messages: ['test'] })
checkMetrics(results[4][0].request)
checkPageAction(results[5][0].request, { specificAction: 'test', actionContents: { test: 1 } })
checkGenericEvents(results[5][0].request, { specificAction: 'test', actionContents: { test: 1 } })
checkSessionTrace(results[6][0].request)
checkSpa(results[7][0].request)
})
Expand Down
19 changes: 2 additions & 17 deletions tests/specs/ins/harvesting.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,8 @@ describe('ins harvesting', () => {
expect(estimatedEventTime < receiptTime).toEqual(true) //, 'estimated event time (' + estimatedEventTime + ') < receipt time (' + receiptTime + ')')
})

it('should submit PageActions even with other features disabled', async () => {
const testUrl = await browser.testHandle.assetURL('instrumented.html', { init: { user_actions: { enabled: false } } })
await browser.url(testUrl).then(() => browser.waitForAgentLoad())

const [[{ request: { body: { ins: pageActionsHarvest } } }]] = await Promise.all([
insightsCapture.waitForResult({ totalCount: 1 }),
browser.execute(function () {
newrelic.addPageAction('DummyEvent', { free: 'tacos' })
})
])

expect(pageActionsHarvest.length).toEqual(1)
expect(pageActionsHarvest[0].actionName).toEqual('DummyEvent')
})

it('should submit UserAction', async () => {
const testUrl = await browser.testHandle.assetURL('user-actions.html')
it('should submit UserAction (when enabled)', async () => {
const testUrl = await browser.testHandle.assetURL('user-actions.html', { init: { user_actions: { enabled: true } } })
await browser.url(testUrl).then(() => browser.waitForAgentLoad())

const [[{ request: { body: { ins: userActionsHarvest } } }]] = await Promise.all([
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/loaders.e2e.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { checkAjaxEvents, checkJsErrors, checkMetrics, checkPVT, checkPageAction, checkRumBody, checkRumQuery, checkSessionTrace, checkSpa } from '../util/basic-checks'
import { checkAjaxEvents, checkJsErrors, checkMetrics, checkPVT, checkGenericEvents, checkRumBody, checkRumQuery, checkSessionTrace, checkSpa } from '../util/basic-checks'
import { testAjaxEventsRequest, testBlobTraceRequest, testErrorsRequest, testInsRequest, testInteractionEventsRequest, testMetricsRequest, testRumRequest, testTimingEventsRequest } from '../../tools/testing-server/utils/expect-tests'

const scriptLoadTypes = [null, 'defer', 'async', 'injection']
Expand Down Expand Up @@ -83,7 +83,7 @@ describe('Loaders', () => {
metricsHarvests.forEach(harvest => checkMetrics(harvest.request))
ajaxEventsHarvests.forEach(harvest => checkAjaxEvents(harvest.request))
errorsHarvests.forEach(harvest => checkJsErrors(harvest.request))
insightsHarvests.forEach(harvest => checkPageAction(harvest.request))
insightsHarvests.forEach(harvest => checkGenericEvents(harvest.request))
tracesHarvests.forEach(harvest => checkSessionTrace(harvest.request))

expect(interactionEventsHarvests.length).toEqual(0)
Expand Down Expand Up @@ -112,7 +112,7 @@ describe('Loaders', () => {
metricsHarvests.forEach(harvest => checkMetrics(harvest.request))
ajaxEventsHarvests.forEach(harvest => checkAjaxEvents(harvest.request))
errorsHarvests.forEach(harvest => checkJsErrors(harvest.request))
insightsHarvests.forEach(harvest => checkPageAction(harvest.request))
insightsHarvests.forEach(harvest => checkGenericEvents(harvest.request))
tracesHarvests.forEach(harvest => checkSessionTrace(harvest.request))
interactionEventsHarvests.forEach(harvest => checkSpa(harvest.request))
})
Expand Down
7 changes: 1 addition & 6 deletions tests/util/basic-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,13 @@ export function checkMetrics ({ query, body }) {
})
}

export function checkPageAction ({ query, body }, { specificAction, actionContents } = {}) {
export function checkGenericEvents ({ query, body }, { specificAction, actionContents } = {}) {
expect(query).toEqual(baseQuery)
expect(body.ins?.length).toBeGreaterThanOrEqual(1)
body.ins.forEach(ins => {
expect(ins).toMatchObject({
actionName: expect.any(String),
browserHeight: expect.any(Number),
browserWidth: expect.any(Number),
currentUrl: expect.any(String),
eventType: expect.any(String),
pageUrl: expect.any(String),
timeSinceLoad: expect.any(Number),
timestamp: expect.any(Number)
})

Expand Down
2 changes: 1 addition & 1 deletion tools/testing-server/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports.defaultInitBlock = {
metrics: { enabled, autoStart },
obfuscate: undefined,
page_action: { enabled },
user_actions: { enabled },
user_actions: { enabled: false },
page_view_event: { enabled, autoStart },
page_view_timing: enabledFeature,
privacy: { cookies_enabled: true },
Expand Down

0 comments on commit db404b8

Please sign in to comment.