Swift 5.10 & Vapor 18.7.5 changes
- Dominant language
- Swift
- Stars
- 415
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
Hey folks,
I used this today with:
- Swift 5.10
- Vapor 18.7.5
- PromiseKit 6.22.1
- XCode 15.3
- Sonoma 14.5
I noted the following changes:
I used SwiftPM, so I needed this from the README (note the alpha version):
```swift
dependencies: [
.package(url: "https://github.com/LinusU/Marionette", from: "1.0.0-alpha.11"),
]
```
However, I also needed this in the `.testTarget` `dependencies` section, which isn't mentioned in the README, probably because not everyone is using this with a `testTarget`:
```swift
dependencies: [
.product(name: "Marionette", package: "Marionette"),
]
```
I had a ton of trouble figuring out the test case syntax as it appears some things have changed. This is what I ended up with:
```swift
import Marionette
import PromiseKit
import XCTest
@testable import App
final class ExampleIntegrationTests: XCTestCase {
func testIndex() {
let page = Marionette()
let expectation = XCTestExpectation(description: "Goto page")
_ = firstly {
page.goto(URL(string: "http://127.0.0.1:8080/example")!)
}.then {
page.waitForSelector("body")
}.then {
page.evaluate("document.body.innerHTML") as Promise
}.done {
XCTAssertEqual($0, "Foo")
expectation.fulfill()
}
wait(for: [expectation], timeout: 10.0)
}
}
```
Without the `expectation` code, the tests would always pass because they wouldn't wait.
I realize not everyone is using this within an `XCTestCase`, but I just wanted to point out the `expectation` syntax since I noticed it differed from what I see in https://github.com/LinusU/Marionette/blob/3c0699e869fdbe13a5d03042884c17d418293a12/Tests/WaitTests.swift#L53
The `_ = firstly {` assignment is to silence the warning `result of call to 'done(on:flags:_:)' is unused`. I don't know if that is the best way to handle it, but it worked for me.
Anyway, I'm not a Swift expert. There may be better ways to handle this. Just posting here in case this helps someone in the future.
I'm coming from the JS ecosystem, so it was disappointing to learn that `Promise`s are not forward compatible with `async/await` in Swift. Bummer. Maybe there will be an `async/await` version of `Marionette` sometime?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by comparing the README's SwiftPM and test examples with Tests/WaitTests.swift and the reported Swift 5.10 setup. Document the missing testTarget dependency and XCTest expectation pattern in the README; done means a SwiftPM XCTest user can configure and wait for the async assertion without relying on unstated steps.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100