Skip to content

feat: PER-7348 add waitForReady() call before serialize()#31

Draft
Shivanshu-07 wants to merge 1 commit intomainfrom
PER-7348-readiness-in-serialize
Draft

feat: PER-7348 add waitForReady() call before serialize()#31
Shivanshu-07 wants to merge 1 commit intomainfrom
PER-7348-readiness-in-serialize

Conversation

@Shivanshu-07
Copy link
Copy Markdown

Summary

Adopts the readiness gate from percy/cli#2184 (PER-7348). New waitForReady(options) helper runs PercyDOM.waitForReady(config) via page.evaluate inside getSerializedDOM. Playwright auto-awaits the returned Promise. The result (readiness diagnostics) is attached to the mutable domSnapshot map as readiness_diagnostics. The PercyDOM.serialize call is unchanged.

Contract

  • Config precedence: options["readiness"]cliConfig.snapshot.readiness → empty (CLI applies balanced default)
  • Backward compat: in-browser typeof PercyDOM.waitForReady === 'function' guard
  • Disabled preset short-circuits (no page.evaluate at all)
  • Graceful: any exception is swallowed at debug level; serialize still runs

Tests

Three new tests in SDKTest using Mockito:

  • readinessRunsBeforeSerializeAndAttachesDiagnostics — waitForReady JS sent via the 2-arg evaluate overload, diagnostics propagated to the snapshot
  • readinessSkippedWhenPresetDisabledreadiness: { preset: 'disabled' } → no 2-arg evaluate, no diagnostics
  • snapshotSurvivesReadinessThrow — readiness evaluate throws → serialize still runs, no diagnostics attached

Test results

Check Status Notes
Compile (mvn compile + test-compile) ✅ pass
Unit tests (mvn test -Dtest=...) 3 passed, 0 failed Ran only the new readiness tests locally
Smoke test (example-percy-playwright-java) ⚠️ skipped: toolchain missing Example needs Playwright browser install

Related

Adds the readiness gate from percy/cli#2184. New waitForReady() helper
runs PercyDOM.waitForReady before the existing PercyDOM.serialize
page.evaluate inside getSerializedDOM. Playwright auto-awaits the
returned Promise. Diagnostics are attached to the mutable domSnapshot as
readiness_diagnostics so the CLI can log timing and pass/fail.

Config precedence: options['readiness'] > cliConfig.snapshot.readiness >
empty (CLI applies balanced default). Backward compat via in-browser
typeof PercyDOM.waitForReady === 'function' guard. Disabled preset
short-circuits. Any exception is swallowed at debug level.

Tests (Mockito): diagnostics attached + readiness JS sent, disabled
preset skips the evaluate, and readiness throw leaves the serialize path
intact. Local: mvn test → 3 passed, 0 failed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant