diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a174da2..8e511d1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -413,6 +413,9 @@ One removal 2.0 cannot warn about, written down instead: the legacy `LOADED_DRIV `skip_stack_frames: 1` (see docs/configuration.md) - **RSpec prints a failed screenshot once.** The adapter re-raised it inside a `rescue`, so RSpec repeated the whole failure under `Caused by:` +- **A size change labels its images like every other failure.** `Dimensions have + changed` now lists `baseline:` and `actual:`, relative to the project root, instead of + two bare absolute paths, and never names annotations left over from an earlier run ### Known limitations - **One process per worker** (`parallel_tests`, RSpec, CI sharding) still writes one diff --git a/lib/snap_diff/reporters/default.rb b/lib/snap_diff/reporters/default.rb index dbe1988d..021a9fa8 100644 --- a/lib/snap_diff/reporters/default.rb +++ b/lib/snap_diff/reporters/default.rb @@ -51,8 +51,10 @@ def annotate_and_save_images annotation_service.annotate_and_save_images end + # Images of different sizes are never annotated, so only the two inputs + # are listed: annotations on disk are leftovers from an earlier failure. def build_error_for_different_dimensions - "Dimensions have changed: #{dimension_change}\n#{base_image_path.to_path}\n#{image_path.to_path}" + ["Dimensions have changed: #{dimension_change}", *artifact_lines(INPUT_ARTIFACTS)].join(NEW_LINE) end # "WxH => WxH", baseline first. Public so Reporters::HTML says it the @@ -93,6 +95,8 @@ def self.percent(fraction) "heatmap" => :heatmap_diff_path }.freeze + INPUT_ARTIFACTS = ARTIFACT_LABELS.slice("baseline", "actual").freeze + def build_error_message [headline, *metric_lines, *artifact_lines].join(NEW_LINE) end @@ -138,8 +142,8 @@ def thresholds # Only what is on disk gets a line: the heatmap exists solely for # drivers that produce a diff mask, and a comparison can be reported # before either input has been written out. - def artifact_lines - present = ARTIFACT_LABELS.filter_map do |label, path_method| + def artifact_lines(labels = ARTIFACT_LABELS) + present = labels.filter_map do |label, path_method| path = send(path_method) [label, path] if path.exist? end diff --git a/test/unit/reporters/default_test.rb b/test/unit/reporters/default_test.rb index fd33ae63..fdace459 100644 --- a/test/unit/reporters/default_test.rb +++ b/test/unit/reporters/default_test.rb @@ -161,6 +161,24 @@ class DefaultReporterTest < ActiveSupport::TestCase end end + # A size change draws no annotations, so its message lists only the two + # inputs, even when an earlier same-size failure left annotations on disk. + test "a size change labels its two inputs like any other failure" do + base = @_tmpdir / "header.base.png" + new = @_tmpdir / "header.png" + FileUtils.cp(TEST_IMAGES_DIR / "a.png", base) + FileUtils.cp(TEST_IMAGES_DIR / "a_cropped.png", new) + %w[header.diff.png header.base.diff.png header.heatmap.diff.png].each { |stale| FileUtils.touch(@_tmpdir / stale) } + + with_config_root(@_tmpdir) do + assert_equal <<~MESSAGE.chomp, SnapDiff::Comparison.new(new, base).processed.error_message + Dimensions have changed: 80x80 => 80x60 + baseline: header.base.png + actual: header.png + MESSAGE + end + end + private def with_config_root(root)