Skip to content

Commit

Permalink
Replace Quick/Nimble with XCTest (#139)
Browse files Browse the repository at this point in the history
* Replace Quick/Nimble with XCTest

* Format file

* Move last test helper to Test.swift with the rest

* Specify latest stable version of Xcode on CI

* Don't use async version of expectations in tests

* Update CI to latest version of macOS and iOS

* Address warnings from latest Xcode

* Clean up GitHub action file

* Perform all test visits async

Increase timeout of failed page load to MORE than Turbo.js timeout so it
triggers the invalid configuration error.

* Increase XCTest timeout for slow GitHub Actions

* Try Silicon on GitHub Actions

* Try faster macOS image

* Convert Swifter to Embassy

* Remove xcpretty formatter - GitHub can't stream it

* Move Embassy server config to helper file

* Revert back to non-XL box on CI

* Update Tests/ScriptMessageTests.swift

Co-authored-by: Zoë Smith <zoews@me.com>

* Remove force try calls in favor of XCTUnwrap

* Move Embassy server outside of class-level

* Remove empty test file

* Update Tests/SessionTests.swift

Co-authored-by: Zoë Smith <zoews@me.com>

---------

Co-authored-by: Zoë Smith <zoews@me.com>
  • Loading branch information
joemasilotti and zoejessica committed Nov 13, 2023
1 parent c476bac commit b975b95
Show file tree
Hide file tree
Showing 22 changed files with 635 additions and 846 deletions.
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
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable

- 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.

Loading

0 comments on commit b975b95

Please sign in to comment.