Skip to content

Commit

Permalink
Use package name in the generated integration
Browse files Browse the repository at this point in the history
  • Loading branch information
keynmol committed Feb 11, 2024
1 parent e45e2f9 commit 03c41a8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
Expand Up @@ -19,7 +19,7 @@ package com.indoorvivants.snapshots.munit_integration
import munit._
import com.indoorvivants.snapshots._
import munit.internal.difflib.Diffs
import example.Snapshots
import _root_.$$PACKAGE$$.Snapshots

// This is a sample integration for Munit
trait MunitSnapshotsIntegration {
Expand Down
Expand Up @@ -166,7 +166,8 @@ object SnapshotsBuild {

def generateIntegrationSources(
sourceDestination: File,
integration: SnapshotIntegration
integration: SnapshotIntegration,
packageName: String
) = {
Files.createDirectories(sourceDestination.getParentFile().toPath)

Expand All @@ -181,6 +182,7 @@ object SnapshotsBuild {
)
.getLines()
.toList
.map(_.replace("$$PACKAGE$$", packageName))

IO.writeLines(
sourceDestination,
Expand Down
Expand Up @@ -30,20 +30,27 @@ object SnapshotsPlugin extends AutoPlugin {
val snapshotsProjectIdentifier = settingKey[String](
"Project identifier to separate snapshots coming from cross-platform projects"
)

val snapshotsPackageName = settingKey[String](
"Package name under which the generated Snapshots object will be created"
)

val snapshotsIntegrations = settingKey[Seq[SnapshotIntegration]](
"Test framework integrations to generate in test sources"
)

val snapshotsAddRuntimeDependency = settingKey[Boolean](
"Whether to add snapshot runtime to the build - true by default, you shouldn't need to touch this"
)

val snapshotsTemporaryDirectory =
settingKey[File]("Temp folder where snapshot diffs will be created")

val snapshotsCheck =
taskKey[Unit]("Interactively accept modified snapshotsAcceptAll")

val snapshotsAcceptAll = taskKey[Unit]("Accept all modified snapshots")

val snapshotsDiscardAll =
taskKey[Unit]("Discard all modifications to snapshots")

Expand Down Expand Up @@ -121,7 +128,8 @@ object SnapshotsPlugin extends AutoPlugin {
val integrations = snapshotsIntegrations.value.flatMap { integ =>
SnapshotsBuild.generateIntegrationSources(
dest / s"${integ}Integration.scala",
integ
integ,
snapshotsPackageName.value
)
}

Expand Down
Expand Up @@ -4,7 +4,7 @@ lazy val root = projectMatrix
.nativePlatform(Seq("3.3.1"))
.jsPlatform(Seq("3.3.1"))
.settings(
snapshotsPackageName := "example",
snapshotsPackageName := "example.bla",
snapshotsIntegrations += SnapshotIntegration.MUnit,
libraryDependencies +=
"org.scalameta" %%% "munit" % "1.0.0-M7" % Test,
Expand Down
@@ -1,3 +1,5 @@
package example.bla

import com.indoorvivants.snapshots.munit_integration._
import munit._

Expand Down

0 comments on commit 03c41a8

Please sign in to comment.