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

Swift 5.10 & Vapor 18.7.5 changes #5

Open
createthis opened this issue Jun 9, 2024 · 0 comments
Open

Swift 5.10 & Vapor 18.7.5 changes #5

createthis opened this issue Jun 9, 2024 · 0 comments

Comments

@createthis
Copy link

createthis commented Jun 9, 2024

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):

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:

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:

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

waitForExpectations(timeout: 5)

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 Promises are not forward compatible with async/await in Swift. Bummer. Maybe there will be an async/await version of Marionette sometime?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant