Skip to content

Commit

Permalink
Fix compare dir cache
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirom committed Dec 7, 2024
1 parent cc43b63 commit 8c1a94f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ class RoborazziGradleProjectTest {
checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png")
checkRecordedFileNotExists("app/$customDirFromGradle/$className.testCapture_compare.png")

// We should be able to use the cache
changeScreen()
removeRoborazziOutputDir()
compare()
checkRecordedFileExists("$screenshotAndName.testCapture_compare.png")
removeRoborazziOutputDir()
compare()

checkResultsSummaryFileExists()
Expand All @@ -190,8 +195,11 @@ class RoborazziGradleProjectTest {
checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png")

// We should be able to use the cache
removeCompareOutputDir()
removeRoborazziOutputDir()
compare()
removeRoborazziOutputDir()
val buildResult = compare()
assertSkipped(buildResult.output)

checkResultsSummaryFileExists()
checkRecordedFileExists("$screenshotAndName.testCapture.png")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ abstract class RoborazziPlugin : Plugin<Project> {
val outputDir =
extension.outputDir.convention(project.layout.buildDirectory.dir(DEFAULT_OUTPUT_DIR))
val compareOutputDir =
extension.compare.outputDir
extension.compare.outputDir.convention(project.layout.buildDirectory.dir(DEFAULT_OUTPUT_DIR))
val testTaskOutputDir: DirectoryProperty = project.objects.directoryProperty()
val intermediateDir =
testTaskOutputDir.convention(project.layout.buildDirectory.dir(DEFAULT_TEMP_DIR))
Expand Down Expand Up @@ -333,32 +333,30 @@ abstract class RoborazziPlugin : Plugin<Project> {
test.inputs.files(
imageInputProvider
)
if (compareOutputDir.isPresent) {
test.outputs.dirs(
compareOutputDir.flatMap { compareOutputDirValue: Directory ->
imageInputProvider
.map { imageInputProviderValue: FileCollection ->
// Check if the compare output directory is the same as the input directory
if (imageInputProviderValue.files.any {
if (it.isDirectory) {
it.absolutePath == compareOutputDirValue.asFile.absolutePath
} else {
it.parentFile.absolutePath == compareOutputDirValue.asFile.absolutePath
}
}) {
outputDir.files(/* empty files */)
} else {
if (!compareOutputDirValue.asFile.exists()) {
compareOutputDirValue.asFile.mkdirs()
test.outputs.dirs(
compareOutputDir.flatMap { compareOutputDirValue: Directory ->
imageInputProvider
.map { imageInputProviderValue: FileCollection ->
// Check if the compare output directory is the same as the input directory
if (imageInputProviderValue.files.any {
if (it.isDirectory) {
it.absolutePath == compareOutputDirValue.asFile.absolutePath
} else {
it.parentFile.absolutePath == compareOutputDirValue.asFile.absolutePath
}
compareOutputDirValue
}) {
outputDir.files(/* empty files */)
} else {
if (!compareOutputDirValue.asFile.exists()) {
compareOutputDirValue.asFile.mkdirs()
}
compareOutputDirValue
}
}.map {
test.infoln("Roborazzi: Set output files ${it} to test task")
it
})
}
}
}.map {
test.infoln("Roborazzi: Set output files ${it} to test task")
it
})
test.outputs.dir(intermediateDirForEachVariant.map {
test.infoln("Roborazzi: Set output dir $it to test task")
it
Expand Down

0 comments on commit 8c1a94f

Please sign in to comment.