Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ struct HTMLRenderer {
return try String(contentsOfFile: customTemplatePath, encoding: .utf8)
}

if let moduleTemplateURL = Bundle.module.url(forResource: "default-report", withExtension: "stencil") {
return try String(contentsOf: moduleTemplateURL, encoding: .utf8)
}

for candidate in Self.defaultTemplateCandidateURLs() {
guard fileManager.fileExists(atPath: candidate.path) else { continue }
return try String(contentsOf: candidate, encoding: .utf8)
Expand All @@ -128,7 +132,10 @@ struct HTMLRenderer {
executablePath: String = CommandLine.arguments.first ?? ""
) -> [URL] {
let bundleName = "SnapshotReportKit_SnapshotReportCore.bundle"
let templateRelativePath = "Contents/Resources/default-report.stencil"
let templateRelativePaths = [
"default-report.stencil",
"Contents/Resources/default-report.stencil",
]
var candidateDirectories: [URL] = []

if executablePath.isEmpty == false {
Expand All @@ -150,17 +157,19 @@ struct HTMLRenderer {

var candidates: [URL] = []
for directory in uniqueDirectories {
let bundleInExecutableDirectory = directory
.appendingPathComponent(bundleName, isDirectory: true)
.appendingPathComponent(templateRelativePath)
candidates.append(bundleInExecutableDirectory)

let bundleInLibexecDirectory = directory
.appendingPathComponent("..", isDirectory: true)
.appendingPathComponent("libexec", isDirectory: true)
.appendingPathComponent(bundleName, isDirectory: true)
.appendingPathComponent(templateRelativePath)
candidates.append(bundleInLibexecDirectory)
for templateRelativePath in templateRelativePaths {
let bundleInExecutableDirectory = directory
.appendingPathComponent(bundleName, isDirectory: true)
.appendingPathComponent(templateRelativePath)
candidates.append(bundleInExecutableDirectory)

let bundleInLibexecDirectory = directory
.appendingPathComponent("..", isDirectory: true)
.appendingPathComponent("libexec", isDirectory: true)
.appendingPathComponent(bundleName, isDirectory: true)
.appendingPathComponent(templateRelativePath)
candidates.append(bundleInLibexecDirectory)
}
}

let sourceTemplate = URL(fileURLWithPath: #filePath)
Expand Down
8 changes: 6 additions & 2 deletions Tests/SnapshotReportCoreTests/SnapshotReportCoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,15 @@ func htmlRendererTemplateCandidatesIncludeResolvedSymlinkPath() throws {
try FileManager.default.createSymbolicLink(atPath: linkedExecutable.path, withDestinationPath: cellarExecutable.path)

let candidates = HTMLRenderer.defaultTemplateCandidateURLs(executablePath: linkedExecutable.path).map(\.path)
let expected = cellarBin
let expectedSwiftPMLayout = cellarBin
.appendingPathComponent("SnapshotReportKit_SnapshotReportCore.bundle/default-report.stencil")
.path
let expectedCFBundleLayout = cellarBin
.appendingPathComponent("SnapshotReportKit_SnapshotReportCore.bundle/Contents/Resources/default-report.stencil")
.path

#expect(candidates.contains(expected))
#expect(candidates.contains(expectedSwiftPMLayout))
#expect(candidates.contains(expectedCFBundleLayout))
}

@Test
Expand Down