Skip to content

Add support for new PreviewWrapper in snapshot tests - #8

Merged
mottljan merged 8 commits into
mainfrom
feat/preview-wrapper
Sep 7, 2026
Merged

mottljan merged 8 commits into
mainfrom
feat/preview-wrapper

Conversation

@mottljan

@mottljan mottljan commented Sep 3, 2026

Copy link
Copy Markdown
Contributor
  • library automatically discovers the annotation and uses it to wrap the preview generated in snapshot test
  • backward-compatible change - previews without PreviewWrapper works as before
  • feature is enabled by default, but can be turned off or customized in case of potential issues in the future

mottljan1 and others added 8 commits September 3, 2026 15:43
Compose UI 1.12.0 adds the ANNOTATION_CLASS target to @PreviewWrapper,
which upcoming @PreviewWrapper support needs. ASM and ui-tooling-preview
become implementation dependencies of :framework so they reach consumers'
test classpaths transitively.

Goldens are unchanged: the bump moves no pixels.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Resolves androidx @PreviewWrapper on Showkase-discovered previews. The
annotation has BINARY retention, so it is invisible to reflection and
must be read from class-file bytes with ASM: a component's Showkase key
maps to its generated host class, from there to the declaring function,
whose runtime-invisible annotations are read (following custom preview
annotations recursively and cycle-safely).

Adds the public PreviewWrappers / PreviewFunction value types and the
internal framework.wrapper pipeline. Nothing is wired into the DSL or
the resolver yet.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Extracts the annotation reader's private byte cache into a
CachingClassBytesSource decorator shared with the call finder, so a
class read during call finding is not read again while reading
annotations. Adds shared name-conversion helpers and a parsing-options
constant to Bytecode.kt.

Chains ASM's refusal as the cause of UnsupportedClassFileException
rather than dropping it, with a test pinning that the translated
message stays free of the cause's near-identical text.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Adds the previewWrappers(...) DSL entry and carries the setting through
SnapshotConfig. SnapshotResolver runs the wrapper pipeline once per
tagged preview and attaches the resolved factory to each of its
variants; resolution failures join the existing aggregated
SnapshotConfigException. AckeeSnapshotTests creates one wrapper per
snapshot and composes decorate -> density -> Wrap -> content, so
previews without a wrapper render exactly as before.

The primary constructor becomes internal to allow injecting a resolver
in tests; internal constructors are excluded from the ABI dump, so the
public surface is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Dispatches the resolution once instead of testing it twice, drops the
unused default on ResolvedSnapshot.wrapper, and hoists the duplicated
resolver-factory test helper into Factories.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Adds two sample wrappers reading MaterialTheme colours, previews using
them directly and through a custom preview annotation, an unwrapped
control, and object-nested and @PreviewParameter shape controls that
exercise the mapper against real Showkase codegen. The 11 recorded
goldens are the only regression net for the render-time nesting, which
no unit test can reach; the dark ones show the wrapper picking up the
dark scheme, proving decorate sits outside it.

All 60 pre-existing goldens are unchanged.

Documents the feature in the README and CHANGELOG and bumps the
framework, paparazzi and BOM versions.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Replaces LabelledFrame's boolean flag with a Color parameter defaulting
to the primary scheme colour. Both wrappers read MaterialTheme in the
same composition, so the rendered output is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@mottljan
mottljan requested a review from petrs143 September 3, 2026 19:57
@mottljan mottljan self-assigned this Sep 3, 2026
@mottljan
mottljan merged commit 9c3e812 into main Sep 7, 2026
1 check passed
@mottljan
mottljan deleted the feat/preview-wrapper branch September 7, 2026 09:46
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.

3 participants