Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore previous XCTVaporTests behavior if necc. #2587

Merged
merged 2 commits into from
Mar 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 34 additions & 7 deletions Sources/XCTVapor/XCTVaporTests.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
public var app: (() throws -> Application) = {
fatalError("implement static app generator")
}
/**
We recommend configuring this in your test’s `class func setUp()`
*/
public var app: (() throws -> Application)!

open class XCTVaporTests: XCTestCase {
open var app: Application!

open override func setUpWithError() throws {

// The XCTest runner calls this function before setUp()

try super.setUpWithError()

// this optional check due to prior usage by users
// see: https://github.com/vapor/vapor/pull/2585#issuecomment-802144636
if let _app = XCTVapor.app {
self.app = try _app()
}
}

open override func setUp() {

// The XCTest runner calls this after setupWithError()

super.setUp()
self.app = try XCTVapor.app()

if self.app == nil, let _app = XCTVapor.app {
// this was the behavior of this class pre 4.41.5
// keeping for compatability however it will crash obv if
// the function throws. Provided the user assigns to
// XCTVapor.app in the class setUp everything will work
// as we intend.
self.app = try! _app()
} else {
fatalError("implement static app generator")
}
}

open override func tearDown() {
super.tearDown()
self.app?.shutdown()
app = nil
self.app = nil
}
}