Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ class PaparazziPlugin : Plugin<Project> {
writeResourcesTask.flatMap { it.paparazziResources.asFile }.get().path
test.systemProperties["paparazzi.build.dir"] =
buildDirectory.get().toString()
test.systemProperties["kotlinx.coroutines.main.delay"] = true
test.systemProperties.putAll(project.properties.filterKeys { it.startsWith("app.cash.paparazzi") })

test.inputs.property("paparazzi.test.record", isRecordRun)
test.inputs.property("paparazzi.test.verify", isVerifyRun)

test.inputs.dir(mergeResourcesOutputDir)
test.inputs.dir(mergeAssetsOutputDir)
Expand All @@ -168,18 +173,16 @@ class PaparazziPlugin : Plugin<Project> {
test.outputs.dir(reportOutputDir)
test.outputs.dir(snapshotOutputDir)

val paparazziProperties = project.properties.filterKeys { it.startsWith("app.cash.paparazzi") }

@Suppress("ObjectLiteralToLambda")
// why not a lambda? See: https://docs.gradle.org/7.2/userguide/validation_problems.html#implementation_unknown
test.doFirst(object : Action<Task> {
override fun execute(t: Task) {
// Note: these are lazy properties that are not resolvable in the Gradle configuration phase.
// They need special handling, so they're added as inputs.property above, and systemProperty here.
test.systemProperties["paparazzi.platform.data.root"] =
nativePlatformFileCollection.singleFile.absolutePath
test.systemProperties["paparazzi.test.record"] = isRecordRun.get()
test.systemProperties["paparazzi.test.verify"] = isVerifyRun.get()
test.systemProperties["kotlinx.coroutines.main.delay"] = true
test.systemProperties.putAll(paparazziProperties)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,44 @@ class PaparazziPluginTest {
snapshotsDir.deleteRecursively()
}

@Test
fun rerunTestsOnPropertyChange() {
val fixtureRoot = File("src/test/projects/rerun-property-change")

// Take 1
val firstRunResult = gradleRunner
.withArguments("testDebugUnitTest", "--stacktrace")
.forwardOutput()
.runFixture(fixtureRoot) { build() }

with(firstRunResult.task(":testDebugUnitTest")) {
assertThat(this).isNotNull()
assertThat(this!!.outcome).isEqualTo(SUCCESS)
}

// Take 2
val secondRunResult = gradleRunner
.withArguments("recordPaparazziDebug", "--stacktrace")
.forwardOutput()
.runFixture(fixtureRoot) { build() }

with(secondRunResult.task(":testDebugUnitTest")) {
assertThat(this).isNotNull()
assertThat(this!!.outcome).isEqualTo(SUCCESS) // not UP-TO-DATE
}

// Take 3
val thirdRunResult = gradleRunner
.withArguments("verifyPaparazziDebug", "--stacktrace")
.forwardOutput()
.runFixture(fixtureRoot) { build() }

with(thirdRunResult.task(":testDebugUnitTest")) {
assertThat(this).isNotNull()
assertThat(this!!.outcome).isEqualTo(SUCCESS) // not UP-TO-DATE
}
}

@Test
fun verifySuccess() {
val fixtureRoot = File("src/test/projects/verify-mode-success")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'app.cash.paparazzi'
}

repositories {
maven {
url "file://${projectDir.absolutePath}/../../../../../build/localMaven"
}
mavenCentral()
//mavenLocal()
google()
}

android {
namespace 'app.cash.paparazzi.plugin.test'
compileSdk libs.versions.compileSdk.get() as int
defaultConfig {
minSdk libs.versions.minSdk.get() as int
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package app.cash.paparazzi.plugin.test

import android.view.View
import app.cash.paparazzi.Paparazzi
import org.junit.Rule
import org.junit.Test

class RecordTest {
@get:Rule
val paparazzi = Paparazzi()

@Test
fun record() {
paparazzi.snapshot(View(paparazzi.context))
}
}