diff --git a/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProject.kt b/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProject.kt index 1b17f18a..1f3ffaed 100644 --- a/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProject.kt +++ b/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProject.kt @@ -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): BuildResult { + fun runTask( + task: String, + buildType: BuildType, + additionalParameters: Array + ): BuildResult { val buildResult = GradleRunner.create() .withProjectDir(testProjectDir.root) .withArguments( @@ -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( @@ -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) @@ -181,7 +195,7 @@ class AppModule(val rootProject: RoborazziGradleRootProject, val testProjectDir: buildGradle.addIncludeBuild() val buildResult = rootProject.runTask( - "app:"+task, + "app:" + task, buildType, additionalParameters ) @@ -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() { @@ -300,14 +315,6 @@ dependencies { """.trimIndent() ) } - buildFile.appendText( - """ - - roborazzi { - deleteOldScreenshots = true - } - """.trimIndent() - ) } } @@ -329,7 +336,7 @@ dependencies { fun checkResultsSummaryFileNotExists() { val recordedFile = testProjectDir.root.resolve("app/$buildDirName/test-results/roborazzi/results-summary.json") - assert(!recordedFile.exists()) { + assert(! recordedFile.exists()) { "File exists: ${recordedFile.absolutePath}" } } @@ -367,7 +374,7 @@ dependencies { fun checkRecordedFileNotExists(path: String) { val recordedFile = testProjectDir.root.resolve(path) - assert(!recordedFile.exists()) { + assert(! recordedFile.exists()) { "File exists: $path" } } diff --git a/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProjectTest.kt b/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProjectTest.kt index f6e2e70c..a80e69a0 100644 --- a/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProjectTest.kt +++ b/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProjectTest.kt @@ -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") diff --git a/include-build/roborazzi-gradle-plugin/src/main/java/io/github/takahirom/roborazzi/RoborazziPlugin.kt b/include-build/roborazzi-gradle-plugin/src/main/java/io/github/takahirom/roborazzi/RoborazziPlugin.kt index f2a11068..720f3f5e 100644 --- a/include-build/roborazzi-gradle-plugin/src/main/java/io/github/takahirom/roborazzi/RoborazziPlugin.kt +++ b/include-build/roborazzi-gradle-plugin/src/main/java/io/github/takahirom/roborazzi/RoborazziPlugin.kt @@ -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 = objects.property(Boolean::class.java) - .convention(false) - @ExperimentalRoborazziApi val generateComposePreviewRobolectricTests: GenerateComposePreviewRobolectricTestsExtension = objects.newInstance(GenerateComposePreviewRobolectricTestsExtension::class.java) @@ -297,7 +292,7 @@ abstract class RoborazziPlugin : Plugin { 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 = outputDir.get().asFile .listFiles()