Skip to main content

Setting up your project

You can enable snapshot4s for a variety of project layouts.

Single project builds

For single project builds, follow the quick start.

Multi-project builds

If you have a multi-project setup, you must enable the plugin in each project containing snapshot tests.

Add the plugin to plugins.sbt.

addSbtPlugin("com.siriusxm" % "sbt-snapshot4s" % "0.2.11")

Enable it for each project in build.sbt.

val core = (project in file("core")).enablePlugins(Snapshot4sPlugin)

val utils = (project in file("utils")).enablePlugins(Snapshot4sPlugin)

val root = (project in file(".")).aggregate(core, utils)

Finally, add the integration library for your test framework.

sbt-projectmatrix

If you use sbt-projectmatrix, you can enable the plugin for a matrix.

Add the plugin to plugins.sbt.

addSbtPlugin("com.siriusxm" % "sbt-snapshot4s" % "0.2.11")

Enable it for each matrix in build.sbt.

val core = (projectMatrix in file("core")).enablePlugins(Snapshot4sPlugin)

Finally, add the integration library for your test framework.

sbt-crossproject and sbt-typelevel

You can enable the plugin for all cross types, for both JVM and JS.

Add the plugin to plugins.sbt.

addSbtPlugin("com.siriusxm" % "sbt-snapshot4s" % "0.2.11")

Enable the plugin.

val core = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Dummy)
.in(file("core"))
.enablePlugins(Snapshot4sPlugin)

If you use the Pure or Full cross types, set the snapshot4sResourceDirectory to the shared test resource directory.

val core = crossProject(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("core"))
.settings(
snapshot4sResourceDirectory := CrossType.Pure
.sharedResourcesDir(baseDirectory.value, "test")
.get / "snapshot",
)
.enablePlugins(Snapshot4sPlugin)

Finally, add the integration library for your test framework.

Mill builds

Snapshot4s supports mill version 1.

Import the mill-snapshot4s plugin into your build.mill.

//| mvnDeps: ["com.siriusxm::mill-snapshot4s::0.2.11"]

Extend the Snapshot4sModule in your test object.

import snapshot4s.Snapshot4sModule

object myProject extends ScalaModule {
object test extends ScalaTests with Snapshot4sModule { ... }
}

Finally, add the integration library for your test framework.

For example, to use snapshot4s with MUnit:

//| mvnDeps: ["com.siriusxm::mill-snapshot4s::0.2.11"]
import snapshot4s.Snapshot4sModule

object myProject extends ScalaModule {
object test extends ScalaTests with Snapshot4sModule with TestModule.Munit {
override def mvnDeps =
super.mvnDeps() :+ mvn"com.siriusxm::snapshot4s-munit:${snapshot4s.BuildInfo.snapshot4sVersion}"
}
}

You can update your tests via the snapshot4sPromote task:

mill myProject.test.snapshot4sPromote