ci/carton test --environment defaultbrowser (#209)
* Added Test for carton test --environment defaultBrowser * Method documentation, test file cleanup, print statement removals, var scope changes * Delete docker-compose.yml Co-authored-by: thecb4 <cavelle@tehcb4.io> Co-authored-by: Max Desiatov <max@desiatov.com>
This commit is contained in:
parent
084dbf17a4
commit
794eb9f85e
|
@ -194,12 +194,15 @@ public extension XCTest {
|
|||
: bundleURL
|
||||
}
|
||||
|
||||
/// Execute shell command and return the process the command is running in
|
||||
///
|
||||
/// - parameter command: The command to execute.
|
||||
/// - parameter cwd: The current working directory for executing the command.
|
||||
/// - parameter file: The file the assertion is coming from.
|
||||
/// - parameter line: The line the assertion is coming from.
|
||||
func executeCommand(
|
||||
command: String,
|
||||
cwd: URL? = nil, // To allow for testing of file based output
|
||||
expected: String? = nil,
|
||||
exitCode: ExitCode = .success,
|
||||
debug: Bool = false,
|
||||
file: StaticString = #file, line: UInt = #line
|
||||
) -> Process? {
|
||||
let splitCommand = command.split(separator: " ")
|
||||
|
@ -242,10 +245,21 @@ public extension XCTest {
|
|||
return process
|
||||
}
|
||||
|
||||
/// Execute shell command and assert output is what is expected
|
||||
///
|
||||
/// - parameter command: The command to execute.
|
||||
/// - parameter cwd: The current working directory for executing the command.
|
||||
/// - parameter expected: The expect string output of the command.
|
||||
/// - parameter expectedContains: A flag for whether or not it's exact or 'contains' should be used.
|
||||
/// - parameter exitCode: The exit code of the command. Default is 'success'
|
||||
/// - parameter debug: Debug the assertion by printing out the command string.
|
||||
/// - parameter file: The file the assertion is coming from.
|
||||
/// - parameter line: The line the assertion is coming from.
|
||||
func AssertExecuteCommand(
|
||||
command: String,
|
||||
cwd: URL? = nil, // To allow for testing of file based output
|
||||
expected: String? = nil,
|
||||
expectedContains: Bool = false,
|
||||
exitCode: ExitCode = .success,
|
||||
debug: Bool = false,
|
||||
file: StaticString = #file, line: UInt = #line
|
||||
|
@ -299,13 +313,22 @@ public extension XCTest {
|
|||
let errorActual = String(data: errorData, encoding: .utf8)!
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
let finalString = errorActual + outputActual
|
||||
|
||||
if let expected = expected {
|
||||
AssertEqualStringsIgnoringTrailingWhitespace(
|
||||
expected,
|
||||
errorActual + outputActual,
|
||||
file: file,
|
||||
line: line
|
||||
)
|
||||
if expectedContains {
|
||||
XCTAssertTrue(
|
||||
finalString.contains(expected),
|
||||
"The final string \(finalString) does not contain \(expected)"
|
||||
)
|
||||
} else {
|
||||
AssertEqualStringsIgnoringTrailingWhitespace(
|
||||
expected,
|
||||
errorActual + outputActual,
|
||||
file: file,
|
||||
line: line
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,9 @@ import XCTest
|
|||
extension DevCommandTests: Testable {}
|
||||
|
||||
final class DevCommandTests: XCTestCase {
|
||||
var client: HTTPClient?
|
||||
private var client: HTTPClient?
|
||||
|
||||
override func tearDown() {
|
||||
print("shutting down client")
|
||||
try? client?.syncShutdown()
|
||||
client = nil
|
||||
}
|
||||
|
@ -67,8 +66,7 @@ final class DevCommandTests: XCTestCase {
|
|||
|
||||
guard let process = executeCommand(
|
||||
command: "carton dev --verbose",
|
||||
cwd: packageDirectory.url,
|
||||
debug: true
|
||||
cwd: packageDirectory.url
|
||||
) else {
|
||||
XCTFail("Could not create process")
|
||||
return
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
// Created by Cavelle Benjamin on Dec/28/20.
|
||||
//
|
||||
|
||||
import AsyncHTTPClient
|
||||
@testable import CartonCLI
|
||||
import TSCBasic
|
||||
import XCTest
|
||||
|
@ -22,9 +23,17 @@ import XCTest
|
|||
extension TestCommandTests: Testable {}
|
||||
|
||||
final class TestCommandTests: XCTestCase {
|
||||
private var client: HTTPClient?
|
||||
|
||||
override func tearDown() {
|
||||
try? client?.syncShutdown()
|
||||
client = nil
|
||||
}
|
||||
|
||||
func testWithNoArguments() throws {
|
||||
// given I've created a directory
|
||||
let packageDirectory = testFixturesDirectory.appending(components: "TestApp")
|
||||
let package = "TestApp"
|
||||
let packageDirectory = testFixturesDirectory.appending(components: package)
|
||||
|
||||
XCTAssertTrue(packageDirectory.exists, "The TestApp directory does not exist")
|
||||
|
||||
|
@ -37,4 +46,41 @@ final class TestCommandTests: XCTestCase {
|
|||
let buildDirectory = packageDirectory.appending(component: ".build")
|
||||
do { try buildDirectory.delete() } catch {}
|
||||
}
|
||||
|
||||
func testEnvironmentDefaultBrowser() throws {
|
||||
// given I've created a directory
|
||||
let package = "TestApp"
|
||||
let packageDirectory = testFixturesDirectory.appending(components: package)
|
||||
|
||||
let expectedTestSuiteCount = 1
|
||||
let expectedTestsCount = 1
|
||||
|
||||
let expectedContent =
|
||||
"""
|
||||
Test Suites: \(ControlCode.CSI)32m\(expectedTestSuiteCount) passed\(ControlCode
|
||||
.CSI)0m, \(expectedTestSuiteCount) total
|
||||
Tests: \(ControlCode.CSI)32m\(expectedTestsCount) passed\(ControlCode
|
||||
.CSI)0m, \(expectedTestsCount) total
|
||||
"""
|
||||
|
||||
XCTAssertTrue(packageDirectory.exists, "The TestApp directory does not exist")
|
||||
|
||||
// start clean
|
||||
do { try packageDirectory.appending(component: ".build").delete() } catch {}
|
||||
|
||||
AssertExecuteCommand(
|
||||
command: "carton test",
|
||||
cwd: packageDirectory.url,
|
||||
expected: expectedContent,
|
||||
expectedContains: true
|
||||
)
|
||||
|
||||
// finally, clean up
|
||||
do { try packageDirectory.appending(component: ".build").delete() } catch {}
|
||||
}
|
||||
}
|
||||
|
||||
enum ControlCode {
|
||||
static let ESC = "\u{001B}"
|
||||
static let CSI = "\(ESC)["
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue