Skip to content

Commit

Permalink
Update end to end tests with snapshot (#124)
Browse files Browse the repository at this point in the history
* test: update end-to-end tests
- chore: add PACT_OUTPUT_DIR to macOS scheme
- chore: fix concurrency warning
- test: go back to force unwrapping output directory
- test: convert tests to inline snapshot tests

* chore: re-indent file
* chore: add commas
* fix: indent with tabs
* chore: add empty lines to align with code style

---------

Co-authored-by: Jason Sunde <[email protected]>
  • Loading branch information
jasunde and jasunde-daugherty authored Jun 2, 2024
1 parent 537afad commit f732567
Show file tree
Hide file tree
Showing 6 changed files with 673 additions and 634 deletions.
60 changes: 38 additions & 22 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
{
"object": {
"pins": [
{
"package": "PactMockServer",
"repositoryURL": "https://github.com/surpher/PactMockServer.git",
"state": {
"branch": null,
"revision": "11fe519e6d1b0c513c717ba507e89ba401bdf8de",
"version": "0.1.2"
}
},
{
"package": "PactSwiftMockServer",
"repositoryURL": "https://github.com/surpher/PactSwiftMockServer.git",
"state": {
"branch": null,
"revision": "50c130088b9c7fe7f278beee86b3d161605a1f98",
"version": "0.4.1"
}
"pins" : [
{
"identity" : "pactmockserver",
"kind" : "remoteSourceControl",
"location" : "https://github.com/surpher/PactMockServer.git",
"state" : {
"revision" : "11fe519e6d1b0c513c717ba507e89ba401bdf8de",
"version" : "0.1.2"
}
]
},
"version": 1
},
{
"identity" : "pactswiftmockserver",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ittybittyapps/PactSwiftMockServer.git",
"state" : {
"branch" : "main",
"revision" : "8f690c7c1944871896523cc5ffefb6ef8b1cc856"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "625ccca8570773dd84a34ee51a81aa2bc5a4f97a",
"version" : "1.16.0"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax",
"state" : {
"revision" : "303e5c5c36d6a558407d364878df131c3546fad8",
"version" : "510.0.2"
}
}
],
"version" : 2
}
28 changes: 15 additions & 13 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,48 @@ import PackageDescription

let package = Package(
name: "PactSwift",

platforms: [
.macOS(.v13),
.iOS(.v16),
.tvOS(.v16)
.tvOS(.v16),
],

products: [
.library(
name: "PactSwift",
targets: ["PactSwift"]
)
],

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"),
],

targets: [

// PactSwift
.target(
name: "PactSwift",
dependencies: [
.product(name: "PactSwiftMockServer", package: "PactSwiftMockServer", condition: .when(platforms: [.iOS, .macOS, .tvOS]))
.product(name: "PactSwiftMockServer", package: "PactSwiftMockServer", condition: .when(platforms: [.iOS, .macOS, .tvOS])),
],
path: "./Sources"
),

// Tests
.testTarget(
name: "PactSwiftTests",
dependencies: [
"PactSwift"
"PactSwift",
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
],
path: "./Tests"
),

],

swiftLanguageVersions: [.v5]

)
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
value = "all"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "PACT_OUTPUT_DIR"
value = "${BUILD_DIR}/pacts"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
Expand Down
2 changes: 1 addition & 1 deletion Sources/Matchers/Matcher+V2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public extension Matcher {
var values: Set = values
if let example { values.insert(example) }
let descriptions = values.map(\.description).sorted()
return regex("^(\(descriptions.joined(separator: "|")))$", example: (example?.description ?? values.first?.description) ?? "")
return regex("^(\(descriptions.joined(separator: "|")))$", example: (example?.description ?? descriptions.first) ?? "")
}

/// A matcher that executes a regular expression match against the string representation of a value.
Expand Down
16 changes: 16 additions & 0 deletions Tests/Matchers/MatcherOneOfTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,20 @@ class MatcherOneOfTests: MatcherTestCase {
"""#
)
}

func testMatcher_OneOfWithExample() throws {
let json = try jsonString(for: .oneOf(["enabled", "disabled"], example: "unknown"))

XCTAssertEqual(
json,
#"""
{
"pact:matcher:type" : "regex",
"regex" : "^(disabled|enabled|unknown)$",
"value" : "unknown"
}
"""#
)
}

}
Loading

0 comments on commit f732567

Please sign in to comment.