Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ public struct APIRequestTestSwiftGen: SwiftGenerator {

private let makeTestRequestFunc = #"""

/// A session stored globally that does not cache responses on disk.
let session = URLSession(
configuration: .ephemeral
)

/// Log warning after test case logs
func XCTWarn(_ message: String, at url: URL) {
print("[\(url.absoluteString)] : warning - \(message)")
Expand Down Expand Up @@ -401,7 +406,7 @@ func makeTestRequest<RequestBody>(
completionExpectation.fulfill()
}

let task = URLSession.shared.dataTask(with: request, completionHandler: taskCompletion)
let task = session.dataTask(with: request, completionHandler: taskCompletion)
task.resume()

XCTWaiter().wait(for: [completionExpectation], timeout: 5)
Expand Down
7 changes: 6 additions & 1 deletion Tests/JSONAPISwiftGenTests/APIRequestTestSwiftGenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ final class APIRequestTestSwiftGenTests: XCTestCase {
}

// MARK: - START - Function written to generated test suites
/// A session stored globally that does not cache responses on disk.
let session = URLSession(
configuration: .ephemeral
)

/// Log warning after test case logs
func XCTWarn(_ message: String, at url: URL) {
print("[\(url.absoluteString)] : warning - \(message)")
Expand Down Expand Up @@ -178,7 +183,7 @@ func makeTestRequest<RequestBody>(
completionExpectation.fulfill()
}

let task = URLSession.shared.dataTask(with: request, completionHandler: taskCompletion)
let task = session.dataTask(with: request, completionHandler: taskCompletion)
task.resume()

XCTWaiter().wait(for: [completionExpectation], timeout: 5)
Expand Down