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

Replace Quick/Nimble with XCTest #139

Merged
merged 21 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
10 changes: 7 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ on: [push]

jobs:
test:
runs-on: macos-latest
runs-on: macos-13-xl
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
joemasilotti marked this conversation as resolved.
Show resolved Hide resolved

- name: Run Tests
run: xcodebuild -scheme Turbo test -quiet -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14'
run: xcodebuild test -scheme Turbo -destination "name=iPhone 15 Pro" | xcpretty && exit ${PIPESTATUS[0]}
44 changes: 4 additions & 40 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
{
"pins" : [
{
"identity" : "cwlcatchexception",
"identity" : "embassy",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattgallagher/CwlCatchException.git",
"location" : "https://github.com/envoy/Embassy.git",
"state" : {
"revision" : "3b123999de19bf04905bc1dfdb76f817b0f2cc00",
"version" : "2.1.2"
}
},
{
"identity" : "cwlpreconditiontesting",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state" : {
"revision" : "a23ded2c91df9156628a6996ab4f347526f17b6b",
"version" : "2.1.2"
}
},
{
"identity" : "nimble",
"kind" : "remoteSourceControl",
"location" : "https://github.com/quick/nimble",
"state" : {
"revision" : "1f3bde57bde12f5e7b07909848c071e9b73d6edc",
"version" : "10.0.0"
"revision" : "8469f2c1b334a7c1c3566e2cb2f97826c7cca898",
"version" : "4.1.6"
}
},
{
Expand All @@ -35,24 +17,6 @@
"revision" : "12f19662426d0434d6c330c6974d53e2eb10ecd9",
"version" : "9.1.0"
}
},
{
"identity" : "quick",
"kind" : "remoteSourceControl",
"location" : "https://github.com/quick/quick",
"state" : {
"revision" : "f9d519828bb03dfc8125467d8f7b93131951124c",
"version" : "5.0.1"
}
},
{
"identity" : "swifter",
"kind" : "remoteSourceControl",
"location" : "https://github.com/httpswift/swifter",
"state" : {
"revision" : "9483a5d459b45c3ffd059f7b55f9638e268632fd",
"version" : "1.5.0"
}
}
],
"version" : 2
Expand Down
8 changes: 2 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/quick/quick", .upToNextMajor(from: "5.0.0")),
.package(url: "https://github.com/quick/nimble", .upToNextMajor(from: "10.0.0")),
.package(url: "https://github.com/AliSoftware/OHHTTPStubs", .upToNextMajor(from: "9.0.0")),
.package(url: "https://github.com/httpswift/swifter.git", .upToNextMajor(from: "1.5.0"))
.package(url: "https://github.com/envoy/Embassy.git", .upToNextMajor(from: "4.1.4"))
],
targets: [
.target(
Expand All @@ -33,10 +31,8 @@ let package = Package(
name: "TurboTests",
dependencies: [
"Turbo",
.product(name: "Quick", package: "quick"),
.product(name: "Nimble", package: "nimble"),
.product(name: "OHHTTPStubsSwift", package: "OHHTTPStubs"),
.product(name: "Swifter", package: "Swifter")
.product(name: "Embassy", package: "Embassy")
],
path: "Tests",
resources: [
Expand Down
121 changes: 0 additions & 121 deletions Tests/ColdBootVisitSpec.swift

This file was deleted.

52 changes: 52 additions & 0 deletions Tests/ColdBootVisitTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@testable import Turbo
import WebKit
import XCTest

class ColdBootVisitTests: XCTestCase {
private let webView = WKWebView()
private let visitDelegate = TestVisitDelegate()
private var visit: ColdBootVisit!

override func setUp() {
let url = URL(string: "http://localhost/")!
let bridge = WebViewBridge(webView: webView)

visit = ColdBootVisit(visitable: TestVisitable(url: url), options: VisitOptions(), bridge: bridge)
visit.delegate = visitDelegate
}

func test_start_transitionsToStartState() {
XCTAssertEqual(visit.state, .initialized)
visit.start()
XCTAssertEqual(visit.state, .started)
}

func test_start_notifiesTheDelegateTheVisitWillStart() {
visit.start()
XCTAssertTrue(visitDelegate.didCall("visitWillStart(_:)"))
}

func test_start_kicksOffTheWebViewLoad() {
visit.start()
XCTAssertNotNil(visit.navigation)
}

func test_visit_becomesTheNavigationDelegate() {
visit.start()
XCTAssertIdentical(webView.navigationDelegate, visit)
}

func test_visit_notifiesTheDelegateTheVisitDidStart() {
visit.start()
XCTAssertTrue(visitDelegate.didCall("visitDidStart(_:)"))
}

func test_visit_ignoresTheCallIfAlreadyStarted() {
visit.start()
XCTAssertTrue(visitDelegate.methodsCalled.contains("visitDidStart(_:)"))

visitDelegate.methodsCalled.remove("visitDidStart(_:)")
visit.start()
XCTAssertFalse(visitDelegate.didCall("visitDidStart(_:)"))
}
}
37 changes: 0 additions & 37 deletions Tests/JavaScriptExpressionSpec.swift

This file was deleted.

30 changes: 30 additions & 0 deletions Tests/JavaScriptExpressionTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@testable import Turbo
import XCTest

class JavaScriptExpressionTests: XCTestCase {
func test_string_convertsFunctionAndArgumentsIntoAValidExpression() {
let expression = JavaScriptExpression(function: "console.log", arguments: [])
XCTAssertEqual(expression.string, "console.log()")

let expression2 = JavaScriptExpression(function: "console.log", arguments: ["one", nil, 2])
XCTAssertEqual(expression2.string, "console.log(\"one\",null,2)")
}

func test_wrapped_wrapsExpressionIn_IIFE_AndTryCatch() {
let expression = JavaScriptExpression(function: "console.log", arguments: [])
let expected = """
(function(result) {
try {
result.value = console.log()
} catch (error) {
result.error = error.toString()
result.stack = error.stack
}

return result
})({})
"""

XCTAssertEqual(expression.wrappedString, expected)
}
}
8 changes: 0 additions & 8 deletions Tests/JavaScriptVisitSpec.swift

This file was deleted.

3 changes: 3 additions & 0 deletions Tests/JavaScriptVisitTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import XCTest

class JavaScriptVisitTests: XCTestCase {}
joemasilotti marked this conversation as resolved.
Show resolved Hide resolved
Loading