Migrated RulesEngine DOM action functional tests to Vitest+Playwright+MSW#1550
Migrated RulesEngine DOM action functional tests to Vitest+Playwright+MSW#1550carterworks wants to merge 3 commits into
Conversation
|
|
| Filename | Overview |
|---|---|
| packages/browser/test/integration/specs/RulesEngine/rulesEngine.spec.js | New integration spec migrating three TestCafe RulesEngine tests; missing DOM cleanup between tests risks false-positive assertions in C13348429 and C13405889, and configure is not awaited in C13419240. |
Sequence Diagram
sequenceDiagram
participant T as Test
participant A as Alloy (browser)
participant MSW as MSW Worker
participant DOM as Browser DOM
note over T,DOM: C13419240 — sendEvent path
T->>A: configure(alloyConfig)
T->>MSW: worker.use(inAppMessageHandler)
T->>A: "sendEvent({renderDecisions:true, surfaces:[…]})"
A->>MSW: POST /v1/interact
MSW-->>A: "inAppMessageResponse.json (ruleset-item ~type=edge)"
A->>A: "evaluate ruleset (condition: ~type=edge ✓)"
A->>DOM: "inject #alloy-messaging-container + alloy-content-iframe"
T->>DOM: getElementById(alloy-messaging-container)
T->>T: assert toBeInTheDocument + innerHTML contains iframe
note over T,DOM: C13348429 — applyResponse path
T->>A: configure(alloyConfig)
T->>A: "applyResponse({renderDecisions:true, responseBody: inAppMessageResponse})"
A->>A: "evaluate ruleset (condition: ~type=edge ✓)"
A->>DOM: "inject #alloy-messaging-container + alloy-content-iframe"
T->>DOM: getElementById(alloy-messaging-container)
T->>T: assert toBeInTheDocument + innerHTML contains iframe
note over T,DOM: C13405889 — evaluateRulesets path
T->>A: configure(alloyConfig)
T->>A: "applyResponse({renderDecisions:false, responseBody: rulesEngineEvaluateResponse})"
A->>A: "store ruleset (condition: ~type=rulesEngine), no render"
T->>A: "evaluateRulesets({renderDecisions:true, decisionContext:{user:alloy}})"
A->>A: "evaluate ruleset (condition: ~type=rulesEngine ✓)"
A->>DOM: "inject #alloy-messaging-container + alloy-content-iframe"
T->>DOM: getElementById(alloy-messaging-container)
T->>T: assert toBeInTheDocument + innerHTML contains iframe
Reviews (1): Last reviewed commit: "test(integration): migrate rules engine ..." | Re-trigger Greptile
| }); | ||
|
|
||
| const container = document.getElementById("alloy-messaging-container"); | ||
| await expect.element(container).toBeInTheDocument(); | ||
| expect(container.innerHTML).toContain("alloy-content-iframe"); |
There was a problem hiding this comment.
Missing DOM cleanup between tests
cleanAlloy() (called by the alloy fixture between tests) removes the Alloy instance but does not remove DOM nodes created by Alloy's rendering (e.g., #alloy-messaging-container, #alloy-overlay-container, #alloy-content-iframe). Running three tests in sequence means C13348429 and C13405889 both find these elements already present in the DOM from C13419240, so their document.getElementById and expect.element(container).toBeInTheDocument() assertions pass trivially even if applyResponse/evaluateRulesets never rendered anything.
The established pattern in this repo (see inapp_messages.spec.js lines 38–43) is to explicitly remove the injected containers at the end of each test. All three tests here should do the same.
| // onBeforeEvent sets ~type="com.adobe.eventType.edge" → inAppMessageResponse condition matches | ||
| test("C13419240 - Verify DOM action using the sendEvent command", async ({ | ||
| alloy, |
There was a problem hiding this comment.
In C13419240, alloy("configure", alloyConfig) is called without await before alloy("sendEvent", ...) is awaited. If configure has not resolved (e.g., identity-acquire response is slow to return even in bypass mode), the sendEvent call queued behind it could race. Compare inapp_messages.spec.js line 22 which has the same omission — but this PR is a good opportunity to harden the pattern with await alloy("configure", alloyConfig).
| test("C13405889 - Verify DOM action using the evaluateRulesets command", async ({ | ||
| alloy, | ||
| }) => { | ||
| await alloy("configure", alloyConfig); | ||
|
|
||
| await alloy("applyResponse", { | ||
| renderDecisions: false, | ||
| responseBody: rulesEngineEvaluateResponse, | ||
| }); | ||
|
|
||
| await alloy("evaluateRulesets", { | ||
| renderDecisions: true, | ||
| personalization: { | ||
| decisionContext: { user: "alloy" }, |
There was a problem hiding this comment.
Missing network handler for the
evaluateRulesets test
C13405889 calls configure without adding any MSW handler. On configure, Alloy may fire an identity-acquire request (/v1/identity/acquire). With onUnhandledRequest: "bypass", this falls through to the real network. In strict CI (no outbound network) the acquire call will fail, which could prevent Alloy from completing initialization. Adding acquireHandler via worker.use(acquireHandler) (already exported from handlers.js) before configure would make the test fully self-contained and resilient to network conditions.
b9a1fcf to
bd82fca
Compare
c86ea05 to
4793858
Compare
There was a problem hiding this comment.
carterworks has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
bd82fca to
663fb81
Compare
4793858 to
90fa13b
Compare
There was a problem hiding this comment.
carterworks has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
carterworks has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
69eb3dd to
bace201
Compare
bace201 to
2006893
Compare
07cc6ec to
dff13ca
Compare
79b7443 to
c479108
Compare
Keep the original testcafe functional specs alongside the new Vitest+Playwright+MSW integration suite until these migration branches merge, so reviewers retain the pre-migration signal.
c479108 to
61a65a0
Compare
Changed Packages
Description
Migrates the RulesEngine DOM action functional tests to the new Vitest+Playwright+MSW harness. New mock fixture
rulesEngineEvaluateResponse.jsonadded (condition matches~type=rulesEnginefor the evaluateRulesets path).Related Issue
Part of the functional test → integration test migration. See
packages/browser/test/FUNCTIONAL_MIGRATION_PLAN.md.Motivation and Context
The existing TestCafe functional test suite is being migrated to Vitest+Playwright+MSW to enable faster, more reliable CI testing without a running server. This PR is part of a stacked series — each PR migrates one test file.
Functional tests replaced:
packages/browser/test/functional/specs/RulesEngine/C13348429.jspackages/browser/test/functional/specs/RulesEngine/C13405889.jspackages/browser/test/functional/specs/RulesEngine/C13419240.jsTypes of changes
Checklist:
Stack