Skip to content

Commit

Permalink
Use gradle.properties and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirom committed Nov 4, 2024
1 parent f65e2f4 commit f38732a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class RoborazziGradleRootProject(val testProjectDir: TemporaryFolder) {
val appModule = AppModule(this, testProjectDir)
val previewModule = PreviewModule(this, testProjectDir)

fun runTask(task: String, buildType: BuildType, additionalParameters: Array<String>): BuildResult {
fun runTask(
task: String,
buildType: BuildType,
additionalParameters: Array<String>
): BuildResult {
val buildResult = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments(
Expand Down Expand Up @@ -60,6 +64,11 @@ class AppModule(val rootProject: RoborazziGradleRootProject, val testProjectDir:
return runTask(task)
}

fun recordWithDeleteOldScreenshots(): BuildResult {
val task = "recordRoborazziDebug"
return runTask(task, additionalParameters = arrayOf("-Proborazzi.deleteOldScreenshots=true"))
}

fun recordWithFilter1(): BuildResult {
val task = "recordRoborazziDebug"
return runTask(
Expand Down Expand Up @@ -136,6 +145,11 @@ class AppModule(val rootProject: RoborazziGradleRootProject, val testProjectDir:
return runTask(task)
}

fun compareWithDeleteOldScreenshots(): BuildResult {
val task = "compareRoborazziDebug"
return runTask(task, additionalParameters = arrayOf("-Proborazzi.deleteOldScreenshots=true"))
}

fun clear(): BuildResult {
val task = "clearRoborazziDebug"
return runTask(task)
Expand Down Expand Up @@ -181,7 +195,7 @@ class AppModule(val rootProject: RoborazziGradleRootProject, val testProjectDir:
buildGradle.addIncludeBuild()

val buildResult = rootProject.runTask(
"app:"+task,
"app:" + task,
buildType,
additionalParameters
)
Expand All @@ -192,8 +206,9 @@ class AppModule(val rootProject: RoborazziGradleRootProject, val testProjectDir:
private val PATH = "app/build.gradle.kts"
var removeOutputDirBeforeTestTypeTask = false
var customOutputDirPath: String? = null

init {
addIncludeBuild()
addIncludeBuild()
}

fun addIncludeBuild() {
Expand Down Expand Up @@ -300,14 +315,6 @@ dependencies {
""".trimIndent()
)
}
buildFile.appendText(
"""
roborazzi {
deleteOldScreenshots = true
}
""".trimIndent()
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,21 @@ class RoborazziGradleProjectTest {
}
}

@Test
fun compareWithDeleteOldScreenshot() {
RoborazziGradleRootProject(testProjectDir).appModule.apply {
recordWithDeleteOldScreenshots()
changeScreen()
compareWithDeleteOldScreenshots()

checkResultsSummaryFileExists()
checkRecordedFileExists("$screenshotAndName.testCapture.png")
checkResultFileExists(resultFileSuffix)
checkRecordedFileExists("$screenshotAndName.testCapture_compare.png")
checkRecordedFileExists("$screenshotAndName.testCapture_actual.png")
}
}

@Test
fun compareWithSystemParameter() {
println("start compareWithSystemParameter")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ private const val DEFAULT_TEMP_DIR = "intermediates/roborazzi"

open class RoborazziExtension @Inject constructor(objects: ObjectFactory) {
val outputDir: DirectoryProperty = objects.directoryProperty()

@ExperimentalRoborazziApi
val deleteOldScreenshots: Property<Boolean> = objects.property(Boolean::class.java)
.convention(false)

@ExperimentalRoborazziApi
val generateComposePreviewRobolectricTests: GenerateComposePreviewRobolectricTestsExtension =
objects.newInstance(GenerateComposePreviewRobolectricTestsExtension::class.java)
Expand Down Expand Up @@ -297,7 +292,7 @@ abstract class RoborazziPlugin : Plugin<Project> {
val roborazziResults = CaptureResults.from(results)
finalizeTestTask.infoln("Roborazzi: Save result to ${resultsSummaryFile.absolutePath} with results:${results.size} summary:${roborazziResults.resultSummary}")

if (extension.deleteOldScreenshots.get()) {
if (roborazziProperties["roborazzi.deleteOldScreenshots"] == true) {
// Remove all files not in the results
val removingFiles: MutableSet<String> = outputDir.get().asFile
.listFiles()
Expand Down

0 comments on commit f38732a

Please sign in to comment.