Skip to content

Add e2e tests#2

Open
jasunde wants to merge 2 commits into
feat/v2.0.0from
add-e2e-tests
Open

Add e2e tests#2
jasunde wants to merge 2 commits into
feat/v2.0.0from
add-e2e-tests

Conversation

@jasunde
Copy link
Copy Markdown
Owner

@jasunde jasunde commented Apr 30, 2024

  • ☝️ Provide a short but descriptive title for this PR.
  • 🏷 Remember to label your pull request appropriately and select appropriate code reviewers.

Provide a more descriptive summary of the changes in this PR here.

📝 Summary of Changes

Changes proposed in this pull request:

  • Resolves issue #99999 by doing the thing with another thing
  • Add more details here...
  • ...

⚠️ Items of Note

Document anything here that you think the reviewer(s) of this PR may need to know, or would be of specific interest.

🧐🗒 Reviewer Notes

💁 Example

Add an example of using the changes you've implemented (eg, a screenshot or text dump of the output).

🔨 How To Test

Provide instructions on how to test your changes.

Copy link
Copy Markdown

@surpher surpher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very promising! Thanks for taking time to look into this and help out. 🙇

A few nitpicks I left for you but I'll be happy to accept your PR once you're ready to open it. 👍

Comment thread Package.swift
dependencies: [
.package(url: "https://github.com/ittybittyapps/PactSwiftMockServer.git", branch: "main")
.package(url: "https://github.com/ittybittyapps/PactSwiftMockServer.git", branch: "main"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", exact: "1.16.0")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: As a general rule in PactSwift I wanted to avoid 3rd party dependencies and stick to what Swift and Xcode provide us. Saying that, I'm a fan of PointFree's mission and what they do myself and pulling in their tools/frameworks that can increase confidence is okay with me. 👍

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm planning to make a couple PRs one with snapshot testing and one without. Like I say, I'm not set on it so I want you to choose what you like.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff. Really appreciate your help! 🙇

Comment thread Package.swift
dependencies: [
"PactSwift"
"PactSwift",
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Indentation to match "PactSwift". (applies to other spots too, but I'll nitpick only here 😉 )

reasoning: Because this is an open source project that could (hopefully 🤞) be picked up by other contributors in a very async manner it is important to stick to a certain code style (open to discussion on what that might be). It might not seem like a big deal now, but as the project evolves and contributions introduce code style deviance it gets harder and harder to read through the code and maintain it.


private var pactDirectory: String {
ProcessInfo.processInfo.environment["PACT_OUTPUT_DIR"]!
ProcessInfo.processInfo.environment["PACT_OUTPUT_DIR"] ?? "/tmp/pacts"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: I'm personally a fan of force-unwrapping in tests. But only in tests. Why? Fail fast. If my test crashes it's most likely "developer issue" and should be looked into much deeper.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That force unwrap is finding nil for me. What should I be doing differently?

Copy link
Copy Markdown

@surpher surpher May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah of course, that thing is a bit obscure in PactSwift's readme paragraph Generated Pact Contracts:

scheme build config

If that doesn't work, great, we can find a setup that works across contributors' systems.
I'm digging into re-introducing Linux support with adding Swift Package Manager Plugin to pull down a .so from pact-foundation/pact-reference releases.

There definitely was an interface that would take URL:

MockService(
    consumer: "consumer",
    provider: "provider",
    writePactTo: URL(fileURLWithPath: "/absolute/path/pacts/folder", isDirectory: true)
)

But I'm not quite sure anymore if it's still there. Like I said, I haven't used PactSwift on a project in more than a year 😞

Comment on lines +1 to +6
//
// PactContractTests2.swift
//
//
// Created by Jason Sunde on 4/30/24.
//
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note-to-self: I need to add the file template to the project that renders the author and MIT licence block of text.

}


extension PactContractTests2 {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Could private extension this one and maybe split it with a // MARK: - Private comment above it. This way it helps in your minimap:

Screenshot 2024-05-03 at 9 45 35 AM

If you think this could be a useful re-usable utillity in other tests as well, maybe extract it into a "base test" that you then inherit from or a protocol with default implementation you conform your test class to.

Comment on lines +144 to +147
guard let data = fileContents.data(using: .utf8),
let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else {
return [:]
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: This is obviously a very subjective thing. Though if there's guarding against multiple optionals, maybe moving them all to their own lines could be easier to read? If there's only one, then guard expression else { is fine on one line. IMO, and again, this is very subjective, and it ties into the comment I left above regarding sticking to code style across the project and project timeline.

guard 
    let data = fileContents.data(using: .utf8),
    let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] 
else {
    return [:]
}

note-to-self: Should add/update guard let code style in PactSwift ADRs.

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

Successfully merging this pull request may close these issues.

3 participants