Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw committed Jan 11, 2023
1 parent ff3705c commit 3fa0e16
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 71 deletions.
7 changes: 6 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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__",
]
Expand All @@ -129,6 +133,7 @@ let package = Package(
"CssTestSupport",
"HtmlCssSupport",
.product(name: "HtmlSnapshotTesting", package: "swift-html"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
]
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 {
Expand All @@ -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")
}
}

Expand Down
8 changes: 4 additions & 4 deletions Tests/ApplicativeRouterTests/SyntaxRouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -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
)
Expand Down
8 changes: 4 additions & 4 deletions Tests/CssResetTests/CssResetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
4 changes: 2 additions & 2 deletions Tests/CssTests/FlexBoxTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SnapshotTesting

class FlexBoxTests: XCTestCase {

func testFlexBox() {
func testFlexBox() async {
let css: Stylesheet =
".wrapper" % (
display(.flex)
Expand All @@ -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)
}
}
4 changes: 2 additions & 2 deletions Tests/CssTests/FullStylesheetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SnapshotTesting

class FullStylesheetTests: XCTestCase {

func testABigStyleSheet() {
func testABigStyleSheet() async {
let css: Stylesheet =
body % (
background(Color.red)
Expand All @@ -30,6 +30,6 @@ class FullStylesheetTests: XCTestCase {
<> appearance(.button)
)

assertSnapshot(matching: css, as: .css)
await assertSnapshot(matching: css, as: .css)
}
}
4 changes: 2 additions & 2 deletions Tests/HtmlPlainTextPrintTests/HtmlPlainTextPrintTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SnapshotTesting
import HtmlPlainTextPrint

class PlainTextTests: XCTestCase {
func testPlainText() {
func testPlainText() async {
let doc = Node.html(
.head(
.title("Hello!"),
Expand Down Expand Up @@ -48,6 +48,6 @@ class PlainTextTests: XCTestCase {
)
)

assertSnapshot(matching: HtmlPlainTextPrint.plainText(for: doc), as: .lines)
await assertSnapshot(matching: HtmlPlainTextPrint.plainText(for: doc), as: .lines)
}
}
14 changes: 7 additions & 7 deletions Tests/HttpPipelineTests/HttpPipelineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -32,22 +32,22 @@ class HttpPipelineTests: XCTestCase {
>=> respond(html: "<p>Hello, world</p>")

let response = await middleware(conn).performAsync()
assertSnapshot(matching: response, as: .conn)
await assertSnapshot(matching: response, as: .conn)
}

func testRedirect() async {
let middleware: Middleware<StatusLineOpen, ResponseEnded, Prelude.Unit, Data> = 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 {
let middleware: Middleware<StatusLineOpen, ResponseEnded, Prelude.Unit, Data> =
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 {
Expand All @@ -60,7 +60,7 @@ class HttpPipelineTests: XCTestCase {
>=> respond(html: "<p>Hello, world</p>")

let response = await middleware(conn).performAsync()
assertSnapshot(matching: response, as: .conn)
await assertSnapshot(matching: response, as: .conn)
}

func testCookies() async {
Expand All @@ -72,7 +72,7 @@ class HttpPipelineTests: XCTestCase {
>=> respond(html: "<p>Hello, world</p>")

let response = await middleware(conn).performAsync()
assertSnapshot(matching: response, as: .conn)
await assertSnapshot(matching: response, as: .conn)
}

func testCookieOptions() async {
Expand All @@ -92,6 +92,6 @@ class HttpPipelineTests: XCTestCase {
>=> respond(html: "<p>Hello, world</p>")

let response = await middleware(conn).performAsync()
assertSnapshot(matching: response, as: .conn)
await assertSnapshot(matching: response, as: .conn)
}
}
30 changes: 15 additions & 15 deletions Tests/HttpPipelineTests/SharedMiddlewareTransformersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SharedMiddlewareTransformersTests: XCTestCase {
>=> respond(html: "<p>Hello, world</p>")

let response = await middleware(conn).performAsync()
assertSnapshot(matching: response, as: .conn)
await assertSnapshot(matching: response, as: .conn)
}

func testBasicAuth_Unauthorized_ProtectedPredicate() async {
Expand All @@ -34,7 +34,7 @@ class SharedMiddlewareTransformersTests: XCTestCase {
>=> respond(html: "<p>Hello, world</p>")

let response = await middleware(conn).performAsync()
assertSnapshot(matching: response, as: .conn)
await assertSnapshot(matching: response, as: .conn)
}

func testBasicAuth_Unauthorized_Realm() async {
Expand All @@ -44,7 +44,7 @@ class SharedMiddlewareTransformersTests: XCTestCase {
>=> respond(html: "<p>Hello, world</p>")

let response = await middleware(conn).performAsync()
assertSnapshot(matching: response, as: .conn)
await assertSnapshot(matching: response, as: .conn)
}

func testBasicAuth_Unauthorized_CustomFailure() async {
Expand All @@ -58,7 +58,7 @@ class SharedMiddlewareTransformersTests: XCTestCase {
>=> respond(html: "<p>Hello, world</p>")

let response = await middleware(conn).performAsync()
assertSnapshot(matching: response, as: .conn)
await assertSnapshot(matching: response, as: .conn)
}

func testBasicAuth_Authorized() async {
Expand All @@ -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 {
Expand All @@ -100,27 +100,27 @@ 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(
from: URLRequest(url: URL(string: "http://www.point-free.co")!), defaultHeaders: []
)
)
.performAsync()
assertSnapshot(matching: response, as: .conn)
await assertSnapshot(matching: response, as: .conn)
}

func testRequireHerokuHttps() async {
Expand Down Expand Up @@ -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 {
Expand All @@ -188,21 +188,21 @@ 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://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 testRequestLogger() async {
Expand Down
8 changes: 4 additions & 4 deletions Tests/HttpPipelineTests/SignedCookieTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down
Loading

0 comments on commit 3fa0e16

Please sign in to comment.