diff --git a/Services/Website/Package.swift b/Services/Website/Package.swift index f3539f9..f21be13 100644 --- a/Services/Website/Package.swift +++ b/Services/Website/Package.swift @@ -120,7 +120,12 @@ let package = Package( package: "hummingbird" ), ], - path: "Tests/App" + path: "Tests/App", + resources: [ + // `Static` links to the service's `Resources/Static`, copying it into the test bundle at build + // time — the tests must not read the repository tree, which Xcode's test runner is denied. + .copy("Static") + ] ), .testTarget( name: "WebsiteLibraryTests", diff --git a/Services/Website/Tests/App/AppTests.swift b/Services/Website/Tests/App/AppTests.swift index e8b425c..a455a32 100644 --- a/Services/Website/Tests/App/AppTests.swift +++ b/Services/Website/Tests/App/AppTests.swift @@ -20,14 +20,18 @@ struct AppTests { .js ] - // Absolute path to the package's "Resources/Static" folder, derived from this - // file's location so the static files resolve regardless of the working directory. - private let staticFilesPath = URL(fileURLWithPath: #filePath) - .deletingLastPathComponent() // Tests/App - .deletingLastPathComponent() // Tests - .deletingLastPathComponent() // package root - .appendingPathComponent(.Path.staticResources) - .path + // Absolute path to the copy of the package's "Resources/Static" folder made into the test bundle + // at build time — the repository tree itself is off limits to Xcode's test runner. + private let staticFilesPath: String = { + guard let url = Bundle.module.url( + forResource: "Static", + withExtension: nil + ) else { + preconditionFailure("The static files are missing from the test bundle.") + } + + return url.path + }() // MARK: Functional tests diff --git a/Services/Website/Tests/App/Static b/Services/Website/Tests/App/Static new file mode 120000 index 0000000..dcadd44 --- /dev/null +++ b/Services/Website/Tests/App/Static @@ -0,0 +1 @@ +../../Resources/Static \ No newline at end of file