Skip to content

Commit 155650c

Browse files
mormubisclaude
andcommitted
✅ test: add E2E tests for localStorage remote configuration strategy
Add 4 new E2E tests for the localStorage strategy: 1. Basic localStorage retrieval - reads simple string values 2. localStorage with regex extractor - parses extracted values 3. Missing key handling - gracefully falls back when key doesn't exist 4. localStorage unavailable - handles access errors and falls back Tests follow the same pattern as the js strategy tests (PR #3766) and validate: - Synchronous value resolution during SDK initialization - Regex extraction functionality - Fallback behavior for missing or inaccessible keys - Integration with both CDN and npm setups Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent b2737b9 commit 155650c

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

test/e2e/scenario/rum/remoteConfiguration.scenario.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,93 @@ test.describe('remote configuration', () => {
9393
expect(initConfiguration.version).toBe('js-version')
9494
})
9595

96+
createTest('should resolve an option value from localStorage')
97+
.withRum({
98+
remoteConfigurationId: 'e2e',
99+
})
100+
.withRemoteConfiguration({
101+
rum: {
102+
applicationId: 'e2e',
103+
version: { rcSerializedType: 'dynamic', strategy: 'localStorage', key: 'dd_app_version' },
104+
},
105+
})
106+
.withBody(html`
107+
<script>
108+
localStorage.setItem('dd_app_version', 'localStorage-version')
109+
</script>
110+
`)
111+
.run(async ({ page }) => {
112+
const initConfiguration = await page.evaluate(() => window.DD_RUM!.getInitConfiguration()!)
113+
expect(initConfiguration.version).toBe('localStorage-version')
114+
})
115+
116+
createTest('should resolve an option value from localStorage with an extractor')
117+
.withRum({
118+
remoteConfigurationId: 'e2e',
119+
})
120+
.withRemoteConfiguration({
121+
rum: {
122+
applicationId: 'e2e',
123+
version: {
124+
rcSerializedType: 'dynamic',
125+
strategy: 'localStorage',
126+
key: 'dd_app_version',
127+
extractor: { rcSerializedType: 'regex', value: '\\d+\\.\\d+\\.\\d+' },
128+
},
129+
},
130+
})
131+
.withBody(html`
132+
<script>
133+
localStorage.setItem('dd_app_version', 'version-1.2.3-beta')
134+
</script>
135+
`)
136+
.run(async ({ page }) => {
137+
const initConfiguration = await page.evaluate(() => window.DD_RUM!.getInitConfiguration()!)
138+
expect(initConfiguration.version).toBe('1.2.3')
139+
})
140+
141+
createTest('should resolve to undefined when localStorage key is missing')
142+
.withRum({
143+
remoteConfigurationId: 'e2e',
144+
version: 'fallback-version',
145+
})
146+
.withRemoteConfiguration({
147+
rum: {
148+
applicationId: 'e2e',
149+
version: { rcSerializedType: 'dynamic', strategy: 'localStorage', key: 'non_existent_key' },
150+
},
151+
})
152+
.run(async ({ page }) => {
153+
const initConfiguration = await page.evaluate(() => window.DD_RUM!.getInitConfiguration()!)
154+
expect(initConfiguration.version).toBe('fallback-version')
155+
})
156+
157+
createTest('should handle localStorage access failure gracefully')
158+
.withRum({
159+
remoteConfigurationId: 'e2e',
160+
version: 'fallback-version',
161+
})
162+
.withRemoteConfiguration({
163+
rum: {
164+
applicationId: 'e2e',
165+
version: { rcSerializedType: 'dynamic', strategy: 'localStorage', key: 'dd_app_version' },
166+
},
167+
})
168+
.withBody(html`
169+
<script>
170+
Object.defineProperty(window, 'localStorage', {
171+
get: function() {
172+
throw new Error('localStorage is not available')
173+
},
174+
configurable: true,
175+
})
176+
</script>
177+
`)
178+
.run(async ({ page }) => {
179+
const initConfiguration = await page.evaluate(() => window.DD_RUM!.getInitConfiguration()!)
180+
expect(initConfiguration.version).toBe('fallback-version')
181+
})
182+
96183
createTest('should resolve user context')
97184
.withRum({
98185
remoteConfigurationId: 'e2e',

0 commit comments

Comments
 (0)