Skip to content

Commit c4e7484

Browse files
committed
✅ Fix referrer assertion in Next.js router tests after query param stripping
When Next.js hydrates with the test query params (rum-config, rum-context) stripped via history.replaceState, the referrer recorded by RUM for SPA navigations is the clean home URL (without params) rather than the full baseUrl. Update the shared test to account for this with a stripsTestQueryParams flag, and enable it for the Next.js scenarios.
1 parent ccc134e commit c4e7484

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

test/e2e/scenario/plugins/basePluginRouterTests.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ interface RouterConfig {
88
homeUrlPattern: string | RegExp
99
userRouteName: string
1010
guidesRouteName: string
11+
/**
12+
* Set to true when the app strips test query params (rum-config, rum-context) from the URL
13+
* on load (e.g. via history.replaceState). When true, the referrer for the first SPA navigation
14+
* will be the clean home URL (without query params) instead of the full baseUrl.
15+
*/
16+
stripsTestQueryParams?: boolean
1117
}
1218

1319
interface RouterPluginTestConfig {
@@ -19,7 +25,7 @@ interface RouterPluginTestConfig {
1925

2026
export function runBasePluginRouterTests(configs: RouterPluginTestConfig[]) {
2127
for (const { name, loadApp, viewPrefix, router } of configs) {
22-
const { homeViewName, homeUrlPattern, userRouteName, guidesRouteName } = router
28+
const { homeViewName, homeUrlPattern, userRouteName, guidesRouteName, stripsTestQueryParams } = router
2329

2430
test.describe(`base plugin: ${name}`, () => {
2531
test.describe('router', () => {
@@ -61,7 +67,9 @@ export function runBasePluginRouterTests(configs: RouterPluginTestConfig[]) {
6167
expect(guidesView).toBeDefined()
6268
expect(guidesView?.view.loading_type).toBe('route_change')
6369
expect(guidesView?.view.url).toContain('/guides/123')
64-
expect(guidesView?.view.referrer).toBe(baseUrl)
70+
expect(guidesView?.view.referrer).toBe(
71+
stripsTestQueryParams ? `${baseOrigin}${homeViewName}` : baseUrl
72+
)
6573

6674
const userView = viewEvents.find((e) => e.view.name === `${viewPrefix}${userRouteName}`)
6775
expect(userView).toBeDefined()

test/e2e/scenario/plugins/nextjsPlugin.scenario.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ runBasePluginRouterTests(
3030
homeUrlPattern,
3131
userRouteName: '/user/[id]',
3232
guidesRouteName: '/guides/[...slug]',
33+
stripsTestQueryParams: true,
3334
},
3435
}))
3536
)

0 commit comments

Comments
 (0)