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
4 changes: 3 additions & 1 deletion Sources/Ignite/Framework/Environment/EnvironmentValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public struct EnvironmentValues {
site: any Site,
allContent: [Article],
pageMetadata: PageMetadata,
pageContent: any LayoutContent
pageContent: any LayoutContent,
Copy link
Copy Markdown
Collaborator

@JPToroDev JPToroDev Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a dedicated init that mirrors the other convenience initializers?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by this? EnvironmentValues has 5 different inits and I only modified the one that required the fix

httpError: HTTPError = EmptyHTTPError()
) {
self.decode = DecodeAction(sourceDirectory: sourceDirectory)
self.articles = ArticleLoader(content: allContent)
Expand All @@ -117,6 +118,7 @@ public struct EnvironmentValues {
self.builtInIconsEnabled = site.builtInIconsEnabled
self.timeZone = site.timeZone
self.page = pageMetadata
self.httpError = httpError

self.site = SiteMetadata(
name: site.name,
Expand Down
6 changes: 3 additions & 3 deletions Sources/Ignite/Publishing/PublishingContext-Rendering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ extension PublishingContext {
if site.errorPage is EmptyErrorPage { return }

for error in [PageNotFoundError()] {
environment.httpError = error

let metadata = PageMetadata(
title: site.errorPage.title,
description: site.errorPage.description,
Expand All @@ -151,7 +149,9 @@ extension PublishingContext {
site: site,
allContent: allContent,
pageMetadata: metadata,
pageContent: site.errorPage)
pageContent: site.errorPage,
httpError: error
)

let outputString = withEnvironment(values) {
site.errorPage.layout.body.markupString()
Expand Down
6 changes: 5 additions & 1 deletion Tests/IgniteTesting/Publishing/Site.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ struct SiteTests {

@Test("Site published with a custom ErrorPage and custom content")
func publishingWithCustomErrorPageAndContent() async throws {
let errorPage = TestErrorPage(title: "A different title", description: "A different description")
let expectedError = PageNotFoundError()

let errorPage = TestErrorPage(title: "A different title", description: "A different description") { error in
#expect(error.statusCode == expectedError.statusCode)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we simply check #expect(errorPage.error.statusCode == expectedError.statusCode) instead of introducing the errorChecker closure?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heya sorry for the delay, life happened.

Unless I'm missing something, checking the page's error after calling site.publish() will not work as it's set (and reset) dynamically during publishing?

What I want the test to do is to guarantee that the correct error is present during site publishing. I can only do so by injecting this check when the rendering actually happens.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha—thanks for clarifying!

}
let site = TestSiteWithErrorPage(errorPage: errorPage)
var publisher = TestSitePublisher(site: site)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,29 @@ struct TestErrorPage: ErrorPage {
var title: String = "Test Error Page"
var description: String = "Test Error Page Description"

let errorChecker: (HTTPError) -> Void

init(
title: String = "Test Error Page",
description: String = "Test Error Page Description",
errorChecker: @escaping (HTTPError) -> Void = { _ in }
) {
self.title = title
self.description = description
self.errorChecker = errorChecker
}

var body: some HTML {
EmptyHTML()
ErrorChecker { errorChecker(error) }
}

struct ErrorChecker: HTML {
init(handler: @escaping () -> Void) {
handler()
}

var body: some HTML {
EmptyHTML()
}
}
}