Skip to content

Commit

Permalink
use full subpaths of suites instead of just file name
Browse files Browse the repository at this point in the history
  • Loading branch information
majk-p committed Sep 18, 2024
1 parent 5ee6963 commit f5c4708
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ private[snapshot4s] object FileSnapshot {
eq: SnapshotEq[String],
resultLike: ResultLike[String, E]
): E = resultLike { () =>
val sourceFileName = Locations.getFileName(sourceFile)
val relativePath = Locations.relativeSourceFilePath(sourceFile, config)
val absoluteSnapshotPath = config.resourceDirectory / RelPath(snapshotPath)
def writePatchFile() = {
val patchPath =
config.outputDirectory / RelPath("resource-patch") / RelPath(sourceFileName) / RelPath(
snapshotPath
)
config.outputDirectory / RelPath("resource-patch") / relativePath / RelPath(snapshotPath)
patchPath.write(found)
}
if (absoluteSnapshotPath.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ package snapshot4s

private[snapshot4s] object Locations {

private[snapshot4s] def getFileName(filePath: String): String =
filePath.split("/").last

private[snapshot4s] def relativeSourceFilePath(
sourceFile: String,
config: SnapshotConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,4 @@ We have detected the following configuration:

}

pureTest("calculates file name from path") {
val fileName = "MySuites.cala"
val path = s"/path/to/$fileName"
expect.eql(Locations.getFileName(path), fileName)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ object generated {
private def locateResourceFile(resourcePatchDir: File, patchFile: File, resourceDir: File) = {
val relativePath =
IO.relativize(resourcePatchDir, patchFile).get
// relative path contains file name like "MyTest.scala" as it's first segment, we need to remove that
val withoutSourceTestFileName = relativePath.split("/").tail.mkString("/")
// relative path starts with subpath like "src/test/scala/MyTest.scala" we need to remove that
val withoutSourceTestFileName = relativePath.split("\\.scala/").tail.mkString("/")
resourceDir / withoutSourceTestFileName
}

Expand Down

0 comments on commit f5c4708

Please sign in to comment.