Skip to content

Commit 6fb1287

Browse files
fix head error
1 parent 8d16cc6 commit 6fb1287

3 files changed

Lines changed: 47 additions & 77 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { resolve } from 'node:path'
2+
import { command } from './command.ts'
3+
4+
const salesforceAppDir = resolve(import.meta.dirname, '../../../apps/sf-lwc-app')
5+
const salesforceHomePath = '/lightning/app/c__SF_LWC_App/page/home'
6+
const defaultTargetOrg = 'sf-lwc-ci'
7+
8+
// The frontdoor.jsp OTP expires in ~1 minute, so the URL must be generated at test time —
9+
// not at suite startup — to guarantee a valid token when the test actually navigates.
10+
export function buildSalesforceLwcUrl(proxy?: string): string {
11+
const targetOrg = process.env.SF_TARGET_ORG ?? defaultTargetOrg
12+
const path = new URL(salesforceHomePath, 'https://salesforce.local')
13+
14+
// c__datadogInitConfiguration must be part of the path (not a top-level frontdoor.jsp param)
15+
// so that Salesforce passes it through to the Lightning app after authentication.
16+
if (proxy) {
17+
path.searchParams.set(
18+
'c__datadogInitConfiguration',
19+
JSON.stringify({
20+
applicationId: '37fe52bf-b3d5-4ac7-ad9b-44882d479ec8',
21+
clientToken: 'pubf2099de38f9c85797d20d64c7d632a69',
22+
defaultPrivacyLevel: 'allow',
23+
trackResources: true,
24+
trackLongTasks: true,
25+
proxy,
26+
})
27+
)
28+
}
29+
30+
const output = command`sf org open --target-org ${targetOrg} --path ${path.pathname}${path.search} --url-only`
31+
.withCurrentWorkingDirectory(salesforceAppDir)
32+
.run()
33+
34+
// The sf CLI appends ANSI reset codes (\x1b[39m etc.) directly to the URL on stdout.
35+
// Excluding control characters (0x00–0x1f, which includes ESC/0x1b) strips them cleanly.
36+
// eslint-disable-next-line no-control-regex
37+
const url = output.match(/https:\/\/[^\s\x00-\x1f]+/g)?.at(-1)
38+
if (!url) {
39+
throw new Error(`Unable to find Salesforce URL in command output:\n${output}`)
40+
}
41+
return url
42+
}

scripts/salesforce-lwc-app.ts

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { chmodSync, copyFileSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
1+
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
22
import { dirname, resolve } from 'node:path'
33
import { fileURLToPath } from 'node:url'
44
import { tmpdir } from 'node:os'
@@ -7,12 +7,10 @@ import { parseArgs } from 'node:util'
77
import { printLog, runMain } from './lib/executionUtils.ts'
88
import { getSfLwcClientId, getSfLwcInstanceUrl, getSfLwcJwtPrivateKey, getSfLwcUsername } from './lib/secrets.ts'
99
import { command } from './lib/command.ts'
10+
import { buildSalesforceLwcUrl } from './lib/buildSalesforceLwcUrl.ts'
1011

1112
const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..')
1213
const salesforceAppDir = resolve(repositoryRoot, 'test/apps/sf-lwc-app')
13-
const bundlePath = resolve(repositoryRoot, 'packages/browser-rum-slim/bundle/datadog-rum-slim.js')
14-
const stableStaticResourcePath = resolve(salesforceAppDir, 'force-app/main/default/staticresources/datadog_rum_slim.js')
15-
const salesforceHomePath = '/lightning/app/c__SF_LWC_App/page/home'
1614
const defaultTargetOrg = 'sf-lwc-ci'
1715

1816
runMain(() => {
@@ -50,7 +48,7 @@ runMain(() => {
5048
break
5149
// Get the authenticated URL of the app with the RUM configuration.
5250
case 'get-url':
53-
process.stdout.write(`with the following URL: ${buildOpenUrl(values.proxy)}\n`)
51+
process.stdout.write(`with the following URL: ${buildSalesforceLwcUrl(values.proxy)}\n`)
5452
break
5553
default:
5654
throw new Error(`Unknown command "${commandName ?? ''}". Expected: auth|deploy-app|get-url`)
@@ -85,62 +83,12 @@ function authenticate() {
8583
}
8684

8785
function deployApp() {
88-
const targetOrg = getTargetOrg()
86+
const targetOrg = process.env.SF_TARGET_ORG ?? defaultTargetOrg
8987

9088
printLog(`Deploying Salesforce LWC app to ${targetOrg}...`)
91-
// Deploy the app to the Salesforce org. To be done only when the app is updated.
92-
copyFileSync(bundlePath, stableStaticResourcePath)
93-
94-
// Clear stale source-tracking state so the deploy doesn't skip files it thinks are already in sync.
95-
resetSourceTracking(targetOrg)
9689
command`sf project deploy start --target-org ${targetOrg} --source-dir force-app --ignore-conflicts --concise`
9790
.withCurrentWorkingDirectory(salesforceAppDir)
9891
.withLogs()
9992
.run()
10093
printLog('Salesforce LWC app deployed.')
10194
}
102-
103-
function resetSourceTracking(targetOrg: string) {
104-
command`sf project reset tracking --target-org ${targetOrg} --no-prompt`
105-
.withCurrentWorkingDirectory(salesforceAppDir)
106-
.withLogs()
107-
.run()
108-
}
109-
110-
function buildOpenUrl(proxy?: string): string {
111-
const targetOrg = getTargetOrg()
112-
const path = new URL(salesforceHomePath, 'https://salesforce.local')
113-
114-
// c__datadogInitConfiguration must be part of the path (not a top-level frontdoor.jsp param)
115-
// so that Salesforce passes it through to the Lightning app after authentication.
116-
if (proxy) {
117-
path.searchParams.set(
118-
'c__datadogInitConfiguration',
119-
JSON.stringify({
120-
applicationId: '37fe52bf-b3d5-4ac7-ad9b-44882d479ec8',
121-
clientToken: 'pubf2099de38f9c85797d20d64c7d632a69',
122-
defaultPrivacyLevel: 'allow',
123-
trackResources: true,
124-
trackLongTasks: true,
125-
proxy,
126-
})
127-
)
128-
}
129-
130-
const output = command`sf org open --target-org ${targetOrg} --path ${path.pathname}${path.search} --url-only`
131-
.withCurrentWorkingDirectory(salesforceAppDir)
132-
.run()
133-
134-
// The sf CLI appends ANSI reset codes (\x1b[39m etc.) directly to the URL on stdout.
135-
// Excluding control characters (0x00–0x1f, which includes ESC/0x1b) strips them cleanly.
136-
// eslint-disable-next-line no-control-regex
137-
const url = output.match(/https:\/\/[^\s\x00-\x1f]+/g)?.at(-1)
138-
if (!url) {
139-
throw new Error(`Unable to find Salesforce URL in command output:\n${output}`)
140-
}
141-
return url
142-
}
143-
144-
function getTargetOrg(): string {
145-
return process.env.SF_TARGET_ORG || defaultTargetOrg
146-
}

test/e2e/lib/framework/createTest.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from '../helpers/configuration'
1717
import { validateRumFormat } from '../helpers/validation'
1818
import type { BrowserConfiguration } from '../../../browsers.conf'
19-
import { command } from '../../../../scripts/lib/command.ts'
19+
import { buildSalesforceLwcUrl } from '../../../../scripts/lib/buildSalesforceLwcUrl'
2020
import {
2121
NEXTJS_APP_ROUTER_PORT,
2222
NUXT_APP_PORT,
@@ -37,8 +37,6 @@ import type { Extension } from './createExtension'
3737
import type { Worker } from './createWorker'
3838
import { isBrowserStack } from './environment'
3939

40-
const repositoryRoot = resolve(__dirname, '../../../..')
41-
4240
/**
4341
* Init script applied to every WebKit context to work around a Playwright-specific
4442
* quirk observed on the bundled WebKit (Safari 26). Real Safari users are unaffected;
@@ -388,24 +386,6 @@ function declareTestsForSetups(
388386
}
389387
}
390388

391-
// The frontdoor.jsp OTP expires in ~1 minute, so the URL must be generated at test time —
392-
// not at suite startup — to guarantee a valid token when the test actually navigates.
393-
function buildSalesforceLwcUrl(proxy: string): string {
394-
const output = command`node scripts/salesforce-lwc-app.ts get-url --proxy ${proxy}`
395-
.withCurrentWorkingDirectory(repositoryRoot)
396-
.run()
397-
const url =
398-
// eslint-disable-next-line no-control-regex
399-
output.match(/with the following URL: (?<url>https:\/\/[^\s\x00-\x1f]+)/)?.groups?.url ??
400-
// eslint-disable-next-line no-control-regex
401-
output.match(/https:\/\/[^\s\x00-\x1f]+/g)?.at(-1)
402-
403-
if (!url) {
404-
throw new Error(`Unable to find Salesforce URL in command output:\n${output}`)
405-
}
406-
return url
407-
}
408-
409389
/**
410390
* Resolves the Playwright test function to use for declaring a test.
411391
*

0 commit comments

Comments
 (0)