diff --git a/Tests/IgniteTesting/Publishing/Site.swift b/Tests/IgniteTesting/Publishing/Site.swift index 1f6c33c6..b5abd15a 100644 --- a/Tests/IgniteTesting/Publishing/Site.swift +++ b/Tests/IgniteTesting/Publishing/Site.swift @@ -11,22 +11,34 @@ import Testing @testable import Ignite /// Tests for the `Site` type. +/// +/// > Warning: Calling `PublishingContext.initialize` as a part of the suite set-up +/// can lead to false positive results because these tests are calling `TestSite/publish` +/// that includes the `PublishingContext.initialize` call. +/// **Workaround:** Run this suite in isolation. @Suite("Site Tests", .serialized) @MainActor struct SiteTests { private let package = TestPackage() - @Test("Site published given there is no Markdown content") - func publishingWithNoMarkdownContent() async throws { - let markdownFileURL = package.contentDirectoryURL.appending(path: "story-with-valid-metadata.md") + init() { + try? package.clearBuildFolderAndTestContent() + } + + @Test( + "Site published when Markdown content contains invalid lastModified date", + .bug("https://github.com/twostraws/Ignite/issues/445") + ) + func publishingWithInvalidLastModifiedDate() async throws { + let markdownFileURL = package.contentDirectoryURL.appending(path: "story-with-invalid-lastModified.md") let markdownContent = """ --- layout: TestStory - lastModified: 2020-03-30 16:37 + lastModified: 2020-03-30 16:37:21 --- - # Story with valid metadata + # Story with invalid lastModified """ try markdownContent.write(to: markdownFileURL, atomically: false, encoding: .utf8) @@ -35,20 +47,19 @@ struct SiteTests { #expect(package.checkIndexFileExists() == true) - try FileManager.default.removeItem(at: markdownFileURL) - try FileManager.default.removeItem(at: package.buildDirectoryURL) + try package.clearBuildFolderAndTestContent() } - @Test("Site published when Markdown content contains invalid lastModified date") - func publishingWithInvalidLastModifiedDate() async throws { - let markdownFileURL = package.contentDirectoryURL.appending(path: "story-with-invalid-lastModified.md") + @Test("Site published given Markdown content with valid metadata") + func publishingWithMarkdownContent() async throws { + let markdownFileURL = package.contentDirectoryURL.appending(path: "story-with-valid-metadata.md") let markdownContent = """ --- layout: TestStory - lastModified: 2020-03-30 16:37:21 + lastModified: 2020-03-30 16:37 --- - # Story with invalid lastModified + # Story with valid metadata """ try markdownContent.write(to: markdownFileURL, atomically: false, encoding: .utf8) @@ -57,8 +68,7 @@ struct SiteTests { #expect(package.checkIndexFileExists() == true) - try FileManager.default.removeItem(at: markdownFileURL) - try FileManager.default.removeItem(at: package.buildDirectoryURL) + try package.clearBuildFolderAndTestContent() } } @@ -80,4 +90,13 @@ private struct TestPackage { func checkIndexFileExists() -> Bool { (try? buildDirectoryURL.appending(path: "index.html").checkPromisedItemIsReachable()) ?? false } + + func clearBuildFolderAndTestContent() throws { + try FileManager.default.removeItem(at: buildDirectoryURL) + let enumerator = FileManager.default.enumerator(at: contentDirectoryURL, includingPropertiesForKeys: nil) + while let fileURL = enumerator?.nextObject() as? URL { + guard fileURL.isFileURL, fileURL.pathExtension == "md" else { continue } + try FileManager.default.removeItem(at: fileURL) + } + } }