Skip to content

Commit

Permalink
chore: Convert browser/spa/fetch-body-propagation-ext.browser.js (#970)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwli24 authored Apr 12, 2024
1 parent 12e7f99 commit c3e1e09
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 72 deletions.
25 changes: 25 additions & 0 deletions tests/assets/spa/fetch-formdata-onclick.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>formdata on click interaction</title>
{init}
{config}
{loader}
</head>
<body>
this page tests formdata after a click then sends the interaction
<script>
document.addEventListener('click', function () {
const formData = new FormData()
formData.append("hi", "bye") // empty FormData causes fetch failure in Request.formData

const req = new Request('/formdata', { method: 'POST', body: formData })

req.formData().then(function () {
setTimeout(newrelic.interaction().save().createTracer('timer'), 0)
})
})
</script>
</body>
</html>
70 changes: 0 additions & 70 deletions tests/browser/spa/fetch-body-propagation-ext.browser.js

This file was deleted.

2 changes: 0 additions & 2 deletions tests/browser/spa/fetch-body-propagation-ext.spec.js

This file was deleted.

31 changes: 31 additions & 0 deletions tests/specs/spa/interaction-tracking.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { notIE } from '../../../tools/browser-matcher/common-matchers.mjs'

describe('interaction tracking works inside', () => {
it.withBrowsersMatching(notIE)('single fetch with formData', async () => {
const url = await browser.testHandle.assetURL('spa/fetch-formdata-onclick.html')
await Promise.all([
browser.testHandle.expectInteractionEvents(), // Discard the initial page load interaction
browser.url(url).then(() => browser.waitForAgentLoad())
])

const [clickInteractionResults] = await Promise.all([
browser.testHandle.expectInteractionEvents(7000),
$('body').click()
])

expect(clickInteractionResults.request.body).toEqual(expect.arrayContaining([
expect.objectContaining({
category: 'Custom',
type: 'interaction',
trigger: 'click',
children: [
expect.objectContaining({
type: 'customTracer',
name: 'timer',
children: []
})
]
})
]))
})
})

0 comments on commit c3e1e09

Please sign in to comment.