Skip to content

Commit 49b5b45

Browse files
TWiStErRobjrodbx
andcommitted
Add failing tests that reproduce the problem where the record and verify parameters are not playing in up to date checks and fix by registering inputs explicitly.
Co-authored-by: John Rodriguez <john.rodriguez@gmail.com>
1 parent 7e5dea4 commit 49b5b45

File tree

7 files changed

+135
-0
lines changed

7 files changed

+135
-0
lines changed

paparazzi/paparazzi-gradle-plugin/src/main/java/app/cash/paparazzi/gradle/PaparazziPlugin.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ class PaparazziPlugin : Plugin<Project> {
164164

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

167+
// Explicitly register these as inputs so that they are considered when determining up-to-date.
168+
// The properties become resolvable after the last afterEvaluate runs.
169+
test.inputs.property("paparazzi.test.record", isRecordRun)
170+
test.inputs.property("paparazzi.test.verify", isVerifyRun)
171+
167172
@Suppress("ObjectLiteralToLambda")
168173
// why not a lambda? See: https://docs.gradle.org/7.2/userguide/validation_problems.html#implementation_unknown
169174
test.doFirst(object : Action<Task> {

paparazzi/paparazzi-gradle-plugin/src/test/java/app/cash/paparazzi/gradle/PaparazziPluginTest.kt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,60 @@ class PaparazziPluginTest {
476476
snapshotsDir.deleteRecursively()
477477
}
478478

479+
@Test
480+
fun rerunTestsOnRecordPropertyChange() {
481+
val fixtureRoot = File("src/test/projects/rerun-after-test-record")
482+
483+
// Take 1
484+
val firstRunResult = gradleRunner
485+
.withArguments("testDebugUnitTest", "--stacktrace")
486+
.forwardOutput()
487+
.runFixture(fixtureRoot) { build() }
488+
489+
with(firstRunResult.task(":testDebugUnitTest")) {
490+
assertThat(this).isNotNull()
491+
assertThat(this!!.outcome).isEqualTo(SUCCESS)
492+
}
493+
494+
// Take 2
495+
val secondRunResult = gradleRunner
496+
.withArguments("recordPaparazziDebug", "--stacktrace")
497+
.forwardOutput()
498+
.runFixture(fixtureRoot) { build() }
499+
500+
with(secondRunResult.task(":testDebugUnitTest")) {
501+
assertThat(this).isNotNull()
502+
assertThat(this!!.outcome).isEqualTo(SUCCESS) // not UP-TO-DATE
503+
}
504+
}
505+
506+
@Test
507+
fun rerunTestsOnVerifyPropertyChange() {
508+
val fixtureRoot = File("src/test/projects/rerun-after-test-verify")
509+
510+
// Take 1
511+
val firstRunResult = gradleRunner
512+
.withArguments("testDebugUnitTest", "--stacktrace")
513+
.forwardOutput()
514+
.runFixture(fixtureRoot) { build() }
515+
516+
with(firstRunResult.task(":testDebugUnitTest")) {
517+
assertThat(this).isNotNull()
518+
assertThat(this!!.outcome).isEqualTo(SUCCESS)
519+
}
520+
521+
// Take 2
522+
val secondRunResult = gradleRunner
523+
.withArguments("verifyPaparazziDebug", "--stacktrace")
524+
.forwardOutput()
525+
.runFixture(fixtureRoot) { build() }
526+
527+
with(secondRunResult.task(":testDebugUnitTest")) {
528+
assertThat(this).isNotNull()
529+
assertThat(this!!.outcome).isEqualTo(SUCCESS) // not UP-TO-DATE
530+
}
531+
}
532+
479533
@Test
480534
fun verifySuccess() {
481535
val fixtureRoot = File("src/test/projects/verify-mode-success")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
id 'com.android.library'
3+
id 'kotlin-android'
4+
id 'app.cash.paparazzi'
5+
}
6+
7+
repositories {
8+
maven {
9+
url "file://${projectDir.absolutePath}/../../../../../build/localMaven"
10+
}
11+
mavenCentral()
12+
//mavenLocal()
13+
google()
14+
}
15+
16+
android {
17+
namespace 'app.cash.paparazzi.plugin.test'
18+
compileSdk libs.versions.compileSdk.get() as int
19+
defaultConfig {
20+
minSdk libs.versions.minSdk.get() as int
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package app.cash.paparazzi.plugin.test
2+
3+
import android.view.View
4+
import app.cash.paparazzi.Paparazzi
5+
import org.junit.Rule
6+
import org.junit.Test
7+
8+
class RecordTest {
9+
@get:Rule
10+
val paparazzi = Paparazzi()
11+
12+
@Test
13+
fun record() {
14+
paparazzi.snapshot(View(paparazzi.context))
15+
}
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
id 'com.android.library'
3+
id 'kotlin-android'
4+
id 'app.cash.paparazzi'
5+
}
6+
7+
repositories {
8+
maven {
9+
url "file://${projectDir.absolutePath}/../../../../../build/localMaven"
10+
}
11+
mavenCentral()
12+
//mavenLocal()
13+
google()
14+
}
15+
16+
android {
17+
namespace 'app.cash.paparazzi.plugin.test'
18+
compileSdk libs.versions.compileSdk.get() as int
19+
defaultConfig {
20+
minSdk libs.versions.minSdk.get() as int
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package app.cash.paparazzi.plugin.test
2+
3+
import android.view.View
4+
import app.cash.paparazzi.Paparazzi
5+
import org.junit.Rule
6+
import org.junit.Test
7+
8+
class RecordTest {
9+
@get:Rule
10+
val paparazzi = Paparazzi()
11+
12+
@Test
13+
fun record() {
14+
paparazzi.snapshot(View(paparazzi.context))
15+
}
16+
}
6.65 KB
Loading

0 commit comments

Comments
 (0)