Write .new.png file if snapshot is missing (#7610)
We should write the .new.png whenever the test fails and snapshots aren't updated. Necessary for the kitdiff-snapshot-update-workflow to work
This commit is contained in:
parent
9e13889589
commit
32336e260b
|
|
@ -397,13 +397,24 @@ fn try_image_snapshot_options_impl(
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let write_new_png = || {
|
||||||
|
new.save(&new_path)
|
||||||
|
.map_err(|err| SnapshotError::WriteSnapshot {
|
||||||
|
err,
|
||||||
|
path: new_path.clone(),
|
||||||
|
})?;
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
|
||||||
let previous = match image::open(&snapshot_path) {
|
let previous = match image::open(&snapshot_path) {
|
||||||
Ok(image) => image.to_rgba8(),
|
Ok(image) => image.to_rgba8(),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// No previous snapshot - probablye a new test.
|
// No previous snapshot - probably a new test.
|
||||||
if mode.is_update() {
|
if mode.is_update() {
|
||||||
return update_snapshot();
|
return update_snapshot();
|
||||||
} else {
|
} else {
|
||||||
|
write_new_png()?;
|
||||||
|
|
||||||
return Err(SnapshotError::OpenSnapshot {
|
return Err(SnapshotError::OpenSnapshot {
|
||||||
path: snapshot_path.clone(),
|
path: snapshot_path.clone(),
|
||||||
err,
|
err,
|
||||||
|
|
@ -416,6 +427,8 @@ fn try_image_snapshot_options_impl(
|
||||||
if mode.is_update() {
|
if mode.is_update() {
|
||||||
return update_snapshot();
|
return update_snapshot();
|
||||||
} else {
|
} else {
|
||||||
|
write_new_png()?;
|
||||||
|
|
||||||
return Err(SnapshotError::SizeMismatch {
|
return Err(SnapshotError::SizeMismatch {
|
||||||
name,
|
name,
|
||||||
expected: previous.dimensions(),
|
expected: previous.dimensions(),
|
||||||
|
|
@ -454,11 +467,7 @@ fn try_image_snapshot_options_impl(
|
||||||
if below_threshold {
|
if below_threshold {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
new.save(&new_path)
|
write_new_png()?;
|
||||||
.map_err(|err| SnapshotError::WriteSnapshot {
|
|
||||||
err,
|
|
||||||
path: new_path.clone(),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
Err(SnapshotError::Diff {
|
Err(SnapshotError::Diff {
|
||||||
name,
|
name,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue