Skip to content

Commit c2b1b4a

Browse files
Add headmarkup tests
1 parent 8e5d38b commit c2b1b4a

3 files changed

Lines changed: 46 additions & 23 deletions

File tree

test/e2e/lib/framework/buildSalesforceUrl.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ import {
77
getSfLwcUsername,
88
} from '../../../../scripts/lib/secrets.ts'
99

10-
export type SalesforceApp = 'lwc' | 'experience-cloud'
10+
export type SalesforceApp = 'lwc' | 'experience-cloud' | 'experience-cloud-headmarkup'
1111

1212
const salesforceHomePath = '/lightning/app/c__SF_LWC_App/page/home'
13-
const experienceSitePath = '/sfexperiencecloud/'
13+
const experienceSitePaths: Record<Exclude<SalesforceApp, 'lwc'>, string> = {
14+
'experience-cloud': '/sfexperiencecloud/',
15+
'experience-cloud-headmarkup': '/sfexperienceheadmarkup/',
16+
}
1417

1518
let salesforceLwcSession: Promise<SalesforceLwcSession> | undefined
1619

@@ -20,7 +23,7 @@ export interface SalesforceLwcSession {
2023
}
2124

2225
export async function buildSalesforceUrl(app: SalesforceApp): Promise<string> {
23-
return app === 'lwc' ? await buildSalesforceLwcUrl() : buildSalesforceExperienceUrl()
26+
return app === 'lwc' ? await buildSalesforceLwcUrl() : buildSalesforceExperienceUrl(app)
2427
}
2528

2629
export function getSalesforceLwcSession(): Promise<SalesforceLwcSession> {
@@ -93,13 +96,13 @@ async function getAccessToken(
9396
// Unlike the Lightning app, the Experience Cloud site is public, so we don't need to
9497
// authenticate or exchange a frontdoor token: we can derive the site URL directly from the
9598
// org's instance URL.
96-
function buildSalesforceExperienceUrl(): string {
99+
function buildSalesforceExperienceUrl(app: Exclude<SalesforceApp, 'lwc'>): string {
97100
const instanceUrl = getSfLwcInstanceUrl()
98101
if (!instanceUrl) {
99102
console.error('Salesforce credentials are not set')
100103
return ''
101104
}
102105

103106
const siteDomain = instanceUrl.replace('.my.salesforce.com', '.my.site.com')
104-
return `${siteDomain}${experienceSitePath}`
107+
return `${siteDomain}${experienceSitePaths[app]}`
105108
}

test/e2e/lib/framework/pageSetups.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,23 @@ export function microfrontendSetup(options: SetupOptions, servers: Servers) {
304304
})
305305
}
306306

307+
const salesforceAppDirectories: Record<SalesforceApp, string> = {
308+
lwc: 'sf-lwc-app',
309+
'experience-cloud': 'sf-experience-app',
310+
'experience-cloud-headmarkup': 'sf-experience-headmarkup-app',
311+
}
312+
307313
// Salesforce apps don't serve a locally-generated page body; this factory only drives the
308314
// page-side setup needed to init RUM on the remote Salesforce page.
309315
export async function salesforceSetup(options: SetupOptions, servers: Servers, page: Page): Promise<string> {
310-
const salesforceAppDirectory = options.salesforceApp === 'experience-cloud' ? 'sf-experience-app' : 'sf-lwc-app'
316+
if (!options.salesforceApp) {
317+
throw new Error('Salesforce app is not set')
318+
}
319+
const salesforceAppDirectory = salesforceAppDirectories[options.salesforceApp]
311320
const salesforceBundlePath = resolve(
312321
__dirname,
313322
`../../../apps/${salesforceAppDirectory}/force-app/main/default/staticresources/datadog_rum_salesforce.js`
314323
)
315-
316324
await page.route(/\/resource(?:\/[^/?#]+)?\/datadog_rum_salesforce(?:\.js)?(?:[/?#].*)?$/, async (route) => {
317325
await route.fulfill({
318326
body: await readFile(salesforceBundlePath),
@@ -332,9 +340,9 @@ export async function salesforceSetup(options: SetupOptions, servers: Servers, p
332340
}
333341

334342
if (options.rum) {
335-
// Both sf-lwc-app and sf-experience-app have a committed datadogInit LWC that reads
336-
// these globals and calls DD_RUM.init. On experience-cloud, that component only runs
337-
// when the page is loaded with init=true.
343+
// The LWC and standard Experience Cloud apps have a committed datadogInit LWC that reads
344+
// these globals and calls DD_RUM.init. The Head Markup site reads the same globals from its
345+
// configured head markup instead.
338346
await page.addInitScript(
339347
`window.RUM_CONFIGURATION = ${formatConfiguration(options.rum, servers)}
340348
window.RUM_CONTEXT = ${JSON.stringify(options.context)}`

test/e2e/scenario/salesforce.scenario.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ const baseSalesforceRumConfiguration = {
1717
trackUserInteractions: true,
1818
}
1919

20-
const salesforceApps: SalesforceApp[] = ['lwc', 'experience-cloud']
20+
const salesforceApps: SalesforceApp[] = ['lwc', 'experience-cloud', 'experience-cloud-headmarkup']
2121

2222
for (const app of salesforceApps) {
23+
const canCallRumFromComponents = app !== 'experience-cloud-headmarkup'
24+
2325
createTest(`salesforce ${app} views`)
2426
.withRum(baseSalesforceRumConfiguration)
2527
.withSalesforceApp(app)
@@ -59,19 +61,23 @@ for (const app of salesforceApps) {
5961
}
6062
})
6163

62-
createTest(`salesforce ${app} long tasks and vitals`)
64+
createTest(`salesforce ${app} long tasks${canCallRumFromComponents ? ' and vitals' : ''}`)
6365
.withRum(baseSalesforceRumConfiguration)
6466
.withSalesforceApp(app)
6567
.run(async ({ page, intakeRegistry, flushEvents }) => {
6668
await expect(page.getByTestId('home-custom-actions')).toBeVisible({ timeout: 30000 })
6769

6870
await page.getByTestId('long-task').click()
69-
await page.getByRole('button', { name: 'Add Duration Vital' }).click()
71+
if (canCallRumFromComponents) {
72+
await page.getByRole('button', { name: 'Add Duration Vital' }).click()
73+
}
7074

7175
await flushEvents()
7276

7377
expect(intakeRegistry.rumLongTaskEvents.length).toBeGreaterThanOrEqual(1)
74-
expect(intakeRegistry.rumVitalEvents.length).toBeGreaterThanOrEqual(1)
78+
if (canCallRumFromComponents) {
79+
expect(intakeRegistry.rumVitalEvents.length).toBeGreaterThanOrEqual(1)
80+
}
7581
})
7682

7783
createTest(`salesforce ${app} actions`)
@@ -87,10 +93,12 @@ for (const app of salesforceApps) {
8793
const actionTypes = new Set(intakeRegistry.rumActionEvents.map((e) => e.action.type))
8894
expect(actionTypes.has('click')).toBe(true)
8995

90-
const customAction = intakeRegistry.rumActionEvents.find(
91-
(e) => e.action.type === 'custom' && e.action.target?.name?.includes('custom action 1') === true
92-
)
93-
expect(customAction).toBeDefined()
96+
if (canCallRumFromComponents) {
97+
const customAction = intakeRegistry.rumActionEvents.find(
98+
(e) => e.action.type === 'custom' && e.action.target?.name?.includes('custom action 1') === true
99+
)
100+
expect(customAction).toBeDefined()
101+
}
94102
})
95103

96104
createTest(`salesforce ${app} errors`)
@@ -99,7 +107,9 @@ for (const app of salesforceApps) {
99107
.run(async ({ page, intakeRegistry, flushEvents, withBrowserLogs }) => {
100108
await expect(page.getByTestId('home-custom-actions')).toBeVisible({ timeout: 30000 })
101109

102-
await page.getByTestId('custom-error-1').click()
110+
if (canCallRumFromComponents) {
111+
await page.getByTestId('custom-error-1').click()
112+
}
103113
await page.getByTestId('runtime-error').click()
104114
await page.evaluate(() => window.console.error('salesforce console error test'))
105115

@@ -119,9 +129,11 @@ for (const app of salesforceApps) {
119129
)
120130
expect(errorEvent).toBeDefined()
121131

122-
const customError = intakeRegistry.rumErrorEvents.find(
123-
(e) => e.error.source === 'custom' && e.error.message?.includes('custom error 1') === true
124-
)
125-
expect(customError).toBeDefined()
132+
if (canCallRumFromComponents) {
133+
const customError = intakeRegistry.rumErrorEvents.find(
134+
(e) => e.error.source === 'custom' && e.error.message?.includes('custom error 1') === true
135+
)
136+
expect(customError).toBeDefined()
137+
}
126138
})
127139
}

0 commit comments

Comments
 (0)