Skip to content

Commit

Permalink
Fix bug with updating snapshots in CI env
Browse files Browse the repository at this point in the history
stvd


fgbfy


srvd
  • Loading branch information
theramis committed Oct 1, 2020
1 parent 987c82b commit 4ab9e68
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions project/Snapper/Core/SnapperCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,20 @@ protected SnapResult Snap(SnapshotId snapshotId, object newSnapshot)

private bool ShouldUpdateSnapshot(object currentSnapshot, object newSnapshot)
{
var snapshotsAreEqual = currentSnapshot != null
&& _snapshotComparer.CompareSnapshots(currentSnapshot, newSnapshot);
if (!snapshotsAreEqual && _snapshotUpdateDecider.ShouldUpdateSnapshot())
{
return true;
}

// Create snapshot if it doesn't currently exist and its not a CI env
if (currentSnapshot == null)
{
return !CiEnvironmentDetector.IsCiEnv();
}

return !_snapshotComparer.CompareSnapshots(currentSnapshot, newSnapshot)
&& _snapshotUpdateDecider.ShouldUpdateSnapshot();
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public void SnapshotDoesNotExist_ShouldUpdate_ResultStatusIs_SnapshotUpdated()
[Fact]
public void SnapshotDoesNotExist_ResultStatusIs_SnapshotUpdated()
{
// Tests run on CI so clearing the CI environment variable to emulate local machine
Environment.SetEnvironmentVariable("CI", null, EnvironmentVariableTarget.Process);

_store.Setup(a => a.GetSnapshot(It.IsAny<SnapshotId>())).Returns(null);
_updateDecider.Setup(a => a.ShouldUpdateSnapshot()).Returns(false);

Expand Down
4 changes: 4 additions & 0 deletions project/Tests/Snapper.Tests/SnapperSnapshotsPerClassTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ public void SnapshotDoesNotExist_And_IsCiEnv_SnapshotDoesNotExistException_IsThr
public void SnapshotsDoesNotExist_SnapshotIsCreated()
{
// Arrange

// Tests run on CI so clearing the CI environment variable to emulate local machine
Environment.SetEnvironmentVariable("CI", null, EnvironmentVariableTarget.Process);

var snapshotFilePath = GetSnapshotFilePath<SnapperSnapshotsPerClassTests>();

var content = File.ReadAllText(snapshotFilePath);
Expand Down
3 changes: 3 additions & 0 deletions project/Tests/Snapper.Tests/SnapperSnapshotsPerMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ public void SnapshotDoesNotExist_And_IsCiEnv_SnapshotDoesNotExistException_IsThr
[Fact]
public void SnapshotsDoesNotExist_SnapshotIsCreated()
{
// Tests run on CI so clearing the CI environment variable to emulate local machine
Environment.SetEnvironmentVariable("CI", null, EnvironmentVariableTarget.Process);

// Arrange
var snapshotFilePath = GetSnapshotFilePath<SnapperSnapshotsPerMethodTests>(
nameof(SnapshotsDoesNotExist_SnapshotIsCreated));
Expand Down

0 comments on commit 4ab9e68

Please sign in to comment.