Skip to content

Commit

Permalink
Merge pull request #616 from pedromfmachado/delete-existing-intermedi…
Browse files Browse the repository at this point in the history
…ates-before-caching

Removing files from intermediate dir to prevent old screenshots from reappearing
  • Loading branch information
takahirom authored Dec 22, 2024
2 parents 64ab45f + c9c702b commit f6f9324
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -607,4 +607,39 @@ class RoborazziGradleProjectTest {
checkResultCount(recorded = 1)
}
}
}

@Test
fun shouldNotRetainOutdatedImagesWhenRecording() {
RoborazziGradleRootProject(testProjectDir).appModule.apply {
record().output.run(::assertNotSkipped)
checkRecordedFileExists("$screenshotAndName.testCapture.png")
checkRecordedFileNotExists("$screenshotAndName.testCapture1.png")
checkRecordedFileNotExists("$screenshotAndName.testCapture2.png")

removeTests()
addMultipleTest()
removeRoborazziOutputDir()

record().output.run(::assertNotSkipped)
checkRecordedFileNotExists("$screenshotAndName.testCapture.png")
checkRecordedFileExists("$screenshotAndName.testCapture1.png")
checkRecordedFileExists("$screenshotAndName.testCapture2.png")
}
}

@Test
fun shouldNotDeletePreviousImagesWhenFiltering() {
RoborazziGradleRootProject(testProjectDir).appModule.apply {
removeTests()
addMultipleTest()

recordWithFilter1().output.run(::assertNotSkipped)
checkRecordedFileExists("$screenshotAndName.testCapture1.png")
checkRecordedFileNotExists("$screenshotAndName.testCapture2.png")

recordWithFilter2().output.run(::assertNotSkipped)
checkRecordedFileExists("$screenshotAndName.testCapture1.png")
checkRecordedFileExists("$screenshotAndName.testCapture2.png")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -615,14 +615,19 @@ abstract class RoborazziPlugin : Plugin<Project> {
intermediateDir: DirectoryProperty,
roborazziResults: CaptureResults,
) {
if (roborazziProperties["roborazzi.cleanupOldScreenshots"] == "true") {
val isCleanupRun = roborazziProperties["roborazzi.cleanupOldScreenshots"] == "true"
val isRecordRun = test.systemProperties["roborazzi.test.record"] == true

if (isCleanupRun || isRecordRun) {
// Delete all images from the intermediateDir
intermediateDir.get().asFile.walkTopDown().forEach { file ->
if (KnownImageFileExtensions.contains(file.extension)) {
file.delete()
}
}
}

if (isCleanupRun) {
// Remove all files not in the results from the outputDir
val removingFiles: MutableSet<String> = outputDir.get().asFile
.listFiles()
Expand Down

0 comments on commit f6f9324

Please sign in to comment.