Skip to content

Instantly share code, notes, and snippets.

@YOU54F
Last active September 14, 2023 17:09
Show Gist options
  • Save YOU54F/061bbcee704ef0893a8466c4061b693f to your computer and use it in GitHub Desktop.
Save YOU54F/061bbcee704ef0893a8466c4061b693f to your computer and use it in GitHub Desktop.
simple pact-js http test with axios & jest
npm install
npm run test
[18:07:03.554] INFO (10914): 0.4.7: pact native library successfully found, and the correct version
2023-09-14T17:07:03.562539Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact - ref = 1, keys = [1]
2023-09-14T17:07:03.563697Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact before - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [], metadata: {"pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
2023-09-14T17:07:03.564578Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact after - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [], metadata: {"pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
2023-09-14T17:07:03.564611Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact - ref = 1, keys = [1]
2023-09-14T17:07:03.564614Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact before - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [], metadata: {"pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
2023-09-14T17:07:03.564807Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact after - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [], metadata: {"pact-js": Object {"version": String("12.1.0")}, "pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
2023-09-14T17:07:03.566046Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact - ref = 1, keys = [1]
2023-09-14T17:07:03.566052Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact before - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [], metadata: {"pact-js": Object {"version": String("12.1.0")}, "pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
2023-09-14T17:07:03.566678Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact after - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [SynchronousHttp { id: None, key: None, description: "A request for API health", provider_states: [], request: HttpRequest { method: "GET", path: "/", query: None, headers: None, body: Missing, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }, response: HttpResponse { status: 200, headers: None, body: Missing, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }, comments: {}, pending: false, plugin_config: {}, interaction_markup: InteractionMarkup { markup: "", markup_type: "" }, transport: None }], metadata: {"pact-js": Object {"version": String("12.1.0")}, "pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
2023-09-14T17:07:03.567450Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_interaction - index = 1, interaction = 1
2023-09-14T17:07:03.567455Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_interaction - keys = [1]
2023-09-14T17:07:03.567456Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_interaction - inner = PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [SynchronousHttp { id: None, key: None, description: "A request for API health", provider_states: [], request: HttpRequest { method: "GET", path: "/", query: None, headers: None, body: Missing, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }, response: HttpResponse { status: 200, headers: None, body: Missing, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }, comments: {}, pending: false, plugin_config: {}, interaction_markup: InteractionMarkup { markup: "", markup_type: "" }, transport: None }], metadata: {"pact-js": Object {"version": String("12.1.0")}, "pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 }
2023-09-14T17:07:03.567507Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_interaction - index = 1, interaction = 1
2023-09-14T17:07:03.567510Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_interaction - keys = [1]
2023-09-14T17:07:03.567511Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_interaction - inner = PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [SynchronousHttp { id: None, key: None, description: "A request for API health", provider_states: [ProviderState { name: "Server is healthy", params: {} }], request: HttpRequest { method: "GET", path: "/", query: None, headers: None, body: Missing, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }, response: HttpResponse { status: 200, headers: None, body: Missing, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }, comments: {}, pending: false, plugin_config: {}, interaction_markup: InteractionMarkup { markup: "", markup_type: "" }, transport: None }], metadata: {"pact-js": Object {"version": String("12.1.0")}, "pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 }
2023-09-14T17:07:03.568141Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_interaction - index = 1, interaction = 1
2023-09-14T17:07:03.568147Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_interaction - keys = [1]
2023-09-14T17:07:03.568149Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_interaction - inner = PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [SynchronousHttp { id: None, key: None, description: "A request for API health", provider_states: [ProviderState { name: "Server is healthy", params: {} }], request: HttpRequest { method: "GET", path: "/health", query: None, headers: None, body: Missing, matching_rules: MatchingRules { rules: {PATH: MatchingRuleCategory { name: PATH, rules: {} }} }, generators: Generators { categories: {} } }, response: HttpResponse { status: 200, headers: None, body: Missing, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }, comments: {}, pending: false, plugin_config: {}, interaction_markup: InteractionMarkup { markup: "", markup_type: "" }, transport: None }], metadata: {"pact-js": Object {"version": String("12.1.0")}, "pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 }
2023-09-14T17:07:03.568203Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_interaction - index = 1, interaction = 1
2023-09-14T17:07:03.568208Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_interaction - keys = [1]
2023-09-14T17:07:03.568210Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_interaction - inner = PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [SynchronousHttp { id: None, key: None, description: "A request for API health", provider_states: [ProviderState { name: "Server is healthy", params: {} }], request: HttpRequest { method: "GET", path: "/health", query: None, headers: None, body: Missing, matching_rules: MatchingRules { rules: {PATH: MatchingRuleCategory { name: PATH, rules: {} }} }, generators: Generators { categories: {} } }, response: HttpResponse { status: 200, headers: None, body: Missing, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }, comments: {}, pending: false, plugin_config: {}, interaction_markup: InteractionMarkup { markup: "", markup_type: "" }, transport: None }], metadata: {"pact-js": Object {"version": String("12.1.0")}, "pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 }
2023-09-14T17:07:03.570776Z TRACE ThreadId(01) pact_models::matchingrules: rule_type: type, attributes: {"pact:matcher:type":"type","value":"up"}
2023-09-14T17:07:03.571898Z TRACE ThreadId(01) pactffi_create_mock_server_for_pact{pact=PactHandle { pact_ref: 1 } addr_str=0x16d02c798 tls=false}: pact_ffi::mock_server::handles: with_pact - ref = 1, keys = [1]
2023-09-14T17:07:03.571914Z TRACE ThreadId(01) pactffi_create_mock_server_for_pact{pact=PactHandle { pact_ref: 1 } addr_str=0x16d02c798 tls=false}: pact_ffi::mock_server::handles: with_pact before - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [SynchronousHttp { id: None, key: None, description: "A request for API health", provider_states: [ProviderState { name: "Server is healthy", params: {} }], request: HttpRequest { method: "GET", path: "/health", query: None, headers: None, body: Missing, matching_rules: MatchingRules { rules: {PATH: MatchingRuleCategory { name: PATH, rules: {} }} }, generators: Generators { categories: {} } }, response: HttpResponse { status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(b"{\"status\":\"up\"}", Some(ContentType { main_type: "application", sub_type: "json", attributes: {}, suffix: None }), None), matching_rules: MatchingRules { rules: {BODY: MatchingRuleCategory { name: BODY, rules: {DocPath { path_tokens: [Root, Field("status")], expr: "$.status" }: RuleList { rules: [Type], rule_logic: And, cascaded: false }} }} }, generators: Generators { categories: {} } }, comments: {}, pending: false, plugin_config: {}, interaction_markup: InteractionMarkup { markup: "", markup_type: "" }, transport: None }], metadata: {"pact-js": Object {"version": String("12.1.0")}, "pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
2023-09-14T17:07:03.573280Z TRACE ThreadId(01) pactffi_create_mock_server_for_pact{pact=PactHandle { pact_ref: 1 } addr_str=0x16d02c798 tls=false}: pact_plugin_driver::catalogue_manager: register_core_entries([CatalogueEntry { entry_type: TRANSPORT, provider_type: CORE, plugin: None, key: "http", values: {} }, CatalogueEntry { entry_type: TRANSPORT, provider_type: CORE, plugin: None, key: "https", values: {} }])
2023-09-14T17:07:03.574882Z DEBUG ThreadId(01) pactffi_create_mock_server_for_pact{pact=PactHandle { pact_ref: 1 } addr_str=0x16d02c798 tls=false}: pact_plugin_driver::catalogue_manager: Updated catalogue entries:
core/transport/http
core/transport/https
2023-09-14T17:07:03.575487Z TRACE ThreadId(01) pactffi_create_mock_server_for_pact{pact=PactHandle { pact_ref: 1 } addr_str=0x16d02c798 tls=false}: pact_plugin_driver::catalogue_manager: register_core_entries([CatalogueEntry { entry_type: CONTENT_MATCHER, provider_type: CORE, plugin: None, key: "xml", values: {"content-types": "application/.*xml,text/xml"} }, CatalogueEntry { entry_type: CONTENT_MATCHER, provider_type: CORE, plugin: None, key: "json", values: {"content-types": "application/.*json,application/json-rpc,application/jsonrequest"} }, CatalogueEntry { entry_type: CONTENT_MATCHER, provider_type: CORE, plugin: None, key: "text", values: {"content-types": "text/plain"} }, CatalogueEntry { entry_type: CONTENT_MATCHER, provider_type: CORE, plugin: None, key: "multipart-form-data", values: {"content-types": "multipart/form-data,multipart/mixed"} }, CatalogueEntry { entry_type: CONTENT_GENERATOR, provider_type: CORE, plugin: None, key: "json", values: {"content-types": "application/.*json,application/json-rpc,application/jsonrequest"} }, CatalogueEntry { entry_type: CONTENT_GENERATOR, provider_type: CORE, plugin: None, key: "binary", values: {"content-types": "application/octet-stream"} }])
2023-09-14T17:07:03.575512Z DEBUG ThreadId(01) pactffi_create_mock_server_for_pact{pact=PactHandle { pact_ref: 1 } addr_str=0x16d02c798 tls=false}: pact_plugin_driver::catalogue_manager: Updated catalogue entries:
core/content-generator/binary
core/content-generator/json
core/content-matcher/json
core/content-matcher/multipart-form-data
core/content-matcher/text
core/content-matcher/xml
2023-09-14T17:07:03.575516Z TRACE ThreadId(01) pactffi_create_mock_server_for_pact{pact=PactHandle { pact_ref: 1 } addr_str=0x16d02c798 tls=false}: pact_plugin_driver::catalogue_manager: register_core_entries([CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v2-regex", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v2-type", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v3-number-type", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v3-integer-type", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v3-decimal-type", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v3-date", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v3-time", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v3-datetime", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v2-min-type", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v2-max-type", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v2-minmax-type", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v3-includes", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v3-null", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v4-equals-ignore-order", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v4-min-equals-ignore-order", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v4-max-equals-ignore-order", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v4-minmax-equals-ignore-order", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v3-content-type", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v4-array-contains", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v1-equality", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v4-not-empty", values: {} }, CatalogueEntry { entry_type: MATCHER, provider_type: CORE, plugin: None, key: "v4-semver", values: {} }])
2023-09-14T17:07:03.575557Z DEBUG ThreadId(01) pactffi_create_mock_server_for_pact{pact=PactHandle { pact_ref: 1 } addr_str=0x16d02c798 tls=false}: pact_plugin_driver::catalogue_manager: Updated catalogue entries:
core/matcher/v1-equality
core/matcher/v2-max-type
core/matcher/v2-min-type
core/matcher/v2-minmax-type
core/matcher/v2-regex
core/matcher/v2-type
core/matcher/v3-content-type
core/matcher/v3-date
core/matcher/v3-datetime
core/matcher/v3-decimal-type
core/matcher/v3-includes
core/matcher/v3-integer-type
core/matcher/v3-null
core/matcher/v3-number-type
core/matcher/v3-time
core/matcher/v4-array-contains
core/matcher/v4-equals-ignore-order
core/matcher/v4-max-equals-ignore-order
core/matcher/v4-min-equals-ignore-order
core/matcher/v4-minmax-equals-ignore-order
core/matcher/v4-not-empty
core/matcher/v4-semver
2023-09-14T17:07:03.577320Z DEBUG ThreadId(01) pactffi_create_mock_server_for_pact{pact=PactHandle { pact_ref: 1 } addr_str=0x16d02c798 tls=false}: pact_mock_server::mock_server: Started mock server on 127.0.0.1:51055
2023-09-14T17:07:03.577695Z TRACE ThreadId(01) pactffi_create_mock_server_for_pact{pact=PactHandle { pact_ref: 1 } addr_str=0x16d02c798 tls=false}: pact_ffi::mock_server::handles: with_pact after - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [SynchronousHttp { id: None, key: None, description: "A request for API health", provider_states: [ProviderState { name: "Server is healthy", params: {} }], request: HttpRequest { method: "GET", path: "/health", query: None, headers: None, body: Missing, matching_rules: MatchingRules { rules: {PATH: MatchingRuleCategory { name: PATH, rules: {} }} }, generators: Generators { categories: {} } }, response: HttpResponse { status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(b"{\"status\":\"up\"}", Some(ContentType { main_type: "application", sub_type: "json", attributes: {}, suffix: None }), None), matching_rules: MatchingRules { rules: {BODY: MatchingRuleCategory { name: BODY, rules: {DocPath { path_tokens: [Root, Field("status")], expr: "$.status" }: RuleList { rules: [Type], rule_logic: And, cascaded: false }} }} }, generators: Generators { categories: {} } }, comments: {}, pending: false, plugin_config: {}, interaction_markup: InteractionMarkup { markup: "",
 RUNS  ./test.js
2023-09-14T17:07:03.583153Z TRACE tokio-runtime-worker hyper::proto::h1::conn: Conn::read_head
2023-09-14T17:07:03.583210Z TRACE tokio-runtime-worker hyper::proto::h1::conn: flushed({role=server}): State { reading: Init, writing: Init, keep_alive: Busy }
2023-09-14T17:07:03.585513Z TRACE tokio-runtime-worker hyper::proto::h1::conn: Conn::read_head
2023-09-14T17:07:03.585529Z TRACE tokio-runtime-worker hyper::proto::h1::io: received 180 bytes
2023-09-14T17:07:03.585558Z TRACE tokio-runtime-worker parse_headers: hyper::proto::h1::role: Request.parse bytes=180
2023-09-14T17:07:03.585614Z TRACE tokio-runtime-worker parse_headers: hyper::proto::h1::role: Request.parse Complete(180)
2023-09-14T17:07:03.585662Z DEBUG tokio-runtime-worker hyper::proto::h1::io: parsed 5 headers
2023-09-14T17:07:03.585665Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is empty
2023-09-14T17:07:03.585667Z TRACE tokio-runtime-worker hyper::proto::h1::conn: remote disabling keep-alive
2023-09-14T17:07:03.585936Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Creating pact request from hyper request
2023-09-14T17:07:03.586107Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Extracting query from uri /health
2023-09-14T17:07:03.586189Z TRACE tokio-runtime-worker pact_mock_server::hyper_server: path_and_query -> /health
2023-09-14T17:07:03.586241Z  INFO tokio-runtime-worker pact_mock_server::hyper_server: Received request GET /health
2023-09-14T17:07:03.586256Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server:
      ----------------------------------------------------------------------------------------
       method: GET
       path: /health
       query: None
       headers: Some({"host": ["127.0.0.1:51055"], "accept-encoding": ["gzip", "compress", "deflate", "br"], "user-agent": ["axios/1.5.0"], "connection": ["close"], "accept": ["application/json", "text/plain", "*/*"]})
       body: Empty
      ----------------------------------------------------------------------------------------

2023-09-14T17:07:03.586604Z  INFO tokio-runtime-worker pact_matching: comparing to expected HTTP Request ( method: GET, path: /health, query: None, headers: None, body: Missing )
2023-09-14T17:07:03.586620Z DEBUG tokio-runtime-worker pact_matching:      body: ''
2023-09-14T17:07:03.586621Z DEBUG tokio-runtime-worker pact_matching:      matching_rules: MatchingRules { rules: {PATH: MatchingRuleCategory { name: PATH, rules: {} }} }
2023-09-14T17:07:03.586624Z DEBUG tokio-runtime-worker pact_matching:      generators: Generators { categories: {} }
2023-09-14T17:07:03.586814Z TRACE tokio-runtime-worker pact_matching: plugin_data = {}
2023-09-14T17:07:03.587063Z TRACE tokio-runtime-worker matcher_is_defined{self=CoreMatchingContext { matchers: MatchingRuleCategory { name: PATH, rules: {} }, config: NoUnexpectedKeys, matching_spec: V3, plugin_configuration: {} } path=DocPath { path_tokens: [], expr: "" }}: pact_models::matchingrules: matcher_is_defined: for category path and path [] -> false
2023-09-14T17:07:03.587275Z DEBUG tokio-runtime-worker matches_with{self="/health" actual="/health" matcher=Equality cascaded=false}: pact_matching::matchers: String -> String: comparing '/health' to '/health' ==> true cascaded=false matcher=Equality
2023-09-14T17:07:03.587283Z DEBUG tokio-runtime-worker pact_matching: expected content type = '*/*', actual content type = '*/*'
2023-09-14T17:07:03.587359Z DEBUG tokio-runtime-worker pact_matching: content type header matcher = 'RuleList { rules: [], rule_logic: And, cascaded: false }'
2023-09-14T17:07:03.587377Z DEBUG tokio-runtime-worker pact_matching: --> Mismatches: []
2023-09-14T17:07:03.587453Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Test context = {"mockServer": Object {"port": Number(51055), "url": String("http://127.0.0.1:51055")}}
2023-09-14T17:07:03.587460Z TRACE tokio-runtime-worker pact_matching: generate_response response=HttpResponse { status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(b"{\"status\":\"up\"}", Some(ContentType { main_type: "application", sub_type: "json", attributes: {}, suffix: None }), None), matching_rules: MatchingRules { rules: {BODY: MatchingRuleCategory { name: BODY, rules: {DocPath { path_tokens: [Root, Field("status")], expr: "$.status" }: RuleList { rules: [Type], rule_logic: And, cascaded: false }} }} }, generators: Generators { categories: {} } } mode=Consumer context={"mockServer": Object {"port": Number(51055), "url": String("http://127.0.0.1:51055")}}
2023-09-14T17:07:03.587493Z  INFO tokio-runtime-worker pact_mock_server::hyper_server: Request matched, sending response
2023-09-14T17:07:03.587496Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server:
          ----------------------------------------------------------------------------------------
           status: 200
           headers: Some({"Content-Type": ["application/json"]})
           body: Present(15 bytes, application/json) '{"status":"up"}'
          ----------------------------------------------------------------------------------------

2023-09-14T17:07:03.587508Z TRACE tokio-runtime-worker encode_headers: hyper::proto::h1::role: Server::encode status=200, body=Some(Known(15)), req_method=Some(GET)
2023-09-14T17:07:03.587515Z TRACE tokio-runtime-worker hyper::proto::h1::io: buffer.queue self.len=352 buf.len=15
2023-09-14T17:07:03.587548Z DEBUG tokio-runtime-worker hyper::proto::h1::io: flushed 367 bytes
2023-09-14T17:07:03.587561Z TRACE tokio-runtime-worker hyper::proto::h1::conn: State::close()
2023-09-14T17:07:03.587563Z TRACE tokio-runtime-worker hyper::proto::h1::conn: flushed({role=server}): State { reading: Closed, writing: Closed, keep_alive: Disabled }
2023-09-14T17:07:03.587587Z TRACE tokio-runtime-worker hyper::proto::h1::conn: shut down IO complete
2023-09-14T17:07:03.589863Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: pact_ffi::mock_server::handles::pactffi_pact_handle_write_file FFI function invoked
2023-09-14T17:07:03.589875Z TRACE ThreadId(01) pact_ffi::mock_server::handles: @param pact = PactHandle { pact_ref: 1 }
2023-09-14T17:07:03.589891Z TRACE ThreadId(01) pact_ffi::mock_server::handles: @param directory = 0x16d02cc88
2023-09-14T17:07:03.589892Z TRACE ThreadId(01) pact_ffi::mock_server::handles: @param overwrite = false
2023-09-14T17:07:03.590164Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact - ref = 1, keys = [1]
2023-09-14T17:07:03.590171Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact before - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [SynchronousHttp { id: None, key: None, description: "A request for API health", provider_states: [ProviderState { name: "Server is healthy", params: {} }], request: HttpRequest { method: "GET", path: "/health", query: None, headers: None, body: Missing, matching_rules: MatchingRules { rules: {PATH: MatchingRuleCategory { name: PATH, rules: {} }} }, generators: Generators { categories: {} } }, response: HttpResponse { status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(b"{\"status\":\"up\"}", Some(ContentType { main_type: "application", sub_type: "json", attributes: {}, suffix: None }), None), matching_rules: MatchingRules { rules: {BODY: MatchingRuleCategory { name: BODY, rules: {DocPath { path_tokens: [Root, Field("status")], expr: "$.status" }: RuleList { rules: [Type], rule_logic: And, cascaded: false }} }} }, generators: Generators { categories: {} } }, comments: {}, pending: false, plugin_config: {}, interaction_markup: InteractionMarkup { markup: "", markup_type: "" }, transport: None }], metadata: {"pact-js": Object {"version": String("12.1.0")}, "pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: true, specification_version: V3 } }
2023-09-14T17:07:03.590245Z DEBUG ThreadId(01) pact_models::pact: Merging pact with file "./pacts/consumer-js-v3-provider-js-v3.json"
2023-09-14T17:07:03.594590Z TRACE ThreadId(01) pact_models::file_utils: Attempt 0 of 3 to get a shared lock on '"./pacts/consumer-js-v3-provider-js-v3.json"'
2023-09-14T17:07:03.594753Z TRACE ThreadId(01) pact_models::file_utils: Got shared file lock
2023-09-14T17:07:03.594764Z TRACE ThreadId(01) pact_models::file_utils: Releasing shared file lock
2023-09-14T17:07:03.595007Z TRACE ThreadId(01) pact_models::pact: load_pact_from_json: found spec version V3 in metadata
2023-09-14T17:07:03.595011Z TRACE ThreadId(01) pact_models::pact: load_pact_from_json: loading JSON as a request/response pact
2023-09-14T17:07:03.595055Z TRACE ThreadId(01) pact_models::matchingrules: rule_type: type, attributes: {"match":"type"}
2023-09-14T17:07:03.595065Z  WARN ThreadId(01) pact_models::pact: Note: Existing pact is an older specification version (V3), and will be upgraded
2023-09-14T17:07:03.595247Z TRACE ThreadId(01) pact_models::file_utils: Attempt 0 of 3 to get an exclusive lock on '"./pacts/consumer-js-v3-provider-js-v3.json"'
2023-09-14T17:07:03.595255Z TRACE ThreadId(01) pact_models::file_utils: Got exclusive file lock
2023-09-14T17:07:03.595850Z TRACE ThreadId(01) pact_models::file_utils: Releasing exclusive file lock
2023-09-14T17:07:03.595907Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact after - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [SynchronousHttp { id: None, key: None, description: "A request for API health", provider_states: [ProviderState { name: "Server is healthy", params: {} }], request: HttpRequest { method: "GET", path: "/health", query: None, headers: None, body: Missing, matching_rules: MatchingRules { rules: {PATH: MatchingRuleCategory { name: PATH, rules: {} }} }, generators: Generators { categories: {} } }, response: HttpResponse { status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(b"{\"status\":\"up\"}", Some(ContentType { main_type: "application", sub_type: "json", attributes: {}, suffix: None }), None), matching_rules: MatchingRules { rules: {BODY: MatchingRuleCategory { name: BODY, rules: {DocPath { path_tokens: [Root, Field("status")], expr: "$.status" }: RuleList { rules: [Type], rule_logic: And, cascaded: false }} }} }, generators: Generators { categories: {} } }, comments: {}, pending: false, plugin_config: {}, interaction_markup: InteractionMarkup { markup: "", markup_type: "" }, transport: None }], metadata: {"pact-js": Object {"version": String("12.1.0")}, "pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: true, specification_version: V3 } }
2023-09-14T17:07:03.595938Z TRACE ThreadId(01) pact_ffi::mock_server::handles: pactffi_pact_handle_write_file FFI function completed output=0
2023-09-14T17:07:03.596041Z DEBUG ThreadId(01) pact_matching::metrics: Could not get the tokio runtime, will not send metrics - there is no reactor running, must be called from the context of a Tokio 1.x runtime
2023-09-14T17:07:03.596046Z DEBUG ThreadId(01) pact_mock_server::server_manager: Shutting down mock server with ID 976dd218-3446-461b-b748-179a0cbb2c86 - MockServerMetrics { requests: 1, requests_by_path: {"/health": 1} }
2023-09-14T17:07:03.596081Z DEBUG ThreadId(01) pact_mock_server::mock_server: Mock server 976dd218-3446-461b-b748-179a0cbb2c86 shutdown - MockServerMetrics { requests: 1, requests_by_path: {"/health": 1} }
2023-09-14T17:07:03.596089Z DEBUG tokio-runtime-worker hyper::server::shutdown: signal received, starting graceful shutdown
[18:07:03.596] TRACE (10914): [email protected]: Ffi has already been initialised, no need to repeat it
2023-09-14T17:07:03.597253Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact - ref = 2, keys = [1, 2]
2023-09-14T17:07:03.597258Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact before - ref = 2, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [], metadata: {"pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
2023-09-14T17:07:03.597262Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact after - ref = 2, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [], metadata: {"pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
2023-09-14T17:07:03.597272Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact - ref = 2, keys = [1, 2]
2023-09-14T17:07:03.597274Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact before - ref = 2, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider { name: "provider-js-v3" }, interactions: [], metadata: {"pactRust": Object {"ffi": String("0.4.7")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
 PASS  ./test.js:03.597278Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact after - ref = 2, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "consumer-js-v3" }, provider: Provider
  test with pact
    ✓ should setup a test with pact (32 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.795 s
Ran all test suites.
{
"devDependencies": {
"@pact-foundation/pact": "^12.1.0",
"axios": "^1.5.0",
"jest": "^29.7.0"
},
"scripts": {
"test": "jest"
}
}
const axios = require("axios");
const defaultBaseUrl = "http://your-api.example.com";
const api = (baseUrl = defaultBaseUrl) => ({
getHealth: () =>
axios.get(baseUrl + "/health").then((response) => response.data.status),
/* other endpoints here */
});
const { PactV3, MatchersV3 } = require("@pact-foundation/pact");
const provider = new PactV3({
consumer: "consumer-js-v3",
provider: "provider-js-v3",
logLevel: "trace",
logFile: "./foo.txt",
});
const {
eachLike,
atLeastLike,
integer,
datetime,
boolean,
string,
regex,
like,
eachKeyLike,
} = MatchersV3;
describe("test with pact", () => {
it("should setup a test with pact", () => {
provider
.given("Server is healthy")
.uponReceiving("A request for API health")
.withRequest({
method: "GET",
path: "/health",
})
.willRespondWith({
status: 200,
body: { status: like("up") },
});
return provider.executeTest((mockserver) => {
const client = api(mockserver.url);
return client.getHealth().then((health) => {
expect(health).toEqual("up");
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment