Skip to content

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

Merged
Shivanshu-07 merged 4 commits into
mainfrom
PER-7348-readiness-in-serialize
May 27, 2026
Merged

feat: PER-7348 add waitForReady() call before serialize()#31
Shivanshu-07 merged 4 commits into
mainfrom
PER-7348-readiness-in-serialize

Conversation

@Shivanshu-07

Copy link
Copy Markdown
Contributor

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>
Shivanshu-07 and others added 3 commits May 22, 2026 12:21
- Replaced exclusive precedence (`if perSnapshot else fallback`) with
  shallow-merge in a new `resolveReadinessConfig` helper. Per-snapshot
  options["readiness"] keys win, global cliConfig.snapshot.readiness keys
  inherited — a partial per-snapshot override no longer silently drops a
  global preset:disabled kill switch.
- Strip `readiness` from `buildSnapshotJS` (consumed by waitForReady
  upstream, not a PercyDOM.serialize argument) and from `postSnapshot`
  JSON body (CLI already has it via healthcheck).

`mvn compile` passes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CLI 1.31.15-beta.0 ships PercyDOM.waitForReady (the readiness gate). The SDK changes in this PR call waitForReady end-to-end in tests; old CLI pins (1.30.9, 1.31.10) don't have it, causing the typeof guard's done() callback path to never quite settle in geckodriver's async-script handling. Bump so tests run against a CLI that actually has the feature.
@Shivanshu-07 Shivanshu-07 marked this pull request as ready for review May 26, 2026 04:13
@Shivanshu-07 Shivanshu-07 requested a review from a team as a code owner May 26, 2026 04:13
@Shivanshu-07 Shivanshu-07 merged commit 0cd8b5e into main May 27, 2026
12 checks passed
@Shivanshu-07 Shivanshu-07 deleted the PER-7348-readiness-in-serialize branch May 27, 2026 05:31
Shivanshu-07 added a commit that referenced this pull request May 27, 2026
Bump version to 1.2.1-beta.0 to ship the readiness gate (waitForReady
before serialize, PER-7348) merged in #31.

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.

2 participants