Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions lib/snap_diff/reporters/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions test/unit/reporters/default_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading