-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add preview test #97
Merged
+308
−5
Merged
Add preview test #97
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
f483c93
add paparazzi & showcase
sobaya-0141 48802bb
add test module
sobaya-0141 df249fe
add preview parameter
sobaya-0141 5fd9475
fixed spotless
sobaya-0141 94224d0
fixed sdk32
sobaya-0141 d133d4c
test record snapshots
sobaya-0141 23ac965
Merge branch 'main' into add_preview_test
sobaya-0141 01b8392
remove record snapshots
sobaya-0141 1809b9c
use snapshot1.1.0
sobaya-0141 93208e4
Just use 31
takahirom 9373776
add workflow
sobaya-0141 f3248d6
Merge branch 'main' into add_preview_test
sobaya-0141 19bef16
remove screenshot test in Build.yml
sobaya-0141 bc17d49
Merge branch 'main' into add_preview_test
sobaya-0141 50e642b
fixded review comment
sobaya-0141 38f01f1
update screenshots
sobaya-0141 69ae467
Merge branch 'main' into add_preview_test
sobaya-0141 dff7c71
revert UpdateScreenshots.yml
sobaya-0141 a31ddd4
Merge branch 'main' into add_preview_test
sobaya-0141 cdea948
fixed build error
sobaya-0141 b487928
Merge branch 'main' into add_preview_test
takahirom 0d8f6ef
update setup-java version
sobaya-0141 f6debee
Fix JDK setup error
aqua-ix 8dce810
Fix showkase build error
aqua-ix eece508
Migrate to primitive plugins
aqua-ix 513aaa2
Remove unused attributes
aqua-ix a675e42
Merge pull request #467 from aqua-ix/refine-preview-test
takahirom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
on: | ||
pull_request: | ||
|
||
jobs: | ||
screenshot-test: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 60 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Validate Gradle Wrapper | ||
uses: gradle/wrapper-validation-action@v1 | ||
|
||
- name: Copy CI gradle.properties | ||
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties | ||
|
||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: temurin | ||
java-version: 11 | ||
|
||
- name: Setup Gradle | ||
uses: gradle/gradle-build-action@v2 | ||
|
||
- name: Download Screenshots | ||
id: download-artifact | ||
uses: dawidd6/action-download-artifact@v2 | ||
with: | ||
workflow: UpdateScreenshots.yml | ||
name: screenshots | ||
path: preview-screenshots/src/test/snapshots/images | ||
|
||
- name: Run screenshot tests | ||
id: verifyPaparazziDebug | ||
continue-on-error: true | ||
run: ./gradlew preview-screenshots:verifyPaparazziDebug | ||
|
||
- name: Error Screenshot tests | ||
if: ${{ hashFiles('preview-screenshots/out/failures/*.png') != '' }} | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: scrennshot-test-results | ||
path: preview-screenshots/out/failures | ||
|
||
- name: Comment PR | ||
if: ${{ hashFiles('preview-screenshots/out/failures/*.png') != '' }} | ||
uses: thollander/actions-comment-pull-request@v1 | ||
with: | ||
message: | | ||
There are differences in Compose previews. Please check your build and download the diff artifact. | ||
https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
types: [closed] | ||
|
||
jobs: | ||
update-screenshot: | ||
runs-on: ubuntu-latest | ||
if: github.event.pull_request.merged == true | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
- name: Run Update Screenshots | ||
run: ./gradlew recordPaparazziDebug | ||
|
||
- name: Upload Screenshots | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: screenshots | ||
path: preview-screenshots/src/test/snapshots/images | ||
retention-days: 15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...e/plugins/src/main/kotlin/io/github/droidkaigi/confsched2022/primitive/PaparazziPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.github.droidkaigi.confsched2022.primitive | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
|
||
@Suppress("unused") | ||
class PaparazziPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
pluginManager.apply("app.cash.paparazzi") | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...le/plugins/src/main/kotlin/io/github/droidkaigi/confsched2022/primitive/ShowkasePlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.github.droidkaigi.confsched2022.primitive | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.gradle.kotlin.dsl.get | ||
|
||
@Suppress("unused") | ||
class ShowkasePlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("com.google.devtools.ksp") | ||
} | ||
dependencies { | ||
implementation(libs.findLibrary("showkaseRuntime")) | ||
ksp(libs.findLibrary("showkaseProcessor")) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed | ||
plugins { | ||
id("droidkaigi.primitive.android") | ||
id("droidkaigi.primitive.android.kotlin") | ||
id("droidkaigi.primitive.android.compose") | ||
id("droidkaigi.primitive.molecule") | ||
id("droidkaigi.primitive.spotless") | ||
id("droidkaigi.primitive.android.compose.showkase") | ||
id("droidkaigi.primitive.android.paparazzi") | ||
} | ||
|
||
android.namespace = "io.github.droidkaigi.confsched2022.template.preview.screenshots" | ||
|
||
androidComponents { | ||
// Disable release builds for this test-only library, no need to run screenshot tests more than | ||
// once | ||
beforeVariants(selector().withBuildType("release")) { builder -> | ||
builder.enable = false | ||
} | ||
beforeVariants(selector().withBuildType("prod")) { builder -> | ||
builder.enable = false | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation(project(":core-ui")) | ||
implementation(project(":feature-contributors")) | ||
implementation(project(":feature-sessions")) | ||
|
||
implementation(libs.composeUi) | ||
|
||
testImplementation(projects.coreTesting) | ||
testImplementation(libs.testParameterInjector) | ||
} | ||
|
||
tasks.named("check") { | ||
dependsOn("verifyPaparazziDemoDebug") | ||
} | ||
|
||
tasks.withType<Test>().configureEach { | ||
// Increase memory for Paparazzi tests | ||
maxHeapSize = "2g" | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
79 changes: 79 additions & 0 deletions
79
...ew-screenshots/src/test/java/io/github/droidkaigi/confsched2022/PreviewScreenshotTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package io.github.droidkaigi.confsched2022 | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.platform.LocalInspectionMode | ||
import androidx.compose.ui.unit.Density | ||
import app.cash.paparazzi.DeviceConfig | ||
import app.cash.paparazzi.Paparazzi | ||
import app.cash.paparazzi.androidHome | ||
import app.cash.paparazzi.detectEnvironment | ||
import com.airbnb.android.showkase.models.Showkase | ||
import com.airbnb.android.showkase.models.ShowkaseBrowserComponent | ||
import com.google.testing.junit.testparameterinjector.TestParameter | ||
import com.google.testing.junit.testparameterinjector.TestParameter.TestParameterValuesProvider | ||
import com.google.testing.junit.testparameterinjector.TestParameterInjector | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
class ComponentPreview( | ||
private val showkaseBrowserComponent: ShowkaseBrowserComponent | ||
) { | ||
val content: @Composable () -> Unit = showkaseBrowserComponent.component | ||
override fun toString(): String = showkaseBrowserComponent.componentKey | ||
} | ||
|
||
@RunWith(TestParameterInjector::class) | ||
class PreviewScreenshotTests { | ||
|
||
object PreviewProvider : TestParameterValuesProvider { | ||
override fun provideValues(): List<ComponentPreview> = | ||
Showkase.getMetadata().componentList.map(::ComponentPreview) | ||
} | ||
|
||
enum class BaseDeviceConfig( | ||
val deviceConfig: DeviceConfig, | ||
) { | ||
NEXUS_5(DeviceConfig.NEXUS_5), | ||
PIXEL_5(DeviceConfig.PIXEL_5), | ||
PIXEL_C(DeviceConfig.PIXEL_C), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, sorry. I never know the Pixel C is tablet device...! bit old device than my engineer life...! |
||
} | ||
|
||
@get:Rule | ||
val paparazzi = Paparazzi( | ||
environment = detectEnvironment().copy( | ||
platformDir = "${androidHome()}/platforms/android-31", | ||
compileSdkVersion = 31 | ||
), | ||
maxPercentDifference = 0.0, | ||
) | ||
|
||
@Test | ||
fun preview_tests( | ||
@TestParameter(valuesProvider = PreviewProvider::class) componentPreview: ComponentPreview, | ||
@TestParameter baseDeviceConfig: BaseDeviceConfig, | ||
@TestParameter(value = ["1.0", "1.5"]) fontScale: Float | ||
) { | ||
paparazzi.unsafeUpdateConfig( | ||
baseDeviceConfig.deviceConfig.copy( | ||
softButtons = false, | ||
) | ||
) | ||
paparazzi.snapshot { | ||
CompositionLocalProvider( | ||
LocalInspectionMode provides true, | ||
LocalDensity provides Density( | ||
density = LocalDensity.current.density, | ||
fontScale = fontScale | ||
) | ||
) { | ||
Box { | ||
componentPreview.content() | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for confirmation 👀 , is Paparazzi possible to working with JUnit5? 🤔 if possible, other engineer can use modern toolchain...! ✨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't check this one.
I would like to get it working first.:pray: