Skip to content

Added MSW handlers, mock fixtures, and Vitest+Playwright test harness for functional test migration#1532

Open
carterworks wants to merge 8 commits into
mainfrom
migrate-integration/00-infra
Open

Added MSW handlers, mock fixtures, and Vitest+Playwright test harness for functional test migration#1532
carterworks wants to merge 8 commits into
mainfrom
migrate-integration/00-infra

Conversation

@carterworks

@carterworks carterworks commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Changed Packages

  • core
  • reactor-extension

Description

Adds the shared infrastructure required by all subsequent integration test migration PRs: MSW request handlers, JSON mock response fixtures, updated test fixtures (extend.js), legacyCookies.js utility, consent.js constants, and the functional migration plan document. No functional test files are replaced by this PR — it is the foundation.

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:

  • None (infrastructure only)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (non-breaking change which does not add functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have added a Changeset file with a consumer-facing description of my changes.
  • I have signed the Adobe Open Source CLA or I'm an Adobe employee.
  • I have made any necessary test changes and all tests pass.
  • I have run the Sandbox successfully.

Stack

  1. Added MSW handlers, mock fixtures, and Vitest+Playwright test harness for functional test migration #1532 👈 current
  2. Migrated Install SDK functional tests to Vitest+Playwright+MSW #1533

@carterworks carterworks added the ignore-for-release Do not include this PR in release notes label Jun 12, 2026
@carterworks carterworks self-assigned this Jun 12, 2026
@changeset-bot

changeset-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d5d8556

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment thread packages/browser/test/integration/helpers/utils/legacyCookies.js Fixed
@greptile-apps

greptile-apps Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds the shared infrastructure for migrating the TestCafe functional test suite to Vitest+Playwright+MSW: new MSW handlers, JSON fixtures, consent/cookie utilities, updated test fixtures, and the migration plan document. No functional test files are deleted — this is a pure foundation layer.

  • handlers.js: Added acquireHandler for the identity/acquire endpoint; updated sendEventHandler and setConsentHandler to support a configId:suffix override pattern and made setConsentHandler return a consent state that mirrors the incoming request payload.
  • extend.js / clean.js: Extended the alloy fixture to delete kndctr_ and AMCV_ cookies before each test, and added teardown for click listeners tracked by the new setupBaseCode monkeypatch.
  • New files: consent.js (Adobe 1.0/2.0 + IAB TCF constants), legacyCookies.js (AMCV/s_ecid cookie helpers), six new JSON response fixtures, and the migration plan document.

Confidence Score: 4/5

Safe to merge for non-migration tests; the s_ecid cookie gap will cause cross-test pollution once tests that call setSecidCookie() are added in subsequent PRs

The cookie cleanup introduced in extend.js deliberately handles kndctr_ and AMCV_ cookies, but the new setSecidCookie() utility sets s_ecid, which is the Visitor ID Service ECID-sync cookie Alloy reads during ID migration. Without cleaning it between tests, any test that calls setSecidCookie() will contaminate the Alloy identity state for every subsequent test in the same browser context.

packages/browser/test/integration/helpers/testsSetup/extend.js — the cookie cleanup predicate needs || name === 's_ecid' to match the new setSecidCookie utility

Important Files Changed

Filename Overview
packages/browser/test/integration/helpers/testsSetup/extend.js Cookie cleanup added but misses s_ecid, which will leak between tests that call the new setSecidCookie() utility
packages/browser/test/integration/helpers/mswjs/handlers.js Added acquireHandler for identity/acquire endpoint and updated sendEventHandler/setConsentHandler to support configId override suffix; consent response now reflects actual consent state passed in the request body
packages/browser/test/integration/helpers/utils/legacyCookies.js New AMCV/s_ecid cookie helpers for ID-migration tests; getCookie handles both encoded and unencoded cookie names correctly
packages/browser/test/integration/helpers/alloy/clean.js Added click-listener teardown to flush __alloyClickListeners tracked by the setupBaseCode monkeypatch
packages/browser/test/integration/helpers/alloy/setupBaseCode.js Monkeypatches document.addEventListener once per page lifetime to record click listeners in __alloyClickListeners for cleanup; only tracks document-level handlers
packages/browser/test/integration/helpers/constants/consent.js New constants for Adobe 1.0/2.0 and IAB TCF consent payloads used across consent integration tests
packages/browser/test/functional/specs/Personalization/C17409728.js Fixed broken import paths for createDecorateProposition.js and initDomActionsModules.js after the Personalization component moved from core/src to browser/src
packages/browser/test/FUNCTIONAL_MIGRATION_PLAN.md New migration plan document outlining TestCafe to Vitest+Playwright+MSW strategy, parity matrix, helper translation layer, and execution sequence

Sequence Diagram

sequenceDiagram
    participant Test as Integration Test
    participant Ext as extend.js (alloy fixture)
    participant SBC as setupBaseCode.js
    participant MSW as MSW Worker
    participant Handler as handlers.js
    participant Edge as Edge Network (mocked)

    Test->>Ext: fixture setup
    Ext->>Ext: delete kndctr_/AMCV_ cookies
    Ext->>SBC: setupBaseCode()
    SBC->>SBC: monkeypatch document.addEventListener (once)
    Ext->>Edge: setupAlloy() - identity/acquire
    MSW->>Handler: acquireHandler intercepts
    Handler-->>Edge: acquireResponse.json
    Edge-->>Ext: alloy instance ready
    Ext->>Test: use(alloy)
    Test->>Edge: alloy commands
    MSW->>Handler: sendEventHandler / setConsentHandler
    Handler-->>Edge: fixture JSON
    Edge-->>Test: response
    Test->>Ext: teardown
    Ext->>SBC: cleanAlloy()
    Ext->>MSW: worker.resetHandlers()
Loading

Reviews (2): Last reviewed commit: "test(integration): add MSW handlers, moc..." | Re-trigger Greptile

@carterworks carterworks force-pushed the migrate-integration/00-infra branch from ba71e37 to ee32880 Compare June 12, 2026 17:31
This was referenced Jun 12, 2026
Comment thread packages/browser/test/integration/helpers/testsSetup/extend.js Outdated
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

carterworks has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

carterworks and others added 4 commits June 12, 2026 12:39
… CodeQL alert

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace the kndctr_/AMCV_ prefix allowlist with a generic clear-all so
new cookie helpers (e.g. setSecidCookie) don't leak identity state into
subsequent tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replace document.cookie reads/writes in the integration test helpers with
the async CookieStore API (cookieStore.set/get/getAll/delete). The set/get
helpers and per-test cleanup are now async; delete-by-path removes the
prior path-matching caveat.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@carterworks carterworks marked this pull request as draft June 15, 2026 16:38
@carterworks carterworks marked this pull request as ready for review June 15, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ignore-for-release Do not include this PR in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants