Skip to content

Harden front-end tracker E2E assertions against attribute-order changes#4244

Merged
acicovic merged 2 commits into
developfrom
copilot/investigate-end-to-end-test-failures
May 25, 2026
Merged

Harden front-end tracker E2E assertions against attribute-order changes#4244
acicovic merged 2 commits into
developfrom
copilot/investigate-end-to-end-test-failures

Conversation

Copilot AI commented May 25, 2026

Copy link
Copy Markdown
Contributor
  • Identify failing test: front-end-tracker.spec.ts:98toContainText returns "" for <script> elements (Playwright limitation for non-visible elements)
  • Fix: replace toContainText with evaluate()el.textContent + plain expect().toContain() on line 98

@acicovic acicovic marked this pull request as ready for review May 25, 2026 12:16
@acicovic acicovic requested a review from a team as a code owner May 25, 2026 12:16
@acicovic

Copy link
Copy Markdown
Collaborator

@coderabbitai review

Make sure that the tests have been modified in a way that still keeps them thorough and doesn't introduce any lacks compared to their previous state.

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@acicovic After thoroughly comparing the old and new assertions across both tests, the refactored tests maintain full coverage with no gaps. Here's the analysis:


Test 1 — "Should work as expected when only Site ID is provided"

Old assertion New equivalent Notes
content.toContain('<link rel="dns-prefetch" …>') CSS selector link[rel="dns-prefetch"][href="…"] + toHaveCount(1) Equivalent; DOM-based is more robust
Single string match for <script … id="parsely-cfg"> (attribute-order sensitive) toHaveCount(1) + individual toHaveAttribute() calls for data-parsely-site and src Strictly better — each attribute is independently verified, order-agnostic
Single string match for <script … id="wp-parsely-loader-js"> toHaveCount(1) + toHaveAttribute('src', …) Equivalent
not.toContain("<script id='wp-parsely-loader-js-before'>") script#wp-parsely-loader-js-before + toHaveCount(0) Equivalent
not.toContain('window.wpParselySiteId =') page.locator('script', { hasText: 'window.wpParselySiteId =' }) + toHaveCount(0) Equivalent; scoping to <script> elements is appropriate since this string can only appear there

Test 2 — "Should work as expected when a Site ID and API Secret are provided"

All shared checks mirror Test 1 (same analysis above). The key change:

Old assertion New equivalent Notes
content.toContain('<script id="wp-parsely-loader-js-before">') script#wp-parsely-loader-js-before + toHaveCount(1) Equivalent
content.toContain(window.wpParselySiteId = '${VALID_SITE_ID}') loaderInlineScript.evaluate(el => el.textContent) + expect(scriptContent).toContain(…) Correct Playwright workaround for non-visible elements; same semantic coverage

Conclusion: No coverage gaps were introduced. The refactoring is sound — every original assertion has a direct, semantically equivalent replacement, and the attribute decomposition approach is actually an improvement over the brittle single-string HTML matches.

@acicovic acicovic merged commit fba31f4 into develop May 25, 2026
37 checks passed
@acicovic acicovic deleted the copilot/investigate-end-to-end-test-failures branch May 25, 2026 12:21
github-actions Bot added a commit that referenced this pull request May 25, 2026
…to-end-test-failures Harden front-end tracker E2E assertions against attribute-order changes" (fba31f4)
@acicovic acicovic added this to the 3.23.2 milestone May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants