From 3fa0e161815f7a05187842fbe84583f82c938604 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 11 Jan 2023 11:27:09 -0800 Subject: [PATCH] fix tests --- Package.swift | 7 +++- ...cativeRouterHttpPipelineSupportTests.swift | 8 ++--- .../SyntaxRouterTests.swift | 8 ++--- Tests/CssResetTests/CssResetTests.swift | 8 ++--- Tests/CssTests/FlexBoxTests.swift | 4 +-- Tests/CssTests/FullStylesheetTests.swift | 4 +-- .../HtmlPlainTextPrintTests.swift | 4 +-- .../HttpPipelineTests/HttpPipelineTests.swift | 14 ++++---- .../SharedMiddlewareTransformersTests.swift | 30 ++++++++--------- .../HttpPipelineTests/SignedCookieTests.swift | 8 ++--- .../UrlFormDecoderTests.swift | 32 +++++++++---------- .../UrlFormEncodingTests.swift | 20 ++++++------ 12 files changed, 76 insertions(+), 71 deletions(-) diff --git a/Package.swift b/Package.swift index 23ae8717..710eb053 100644 --- a/Package.swift +++ b/Package.swift @@ -102,7 +102,11 @@ let package = Package( ), .testTarget( name: "CssResetTests", - dependencies: ["CssReset", "CssTestSupport"], + dependencies: [ + "CssReset", + "CssTestSupport", + .product(name: "SnapshotTesting", package: "swift-snapshot-testing"), + ], exclude: [ "__Snapshots__", ] @@ -129,6 +133,7 @@ let package = Package( "CssTestSupport", "HtmlCssSupport", .product(name: "HtmlSnapshotTesting", package: "swift-html"), + .product(name: "SnapshotTesting", package: "swift-snapshot-testing"), ] ), diff --git a/Tests/ApplicativeRouterHttpPipelineSupportTests/ApplicativeRouterHttpPipelineSupportTests.swift b/Tests/ApplicativeRouterHttpPipelineSupportTests/ApplicativeRouterHttpPipelineSupportTests.swift index 2693d3d0..91a342a3 100644 --- a/Tests/ApplicativeRouterHttpPipelineSupportTests/ApplicativeRouterHttpPipelineSupportTests.swift +++ b/Tests/ApplicativeRouterHttpPipelineSupportTests/ApplicativeRouterHttpPipelineSupportTests.swift @@ -29,7 +29,7 @@ class ApplicativeRouterHttpPipelineSupportTests: XCTestCase { connection(from: URLRequest(url: URL(string: "/")!), defaultHeaders: []) ) .performAsync() - assertSnapshot(matching: response, as: .conn, named: "home") + await assertSnapshot(matching: response, as: .conn, named: "home") response = await middleware( connection( @@ -38,13 +38,13 @@ class ApplicativeRouterHttpPipelineSupportTests: XCTestCase { ) ) .performAsync() - assertSnapshot(matching: response, as: .conn, named: "episode") + await assertSnapshot(matching: response, as: .conn, named: "episode") response = await middleware( connection(from: URLRequest(url: URL(string: "/does/not/exist")!), defaultHeaders: []) ) .performAsync() - assertSnapshot(matching: response, as: .conn, named: "unrecognized") + await assertSnapshot(matching: response, as: .conn, named: "unrecognized") } func testRoute_UnrecognizedWithCustomNotFound() async { @@ -59,7 +59,7 @@ class ApplicativeRouterHttpPipelineSupportTests: XCTestCase { connection(from: URLRequest(url: URL(string: "/does/not/exist")!), defaultHeaders: []) ) .performAsync() - assertSnapshot(matching: response, as: .conn, named: "unrecognized") + await assertSnapshot(matching: response, as: .conn, named: "unrecognized") } } diff --git a/Tests/ApplicativeRouterTests/SyntaxRouterTests.swift b/Tests/ApplicativeRouterTests/SyntaxRouterTests.swift index bc78f995..a6e0a306 100644 --- a/Tests/ApplicativeRouterTests/SyntaxRouterTests.swift +++ b/Tests/ApplicativeRouterTests/SyntaxRouterTests.swift @@ -39,12 +39,12 @@ class SyntaxRouterTests: XCTestCase { XCTAssertEqual("/", router.absoluteString(for: .root)) } - func testRequest_WithBaseUrl() { + func testRequest_WithBaseUrl() async { // BUG: https://bugs.swift.org/browse/SR-6407 // NB: Previously we did `XCTAssertEqual` on a left/right side to check that the requests match, but // due to a weird Swift bug (https://bugs.swift.org/browse/SR-6407) we are switching to a snapshot // test. - assertSnapshot( + await assertSnapshot( matching: router.request(for: .home, base: URL(string: "http://www.pointfree.co/"))! // NB: necessary for linux tests: https://bugs.swift.org/browse/SR-6405 |> \.httpMethod .~ "GET", @@ -182,7 +182,7 @@ class SyntaxRouterTests: XCTestCase { // XCTAssertEqual(request, router.request(for: route)) // } - func testCodableFormDataPostBody() { + func testCodableFormDataPostBody() async { var request = URLRequest(url: URL(string: "subscribe")!) request.httpMethod = "post" request.httpBody = Data("plan=1&quantity=2".utf8) @@ -194,7 +194,7 @@ class SyntaxRouterTests: XCTestCase { "subscribe", router.templateUrl(for: route)?.absoluteString ) - assertSnapshot( + await assertSnapshot( matching: router.request(for: .postBodyFormData(SubscribeData(plan: 2, quantity: 3)))!, as: .raw ) diff --git a/Tests/CssResetTests/CssResetTests.swift b/Tests/CssResetTests/CssResetTests.swift index ae5feb80..53c764fd 100644 --- a/Tests/CssResetTests/CssResetTests.swift +++ b/Tests/CssResetTests/CssResetTests.swift @@ -6,11 +6,11 @@ import XCTest import SnapshotTesting class ResetTests: XCTestCase { - func testResetPretty() { - assertSnapshot(matching: reset, as: .css) + func testResetPretty() async { + await assertSnapshot(matching: reset, as: .css) } - func testResetCompact() { - assertSnapshot(matching: reset, as: .css(.compact)) + func testResetCompact() async { + await assertSnapshot(matching: reset, as: .css(.compact)) } } diff --git a/Tests/CssTests/FlexBoxTests.swift b/Tests/CssTests/FlexBoxTests.swift index 73040bd9..5797160b 100644 --- a/Tests/CssTests/FlexBoxTests.swift +++ b/Tests/CssTests/FlexBoxTests.swift @@ -6,7 +6,7 @@ import SnapshotTesting class FlexBoxTests: XCTestCase { - func testFlexBox() { + func testFlexBox() async { let css: Stylesheet = ".wrapper" % ( display(.flex) @@ -25,6 +25,6 @@ class FlexBoxTests: XCTestCase { <> ".aside-2" % order(2) <> ".aside-3" % order(3) - assertSnapshot(matching: css, as: .css) + await assertSnapshot(matching: css, as: .css) } } diff --git a/Tests/CssTests/FullStylesheetTests.swift b/Tests/CssTests/FullStylesheetTests.swift index ee3a17f9..52192aef 100644 --- a/Tests/CssTests/FullStylesheetTests.swift +++ b/Tests/CssTests/FullStylesheetTests.swift @@ -6,7 +6,7 @@ import SnapshotTesting class FullStylesheetTests: XCTestCase { - func testABigStyleSheet() { + func testABigStyleSheet() async { let css: Stylesheet = body % ( background(Color.red) @@ -30,6 +30,6 @@ class FullStylesheetTests: XCTestCase { <> appearance(.button) ) - assertSnapshot(matching: css, as: .css) + await assertSnapshot(matching: css, as: .css) } } diff --git a/Tests/HtmlPlainTextPrintTests/HtmlPlainTextPrintTests.swift b/Tests/HtmlPlainTextPrintTests/HtmlPlainTextPrintTests.swift index 969b92d6..9aafaccf 100644 --- a/Tests/HtmlPlainTextPrintTests/HtmlPlainTextPrintTests.swift +++ b/Tests/HtmlPlainTextPrintTests/HtmlPlainTextPrintTests.swift @@ -4,7 +4,7 @@ import SnapshotTesting import HtmlPlainTextPrint class PlainTextTests: XCTestCase { - func testPlainText() { + func testPlainText() async { let doc = Node.html( .head( .title("Hello!"), @@ -48,6 +48,6 @@ class PlainTextTests: XCTestCase { ) ) - assertSnapshot(matching: HtmlPlainTextPrint.plainText(for: doc), as: .lines) + await assertSnapshot(matching: HtmlPlainTextPrint.plainText(for: doc), as: .lines) } } diff --git a/Tests/HttpPipelineTests/HttpPipelineTests.swift b/Tests/HttpPipelineTests/HttpPipelineTests.swift index d687e0b4..1108310a 100644 --- a/Tests/HttpPipelineTests/HttpPipelineTests.swift +++ b/Tests/HttpPipelineTests/HttpPipelineTests.swift @@ -23,7 +23,7 @@ class HttpPipelineTests: XCTestCase { >=> respond(text: "Hello, world") let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) } func testHtmlResponse() async { @@ -32,14 +32,14 @@ class HttpPipelineTests: XCTestCase { >=> respond(html: "

Hello, world

") let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) } func testRedirect() async { let middleware: Middleware = redirect(to: "/sign-in") let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) } func testRedirect_AdditionalHeaders() async { @@ -47,7 +47,7 @@ class HttpPipelineTests: XCTestCase { redirect(to: "/sign-in", headersMiddleware: writeHeader("Pass-through", "hello!")) let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) } func testWriteHeaders() async { @@ -60,7 +60,7 @@ class HttpPipelineTests: XCTestCase { >=> respond(html: "

Hello, world

") let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) } func testCookies() async { @@ -72,7 +72,7 @@ class HttpPipelineTests: XCTestCase { >=> respond(html: "

Hello, world

") let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) } func testCookieOptions() async { @@ -92,6 +92,6 @@ class HttpPipelineTests: XCTestCase { >=> respond(html: "

Hello, world

") let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) } } diff --git a/Tests/HttpPipelineTests/SharedMiddlewareTransformersTests.swift b/Tests/HttpPipelineTests/SharedMiddlewareTransformersTests.swift index e9934030..edeb1d72 100644 --- a/Tests/HttpPipelineTests/SharedMiddlewareTransformersTests.swift +++ b/Tests/HttpPipelineTests/SharedMiddlewareTransformersTests.swift @@ -24,7 +24,7 @@ class SharedMiddlewareTransformersTests: XCTestCase { >=> respond(html: "

Hello, world

") let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) } func testBasicAuth_Unauthorized_ProtectedPredicate() async { @@ -34,7 +34,7 @@ class SharedMiddlewareTransformersTests: XCTestCase { >=> respond(html: "

Hello, world

") let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) } func testBasicAuth_Unauthorized_Realm() async { @@ -44,7 +44,7 @@ class SharedMiddlewareTransformersTests: XCTestCase { >=> respond(html: "

Hello, world

") let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) } func testBasicAuth_Unauthorized_CustomFailure() async { @@ -58,7 +58,7 @@ class SharedMiddlewareTransformersTests: XCTestCase { >=> respond(html: "

Hello, world

") let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) } func testBasicAuth_Authorized() async { @@ -74,7 +74,7 @@ class SharedMiddlewareTransformersTests: XCTestCase { ) let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) } func testRedirectUnrelatedHosts() async { @@ -100,19 +100,19 @@ class SharedMiddlewareTransformersTests: XCTestCase { ) ) .performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) response = await middleware( connection(from: URLRequest(url: URL(string: "http://0.0.0.0:8080")!), defaultHeaders: []) ) .performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) response = await middleware( connection(from: URLRequest(url: URL(string: "http://pointfree.co")!), defaultHeaders: []) ) .performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) response = await middleware( connection( @@ -120,7 +120,7 @@ class SharedMiddlewareTransformersTests: XCTestCase { ) ) .performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) } func testRequireHerokuHttps() async { @@ -150,20 +150,20 @@ class SharedMiddlewareTransformersTests: XCTestCase { securedConnection(from: URLRequest(url: URL(string: "https://www.pointfree.co")!)) ) .performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) response = await middleware( connection( from: URLRequest(url: URL(string: "https://www.pointfree.co")!), defaultHeaders: []) ) .performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) response = await middleware( connection(from: URLRequest(url: URL(string: "http://0.0.0.0:8080")!), defaultHeaders: []) ) .performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) } func testRequireHttps() async { @@ -188,7 +188,7 @@ class SharedMiddlewareTransformersTests: XCTestCase { ) ) .performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) response = await middleware( connection( @@ -196,13 +196,13 @@ class SharedMiddlewareTransformersTests: XCTestCase { ) ) .performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) response = await middleware( connection(from: URLRequest(url: URL(string: "http://0.0.0.0:8080")!), defaultHeaders: []) ) .performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) } func testRequestLogger() async { diff --git a/Tests/HttpPipelineTests/SignedCookieTests.swift b/Tests/HttpPipelineTests/SignedCookieTests.swift index e115f622..1b2f451e 100644 --- a/Tests/HttpPipelineTests/SignedCookieTests.swift +++ b/Tests/HttpPipelineTests/SignedCookieTests.swift @@ -35,7 +35,7 @@ aGVsbG8td29ybGQ=\ >=> end let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) XCTAssertEqual( "hello-world", @@ -69,7 +69,7 @@ eyJpZCI6NDIsIm5hbWUiOiJBbGwgQWJvdXQgRnVuY3Rpb25zIn0=\ #if !os(Linux) let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) #endif XCTAssertEqual( @@ -103,7 +103,7 @@ eyJpZCI6NDIsIm5hbWUiOiJBbGwgQWJvdXQgRnVuY3Rpb25zIn0=\ >=> end let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) XCTAssertEqual( "hello-world", @@ -144,7 +144,7 @@ cb4db8ac9390ac810837809f11bc6803\ #if !os(Linux) let response = await middleware(conn).performAsync() - assertSnapshot(matching: response, as: .conn) + await assertSnapshot(matching: response, as: .conn) #endif XCTAssertEqual( diff --git a/Tests/UrlFormEncodingTests/UrlFormDecoderTests.swift b/Tests/UrlFormEncodingTests/UrlFormDecoderTests.swift index 8d710c84..e68ce618 100644 --- a/Tests/UrlFormEncodingTests/UrlFormDecoderTests.swift +++ b/Tests/UrlFormEncodingTests/UrlFormDecoderTests.swift @@ -29,21 +29,21 @@ final class UrlFormDecoderTests: XCTestCase { XCTAssertEqual("hello world", try decoder.decode(Foo.self, from: Data("x=hello+world".utf8)).x) } - func testDefaultStrategyAccumulatePairs() throws { + func testDefaultStrategyAccumulatePairs() async throws { struct Foo: Decodable { let x: Int let ys: [Int] } - assertSnapshot(matching: try decoder.decode(Foo.self, from: Data("x=1&ys=1".utf8)), as: .dump) - assertSnapshot(matching: try decoder.decode(Foo.self, from: Data("x=1&ys=1&ys=2".utf8)), as: .dump) + await assertSnapshot(matching: try self.decoder.decode(Foo.self, from: Data("x=1&ys=1".utf8)), as: .dump) + await assertSnapshot(matching: try self.decoder.decode(Foo.self, from: Data("x=1&ys=1&ys=2".utf8)), as: .dump) // FIXME: Make work! // XCTAssertNil(try decoder.decode(Foo?.self, from: Data("ys=1&ys=2".utf8))) // XCTAssertNil(try decoder.decode(Foo?.self, from: Data())) } - func testBrackets() throws { + func testBrackets() async throws { struct Bar: Decodable { let baz: Int } @@ -79,10 +79,10 @@ final class UrlFormDecoderTests: XCTestCase { decoder.parsingStrategy = .brackets - assertSnapshot(matching: try decoder.decode(Foo.self, from: data), as: .dump) + await assertSnapshot(matching: try self.decoder.decode(Foo.self, from: data), as: .dump) } - func testBracketsWithIndices() throws { + func testBracketsWithIndices() async throws { struct Bar: Decodable { let baz: Int } @@ -109,7 +109,7 @@ final class UrlFormDecoderTests: XCTestCase { decoder.parsingStrategy = .bracketsWithIndices - assertSnapshot(matching: try decoder.decode(Foo.self, from: data), as: .dump) + await assertSnapshot(matching: try self.decoder.decode(Foo.self, from: data), as: .dump) } func testDataDecodingWithBase64() throws { @@ -125,7 +125,7 @@ final class UrlFormDecoderTests: XCTestCase { ) } - func testDateDecodingWithSecondsSince1970() throws { + func testDateDecodingWithSecondsSince1970() async throws { struct MyDate: Decodable { let date: Date } @@ -133,10 +133,10 @@ final class UrlFormDecoderTests: XCTestCase { decoder.dateDecodingStrategy = .secondsSince1970 let interval = Int(Date(timeIntervalSinceReferenceDate: 0).timeIntervalSince1970) - assertSnapshot(matching: try decoder.decode(MyDate.self, from: Data("date=\(interval)".utf8)), as: .dump) + await assertSnapshot(matching: try self.decoder.decode(MyDate.self, from: Data("date=\(interval)".utf8)), as: .dump) } - func testDateDecodingWithMillisecondsSince1970() throws { + func testDateDecodingWithMillisecondsSince1970() async throws { struct MyDate: Decodable { let date: Date } @@ -144,21 +144,21 @@ final class UrlFormDecoderTests: XCTestCase { decoder.dateDecodingStrategy = .millisecondsSince1970 let interval = "\(Int(Date(timeIntervalSinceReferenceDate: 0).timeIntervalSince1970))000" - assertSnapshot(matching: try decoder.decode(MyDate.self, from: Data("date=\(interval)".utf8)), as: .dump) + await assertSnapshot(matching: try self.decoder.decode(MyDate.self, from: Data("date=\(interval)".utf8)), as: .dump) } - func testDateDecodingWithIso8601() throws { + func testDateDecodingWithIso8601() async throws { struct MyDate: Decodable { let date: Date } decoder.dateDecodingStrategy = .iso8601 - assertSnapshot( - matching: try decoder.decode(MyDate.self, from: Data("date=2001-01-01T00:00:00.000-00:00".utf8)), + await assertSnapshot( + matching: try self.decoder.decode(MyDate.self, from: Data("date=2001-01-01T00:00:00.000-00:00".utf8)), as: .dump ) - assertSnapshot( - matching: try decoder.decode(MyDate.self, from: Data("date=2001-01-01T00:00:00-00:00".utf8)), + await assertSnapshot( + matching: try self.decoder.decode(MyDate.self, from: Data("date=2001-01-01T00:00:00-00:00".utf8)), as: .dump ) } diff --git a/Tests/UrlFormEncodingTests/UrlFormEncodingTests.swift b/Tests/UrlFormEncodingTests/UrlFormEncodingTests.swift index 7eabdb32..cacf4d70 100644 --- a/Tests/UrlFormEncodingTests/UrlFormEncodingTests.swift +++ b/Tests/UrlFormEncodingTests/UrlFormEncodingTests.swift @@ -4,8 +4,8 @@ import UrlFormEncoding import XCTest final class UrlFormEncoderTests: XCTestCase { - func testEncoding_DeepObject() { - assertSnapshot( + func testEncoding_DeepObject() async { + await assertSnapshot( matching: urlFormEncode( value: [ "id": 42, @@ -27,8 +27,8 @@ final class UrlFormEncoderTests: XCTestCase { ) } - func testEncoding_Emtpy() { - assertSnapshot( + func testEncoding_Emtpy() async { + await assertSnapshot( matching: urlFormEncode( value: [ "id": 42, @@ -42,8 +42,8 @@ final class UrlFormEncoderTests: XCTestCase { ) } - func testEncoding_RootArray_SimpleObjects() { - assertSnapshot( + func testEncoding_RootArray_SimpleObjects() async { + await assertSnapshot( matching: urlFormEncode( values: ["Functions & Purity", "Monoids", "Applicatives"], rootKey: "episodes" @@ -53,8 +53,8 @@ final class UrlFormEncoderTests: XCTestCase { ) } - func testEncoding_DoubleArray() { - assertSnapshot( + func testEncoding_DoubleArray() async { + await assertSnapshot( matching: urlFormEncode( values: [ ["Functions", "Purity"], @@ -68,14 +68,14 @@ final class UrlFormEncoderTests: XCTestCase { ) } - func testEncodingCodable() { + func testEncodingCodable() async { let episode = EpisodeModel( id: 100, title: "Introduction to Functions", blurb: "Everything you wanted to know about functions.", categories: ["Functions", "Composition", "Curry"] ) - assertSnapshot( + await assertSnapshot( matching: urlFormEncode(value: episode) .sortedByFormEncodedKey(), as: .lines