Skip to content

feat(snapshot): Add Compose preview snapshot testing plugin#1083

Draft
runningcode wants to merge 7 commits intomainfrom
no/compose-preview-snapshot-plugin
Draft

feat(snapshot): Add Compose preview snapshot testing plugin#1083
runningcode wants to merge 7 commits intomainfrom
no/compose-preview-snapshot-plugin

Conversation

@runningcode
Copy link
Contributor

@runningcode runningcode commented Feb 20, 2026

Summary

  • Add io.sentry.android.snapshot standalone Gradle plugin that automatically generates Paparazzi snapshot tests for all @Preview composables
  • Uses two-pass ASM bytecode scanning at build time to discover @Preview methods (including custom multi-preview annotations like @PreviewLightDark, @PreviewScreenSizes, etc.)
  • Generates a parameterized JUnit test that invokes each composable via reflection through Paparazzi
  • Supports both direct @Preview annotations, container annotations (@Previews), and custom meta-annotations

Architecture

compileDebugKotlin
        │
        ▼
sentryScanPreviewsDebug (two-pass ASM scan → previewConfigs.json)
        │
        ▼
testDebugUnitTest (Paparazzi)
  └── SentrySnapshotTest.kt (reads JSON, invokes previews via reflection)

Usage

Applied as a standalone plugin (requires Paparazzi):

plugins {
    id("io.sentry.android.snapshot")
    id("app.cash.paparazzi")
}

sentry {
  snapshots {
    // optional:
    // includePrivatePreviews.set(true)
    // variant.set("debug")
  }
}
./gradlew recordPaparazziDebug    # Record golden snapshots
./gradlew verifyPaparazziDebug    # Verify against goldens

🤖 Generated with Claude Code

@github-actions
Copy link
Contributor

github-actions bot commented Feb 20, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (snapshot) Add Compose preview snapshot testing plugin by runningcode in #1083
  • (snapshots) Wire VCS extension to snapshots upload task by runningcode in #1102

Internal Changes 🔧

Deps

  • Update Android SDK to v8.35.0 by github-actions in #1104
  • Bump getsentry/craft from 2.23.1 to 2.24.1 by dependabot in #1103
  • Bump dorny/paths-filter from 3.0.2 to 4.0.0 by dependabot in #1106
  • Update CLI to v3.3.3 by github-actions in #1101

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 20, 2026

Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Features

- Add Compose preview snapshot testing plugin ([#1083](https://github.com/getsentry/sentry-android-gradle-plugin/pull/1083))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against a155982

@runningcode runningcode force-pushed the no/compose-preview-snapshot-plugin branch 2 times, most recently from c7d5b04 to 8988325 Compare March 16, 2026 10:16
runningcode and others added 4 commits March 16, 2026 16:43
Add `io.sentry.android.snapshot` Gradle plugin that automatically
generates Paparazzi snapshot tests for all @Preview composables.

The plugin uses a two-phase approach:
1. Build time: ASM scans compiled .class files to discover @Preview
   methods (including custom multi-preview annotations) and writes
   a JSON config file
2. Test time: A generated parameterized JUnit test reads the config,
   invokes each composable via reflection, and captures snapshots
   through Paparazzi

Usage:
```kotlin
sentry {
  snapshots {
    enabled.set(true)
  }
}
```

Then run `./gradlew recordPaparazziDebug` to record golden snapshots
or `./gradlew verifyPaparazziDebug` to verify against them.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove the afterEvaluate block in SentryPlugin that auto-applied the
snapshot plugin, and remove the SentryPluginExtension fallback in
SentrySnapshotPlugin. The snapshot plugin is now fully standalone with
its own sentrySnapshots extension.

Also add IDE-specific files to .gitignore.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@runningcode runningcode force-pushed the no/compose-preview-snapshot-plugin branch from 86380ad to c887b44 Compare March 16, 2026 15:44
runningcode and others added 3 commits March 16, 2026 18:02
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
These properties were never read from the extension — the upload task
gets appId from the Android variant and path from its own output dir.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was only used by the SentryPlugin.afterEvaluate block that
auto-applied the snapshot plugin. Now that the plugin is standalone,
users apply it explicitly and this flag serves no purpose.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant