Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
34 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import munit._ | ||
import com.indoorvivants.snapshots._ | ||
import munit.internal.difflib.Diffs | ||
import munit.Assertions | ||
import munit.FunSuite | ||
import example.Snapshots | ||
|
||
// This is a sample integration for Munit | ||
trait SnapshotsIntegration { | ||
self: FunSuite => | ||
def assertSnapshot(name: String, contents: String) = { | ||
Snapshots.read(name) match { | ||
case None => | ||
Snapshots.recordChanges( | ||
name, | ||
contents, | ||
Diffs.create(contents, "").createDiffOnlyReport() | ||
) | ||
|
||
Assertions.fail( | ||
s"No snapshot was found for $name, please run checkSnapshots command and accept a snapshot for this test" | ||
) | ||
|
||
case Some(value) => | ||
val diff = Diffs.create(contents, value) | ||
if (!diff.isEmpty) { | ||
val diffReport = diff.createDiffOnlyReport() | ||
Snapshots.recordChanges(name, contents, diffReport) | ||
Assertions.assertNoDiff(contents, value) | ||
} else | ||
Snapshots.clearChanges(name) | ||
} | ||
} | ||
} |