Skip to content

Add childCountScreenshotTest: screenshot after waiting for children to mount#114

Open
EmilioBejasa wants to merge 6 commits into
mainfrom
child-count-screenshot-test
Open

Add childCountScreenshotTest: screenshot after waiting for children to mount#114
EmilioBejasa wants to merge 6 commits into
mainfrom
child-count-screenshot-test

Conversation

@EmilioBejasa
Copy link
Copy Markdown
Collaborator

Summary

Stacked on #113.

Adds childCountScreenshotTest to IsolatedTest: the same view.post polling mechanism from childCountTest is used to wait for Fabric to mount children before calling Screenshot.snap(). This guarantees the screenshot is never blank.

The screenshot is taken on the test thread (not inside runOnMainSync) so the JUnit runner context is intact and the file is named correctly.

Recorded result: renders "Hello" as expected.

Test plan

  • childCountScreenshotTest passes
  • recordDebugAndroidTestScreenshotTest produces a non-blank screenshot named com.rnstorybookautoscreenshots.IsolatedTest_childCountScreenshotTest
  • verifyDebugAndroidTestScreenshotTest passes

🤖 Generated with Claude Code

EmilioBejasa and others added 2 commits April 13, 2026 17:52
…ith view.post check

- Remove ViewHelpers from constructViewTest and childCountTest (IsolatedTest.kt)
  and testSimpleTextView (ScreenshotTest.kt); use explicit measure()/layout() calls
- Replace 30s poll loop in childCountTest with a self-rescheduling Runnable posted
  via view.post(), driven by the main-thread Handler that WindowAttachment.dispatchAttach
  installs in AttachInfo; block test thread on CompletableFuture.get(5s)
- Remove childCountScreenshotTest (duplicate of childCountTest + screenshot)
- assertGoodTask now captures and awaits startTask so the bg executor is drained
  before the future is polled

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…o mount

Uses the same view.post polling mechanism as childCountTest to wait for Fabric
to mount children before snapping the screenshot, ensuring the result is never blank.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@EmilioBejasa EmilioBejasa changed the base branch from assert-child-count to main April 13, 2026 22:13
@EmilioBejasa EmilioBejasa requested a review from tdrhq April 13, 2026 22:49
val view = surface.view!! as ViewGroup
var detacher: WindowAttachment.Detacher? = null
var startTask: TaskInterface<Void>? = null
val childrenMounted = CompletableFuture<Unit>()
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.

this is still using concurrency to coordinate between the threads.

val check = object : Runnable {
override fun run() {
if (view.childCount > 0) childrenMounted.complete(Unit)
else view.postDelayed(this, 50)
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.

this is just a different way of writing the previous loop

EmilioBejasa and others added 3 commits April 14, 2026 15:45
The previous version duplicated childCountTest's CompletableFuture
coordination and view.postDelayed polling. Use prerender()+start()
directly, matching the pattern of constructViewTest.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
One runOnMainSync for all setup + start(). waitUntil polls until
children are mounted (exits immediately on success, 5s timeout),
replacing the CompletableFuture + postDelayed loop from childCountTest.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Use dispatchAttach + onHostResume + waitUntil so Fabric mounts children
before the screenshot is taken. Previously the screenshot was blank.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@EmilioBejasa EmilioBejasa requested a review from tdrhq April 14, 2026 21:06
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